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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user