diff options
3 files changed, 29 insertions, 0 deletions
diff --git a/core/java/com/android/internal/policy/DecorView.java b/core/java/com/android/internal/policy/DecorView.java index 480ff4d528f0..599c354f0a1a 100644 --- a/core/java/com/android/internal/policy/DecorView.java +++ b/core/java/com/android/internal/policy/DecorView.java @@ -249,6 +249,14 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind private Drawable mOriginalBackgroundDrawable; private Drawable mLastOriginalBackgroundDrawable; private Drawable mResizingBackgroundDrawable; + + /** + * Temporary holder for a window background when it is set before {@link #mWindow} is + * initialized. It will be set as the actual background once {@link #setWindow(PhoneWindow)} is + * called. + */ + @Nullable + private Drawable mPendingWindowBackground; private Drawable mCaptionBackgroundDrawable; private Drawable mUserCaptionBackgroundDrawable; @@ -961,6 +969,10 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind } public void setWindowBackground(Drawable drawable) { + if (mWindow == null) { + mPendingWindowBackground = drawable; + return; + } if (mOriginalBackgroundDrawable != drawable) { mOriginalBackgroundDrawable = drawable; updateBackgroundDrawable(); @@ -2003,6 +2015,11 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind DecorContext decorContext = (DecorContext) context; decorContext.setPhoneWindow(mWindow); } + if (mPendingWindowBackground != null) { + Drawable background = mPendingWindowBackground; + mPendingWindowBackground = null; + setWindowBackground(background); + } } @Override diff --git a/core/tests/coretests/res/values/styles.xml b/core/tests/coretests/res/values/styles.xml index dbc46265a96f..0bf4b9278446 100644 --- a/core/tests/coretests/res/values/styles.xml +++ b/core/tests/coretests/res/values/styles.xml @@ -39,4 +39,7 @@ <item name="android:colorBackground">@null</item> <item name="android:windowBackgroundFallback">#0000FF</item> </style> + <style name="ViewDefaultBackground"> + <item name="android:background">#00000000</item> + </style> </resources> diff --git a/core/tests/coretests/src/com/android/internal/policy/DecorViewTest.java b/core/tests/coretests/src/com/android/internal/policy/DecorViewTest.java index f66717e9066c..62e4efe7a543 100644 --- a/core/tests/coretests/src/com/android/internal/policy/DecorViewTest.java +++ b/core/tests/coretests/src/com/android/internal/policy/DecorViewTest.java @@ -76,4 +76,13 @@ public class DecorViewTest { expectedBitmap.getPixels(expPixels, 0, w, 0, 0, w, h); assertThat(Arrays.toString(expPixels)).isEqualTo(Arrays.toString(resPixels)); } + + @Test + public void setBackgroundWithNoWindow() { + PhoneWindow phoneWindow = new PhoneWindow(mContext); + // Set a theme that defines a non-null value for android:background + mContext.setTheme(R.style.ViewDefaultBackground); + DecorView decorView = (DecorView) phoneWindow.getDecorView(); + assertThat(decorView.getBackground()).isNotNull(); + } } |