From 61542bed24a88bb7ce9f23614de1e59d43e0e429 Mon Sep 17 00:00:00 2001 From: Sumedh Sen Date: Thu, 19 Jan 2023 15:59:37 -0800 Subject: [PATCH] Allowlist for exempting packages from being marked as stopped by default An allowlist for packages that should not be scanned in a "stopped" state. Bug: 249514169 Test: Manual. Added a system package in the allowlist, performed factory reset and checked the stopped state of the same package after 1st boot. Change-Id: Iec603243d7c95d4cdf207f7873373a851698b243 --- data/etc/Android.bp | 6 +++ data/etc/initial-package-stopped-states.xml | 38 +++++++++++++++++++ .../java/com/android/server/SystemConfig.java | 22 +++++++++++ 3 files changed, 66 insertions(+) create mode 100644 data/etc/initial-package-stopped-states.xml diff --git a/data/etc/Android.bp b/data/etc/Android.bp index d0c3e5f6a91e1..f233c6eca13b9 100644 --- a/data/etc/Android.bp +++ b/data/etc/Android.bp @@ -35,6 +35,12 @@ prebuilt_etc { src: "preinstalled-packages-platform.xml", } +prebuilt_etc { + name: "initial-package-stopped-states.xml", + sub_dir: "sysconfig", + src: "initial-package-stopped-states.xml", +} + prebuilt_etc { name: "preinstalled-packages-platform-overlays.xml", product_specific: true, diff --git a/data/etc/initial-package-stopped-states.xml b/data/etc/initial-package-stopped-states.xml new file mode 100644 index 0000000000000..6bda2c0dbc260 --- /dev/null +++ b/data/etc/initial-package-stopped-states.xml @@ -0,0 +1,38 @@ + + + + + + diff --git a/services/core/java/com/android/server/SystemConfig.java b/services/core/java/com/android/server/SystemConfig.java index 4854c37933e34..4b7612791fe7d 100644 --- a/services/core/java/com/android/server/SystemConfig.java +++ b/services/core/java/com/android/server/SystemConfig.java @@ -333,6 +333,11 @@ public class SystemConfig { // Update ownership for system applications and the installers eligible to update them. private final ArrayMap mUpdateOwnersForSystemApps = new ArrayMap<>(); + // Set of package names that should not be marked as "stopped" during initial device boot + // or when adding a new user. A new package not contained in this set will be + // marked as stopped by the system + @NonNull private final Set mInitialNonStoppedSystemPackages = new ArraySet<>(); + /** * Map of system pre-defined, uniquely named actors; keys are namespace, * value maps actor name to package name. @@ -527,6 +532,10 @@ public class SystemConfig { ? null : mOverlayConfigSignaturePackage; } + public Set getInitialNonStoppedSystemPackages() { + return mInitialNonStoppedSystemPackages; + } + /** * Only use for testing. Do NOT use in production code. * @param readPermissions false to create an empty SystemConfig; true to read the permissions. @@ -1445,6 +1454,19 @@ public class SystemConfig { } XmlUtils.skipCurrentTag(parser); } break; + case "initial-package-state": { + String pkgName = parser.getAttributeValue(null, "package"); + String stopped = parser.getAttributeValue(null, "stopped"); + if (TextUtils.isEmpty(pkgName)) { + Slog.w(TAG, "<" + name + "> without package in " + permFile + + " at " + parser.getPositionDescription()); + } else if (TextUtils.isEmpty(stopped)) { + Slog.w(TAG, "<" + name + "> without stopped in " + permFile + + " at " + parser.getPositionDescription()); + } else if (!Boolean.parseBoolean(stopped)) { + mInitialNonStoppedSystemPackages.add(pkgName); + } + } default: { Slog.w(TAG, "Tag " + name + " is unknown in " + permFile + " at " + parser.getPositionDescription());