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

Commit f68351c7 authored by wilsonshih's avatar wilsonshih
Browse files

[PB] Do not show snapshot if uiMode has changed.

- Record uiMode in TaskSnapshot.
- While preparing predictive back animation, if the uiMode of snapshot
is not match activity's uiMode, fallback to use splash screen surface.
- Draw windowless splash screen with latest theme & configuration.

Flag: EXEMPT bugfix
Bug: 351119448
Test: follow issue description, switch dark/light theme then trigger
predictive back, verify no serious contrast changes.
Test: atest SnapshotDrawerUtilsTest StartingSurfaceDrawerTests
ActivityTaskManagerThumbnailLoaderTest ActivitySnapshotControllerTests
TaskSnapshotPersisterLoaderTest

Change-Id: I8c3b4e9444e5cfacf21c97da3b0d13c1ef76fcf3
parent 4d1af3ab
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public class TaskSnapshot implements Parcelable {
    int mAppearance;
    private final boolean mIsTranslucent;
    private final boolean mHasImeSurface;
    private final int mUiMode;
    // Must be one of the named color spaces, otherwise, always use SRGB color space.
    private final ColorSpace mColorSpace;
    private int mInternalReferences;
@@ -96,7 +97,7 @@ public class TaskSnapshot implements Parcelable {
            Rect contentInsets, Rect letterboxInsets, boolean isLowResolution,
            boolean isRealSnapshot, int windowingMode,
            @WindowInsetsController.Appearance int appearance, boolean isTranslucent,
            boolean hasImeSurface) {
            boolean hasImeSurface, int uiMode) {
        mId = id;
        mCaptureTime = captureTime;
        mTopActivityComponent = topActivityComponent;
@@ -114,6 +115,7 @@ public class TaskSnapshot implements Parcelable {
        mAppearance = appearance;
        mIsTranslucent = isTranslucent;
        mHasImeSurface = hasImeSurface;
        mUiMode = uiMode;
    }

    private TaskSnapshot(Parcel source) {
@@ -136,6 +138,7 @@ public class TaskSnapshot implements Parcelable {
        mAppearance = source.readInt();
        mIsTranslucent = source.readBoolean();
        mHasImeSurface = source.readBoolean();
        mUiMode = source.readInt();
    }

    /**
@@ -273,6 +276,13 @@ public class TaskSnapshot implements Parcelable {
        return mAppearance;
    }

    /**
     * @return The uiMode the screenshot was taken in.
     */
    public int getUiMode() {
        return mUiMode;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -295,6 +305,7 @@ public class TaskSnapshot implements Parcelable {
        dest.writeInt(mAppearance);
        dest.writeBoolean(mIsTranslucent);
        dest.writeBoolean(mHasImeSurface);
        dest.writeInt(mUiMode);
    }

    @Override
@@ -318,7 +329,8 @@ public class TaskSnapshot implements Parcelable {
                + " mAppearance=" + mAppearance
                + " mIsTranslucent=" + mIsTranslucent
                + " mHasImeSurface=" + mHasImeSurface
                + " mInternalReferences=" + mInternalReferences;
                + " mInternalReferences=" + mInternalReferences
                + " mUiMode=" + Integer.toHexString(mUiMode);
    }

    /**
@@ -370,6 +382,7 @@ public class TaskSnapshot implements Parcelable {
        private boolean mIsTranslucent;
        private boolean mHasImeSurface;
        private int mPixelFormat;
        private int mUiMode;

        public Builder setId(long id) {
            mId = id;
@@ -452,6 +465,14 @@ public class TaskSnapshot implements Parcelable {
            return this;
        }

        /**
         * Sets the original uiMode while capture
         */
        public Builder setUiMode(int uiMode) {
            mUiMode = uiMode;
            return this;
        }

        public int getPixelFormat() {
            return mPixelFormat;
        }
@@ -481,7 +502,8 @@ public class TaskSnapshot implements Parcelable {
                    mWindowingMode,
                    mAppearance,
                    mIsTranslucent,
                    mHasImeSurface);
                    mHasImeSurface,
                    mUiMode);

        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -93,7 +93,8 @@ public class SnapshotDrawerUtilsTest {
                ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
                Surface.ROTATION_0, taskSize, contentInsets, new Rect() /* letterboxInsets */,
                false, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
                0 /* systemUiVisibility */, false /* isTranslucent */, false /* hasImeSurface */);
                0 /* systemUiVisibility */, false /* isTranslucent */, false /* hasImeSurface */,
                0 /* uiMode */);
    }

    private static TaskDescription createTaskDescription(int background,
+3 −11
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.wm.shell.startingsurface;

import static android.graphics.Color.WHITE;
import static android.window.StartingWindowInfo.STARTING_WINDOW_TYPE_SPLASH_SCREEN;

import android.app.ActivityManager;
@@ -69,8 +68,9 @@ class WindowlessSplashWindowCreator extends AbsSplashWindowCreator {
            // Can't show splash screen on requested display, so skip showing at all.
            return;
        }
        final int theme = getSplashScreenTheme(0 /* splashScreenThemeResId */, activityInfo);
        final Context myContext = SplashscreenContentDrawer.createContext(mContext, windowInfo,
                0 /* theme */, STARTING_WINDOW_TYPE_SPLASH_SCREEN, mDisplayManager);
                theme, STARTING_WINDOW_TYPE_SPLASH_SCREEN, mDisplayManager);
        if (myContext == null) {
            return;
        }
@@ -86,19 +86,11 @@ class WindowlessSplashWindowCreator extends AbsSplashWindowCreator {
        final Rect windowBounds = taskInfo.configuration.windowConfiguration.getBounds();
        lp.width = windowBounds.width();
        lp.height = windowBounds.height();
        final ActivityManager.TaskDescription taskDescription;
        if (taskInfo.taskDescription != null) {
            taskDescription = taskInfo.taskDescription;
        } else {
            taskDescription = new ActivityManager.TaskDescription();
            taskDescription.setBackgroundColor(WHITE);
        }

        final FrameLayout rootLayout = new FrameLayout(
                mSplashscreenContentDrawer.createViewContextWrapper(myContext));
        viewHost.setView(rootLayout, lp);

        final int bgColor = taskDescription.getBackgroundColor();
        final int bgColor = mSplashscreenContentDrawer.estimateTaskBackgroundColor(myContext);
        final SplashScreenView splashScreenView = mSplashscreenContentDrawer
                .makeSimpleSplashScreenContentView(myContext, windowInfo, bgColor);
        rootLayout.addView(splashScreenView);
+1 −1
Original line number Diff line number Diff line
@@ -370,6 +370,6 @@ public class StartingSurfaceDrawerTests extends ShellTestCase {
                Surface.ROTATION_0, taskSize, contentInsets, new Rect() /* letterboxInsets */,
                false, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
                0 /* systemUiVisibility */, false /* isTranslucent */,
                hasImeSurface /* hasImeSurface */);
                hasImeSurface /* hasImeSurface */, 0 /* uiMode */);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ class ActivityTaskManagerThumbnailLoaderTest : SysuiTestCase() {
            WindowConfiguration.WINDOWING_MODE_FULLSCREEN,
            /* appearance= */ 0,
            /* isTranslucent= */ false,
            /* hasImeSurface= */ false
            /* hasImeSurface= */ false,
            /* uiMode */ 0
        )
}
Loading