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

Commit 64aa8161 authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Android (Google) Code Review
Browse files

Merge "Use a blank splash screen for new task activity" into sc-dev

parents 5719f05c 4bd7f5a9
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -49,13 +49,20 @@ public final class StartingWindowInfo implements Parcelable {
     * @hide
     */
    public static final int STARTING_WINDOW_TYPE_SNAPSHOT = 2;
    /**
     * Prefer empty splash screen starting window.
     * @hide
     */
    public static final int STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN = 3;

    /**
     * @hide
     */
    @IntDef(flag = true, prefix = "STARTING_WINDOW_TYPE_", value = {
            STARTING_WINDOW_TYPE_NONE,
            STARTING_WINDOW_TYPE_SPLASH_SCREEN,
            STARTING_WINDOW_TYPE_SNAPSHOT
            STARTING_WINDOW_TYPE_SNAPSHOT,
            STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN
    })
    public @interface StartingWindowType {}

@@ -95,7 +102,8 @@ public final class StartingWindowInfo implements Parcelable {
            TYPE_PARAMETER_TASK_SWITCH,
            TYPE_PARAMETER_PROCESS_RUNNING,
            TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT,
            TYPE_PARAMETER_ACTIVITY_CREATED
            TYPE_PARAMETER_ACTIVITY_CREATED,
            TYPE_PARAMETER_SAME_PACKAGE
    })
    public @interface StartingTypeParams {}

