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

Commit 7b2bcd04 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by android-build-merger
Browse files

Merge "Disallow task snapshot starting window for intent != ACTION_MAIN" into oc-dev

am: fe99773a

Change-Id: I88f17c51cb020ed30b771a1bebfa565640f262fc
parents a218d21d fe99773a
Loading
Loading
Loading
Loading
+25 −4
Original line number Original line Diff line number Diff line
@@ -1561,8 +1561,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
        mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
    }
    }


    void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
    void notifyAppResumed(boolean wasStopped) {
        mWindowContainerController.notifyAppResumed(wasStopped, allowSavedSurface);
        mWindowContainerController.notifyAppResumed(wasStopped);
    }
    }


    void notifyUnknownVisibilityLaunched() {
    void notifyUnknownVisibilityLaunched() {
@@ -2112,7 +2112,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
                service.compatibilityInfoForPackageLocked(info.applicationInfo);
                service.compatibilityInfoForPackageLocked(info.applicationInfo);
        final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme,
        final boolean shown = mWindowContainerController.addStartingWindow(packageName, theme,
                compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
                compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
                prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning());
                prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(),
                allowTaskSnapshot());
        if (shown) {
        if (shown) {
            mStartingWindowState = STARTING_WINDOW_SHOWN;
            mStartingWindowState = STARTING_WINDOW_SHOWN;
        }
        }
@@ -2552,7 +2553,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        preserveWindowOnDeferredRelaunch = false;
        preserveWindowOnDeferredRelaunch = false;
    }
    }


    boolean isProcessRunning() {
    private boolean isProcessRunning() {
        ProcessRecord proc = app;
        ProcessRecord proc = app;
        if (proc == null) {
        if (proc == null) {
            proc = service.mProcessNames.get(processName, info.applicationInfo.uid);
            proc = service.mProcessNames.get(processName, info.applicationInfo.uid);
@@ -2560,6 +2561,26 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        return proc != null && proc.thread != null;
        return proc != null && proc.thread != null;
    }
    }


    /**
     * @return Whether a task snapshot starting window may be shown.
     */
    private boolean allowTaskSnapshot() {
        if (newIntents == null) {
            return true;
        }

        // Restrict task snapshot starting window to launcher start, or there is no intent at all
        // (eg. task being brought to front). If the intent is something else, likely the app is
        // going to show some specific page or view, instead of what's left last time.
        for (int i = newIntents.size() - 1; i >= 0; i--) {
            final Intent intent = newIntents.get(i);
            if (intent != null && !ActivityRecord.isMainIntent(intent)) {
                return false;
            }
        }
        return true;
    }

    void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
    void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
        out.attribute(null, ATTR_ID, String.valueOf(createTime));
        out.attribute(null, ATTR_ID, String.valueOf(createTime));
        out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
        out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
+1 −13
Original line number Original line Diff line number Diff line
@@ -2531,26 +2531,14 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                    }
                    }
                }
                }


                boolean allowSavedSurface = true;
                if (next.newIntents != null) {
                if (next.newIntents != null) {
                    // Restrict saved surface to launcher start, or there is no intent at all
                    // (eg. task being brought to front). If the intent is something else,
                    // likely the app is going to show some specific page or view, instead of
                    // what's left last time.
                    for (int i = next.newIntents.size() - 1; i >= 0; i--) {
                        final Intent intent = next.newIntents.get(i);
                        if (intent != null && !ActivityRecord.isMainIntent(intent)) {
                            allowSavedSurface = false;
                            break;
                        }
                    }
                    next.app.thread.scheduleNewIntent(
                    next.app.thread.scheduleNewIntent(
                            next.newIntents, next.appToken, false /* andPause */);
                            next.newIntents, next.appToken, false /* andPause */);
                }
                }


                // Well the app will no longer be stopped.
                // Well the app will no longer be stopped.
                // Clear app token stopped state in window manager if needed.
                // Clear app token stopped state in window manager if needed.
                next.notifyAppResumed(next.stopped, allowSavedSurface);
                next.notifyAppResumed(next.stopped);


                EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId,
                EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId,
                        System.identityHashCode(next), next.getTask().taskId,
                        System.identityHashCode(next), next.getTask().taskId,
