summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2019-05-16 11:04:33 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-05-16 11:04:33 -0700
commitae49e76fba99cb8076047c9c679f4e058a9f49ce (patch)
treec827008f41e897ffd34639bc8a55d916bb43608d
parent89d58c5d8e8010bfa5f0f38aceb3ab6de4df8633 (diff)
parentba6afe1adbb6afed25bd78e88b541326d969dba2 (diff)
Fix NPE from null cellular subscription displayName
am: ba6afe1adb Change-Id: I1f65110c15789f76b8cd7171a7b2f1cf8a05d7f4
-rw-r--r--service/java/com/android/server/wifi/CarrierNetworkConfig.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java23
2 files changed, 28 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/CarrierNetworkConfig.java b/service/java/com/android/server/wifi/CarrierNetworkConfig.java
index 6e754231f..20aac5bc1 100644
--- a/service/java/com/android/server/wifi/CarrierNetworkConfig.java
+++ b/service/java/com/android/server/wifi/CarrierNetworkConfig.java
@@ -249,9 +249,11 @@ public class CarrierNetworkConfig {
// Process the carrier config for each active subscription.
for (SubscriptionInfo subInfo : subInfoList) {
- processNetworkConfig(
- carrierConfigManager.getConfigForSubId(subInfo.getSubscriptionId()),
- subInfo.getDisplayName().toString());
+ CharSequence displayNameCs = subInfo.getDisplayName();
+ String displayNameStr = displayNameCs == null ? "" : displayNameCs.toString();
+ PersistableBundle bundle = carrierConfigManager.getConfigForSubId(
+ subInfo.getSubscriptionId());
+ processNetworkConfig(bundle, displayNameStr);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java
index 082944e5d..9ff5be97d 100644
--- a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java
@@ -46,6 +46,7 @@ import org.mockito.MockitoAnnotations;
import java.security.PublicKey;
import java.util.Arrays;
+import java.util.Collections;
/**
* Unit tests for {@link com.android.server.wifi.CarrierNetworkConfig}.
@@ -150,6 +151,28 @@ public class CarrierNetworkConfigTest {
}
/**
+ * Tests that SubscriptionInfo.getDisplayName() returning null does not throw a
+ * NullPointerException in CarrierNetworkConfig.
+ */
+ @Test
+ public void getExistingCarrierNetworkInfo_nullDisplayName_shouldNotThrowNpe() {
+ when(mCarrierConfigManager.getConfigForSubId(TEST_SUBSCRIPTION_ID))
+ .thenReturn(generateTestConfig(TEST_SSID, TEST_STANDARD_EAP_TYPE,
+ CarrierNetworkConfig.ENCODING_METHOD_RFC_2045,
+ CarrierNetworkConfig.IDENTITY_SEQUENCE_IMSI_V1_0));
+ SubscriptionInfo testSubscriptionInfoNullDisplayName = new SubscriptionInfo(
+ TEST_SUBSCRIPTION_ID, null, 0, null, null, 0, 0,
+ null, 0, null, "0", "0", null, false, null, null);
+ when(mSubscriptionManager.getActiveSubscriptionInfoList())
+ .thenReturn(Collections.singletonList(testSubscriptionInfoNullDisplayName));
+ mCarrierNetworkConfig = new CarrierNetworkConfig(mContext, mLooper.getLooper(),
+ mFrameworkFacade);
+ reset(mCarrierConfigManager);
+
+ assertEquals("", mCarrierNetworkConfig.getCarrierName(TEST_SSID));
+ }
+
+ /**
* Verify that {@link CarrierNetworkConfig#isCarrierEncryptionInfoAvailable} will return true
* when the carrier IMSI encryption info is available.
*