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

Commit 9dc0556f authored by Oliver Scott's avatar Oliver Scott Committed by Michael Bestas
Browse files

fixup! Implement backup/restore for network policy

Test:
1. Block an app's (e.g. Chromium) wifi and mobile data through the firewall
2. Backup to internal storage on user 0
3. Create work profile
4. Copy .SeedVaultAndroid to the work profile (through its Files app)
5. Restore backup from work profile setup wizard
6. Verify the app's wifi and mobile data is still blocked
Issue: calyxos#2586
Change-Id: I44da196614a749c2c8b0113cade92215e88fed4a
parent 7dba506a
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -3003,10 +3003,15 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                    }
                } else if (TAG_UID_POLICY.equals(tag)) {
                    int uid = readUidAttribute(in, forRestore, userId);
                    final int oldPolicy = mUidPolicy.get(uid, POLICY_NONE);
                    final int policy = readIntAttribute(in, ATTR_POLICY);

                    if (UserHandle.isApp(uid)) {
                        if (forRestore) {
                            setUidPolicyUncheckedUL(uid, oldPolicy, policy, true);
                        } else {
                            setUidPolicyUncheckedUL(uid, policy, false);
                        }
                    } else {
                        Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
                    }
@@ -3017,8 +3022,13 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                    // TODO: set for other users during upgrade
                    // app policy is deprecated so this is only used in pre system user split.
                    final int uid = UserHandle.getUid(UserHandle.USER_SYSTEM, appId);
                    final int oldPolicy = mUidPolicy.get(uid, POLICY_NONE);
                    if (UserHandle.isApp(uid)) {
                        if (forRestore) {
                            setUidPolicyUncheckedUL(uid, oldPolicy, policy, true);
                        } else {
                            setUidPolicyUncheckedUL(uid, policy, false);
                        }
                    } else {
                        Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
                    }
@@ -3052,7 +3062,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                final int newPolicy = policy | POLICY_ALLOW_METERED_BACKGROUND;
                if (LOGV)
                    Log.v(TAG, "new policy for " + uid + ": " + uidPoliciesToString(newPolicy));
                if (forRestore) {
                    setUidPolicyUncheckedUL(uid, policy, newPolicy, true);
                } else {
                    setUidPolicyUncheckedUL(uid, newPolicy, false);
                }
            } else {
                Slog.w(TAG, "unable to update policy on UID " + uid);
            }