@@ -112,6 +120,8 @@ public final class StartingWindowInfo implements Parcelable {
    public static final int TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT = 0x00000008;
    /** @hide */
    public static final int TYPE_PARAMETER_ACTIVITY_CREATED = 0x00000010;
    /** @hide */
    public static final int TYPE_PARAMETER_SAME_PACKAGE = 0x00000020;

    /**
     * The parameters which effect the starting window type.
+20 −13
Original line number Diff line number Diff line
@@ -105,8 +105,10 @@ public class StartingSurfaceDrawer {

    /**
     * Called when a task need a splash screen starting window.
     * @param emptyView Whether drawing an empty frame without anything on it.
     */
    public void addSplashScreenStartingWindow(StartingWindowInfo windowInfo, IBinder appToken) {
    void addSplashScreenStartingWindow(StartingWindowInfo windowInfo, IBinder appToken,
            boolean emptyView) {
        final RunningTaskInfo taskInfo = windowInfo.taskInfo;
        final ActivityInfo activityInfo = taskInfo.topActivityInfo;
        if (activityInfo == null) {
@@ -203,7 +205,6 @@ public class StartingSurfaceDrawer {
        }

        final PhoneWindow win = new PhoneWindow(context);
        win.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        win.setIsStartingWindow(true);

        CharSequence label = context.getResources().getText(labelRes, null);
@@ -270,6 +271,7 @@ public class StartingSurfaceDrawer {
        try {
            final View view = win.getDecorView();
            final WindowManager wm = mContext.getSystemService(WindowManager.class);
            if (!emptyView) {
                // splash screen content will be deprecated after S.
                sView = SplashscreenContentDrawer.makeSplashscreenContent(
                        context, splashscreenContentResId[0]);
@@ -280,8 +282,10 @@ public class StartingSurfaceDrawer {
                    sView = mSplashscreenContentDrawer
                            .makeSplashScreenContentView(context, activityInfo);
                    win.setContentView(sView);
                    win.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    sView.cacheRootWindow(win);
                }
            }
            postAddWindow(taskId, appToken, view, wm, params);
        } catch (RuntimeException e) {
            // don't crash if something else bad happens, for example a
@@ -393,6 +397,9 @@ public class StartingSurfaceDrawer {
                        // animation
                        removeWindowInner(record.mDecorView, false);
                    }
                } else {
                    // no animation will be applied
                    removeWindowInner(record.mDecorView, false);
                }
            }
            if (record.mTaskSnapshotWindow != null) {
+33 −9
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.wm.shell.startingsurface;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN;
import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_NONE;
import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_SNAPSHOT;
import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_SPLASH_SCREEN;
@@ -23,6 +24,7 @@ import static android.window.StartingWindowInfo.TYPE_PARAMETER_ACTIVITY_CREATED;
import static android.window.StartingWindowInfo.TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT;
import static android.window.StartingWindowInfo.TYPE_PARAMETER_NEW_TASK;
import static android.window.StartingWindowInfo.TYPE_PARAMETER_PROCESS_RUNNING;
import static android.window.StartingWindowInfo.TYPE_PARAMETER_SAME_PACKAGE;
import static android.window.StartingWindowInfo.TYPE_PARAMETER_TASK_SWITCH;

import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission;
@@ -65,7 +67,8 @@ import java.util.function.BiConsumer;
 */
public class StartingWindowController implements RemoteCallable<StartingWindowController> {
    private static final String TAG = StartingWindowController.class.getSimpleName();
    static final boolean DEBUG_SPLASH_SCREEN = false;
    // TODO b/183150443 Keep this flag open for a while, several things might need to adjust.
    static final boolean DEBUG_SPLASH_SCREEN = true;
    static final boolean DEBUG_TASK_SNAPSHOT = false;

    private final StartingSurfaceDrawer mStartingSurfaceDrawer;
@@ -123,25 +126,38 @@ public class StartingWindowController implements RemoteCallable<StartingWindowCo
            final boolean processRunning = (parameter & TYPE_PARAMETER_PROCESS_RUNNING) != 0;
            final boolean allowTaskSnapshot = (parameter & TYPE_PARAMETER_ALLOW_TASK_SNAPSHOT) != 0;
            final boolean activityCreated = (parameter & TYPE_PARAMETER_ACTIVITY_CREATED) != 0;
            final boolean samePackage = (parameter & TYPE_PARAMETER_SAME_PACKAGE) != 0;
            return estimateStartingWindowType(windowInfo, newTask, taskSwitch,
                    processRunning, allowTaskSnapshot, activityCreated);
                    processRunning, allowTaskSnapshot, activityCreated, samePackage);
        }

        // reference from ActivityRecord#getStartingWindowType
        private int estimateStartingWindowType(StartingWindowInfo windowInfo,
                boolean newTask, boolean taskSwitch, boolean processRunning,
                boolean allowTaskSnapshot, boolean activityCreated) {
                boolean allowTaskSnapshot, boolean activityCreated, boolean samePackage) {
            if (DEBUG_SPLASH_SCREEN || DEBUG_TASK_SNAPSHOT) {
                Slog.d(TAG, "preferredStartingWindowType newTask " + newTask
                        + " taskSwitch " + taskSwitch
                        + " processRunning " + processRunning
                        + " allowTaskSnapshot " + allowTaskSnapshot
                        + " activityCreated " + activityCreated);
                        + " activityCreated " + activityCreated
                        + " samePackage " + samePackage);
            }
            if ((newTask || !processRunning || (taskSwitch && !activityCreated))
                    && windowInfo.taskInfo.topActivityType != ACTIVITY_TYPE_HOME) {
            if (windowInfo.taskInfo.topActivityType != ACTIVITY_TYPE_HOME) {
                if (!processRunning) {
                    return STARTING_WINDOW_TYPE_SPLASH_SCREEN;
                }
                if (newTask) {
                    if (samePackage) {
                        return STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN;
                    } else {
                        return STARTING_WINDOW_TYPE_SPLASH_SCREEN;
                    }
                }
                if (taskSwitch && !activityCreated) {
                    return STARTING_WINDOW_TYPE_SPLASH_SCREEN;
                }
            }
            if (taskSwitch && allowTaskSnapshot) {
                final TaskSnapshot snapshot = getTaskSnapshot(windowInfo.taskInfo.taskId);
                if (isSnapshotCompatible(windowInfo, snapshot)) {
@@ -207,6 +223,10 @@ public class StartingWindowController implements RemoteCallable<StartingWindowCo
        mTaskLaunchingCallback = listener;
    }

    private boolean shouldSendToListener(int suggestionType) {
        return suggestionType != STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN;
    }

    /**
     * Called when a task need a starting window.
     */
@@ -214,11 +234,15 @@ public class StartingWindowController implements RemoteCallable<StartingWindowCo
        mSplashScreenExecutor.execute(() -> {
            final int suggestionType = mStartingTypeChecker.estimateStartingWindowType(windowInfo);
            final RunningTaskInfo runningTaskInfo = windowInfo.taskInfo;
            if (mTaskLaunchingCallback != null) {
            if (mTaskLaunchingCallback != null && shouldSendToListener(suggestionType)) {
                mTaskLaunchingCallback.accept(runningTaskInfo.taskId, suggestionType);
            }
            if (suggestionType == STARTING_WINDOW_TYPE_SPLASH_SCREEN) {
                mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, appToken);
                mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, appToken,
                        false /* emptyView */);
            } else if (suggestionType == STARTING_WINDOW_TYPE_EMPTY_SPLASH_SCREEN) {
                mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, appToken,
                        true /* emptyView */);
            } else if (suggestionType == STARTING_WINDOW_TYPE_SNAPSHOT) {
                final TaskSnapshot snapshot = mStartingTypeChecker.mSnapshot;
                mStartingSurfaceDrawer.makeTaskSnapshotWindow(windowInfo, appToken, snapshot);
+2 −2
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public class StartingSurfaceDrawerTests {
        final Handler mainLoop = new Handler(Looper.getMainLooper());
        final StartingWindowInfo windowInfo =
                createWindowInfo(taskId, android.R.style.Theme);
        mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, mBinder);
        mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, mBinder, false);
        waitHandlerIdle(mainLoop);
        verify(mStartingSurfaceDrawer).postAddWindow(eq(taskId), eq(mBinder), any(), any(), any());
        assertEquals(mStartingSurfaceDrawer.mAddWindowForTask, taskId);
@@ -148,7 +148,7 @@ public class StartingSurfaceDrawerTests {
        final Handler mainLoop = new Handler(Looper.getMainLooper());
        final StartingWindowInfo windowInfo =
                createWindowInfo(taskId, 0);
        mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, mBinder);
        mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, mBinder, false);
        waitHandlerIdle(mainLoop);
        verify(mStartingSurfaceDrawer).postAddWindow(eq(taskId), eq(mBinder), any(), any(), any());
        assertNotEquals(mStartingSurfaceDrawer.mViewThemeResId, 0);
+6 −5
Original line number Diff line number Diff line
@@ -1949,7 +1949,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    boolean addStartingWindow(String pkg, int resolvedTheme, CompatibilityInfo compatInfo,
            CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags,
            IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning,
            boolean allowTaskSnapshot, boolean activityCreated) {
            boolean allowTaskSnapshot, boolean activityCreated, boolean samePackage) {
        // If the display is frozen, we won't do anything until the actual window is
        // displayed so there is no reason to put in the starting window.
        if (!okToDisplay()) {
@@ -1971,7 +1971,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                        false /* restoreFromDisk */, false /* isLowResolution */);
        final int typeParameter = mWmService.mStartingSurfaceController
                .makeStartingWindowTypeParameter(newTask, taskSwitch, processRunning,
                        allowTaskSnapshot, activityCreated);
                        allowTaskSnapshot, activityCreated, samePackage);
        final int type = getStartingWindowType(newTask, taskSwitch, processRunning,
                allowTaskSnapshot, activityCreated, snapshot);

@@ -6141,11 +6141,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    void showStartingWindow(boolean taskSwitch) {
        showStartingWindow(null /* prev */, false /* newTask */, taskSwitch,
                0 /* splashScreenTheme */);
                0 /* splashScreenTheme */, true /* samePackage */);
    }

    void showStartingWindow(ActivityRecord prev, boolean newTask, boolean taskSwitch,
            int splashScreenTheme) {
            int splashScreenTheme, boolean samePackage) {
        if (mTaskOverlay) {
            // We don't show starting window for overlay activities.
            return;
@@ -6165,7 +6165,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags,
                prev != null ? prev.appToken : null, newTask, taskSwitch, isProcessRunning(),
                allowTaskSnapshot(),
                mState.ordinal() >= STARTED.ordinal() && mState.ordinal() <= STOPPED.ordinal());
                mState.ordinal() >= STARTED.ordinal() && mState.ordinal() <= STOPPED.ordinal(),
                samePackage);
        if (shown) {
            mStartingWindowState = STARTING_WINDOW_SHOWN;
        }
Loading