diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-05-07 09:03:20 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-07 09:03:20 +0000 |
commit | 004aa6c2224f17dd800b6ef2e52078fbe4a1a545 (patch) | |
tree | 83be7a7d11e1f62bdd210bebc7a77868cc57e7f8 | |
parent | a6a54aa2d5581191156ba324139ab7a80834d3c0 (diff) | |
parent | 04bc8e6cc67e8e10d757236be77b6608b66dd72a (diff) |
Merge "Show App name when carrier id not set" into rvc-dev am: 431a8ab0ac am: 04bc8e6cc6
Change-Id: I4bdca6a73c23db6175901f442b9ac17c4891446a
-rw-r--r-- | libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java | 16 | ||||
-rw-r--r-- | libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/UtilsTest.java | 14 |
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 934cdf146..ced1d81bd 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java @@ -618,6 +618,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; @@ -641,9 +644,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( @@ -657,6 +659,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(); @@ -691,8 +694,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(); |