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

Commit 20b4d846 authored by Annie Meng's avatar Annie Meng
Browse files

Fix NPE in restoring network policies

When backing up network policies, we write null for policies that are
null or are inferred. When restoring, this sends null policies to be set
which results in a NPE.

Bug: 79961560
Test: 1) atest NetworkPolicyManagerServiceTest
2) Manual: adb restore using backup set with null policies does not
crash

Change-Id: I450685e38acae0658ea984b86ca8b17ca27a71a6
parent 167b451d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2706,6 +2706,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
    private void normalizePoliciesNL(NetworkPolicy[] policies) {
        mNetworkPolicy.clear();
        for (NetworkPolicy policy : policies) {
            if (policy == null) {
                continue;
            }
            // When two normalized templates conflict, prefer the most
            // restrictive policy
            policy.template = NetworkTemplate.normalize(policy.template, mMergedSubscriberIds);
+14 −0
Original line number Diff line number Diff line
@@ -1628,6 +1628,20 @@ public class NetworkPolicyManagerServiceTest {
        }
    }

    /**
     * Test that policy set of {null, NetworkPolicy, null} does not crash and restores the valid
     * NetworkPolicy.
     */
    @Test
    public void testSetNetworkPolicies_withNullPolicies_doesNotThrow() {
        NetworkPolicy[] policies = new NetworkPolicy[3];
        policies[1] = buildDefaultFakeMobilePolicy();
        setNetworkPolicies(policies);

        assertNetworkPolicyEquals(DEFAULT_CYCLE_DAY, mDefaultWarningBytes, mDefaultLimitBytes,
                true);
    }

    private SubscriptionPlan buildMonthlyDataPlan(ZonedDateTime start, long limitBytes) {
        return SubscriptionPlan.Builder
                .createRecurringMonthly(start)