diff --git a/packages/SettingsLib/src/com/android/settingslib/net/DataUsageUtils.java b/packages/SettingsLib/src/com/android/settingslib/net/DataUsageUtils.java index 51e533abebd24..3f95a07cc7500 100644 --- a/packages/SettingsLib/src/com/android/settingslib/net/DataUsageUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/net/DataUsageUtils.java @@ -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); } }