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

Commit 60353798 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue #17507017: took ~3 seconds to move an app to the foreground" into lmp-dev

parents 1a526f58 95465200
Loading
Loading
Loading
Loading
+25 −20
Original line number Original line Diff line number Diff line
@@ -3360,7 +3360,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    intent.setComponent(new ComponentName(
                    intent.setComponent(new ComponentName(
                            ri.activityInfo.packageName, ri.activityInfo.name));
                            ri.activityInfo.packageName, ri.activityInfo.name));
                    mStackSupervisor.startActivityLocked(null, intent, null, ri.activityInfo,
                    mStackSupervisor.startActivityLocked(null, intent, null, ri.activityInfo,
                            null, null, null, null, 0, 0, 0, null, 0, null, false, null, null,
                            null, null, null, null, 0, 0, 0, null, 0, 0, 0, null, false, null, null,
                            null);
                            null);
                }
                }
            }
            }
@@ -3759,8 +3759,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            final long origId = Binder.clearCallingIdentity();
            final long origId = Binder.clearCallingIdentity();
            int res = mStackSupervisor.startActivityLocked(r.app.thread, intent,
            int res = mStackSupervisor.startActivityLocked(r.app.thread, intent,
                    r.resolvedType, aInfo, null, null, resultTo != null ? resultTo.appToken : null,
                    r.resolvedType, aInfo, null, null, resultTo != null ? resultTo.appToken : null,
                    resultWho, requestCode, -1, r.launchedFromUid, r.launchedFromPackage, 0,
                    resultWho, requestCode, -1, r.launchedFromUid, r.launchedFromPackage,
                    options, false, null, null, null);
                    -1, r.launchedFromUid, 0, options, false, null, null, null);
            Binder.restoreCallingIdentity(origId);
            Binder.restoreCallingIdentity(origId);
            r.finishing = wasFinishing;
            r.finishing = wasFinishing;
@@ -8482,7 +8482,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    void moveTaskToFrontLocked(int taskId, int flags, Bundle options) {
    void moveTaskToFrontLocked(int taskId, int flags, Bundle options) {
        if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
        if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
                Binder.getCallingUid(), "Task to front")) {
                Binder.getCallingUid(), -1, -1, "Task to front")) {
            ActivityOptions.abort(options);
            ActivityOptions.abort(options);
            return;
            return;
        }
        }
@@ -8524,7 +8524,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                ActivityStack stack = tr.stack;
                ActivityStack stack = tr.stack;
                if (stack.mResumedActivity != null && stack.mResumedActivity.task == tr) {
                if (stack.mResumedActivity != null && stack.mResumedActivity.task == tr) {
                    if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
                    if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
                            Binder.getCallingUid(), "Task to back")) {
                            Binder.getCallingUid(), -1, -1, "Task to back")) {
                        return;
                        return;
                    }
                    }
                }
                }
@@ -8576,7 +8576,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        synchronized(this) {
        synchronized(this) {
            if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
            if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
                    Binder.getCallingUid(), "Task backwards")) {
                    Binder.getCallingUid(), -1, -1, "Task backwards")) {
                return;
                return;
            }
            }
            final long origId = Binder.clearCallingIdentity();
            final long origId = Binder.clearCallingIdentity();
@@ -10120,20 +10120,31 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
        }
    }
    }
    
    
    boolean checkAppSwitchAllowedLocked(int callingPid, int callingUid,
    boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid,
            String name) {
            int callingPid, int callingUid, String name) {
        if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) {
        if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) {
            return true;
            return true;
        }
        }
        final int perm = checkComponentPermission(
        int perm = checkComponentPermission(
                android.Manifest.permission.STOP_APP_SWITCHES, sourcePid,
                sourceUid, -1, true);
        if (perm == PackageManager.PERMISSION_GRANTED) {
            return true;
        }
        // If the actual IPC caller is different from the logical source, then
        // also see if they are allowed to control app switches.
        if (callingUid != -1 && callingUid != sourceUid) {
            perm = checkComponentPermission(
                    android.Manifest.permission.STOP_APP_SWITCHES, callingPid,
                    android.Manifest.permission.STOP_APP_SWITCHES, callingPid,
                    callingUid, -1, true);
                    callingUid, -1, true);
            if (perm == PackageManager.PERMISSION_GRANTED) {
            if (perm == PackageManager.PERMISSION_GRANTED) {
                return true;
                return true;
            }
            }
        }
        Slog.w(TAG, name + " request from " + callingUid + " stopped");
        Slog.w(TAG, name + " request from " + sourceUid + " stopped");
        return false;
        return false;
    }
    }
    
    
