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

Commit f68b46c3 authored by Alan Stokes's avatar Alan Stokes Committed by android-build-merger
Browse files

Merge "Do not allow app to start background activity after stop app switches...

Merge "Do not allow app to start background activity after stop app switches triggered" into qt-dev am: 02d9b9c3
am: 534529c0

Change-Id: Ia072115fb3233c50bc1729ad782e342677909dd2
parents de7e7780 534529c0
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -509,6 +509,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
     */
     */
    private boolean mDidAppSwitch;
    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;
    IActivityController mController = null;
    boolean mControllerIsAMonkey = false;
    boolean mControllerIsAMonkey = false;


@@ -4749,6 +4755,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches");
        enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches");
        synchronized (mGlobalLock) {
        synchronized (mGlobalLock) {
            mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME;
            mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME;
            mLastStopAppSwitchesTime = SystemClock.uptimeMillis();
            mDidAppSwitch = false;
            mDidAppSwitch = false;
            getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME);
            getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME);
        }
        }
@@ -4765,6 +4772,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
        }
    }
    }


    long getLastStopAppSwitchesTime() {
        return mLastStopAppSwitchesTime;
    }

    void onStartActivitySetDidAppSwitch() {
    void onStartActivitySetDidAppSwitch() {
        if (mDidAppSwitch) {
        if (mDidAppSwitch) {
            // This is the second allowed switch since we stopped switches, so now just generally
            // This is the second allowed switch since we stopped switches, so now just generally
+8 −2
Original line number Original line Diff line number Diff line
@@ -402,12 +402,18 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        if (mAllowBackgroundActivityStarts) {
        if (mAllowBackgroundActivityStarts) {
            return true;
            return true;
        }
        }
        // allow if any activity in the caller has either started or finished very recently
        // allow if any activity in the caller has either started or finished very recently, and
        // it must be started or finished after last stop app switches time.
        final long now = SystemClock.uptimeMillis();
        final long now = SystemClock.uptimeMillis();
        if (now - mLastActivityLaunchTime < ACTIVITY_BG_START_GRACE_PERIOD_MS
        if (now - mLastActivityLaunchTime < ACTIVITY_BG_START_GRACE_PERIOD_MS
                || now - mLastActivityFinishTime < ACTIVITY_BG_START_GRACE_PERIOD_MS) {
                || now - mLastActivityFinishTime < ACTIVITY_BG_START_GRACE_PERIOD_MS) {
            // if activity is started and finished before stop app switch time, we should not
            // let app to be able to start background activity even it's in grace period.
            if (mLastActivityLaunchTime > mAtm.getLastStopAppSwitchesTime()
                    || mLastActivityFinishTime > mAtm.getLastStopAppSwitchesTime()) {
                return true;
                return true;
            }
            }
        }
        // allow if the proc is instrumenting with background activity starts privs
        // allow if the proc is instrumenting with background activity starts privs
        if (mInstrumentingWithBackgroundActivityStartPrivileges) {
        if (mInstrumentingWithBackgroundActivityStartPrivileges) {
            return true;
            return true;