diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index b123aa5d20c74..1b9c14d7f6f9c 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -509,6 +509,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { */ private boolean mDidAppSwitch; + /** + * Last stop app switches time, apps finished before this time cannot start background activity + * even if they are in grace period. + */ + private long mLastStopAppSwitchesTime; + IActivityController mController = null; boolean mControllerIsAMonkey = false; @@ -4749,6 +4755,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); synchronized (mGlobalLock) { mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; + mLastStopAppSwitchesTime = SystemClock.uptimeMillis(); mDidAppSwitch = false; getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); } @@ -4765,6 +4772,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } } + long getLastStopAppSwitchesTime() { + return mLastStopAppSwitchesTime; + } + void onStartActivitySetDidAppSwitch() { if (mDidAppSwitch) { // This is the second allowed switch since we stopped switches, so now just generally diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java index fbd4ec7ff5360..55b28862881e3 100644 --- a/services/core/java/com/android/server/wm/WindowProcessController.java +++ b/services/core/java/com/android/server/wm/WindowProcessController.java @@ -402,11 +402,17 @@ public class WindowProcessController extends ConfigurationContainer mAtm.getLastStopAppSwitchesTime() + || mLastActivityFinishTime > mAtm.getLastStopAppSwitchesTime()) { + return true; + } } // allow if the proc is instrumenting with background activity starts privs if (mInstrumentingWithBackgroundActivityStartPrivileges) {