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

Commit 95b6e959 authored by Michal Karpinski's avatar Michal Karpinski Committed by Android (Google) Code Review
Browse files

Merge "Extend temporary whitelisting mechanism to support trampolines from...

Merge "Extend temporary whitelisting mechanism to support trampolines from PendingIntents for broadcasts and services if PI.send() caller is in the foreground"
parents a33faabf cc88d7ed
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -379,6 +379,10 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
            if (userId == UserHandle.USER_CURRENT) {
                userId = controller.mUserController.getCurrentOrTargetUserId();
            }
            // temporarily allow receivers and services to open activities from background if the
            // PendingIntent.send() caller was foreground at the time of sendInner() call
            final boolean allowTrampoline = uid != callingUid
                    && controller.mAtmInternal.isUidForeground(callingUid);

            switch (key.type) {
                case ActivityManager.INTENT_SENDER_ACTIVITY:
@@ -419,7 +423,8 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
                                uid, finalIntent, resolvedType, finishedReceiver, code, null, null,
                                requiredPermission, options, (finishedReceiver != null),
                                false, userId,
                                mAllowBgActivityStartsForBroadcastSender.contains(whitelistToken));
                                mAllowBgActivityStartsForBroadcastSender.contains(whitelistToken)
                                || allowTrampoline);
                        if (sent == ActivityManager.BROADCAST_SUCCESS) {
                            sendFinish = false;
                        }
@@ -433,7 +438,8 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
                        controller.mAmInternal.startServiceInPackage(uid, finalIntent, resolvedType,
                                key.type == ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE,
                                key.packageName, userId,
                                mAllowBgActivityStartsForServiceSender.contains(whitelistToken));
                                mAllowBgActivityStartsForServiceSender.contains(whitelistToken)
                                || allowTrampoline);
                    } catch (RuntimeException e) {
                        Slog.w(TAG, "Unable to send startService intent", e);
                    } catch (TransactionTooLargeException e) {
+3 −8
Original line number Diff line number Diff line
@@ -924,14 +924,15 @@ class ActivityStarter {
            return false;
        }
        // don't abort if the callingUid is in the foreground or is a persistent system process
        final boolean isCallingUidForeground = isUidForeground(callingUid);
        final boolean isCallingUidForeground = mService.isUidForeground(callingUid);
        final boolean isCallingUidPersistentSystemProcess = isUidPersistentSystemProcess(
                callingUid);
        if (isCallingUidForeground || isCallingUidPersistentSystemProcess) {
            return false;
        }
        // take realCallingUid into consideration
        final boolean isRealCallingUidForeground = isUidForeground(realCallingUid);
        final boolean isRealCallingUidForeground = mService.isUidForeground(
                realCallingUid);
        final boolean isRealCallingUidPersistentSystemProcess = isUidPersistentSystemProcess(
                realCallingUid);
        if (realCallingUid != callingUid) {
@@ -976,12 +977,6 @@ class ActivityStarter {
        return true;
    }

    /** Returns true if uid has a visible window or its process is in a top state. */
    private boolean isUidForeground(int uid) {
        return (mService.getUidStateLocked(uid) == ActivityManager.PROCESS_STATE_TOP)
            || mService.mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid);
    }

    /** Returns true if uid is in a persistent state. */
    private boolean isUidPersistentSystemProcess(int uid) {
        return (mService.getUidStateLocked(uid) <= ActivityManager.PROCESS_STATE_PERSISTENT_UI);
+3 −0
Original line number Diff line number Diff line
@@ -489,4 +489,7 @@ public abstract class ActivityTaskManagerInternal {
     */
    public abstract ActivityManager.TaskSnapshot getTaskSnapshot(int taskId,
            boolean reducedResolution);

    /** Returns true if uid has a visible window or its process is in a top state. */
    public abstract boolean isUidForeground(int uid);
}
+12 −0
Original line number Diff line number Diff line
@@ -5632,6 +5632,11 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        return mActiveUids.get(uid, PROCESS_STATE_NONEXISTENT);
    }

    boolean isUidForeground(int uid) {
        return (getUidStateLocked(uid) == ActivityManager.PROCESS_STATE_TOP)
                || mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid);
    }

    /**
     * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on
     * the whitelist
@@ -7041,5 +7046,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                return ActivityTaskManagerService.this.getTaskSnapshot(taskId, reducedResolution);
            }
        }

        @Override
        public boolean isUidForeground(int uid) {
            synchronized (mGlobalLock) {
                return ActivityTaskManagerService.this.isUidForeground(uid);
            }
        }
    }
}