summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-05-07 08:35:25 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-05-07 08:35:25 +0000
commit431a8ab0ac838e332d43d4264b58d97cae3b7732 (patch)
treea650d2a6525fc4beb7a8927c8d58984c48ee8870
parent6bb85e2c28cbcec84f343e963e1a6397c669ac32 (diff)
parent62667d5e507fc676cfbe7df34bb78b7e25948d37 (diff)
Merge "Show App name when carrier id not set" into rvc-dev
-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 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();