summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java16
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/UtilsTest.java14
2 files changed, 26 insertions, 4 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java
index 78617ba5a..ee115cecc 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java
@@ -616,6 +616,9 @@ class Utils {
* Get the SIM carrier name for target subscription Id.
*/
static @Nullable String getCarrierNameForSubId(@NonNull Context context, int subId) {
+ if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ return null;
+ }
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager == null) return null;
@@ -639,9 +642,8 @@ class Utils {
* Get the best match subscription Id for target WifiConfiguration.
*/
static int getSubIdForConfig(@NonNull Context context, @NonNull WifiConfiguration config) {
- int dataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
if (config.carrierId == TelephonyManager.UNKNOWN_CARRIER_ID) {
- return dataSubId;
+ return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
SubscriptionManager subscriptionManager =
(SubscriptionManager) context.getSystemService(
@@ -655,6 +657,7 @@ class Utils {
}
int matchSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ int dataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
for (SubscriptionInfo subInfo : subInfoList) {
if (subInfo.getCarrierId() == config.carrierId) {
matchSubId = subInfo.getSubscriptionId();
@@ -689,8 +692,13 @@ class Utils {
if (context == null || wifiConfig == null || !isSimCredential(wifiConfig)) {
return "";
}
-
- int subId = getSubIdForConfig(context, wifiConfig);
+ int subId;
+ if (wifiConfig.carrierId == TelephonyManager.UNKNOWN_CARRIER_ID) {
+ // Config without carrierId use default data subscription.
+ subId = SubscriptionManager.getDefaultSubscriptionId();
+ } else {
+ subId = getSubIdForConfig(context, wifiConfig);
+ }
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
|| isImsiPrivacyProtectionProvided(context, subId)) {
return "";
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/UtilsTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/UtilsTest.java
index aa0df1092..de4b6903c 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/UtilsTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/UtilsTest.java
@@ -344,6 +344,13 @@ public class UtilsTest {
}
@Test
+ public void testGetCarrierNameWithInvalidSubId() {
+ when(mSpecifiedTm.getSimCarrierIdName()).thenReturn(TEST_CARRIER_NAME);
+ assertNull(getCarrierNameForSubId(mMockContext,
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID));
+ }
+
+ @Test
public void testCheckRequireImsiPrivacyProtectionWithNoCarrierConfig() {
assertFalse(isImsiPrivacyProtectionProvided(mMockContext, TEST_SUB_ID));
}
@@ -379,6 +386,13 @@ public class UtilsTest {
}
@Test
+ public void testGetSubIdForWifiConfigurationWithoutCarrierId() {
+ WifiConfiguration config = new WifiConfiguration();
+ assertEquals(SubscriptionManager.INVALID_SUBSCRIPTION_ID,
+ getSubIdForConfig(mMockContext, config));
+ }
+
+ @Test
public void testGetImsiProtectionDescription_isSimCredentialFalse_returnEmptyString() {
final WifiConfiguration wificonfig = new WifiConfiguration();