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

Commit b1e7776e authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

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
parent 7aa55b5c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -274,6 +274,11 @@ public abstract class PackageManagerInternal {

    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.
+4 −5
Original line number Diff line number Diff line
@@ -4227,7 +4227,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                            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 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        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 @@ public class ActivityManagerService extends IActivityManager.Stub
    // 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");
+1 −3
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.util.TimeUtils;
 */
public final class UidRecord {
    final int uid;
    final boolean persistent;
    int curProcState;
    int setProcState = ActivityManager.PROCESS_STATE_NONEXISTENT;
    long lastBackgroundTime;
@@ -52,9 +51,8 @@ public final class UidRecord {

    ChangeItem pendingChange;

    public UidRecord(int _uid, boolean _persist) {
    public UidRecord(int _uid) {
        uid = _uid;
        persistent = _persist;
        reset();
    }

+12 −0
Original line number Diff line number Diff line
@@ -22790,6 +22790,18 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
            }
        }
        @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>();