From a639d142001ce8c8398193e0398781d51168a691 Mon Sep 17 00:00:00 2001 From: Patrick Baumann Date: Wed, 2 May 2018 15:00:59 -0700 Subject: [PATCH] Resets system flags when updating PackageSettings In the case that we're updating a system app, we will in-place update the PackageSetting object. This works for most fields but breaks when updating flag fields as we're executing a binary or on the existing flags, thus not unsetting bits when we should be. This change resets all system-related flags before setting the new flag values. Test: manual - move app from priv-app to app, install update, verify that app does not receive priv flag Fixes: 75993951 Fixes: 78265024 Change-Id: I3c88a3583ddb85c4b6b0e3b4d7b6d1d0db93ac17 --- services/core/java/com/android/server/pm/Settings.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java index 898ecf3c26d2b..f8bf9c45e8b1a 100644 --- a/services/core/java/com/android/server/pm/Settings.java +++ b/services/core/java/com/android/server/pm/Settings.java @@ -844,7 +844,12 @@ public final class Settings { } // If what we are scanning is a system (and possibly privileged) package, // then make it so, regardless of whether it was previously installed only - // in the data partition. + // in the data partition. Reset first. + pkgSetting.pkgFlags &= ~ApplicationInfo.FLAG_SYSTEM; + pkgSetting.pkgPrivateFlags &= ~(ApplicationInfo.PRIVATE_FLAG_PRIVILEGED + | ApplicationInfo.PRIVATE_FLAG_OEM + | ApplicationInfo.PRIVATE_FLAG_VENDOR + | ApplicationInfo.PRIVATE_FLAG_PRODUCT); pkgSetting.pkgFlags |= pkgFlags & ApplicationInfo.FLAG_SYSTEM; pkgSetting.pkgPrivateFlags |= pkgPrivateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;