From aefbd7ba69ccaad969af66da0f09d0403a151160 Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Fri, 8 Jan 2021 14:06:40 +0800 Subject: [PATCH] Specify the default theme for splash screen window. By default if application didn't specify a theme, PhoneWindow will get the default theme by Resources#selectDefaultTheme for itself and currently it could be Theme_DeviceDefault_Light_DarkActionBar, which will shows an ActionBar on splash screen window, and looks bad for starting window. For this case, use Theme_DeviceDefault_DayNight for splash screen window should be a better choice. Bug: 73289295 Test: atest StartingSurfaceDrawerTests Change-Id: Ia47afcb26c7aaa7781a24e3fe8122e58901776dc --- .../StartingSurfaceDrawer.java | 6 ++++- .../StartingSurfaceDrawerTests.java | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawer.java index 786a1fd896ebd..8e24e0b516cb5 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawer.java @@ -222,7 +222,11 @@ public class StartingSurfaceDrawer { } Context context = mContext; - final int theme = activityInfo.getThemeResource(); + int theme = activityInfo.getThemeResource(); + if (theme == 0) { + // replace with the default theme if the application didn't set + theme = com.android.internal.R.style.Theme_DeviceDefault_DayNight; + } if (DEBUG_SPLASH_SCREEN) { Slog.d(TAG, "addSplashScreen " + activityInfo.packageName + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawerTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawerTests.java index 07115c2b4d22c..c9537afa37ef3 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawerTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawerTests.java @@ -15,14 +15,13 @@ */ package unittest.src.com.android.wm.shell.startingsurface; -import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; - import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -72,6 +71,7 @@ public class StartingSurfaceDrawerTests { static final class TestStartingSurfaceDrawer extends StartingSurfaceDrawer{ int mAddWindowForTask = 0; + int mViewThemeResId; TestStartingSurfaceDrawer(Context context, ShellExecutor executor) { super(context, executor); @@ -82,6 +82,7 @@ public class StartingSurfaceDrawerTests { View view, WindowManager wm, WindowManager.LayoutParams params) { // listen for addView mAddWindowForTask = taskId; + mViewThemeResId = view.getContext().getThemeResId(); } @Override @@ -121,7 +122,7 @@ public class StartingSurfaceDrawerTests { final int taskId = 1; final Handler mainLoop = new Handler(Looper.getMainLooper()); final StartingWindowInfo windowInfo = - createWindowInfo(taskId, WINDOWING_MODE_FULLSCREEN); + createWindowInfo(taskId, android.R.style.Theme); mStartingSurfaceDrawer.addStartingWindow(windowInfo, mBinder); waitHandlerIdle(mainLoop); verify(mStartingSurfaceDrawer).postAddWindow(eq(taskId), eq(mBinder), any(), any(), any()); @@ -133,12 +134,24 @@ public class StartingSurfaceDrawerTests { assertEquals(mStartingSurfaceDrawer.mAddWindowForTask, 0); } - private StartingWindowInfo createWindowInfo(int taskId, int windowingMode) { + @Test + public void testFallbackDefaultTheme() { + final int taskId = 1; + final Handler mainLoop = new Handler(Looper.getMainLooper()); + final StartingWindowInfo windowInfo = + createWindowInfo(taskId, 0); + mStartingSurfaceDrawer.addStartingWindow(windowInfo, mBinder); + waitHandlerIdle(mainLoop); + verify(mStartingSurfaceDrawer).postAddWindow(eq(taskId), eq(mBinder), any(), any(), any()); + assertNotEquals(mStartingSurfaceDrawer.mViewThemeResId, 0); + } + + private StartingWindowInfo createWindowInfo(int taskId, int themeResId) { StartingWindowInfo windowInfo = new StartingWindowInfo(); final ActivityInfo info = new ActivityInfo(); info.applicationInfo = new ApplicationInfo(); info.packageName = "test"; - info.theme = android.R.style.Theme; + info.theme = themeResId; final ActivityManager.RunningTaskInfo taskInfo = new ActivityManager.RunningTaskInfo(); taskInfo.topActivityInfo = info; taskInfo.taskId = taskId;