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

Commit 9d57437a authored by Chirayu Desai's avatar Chirayu Desai Committed by Michael Bestas
Browse files

restricted-networking: Only add newly installed apps to the allowlist, not upgrades

* Upgrading apps still sends PACKAGE_ADDED, since it's sent for
  "new package installs", which technically an upgrade still is.
* Check EXTRA_REPLACING to see if it's a new app.
* Avoids unconditionally turning on networking on app upgrade

Change-Id: Ie7a4090101d47c7033b7f41792e943129dba0700
parent cd997ae0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static android.content.Intent.ACTION_PACKAGE_ADDED;
import static android.content.Intent.ACTION_UID_REMOVED;
import static android.content.Intent.ACTION_USER_ADDED;
import static android.content.Intent.ACTION_USER_REMOVED;
import static android.content.Intent.EXTRA_REPLACING;
import static android.content.Intent.EXTRA_UID;
import static android.content.pm.PackageManager.MATCH_ANY_USER;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
@@ -1155,6 +1156,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
            final int uid = intent.getIntExtra(EXTRA_UID, -1);
            if (uid == -1) return;

            if (intent.getBooleanExtra(EXTRA_REPLACING, false)) {
                if (LOGV) Slog.v(TAG, "ACTION_PACKAGE_ADDED Not new app, skip it uid=" + uid);
                return;
            }

            if (ACTION_PACKAGE_ADDED.equals(action)) {
                // update rules for UID, since it might be subject to
                // global background data policy