Fix issue #35309312: Background start not allowed: service...
...Intent { flg=0x100 cmp=com.android.systemui/.SystemUIService }
to com.android.systemui/.SystemUIService from pid=28245 uid=1000 pkg=android
Rework the persistent app check to just directly look at the package
manager (but as efficiently as possible). My idea for trying to keep
this in the UidRecord was stupid. :p
Test: manually tested it boots
Change-Id: I5a88717a27fa3529048d37a853518a3ec04055db
diff --git a/core/java/android/content/pm/PackageManagerInternal.java b/core/java/android/content/pm/PackageManagerInternal.java
index e4e0a19..7d59bd6 100644
--- a/core/java/android/content/pm/PackageManagerInternal.java
+++ b/core/java/android/content/pm/PackageManagerInternal.java
@@ -275,6 +275,11 @@
public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy);
/**
+ * Return true if the given package is a persistent app process.
+ */
+ public abstract boolean isPackagePersistent(String packageName);
+
+ /**
* Get all overlay packages for a user.
* @param userId The user for which to get the overlays.
* @return A list of overlay packages. An empty list is returned if the
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index a4a4e62..79dc103 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -4227,7 +4227,7 @@
validateUid = mValidateUids.get(item.uid);
if (validateUid == null && change != UidRecord.CHANGE_GONE
&& change != UidRecord.CHANGE_GONE_IDLE) {
- validateUid = new UidRecord(item.uid, false);
+ validateUid = new UidRecord(item.uid);
mValidateUids.put(item.uid, validateUid);
}
}
@@ -6316,7 +6316,7 @@
}
UidRecord uidRec = mActiveUids.get(proc.uid);
if (uidRec == null) {
- uidRec = new UidRecord(proc.uid, proc.persistent);
+ uidRec = new UidRecord(proc.uid);
// This is the first appearance of the uid, report it now!
if (DEBUG_UID_OBSERVERS) Slog.i(TAG_UID_OBSERVERS,
"Creating new process uid: " + uidRec);
@@ -8115,9 +8115,8 @@
// some other background operations are not. If we're doing a check
// of service-launch policy, allow those callers to proceed unrestricted.
int appServicesRestrictedInBackgroundLocked(int uid, String packageName, int packageTargetSdk) {
- // Persistent app? NB: expects that persistent uids are always active.
- final UidRecord appIdRec = mActiveUids.get(UserHandle.getAppId(uid));
- if (appIdRec != null && appIdRec.persistent) {
+ // Persistent app?
+ if (mPackageManagerInt.isPackagePersistent(packageName)) {
if (DEBUG_BACKGROUND_CHECK) {
Slog.i(TAG, "App " + uid + "/" + packageName
+ " is persistent; not restricted in background");
diff --git a/services/core/java/com/android/server/am/UidRecord.java b/services/core/java/com/android/server/am/UidRecord.java
index 64e3417..302f628 100644
--- a/services/core/java/com/android/server/am/UidRecord.java
+++ b/services/core/java/com/android/server/am/UidRecord.java
@@ -26,7 +26,6 @@
*/
public final class UidRecord {
final int uid;
- final boolean persistent;
int curProcState;
int setProcState = ActivityManager.PROCESS_STATE_NONEXISTENT;
long lastBackgroundTime;
@@ -52,9 +51,8 @@
ChangeItem pendingChange;
- public UidRecord(int _uid, boolean _persist) {
+ public UidRecord(int _uid) {
uid = _uid;
- persistent = _persist;
reset();
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 8345491..ebd0b34 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -22791,6 +22791,18 @@
}
@Override
+ public boolean isPackagePersistent(String packageName) {
+ synchronized (mPackages) {
+ PackageParser.Package pkg = mPackages.get(packageName);
+ return pkg != null
+ ? ((pkg.applicationInfo.flags&(ApplicationInfo.FLAG_SYSTEM
+ | ApplicationInfo.FLAG_PERSISTENT)) ==
+ (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_PERSISTENT))
+ : false;
+ }
+ }
+
+ @Override
public List<PackageInfo> getOverlayPackages(int userId) {
final ArrayList<PackageInfo> overlayPackages = new ArrayList<PackageInfo>();
synchronized (mPackages) {