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

Commit a52e10d6 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "NetworkPolicy: Validate policy templates before updating"

parents 7b6b5942 a4c60984
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -1434,6 +1434,12 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
    public void setNetworkPolicies(NetworkPolicy[] policies) {
        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);

        // Before clear and refresh mNetworkPolicy, we need to ensure all the
        // policies to be added are validated, otherwise this service will throw
        // IllegalArgumentException and cause system crash when updating network
        // template after receiving ACTION_NETWORK_STATS_UPDATED.
        validatePoliciesToSet(policies);

        maybeRefreshTrustedTime();
        synchronized (mRulesLock) {
            mNetworkPolicy.clear();
@@ -1448,6 +1454,27 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        }
    }

    /**
     * ensure the policies have valid template
     *
     * @param policies
     */
    private void validatePoliciesToSet(NetworkPolicy[] policies) {
        for (NetworkPolicy policy : policies) {
            switch (policy.template.getMatchRule()) {
                case MATCH_MOBILE_3G_LOWER:
                case MATCH_MOBILE_4G:
                case MATCH_MOBILE_ALL:
                case MATCH_WIFI:
                case MATCH_ETHERNET:
                    break;
                default:
                    throw new IllegalArgumentException("unexpected template "
                            + policy.template.getMatchRule());
            }
        }
    }

    private void addNetworkPolicyLocked(NetworkPolicy policy) {
        mNetworkPolicy.put(policy.template, policy);