Merge "Usage Settings: Fix NPE when subscriberId is Null." into sc-dev am: a9818b3081

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14842882

Change-Id: Ia2818c9a3f4fbb7f8d6e919ed8f5c15b26106877
This commit is contained in:
Les Lee
2021-06-07 02:51:21 +00:00
committed by Automerger Merge Worker

View File

@@ -73,7 +73,10 @@ public class DataUsageUtils {
private static NetworkTemplate getMobileTemplateForSubId(
TelephonyManager telephonyManager, int subId) {
return NetworkTemplate.buildTemplateCarrierMetered(
telephonyManager.getSubscriberId(subId));
// The null subscriberId means that no any mobile/carrier network will be matched.
// Using old API: buildTemplateMobileAll for the null subscriberId to avoid NPE.
String subscriberId = telephonyManager.getSubscriberId(subId);
return subscriberId != null ? NetworkTemplate.buildTemplateCarrierMetered(subscriberId)
: NetworkTemplate.buildTemplateMobileAll(subscriberId);
}
}