+9 −6
Original line number Original line Diff line number Diff line
@@ -449,7 +449,8 @@ public class AppWindowContainerController


    public boolean addStartingWindow(String pkg, int theme, CompatibilityInfo compatInfo,
    public boolean addStartingWindow(String pkg, int theme, CompatibilityInfo compatInfo,
            CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags,
            CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags,
            IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning) {
            IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning,
            boolean allowTaskSnapshot) {
        synchronized(mWindowMap) {
        synchronized(mWindowMap) {
            if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "setAppStartingWindow: token=" + mToken
            if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "setAppStartingWindow: token=" + mToken
                    + " pkg=" + pkg + " transferFrom=" + transferFrom);
                    + " pkg=" + pkg + " transferFrom=" + transferFrom);
@@ -469,7 +470,8 @@ public class AppWindowContainerController
                return false;
                return false;
            }
            }


            final int type = getStartingWindowType(newTask, taskSwitch, processRunning);
            final int type = getStartingWindowType(newTask, taskSwitch, processRunning,
                    allowTaskSnapshot);


            if (type == STARTING_WINDOW_TYPE_SNAPSHOT) {
            if (type == STARTING_WINDOW_TYPE_SNAPSHOT) {
                return createSnapshot();
                return createSnapshot();
@@ -539,10 +541,11 @@ public class AppWindowContainerController
        return true;
        return true;
    }
    }


    private int getStartingWindowType(boolean newTask, boolean taskSwitch, boolean processRunning) {
    private int getStartingWindowType(boolean newTask, boolean taskSwitch, boolean processRunning,
            boolean allowTaskSnapshot) {
        if (newTask || !processRunning) {
        if (newTask || !processRunning) {
            return STARTING_WINDOW_TYPE_SPLASH_SCREEN;
            return STARTING_WINDOW_TYPE_SPLASH_SCREEN;
        } else if (taskSwitch) {
        } else if (taskSwitch && allowTaskSnapshot) {
            return STARTING_WINDOW_TYPE_SNAPSHOT;
            return STARTING_WINDOW_TYPE_SNAPSHOT;
        } else {
        } else {
            return STARTING_WINDOW_TYPE_NONE;
            return STARTING_WINDOW_TYPE_NONE;
@@ -612,13 +615,13 @@ public class AppWindowContainerController
        }
        }
    }
    }


    public void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
    public void notifyAppResumed(boolean wasStopped) {
        synchronized(mWindowMap) {
        synchronized(mWindowMap) {
            if (mContainer == null) {
            if (mContainer == null) {
                Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " + mToken);
                Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " + mToken);
                return;
                return;
            }
            }
            mContainer.notifyAppResumed(wasStopped, allowSavedSurface);
            mContainer.notifyAppResumed(wasStopped);
        }
        }
    }
    }


+2 −5
Original line number Original line Diff line number Diff line
@@ -582,16 +582,13 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
     * Notify that the app is now resumed, and it was not stopped before, perform a clean
     * Notify that the app is now resumed, and it was not stopped before, perform a clean
     * up of the surfaces
     * up of the surfaces
     */
     */
    void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) {
    void notifyAppResumed(boolean wasStopped) {
        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
                + " allowSavedSurface=" + allowSavedSurface + " " + this);
                + " " + this);
        mAppStopped = false;
        mAppStopped = false;
        if (!wasStopped) {
        if (!wasStopped) {
            destroySurfaces(true /*cleanupOnResume*/);
            destroySurfaces(true /*cleanupOnResume*/);
        }
        }
        if (!allowSavedSurface) {
            destroySavedSurfaces();
        }
    }
    }


    /**
    /**
+5 −5
Original line number Original line Diff line number Diff line
@@ -97,7 +97,7 @@ public class AppWindowContainerControllerTests extends WindowTestsBase {
        final WindowTestUtils.TestAppWindowContainerController controller =
        final WindowTestUtils.TestAppWindowContainerController controller =
                createAppWindowController();
                createAppWindowController();
        controller.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
        controller.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
                android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false);
                android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true);
        waitUntilHandlersIdle();
        waitUntilHandlersIdle();
        final AppWindowToken atoken = controller.getAppWindowToken();
        final AppWindowToken atoken = controller.getAppWindowToken();
        assertHasStartingWindow(atoken);
        assertHasStartingWindow(atoken);
@@ -113,11 +113,11 @@ public class AppWindowContainerControllerTests extends WindowTestsBase {
        final WindowTestUtils.TestAppWindowContainerController controller2 =
        final WindowTestUtils.TestAppWindowContainerController controller2 =
                createAppWindowController();
                createAppWindowController();
        controller1.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
        controller1.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
                android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false);
                android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true);
        waitUntilHandlersIdle();
        waitUntilHandlersIdle();
        controller2.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
        controller2.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
                android.R.style.Theme, null, "Test", 0, 0, 0, 0, controller1.mToken.asBinder(),
                android.R.style.Theme, null, "Test", 0, 0, 0, 0, controller1.mToken.asBinder(),
                true, true, false);
                true, true, false, true);
        waitUntilHandlersIdle();
        waitUntilHandlersIdle();
        assertNoStartingWindow(controller1.getAppWindowToken());
        assertNoStartingWindow(controller1.getAppWindowToken());
        assertHasStartingWindow(controller2.getAppWindowToken());
        assertHasStartingWindow(controller2.getAppWindowToken());
@@ -134,10 +134,10 @@ public class AppWindowContainerControllerTests extends WindowTestsBase {
            // Surprise, ...! Transfer window in the middle of the creation flow.
            // Surprise, ...! Transfer window in the middle of the creation flow.
            controller2.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
            controller2.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
                    android.R.style.Theme, null, "Test", 0, 0, 0, 0, controller1.mToken.asBinder(),
                    android.R.style.Theme, null, "Test", 0, 0, 0, 0, controller1.mToken.asBinder(),
                    true, true, false);
                    true, true, false, true);
        });
        });
        controller1.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
        controller1.addStartingWindow(InstrumentationRegistry.getContext().getPackageName(),
                android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false);
                android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true);
        waitUntilHandlersIdle();
        waitUntilHandlersIdle();
        assertNoStartingWindow(controller1.getAppWindowToken());
        assertNoStartingWindow(controller1.getAppWindowToken());
        assertHasStartingWindow(controller2.getAppWindowToken());
        assertHasStartingWindow(controller2.getAppWindowToken());