From 62667d5e507fc676cfbe7df34bb78b7e25948d37 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Tue, 5 May 2020 12:28:48 -0700 Subject: Show App name when carrier id not set Cherry Pick ag/11398998 and ag/11403417 Bug: 155697387 Test: atest WifiTrackerLibTests Change-Id: I25a18a6a537df2de9e002a6fcdb09ba652561882 --- .../src/com/android/wifitrackerlib/Utils.java | 16 ++++++++++++---- .../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 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 @@ -343,6 +343,13 @@ public class UtilsTest { assertEquals(TEST_CARRIER_NAME, getCarrierNameForSubId(mMockContext, TEST_CARRIER_ID)); } + @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)); @@ -378,6 +385,13 @@ public class UtilsTest { assertEquals(TEST_SUB_ID, getSubIdForConfig(mMockContext, config)); } + @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(); -- cgit v1.2.3