@@ -18944,13 +18955,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    throw new IllegalArgumentException("Unable to find task ID " + mTaskId);
                    throw new IllegalArgumentException("Unable to find task ID " + mTaskId);
                }
                }
                if (tr.getRootActivity() != null) {
                if (tr.getRootActivity() != null) {
                    long origId = Binder.clearCallingIdentity();
                    try {
                    moveTaskToFrontLocked(tr.taskId, 0, null);
                    moveTaskToFrontLocked(tr.taskId, 0, null);
                        return;
                    } finally {
                        Binder.restoreCallingIdentity(origId);
                    }
                }
                }
            }
            }
+1 −1
Original line number Original line Diff line number Diff line
@@ -2949,7 +2949,7 @@ final class ActivityStack {
                    int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent,
                    int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent,
                            null, aInfo, null, null, parent.appToken, null,
                            null, aInfo, null, null, parent.appToken, null,
                            0, -1, parent.launchedFromUid, parent.launchedFromPackage,
                            0, -1, parent.launchedFromUid, parent.launchedFromPackage,
                            0, null, true, null, null, null);
                            -1, parent.launchedFromUid, 0, null, true, null, null, null);
                    foundParentInTask = res == ActivityManager.START_SUCCESS;
                    foundParentInTask = res == ActivityManager.START_SUCCESS;
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    foundParentInTask = false;
                    foundParentInTask = false;
