Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 787685b2 authored by Les Lee's avatar Les Lee Committed by Android (Google) Code Review
Browse files

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

parents b734aa3f 204f0215
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -111,9 +111,13 @@ public class SettingsDumpService extends Service {
            for (SubscriptionInfo info : manager.getAvailableSubscriptionInfoList()) {
                telephonyManager = telephonyManager
                        .createForSubscriptionId(info.getSubscriptionId());
                NetworkTemplate carrier = NetworkTemplate.buildTemplateCarrierMetered(
                        telephonyManager.getSubscriberId());
                final JSONObject usage = dumpDataUsage(carrier, controller);
                String subscriberId = telephonyManager.getSubscriberId();
                // The null subscriberId means that no any mobile/carrier network will be matched.
                // Using old API: buildTemplateMobileAll for the null subscriberId to avoid NPE.
                NetworkTemplate template = subscriberId != null
                        ? NetworkTemplate.buildTemplateCarrierMetered(subscriberId)
                        : NetworkTemplate.buildTemplateMobileAll(subscriberId);
                final JSONObject usage = dumpDataUsage(template, controller);
                usage.put("subId", info.getSubscriptionId());
                array.put(usage);
            }
+5 −2
Original line number Diff line number Diff line
@@ -73,7 +73,10 @@ public class DataUsageLib {

    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);
    }
}