Merge "Use SystemUI theme to inflate FrameLayout and SplashScreenView" into sc-qpr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a23a5d4ab0
@@ -316,7 +316,8 @@ public final class SplashScreenView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SurfaceView createSurfaceView(@NonNull SplashScreenView view) {
|
private SurfaceView createSurfaceView(@NonNull SplashScreenView view) {
|
||||||
final SurfaceView surfaceView = new SurfaceView(view.getContext());
|
final Context viewContext = view.getContext();
|
||||||
|
final SurfaceView surfaceView = new SurfaceView(viewContext);
|
||||||
surfaceView.setPadding(0, 0, 0, 0);
|
surfaceView.setPadding(0, 0, 0, 0);
|
||||||
surfaceView.setBackground(mIconBackground);
|
surfaceView.setBackground(mIconBackground);
|
||||||
if (mSurfacePackage == null) {
|
if (mSurfacePackage == null) {
|
||||||
@@ -326,10 +327,10 @@ public final class SplashScreenView extends FrameLayout {
|
|||||||
+ Thread.currentThread().getId());
|
+ Thread.currentThread().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
SurfaceControlViewHost viewHost = new SurfaceControlViewHost(mContext,
|
SurfaceControlViewHost viewHost = new SurfaceControlViewHost(viewContext,
|
||||||
mContext.getDisplay(),
|
viewContext.getDisplay(),
|
||||||
surfaceView.getHostToken());
|
surfaceView.getHostToken());
|
||||||
ImageView imageView = new ImageView(mContext);
|
ImageView imageView = new ImageView(viewContext);
|
||||||
imageView.setBackground(mIconDrawable);
|
imageView.setBackground(mIconDrawable);
|
||||||
viewHost.setView(imageView, mIconSize, mIconSize);
|
viewHost.setView(imageView, mIconSize, mIconSize);
|
||||||
SurfaceControlViewHost.SurfacePackage surfacePackage = viewHost.getSurfacePackage();
|
SurfaceControlViewHost.SurfacePackage surfacePackage = viewHost.getSurfacePackage();
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import android.os.Trace;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.SurfaceControl;
|
import android.view.SurfaceControl;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.window.SplashScreenView;
|
import android.window.SplashScreenView;
|
||||||
@@ -299,6 +300,11 @@ public class SplashscreenContentDrawer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Creates the wrapper with system theme to avoid unexpected styles from app. */
|
||||||
|
ContextThemeWrapper createViewContextWrapper(Context appContext) {
|
||||||
|
return new ContextThemeWrapper(appContext, mContext.getTheme());
|
||||||
|
}
|
||||||
|
|
||||||
/** The configuration of the splash screen window. */
|
/** The configuration of the splash screen window. */
|
||||||
public static class SplashScreenWindowAttrs {
|
public static class SplashScreenWindowAttrs {
|
||||||
private int mWindowBgResId = 0;
|
private int mWindowBgResId = 0;
|
||||||
@@ -472,7 +478,8 @@ public class SplashscreenContentDrawer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "fillViewWithIcon");
|
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "fillViewWithIcon");
|
||||||
final SplashScreenView.Builder builder = new SplashScreenView.Builder(mContext)
|
final ContextThemeWrapper wrapper = createViewContextWrapper(mContext);
|
||||||
|
final SplashScreenView.Builder builder = new SplashScreenView.Builder(wrapper)
|
||||||
.setBackgroundColor(mThemeColor)
|
.setBackgroundColor(mThemeColor)
|
||||||
.setOverlayDrawable(mOverlayDrawable)
|
.setOverlayDrawable(mOverlayDrawable)
|
||||||
.setIconSize(iconSize)
|
.setIconSize(iconSize)
|
||||||
|
|||||||
@@ -137,24 +137,11 @@ public class StartingSurfaceDrawer {
|
|||||||
private final SparseArray<SurfaceControlViewHost> mAnimatedSplashScreenSurfaceHosts =
|
private final SparseArray<SurfaceControlViewHost> mAnimatedSplashScreenSurfaceHosts =
|
||||||
new SparseArray<>(1);
|
new SparseArray<>(1);
|
||||||
|
|
||||||
/** Obtain proper context for showing splash screen on the provided display. */
|
private Display getDisplay(int displayId) {
|
||||||
private Context getDisplayContext(Context context, int displayId) {
|
return mDisplayManager.getDisplay(displayId);
|
||||||
if (displayId == DEFAULT_DISPLAY) {
|
|
||||||
// The default context fits.
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Display targetDisplay = mDisplayManager.getDisplay(displayId);
|
|
||||||
if (targetDisplay == null) {
|
|
||||||
// Failed to obtain the non-default display where splash screen should be shown,
|
|
||||||
// lets not show at all.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return context.createDisplayContext(targetDisplay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getSplashScreenTheme(int splashScreenThemeResId, ActivityInfo activityInfo) {
|
int getSplashScreenTheme(int splashScreenThemeResId, ActivityInfo activityInfo) {
|
||||||
return splashScreenThemeResId != 0
|
return splashScreenThemeResId != 0
|
||||||
? splashScreenThemeResId
|
? splashScreenThemeResId
|
||||||
: activityInfo.getThemeResource() != 0 ? activityInfo.getThemeResource()
|
: activityInfo.getThemeResource() != 0 ? activityInfo.getThemeResource()
|
||||||
@@ -177,7 +164,7 @@ public class StartingSurfaceDrawer {
|
|||||||
|
|
||||||
final int displayId = taskInfo.displayId;
|
final int displayId = taskInfo.displayId;
|
||||||
final int taskId = taskInfo.taskId;
|
final int taskId = taskInfo.taskId;
|
||||||
Context context = mContext;
|
|
||||||
// replace with the default theme if the application didn't set
|
// replace with the default theme if the application didn't set
|
||||||
final int theme = getSplashScreenTheme(windowInfo.splashScreenThemeResId, activityInfo);
|
final int theme = getSplashScreenTheme(windowInfo.splashScreenThemeResId, activityInfo);
|
||||||
if (DEBUG_SPLASH_SCREEN) {
|
if (DEBUG_SPLASH_SCREEN) {
|
||||||
@@ -186,13 +173,16 @@ public class StartingSurfaceDrawer {
|
|||||||
+ " suggestType=" + suggestType);
|
+ " suggestType=" + suggestType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain proper context to launch on the right display.
|
final Display display = getDisplay(displayId);
|
||||||
final Context displayContext = getDisplayContext(context, displayId);
|
if (display == null) {
|
||||||
if (displayContext == null) {
|
|
||||||
// Can't show splash screen on requested display, so skip showing at all.
|
// Can't show splash screen on requested display, so skip showing at all.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
context = displayContext;
|
Context context = displayId == DEFAULT_DISPLAY
|
||||||
|
? mContext : mContext.createDisplayContext(display);
|
||||||
|
if (context == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (theme != context.getThemeResId()) {
|
if (theme != context.getThemeResId()) {
|
||||||
try {
|
try {
|
||||||
context = context.createPackageContextAsUser(activityInfo.packageName,
|
context = context.createPackageContextAsUser(activityInfo.packageName,
|
||||||
@@ -303,7 +293,8 @@ public class StartingSurfaceDrawer {
|
|||||||
// Record whether create splash screen view success, notify to current thread after
|
// Record whether create splash screen view success, notify to current thread after
|
||||||
// create splash screen view finished.
|
// create splash screen view finished.
|
||||||
final SplashScreenViewSupplier viewSupplier = new SplashScreenViewSupplier();
|
final SplashScreenViewSupplier viewSupplier = new SplashScreenViewSupplier();
|
||||||
final FrameLayout rootLayout = new FrameLayout(context);
|
final FrameLayout rootLayout = new FrameLayout(
|
||||||
|
mSplashscreenContentDrawer.createViewContextWrapper(context));
|
||||||
rootLayout.setPadding(0, 0, 0, 0);
|
rootLayout.setPadding(0, 0, 0, 0);
|
||||||
rootLayout.setFitsSystemWindows(false);
|
rootLayout.setFitsSystemWindows(false);
|
||||||
final Runnable setViewSynchronized = () -> {
|
final Runnable setViewSynchronized = () -> {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertNotEquals;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -101,7 +102,6 @@ public class StartingSurfaceDrawerTests {
|
|||||||
|
|
||||||
static final class TestStartingSurfaceDrawer extends StartingSurfaceDrawer{
|
static final class TestStartingSurfaceDrawer extends StartingSurfaceDrawer{
|
||||||
int mAddWindowForTask = 0;
|
int mAddWindowForTask = 0;
|
||||||
int mViewThemeResId;
|
|
||||||
|
|
||||||
TestStartingSurfaceDrawer(Context context, ShellExecutor splashScreenExecutor,
|
TestStartingSurfaceDrawer(Context context, ShellExecutor splashScreenExecutor,
|
||||||
TransactionPool pool) {
|
TransactionPool pool) {
|
||||||
@@ -113,7 +113,6 @@ public class StartingSurfaceDrawerTests {
|
|||||||
View view, WindowManager wm, WindowManager.LayoutParams params, int suggestType) {
|
View view, WindowManager wm, WindowManager.LayoutParams params, int suggestType) {
|
||||||
// listen for addView
|
// listen for addView
|
||||||
mAddWindowForTask = taskId;
|
mAddWindowForTask = taskId;
|
||||||
mViewThemeResId = view.getContext().getThemeResId();
|
|
||||||
// Do not wait for background color
|
// Do not wait for background color
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -183,12 +182,15 @@ public class StartingSurfaceDrawerTests {
|
|||||||
final int taskId = 1;
|
final int taskId = 1;
|
||||||
final StartingWindowInfo windowInfo =
|
final StartingWindowInfo windowInfo =
|
||||||
createWindowInfo(taskId, 0);
|
createWindowInfo(taskId, 0);
|
||||||
|
final int[] theme = new int[1];
|
||||||
|
doAnswer(invocation -> theme[0] = (Integer) invocation.callRealMethod())
|
||||||
|
.when(mStartingSurfaceDrawer).getSplashScreenTheme(eq(0), any());
|
||||||
|
|
||||||
mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, mBinder,
|
mStartingSurfaceDrawer.addSplashScreenStartingWindow(windowInfo, mBinder,
|
||||||
STARTING_WINDOW_TYPE_SPLASH_SCREEN);
|
STARTING_WINDOW_TYPE_SPLASH_SCREEN);
|
||||||
waitHandlerIdle(mTestHandler);
|
waitHandlerIdle(mTestHandler);
|
||||||
verify(mStartingSurfaceDrawer).addWindow(eq(taskId), eq(mBinder), any(), any(), any(),
|
verify(mStartingSurfaceDrawer).getSplashScreenTheme(eq(0), any());
|
||||||
eq(STARTING_WINDOW_TYPE_SPLASH_SCREEN));
|
assertNotEquals(theme[0], 0);
|
||||||
assertNotEquals(mStartingSurfaceDrawer.mViewThemeResId, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user