+20 −15
Original line number Original line Diff line number Diff line
@@ -785,8 +785,8 @@ public final class ActivityStackSupervisor implements DisplayListener {


    void startHomeActivity(Intent intent, ActivityInfo aInfo) {
    void startHomeActivity(Intent intent, ActivityInfo aInfo) {
        moveHomeStackTaskToTop(HOME_ACTIVITY_TYPE);
        moveHomeStackTaskToTop(HOME_ACTIVITY_TYPE);
        startActivityLocked(null, intent, null, aInfo, null, null, null, null, 0, 0, 0, null, 0,
        startActivityLocked(null, intent, null, aInfo, null, null, null, null, 0, 0, 0, null,
                null, false, null, null, null);
                0, 0, 0, null, false, null, null, null);
    }
    }


    final int startActivityMayWait(IApplicationThread caller, int callingUid,
    final int startActivityMayWait(IApplicationThread caller, int callingUid,
@@ -810,12 +810,14 @@ public final class ActivityStackSupervisor implements DisplayListener {


        ActivityContainer container = (ActivityContainer)iContainer;
        ActivityContainer container = (ActivityContainer)iContainer;
        synchronized (mService) {
        synchronized (mService) {
            final int realCallingPid = Binder.getCallingPid();
            final int realCallingUid = Binder.getCallingUid();
            int callingPid;
            int callingPid;
            if (callingUid >= 0) {
            if (callingUid >= 0) {
                callingPid = -1;
                callingPid = -1;
            } else if (caller == null) {
            } else if (caller == null) {
                callingPid = Binder.getCallingPid();
                callingPid = realCallingPid;
                callingUid = Binder.getCallingUid();
                callingUid = realCallingUid;
            } else {
            } else {
                callingPid = callingUid = -1;
                callingPid = callingUid = -1;
            }
            }
@@ -841,11 +843,11 @@ public final class ActivityStackSupervisor implements DisplayListener {
                    if (mService.mHeavyWeightProcess != null &&
                    if (mService.mHeavyWeightProcess != null &&
                            (mService.mHeavyWeightProcess.info.uid != aInfo.applicationInfo.uid ||
                            (mService.mHeavyWeightProcess.info.uid != aInfo.applicationInfo.uid ||
                            !mService.mHeavyWeightProcess.processName.equals(aInfo.processName))) {
                            !mService.mHeavyWeightProcess.processName.equals(aInfo.processName))) {
                        int realCallingUid = callingUid;
                        int appCallingUid = callingUid;
                        if (caller != null) {
                        if (caller != null) {
                            ProcessRecord callerApp = mService.getRecordForAppLocked(caller);
                            ProcessRecord callerApp = mService.getRecordForAppLocked(caller);
                            if (callerApp != null) {
                            if (callerApp != null) {
                                realCallingUid = callerApp.info.uid;
                                appCallingUid = callerApp.info.uid;
                            } else {
                            } else {
                                Slog.w(TAG, "Unable to find app for caller " + caller
                                Slog.w(TAG, "Unable to find app for caller " + caller
                                      + " (pid=" + callingPid + ") when starting: "
                                      + " (pid=" + callingPid + ") when starting: "
@@ -857,7 +859,7 @@ public final class ActivityStackSupervisor implements DisplayListener {


                        IIntentSender target = mService.getIntentSenderLocked(
                        IIntentSender target = mService.getIntentSenderLocked(
                                ActivityManager.INTENT_SENDER_ACTIVITY, "android",
                                ActivityManager.INTENT_SENDER_ACTIVITY, "android",
                                realCallingUid, userId, null, null, 0, new Intent[] { intent },
                                appCallingUid, userId, null, null, 0, new Intent[] { intent },
                                new String[] { resolvedType }, PendingIntent.FLAG_CANCEL_CURRENT
                                new String[] { resolvedType }, PendingIntent.FLAG_CANCEL_CURRENT
                                | PendingIntent.FLAG_ONE_SHOT, null);
                                | PendingIntent.FLAG_ONE_SHOT, null);


@@ -903,7 +905,8 @@ public final class ActivityStackSupervisor implements DisplayListener {


            int res = startActivityLocked(caller, intent, resolvedType, aInfo,
            int res = startActivityLocked(caller, intent, resolvedType, aInfo,
                    voiceSession, voiceInteractor, resultTo, resultWho,
                    voiceSession, voiceInteractor, resultTo, resultWho,
                    requestCode, callingPid, callingUid, callingPackage, startFlags, options,
                    requestCode, callingPid, callingUid, callingPackage,
                    realCallingPid, realCallingUid, startFlags, options,
                    componentSpecified, null, container, inTask);
                    componentSpecified, null, container, inTask);


            Binder.restoreCallingIdentity(origId);
            Binder.restoreCallingIdentity(origId);
@@ -1017,7 +1020,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
                        theseOptions = null;
                        theseOptions = null;
                    }
                    }
                    int res = startActivityLocked(caller, intent, resolvedTypes[i],
                    int res = startActivityLocked(caller, intent, resolvedTypes[i],
                            aInfo, null, null, resultTo, null, -1, callingPid, callingUid, callingPackage,
                            aInfo, null, null, resultTo, null, -1, callingPid, callingUid,
                            callingPackage, callingPid, callingUid,
                            0, theseOptions, componentSpecified, outActivity, null, null);
                            0, theseOptions, componentSpecified, outActivity, null, null);
                    if (res < 0) {
                    if (res < 0) {
                        return res;
                        return res;
@@ -1248,7 +1252,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
            Intent intent, String resolvedType, ActivityInfo aInfo,
            Intent intent, String resolvedType, ActivityInfo aInfo,
            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
            IBinder resultTo, String resultWho, int requestCode,
            IBinder resultTo, String resultWho, int requestCode,
            int callingPid, int callingUid, String callingPackage, int startFlags, Bundle options,
            int callingPid, int callingUid, String callingPackage,
            int realCallingPid, int realCallingUid, int startFlags, Bundle options,
            boolean componentSpecified, ActivityRecord[] outActivity, ActivityContainer container,
            boolean componentSpecified, ActivityRecord[] outActivity, ActivityContainer container,
            TaskRecord inTask) {
            TaskRecord inTask) {
        int err = ActivityManager.START_SUCCESS;
        int err = ActivityManager.START_SUCCESS;
@@ -1293,8 +1298,7 @@ public final class ActivityStackSupervisor implements DisplayListener {


        final int launchFlags = intent.getFlags();
        final int launchFlags = intent.getFlags();


        if ((launchFlags&Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0
        if ((launchFlags&Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0 && sourceRecord != null) {
                && sourceRecord != null) {
            // Transfer the result target from the source activity to the new
            // Transfer the result target from the source activity to the new
            // one being started, including any failures.
            // one being started, including any failures.
            if (requestCode >= 0) {
            if (requestCode >= 0) {
@@ -1344,8 +1348,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
            if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
                    && sourceRecord.info.applicationInfo.uid != aInfo.applicationInfo.uid) {
                    && sourceRecord.info.applicationInfo.uid != aInfo.applicationInfo.uid) {
                try {
                try {
                    if (!AppGlobals.getPackageManager().activitySupportsIntent(intent.getComponent(),
                    if (!AppGlobals.getPackageManager().activitySupportsIntent(
                            intent, resolvedType)) {
                            intent.getComponent(), intent, resolvedType)) {
                        err = ActivityManager.START_NOT_VOICE_COMPATIBLE;
                        err = ActivityManager.START_NOT_VOICE_COMPATIBLE;
                    }
                    }
                } catch (RemoteException e) {
                } catch (RemoteException e) {
@@ -1439,7 +1443,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
        final ActivityStack stack = getFocusedStack();
        final ActivityStack stack = getFocusedStack();
        if (voiceSession == null && (stack.mResumedActivity == null
        if (voiceSession == null && (stack.mResumedActivity == null
                || stack.mResumedActivity.info.applicationInfo.uid != callingUid)) {
                || stack.mResumedActivity.info.applicationInfo.uid != callingUid)) {
            if (!mService.checkAppSwitchAllowedLocked(callingPid, callingUid, "Activity start")) {
            if (!mService.checkAppSwitchAllowedLocked(callingPid, callingUid,
                    realCallingPid, realCallingUid, "Activity start")) {
                PendingActivityLaunch pal =
                PendingActivityLaunch pal =
                        new PendingActivityLaunch(r, sourceRecord, startFlags, stack);
                        new PendingActivityLaunch(r, sourceRecord, startFlags, stack);
                mPendingActivityLaunches.add(pal);
                mPendingActivityLaunches.add(pal);