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

Commit 56c68bc2 authored by Nader Jawad's avatar Nader Jawad
Browse files

Fixed issue where color attributes used for window background Activity

themes would not be applied

Updated windowBackground attribute in attrs.xml to take either a
reference or a color parameter. Updated PhoneWindow to consume the
drawable defined from the TypedArray. Added test to PhoneWindowTest to
handle verifying if a theme has a background color defined that it is
applied properly.

Fixes: 70268864
Test: Re-ran core tests on PhoneWindowTest with an updated test to
verify color literals are applied properly

Change-Id: I77083d5ee366ca0236633ac7039d2a5acf127fe7
parent bccd1711
Loading
Loading
Loading
Loading
+19 −20
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.internal.policy;
package com.android.internal.policy;


import android.annotation.Nullable;
import android.annotation.TestApi;
import android.app.WindowConfiguration;
import android.app.WindowConfiguration;
import android.graphics.Outline;
import android.graphics.Outline;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.InsetDrawable;
@@ -41,7 +43,6 @@ import java.util.List;
import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ObjectAnimator;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources;
@@ -55,7 +56,6 @@ import android.graphics.Region;
import android.graphics.Shader;
import android.graphics.Shader;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Log;
import android.util.TypedValue;
import android.util.TypedValue;
@@ -281,11 +281,16 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
        initResizingPaints();
        initResizingPaints();
    }
    }


    void setBackgroundFallback(int resId) {
    void setBackgroundFallback(@Nullable Drawable fallbackDrawable) {
        mBackgroundFallback.setDrawable(resId != 0 ? getContext().getDrawable(resId) : null);
        mBackgroundFallback.setDrawable(fallbackDrawable);
        setWillNotDraw(getBackground() == null && !mBackgroundFallback.hasFallback());
        setWillNotDraw(getBackground() == null && !mBackgroundFallback.hasFallback());
    }
    }


    @TestApi
    public @Nullable Drawable getBackgroundFallback() {
        return mBackgroundFallback.getDrawable();
    }

    @Override
    @Override
    public boolean gatherTransparentRegion(Region region) {
    public boolean gatherTransparentRegion(Region region) {
        boolean statusOpaque = gatherTransparentRegion(mStatusColorViewState, region);
        boolean statusOpaque = gatherTransparentRegion(mStatusColorViewState, region);
@@ -946,7 +951,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
                        mWindow.isTranslucent() || mWindow.isShowingWallpaper());
                        mWindow.isTranslucent() || mWindow.isShowingWallpaper());
            } else {
            } else {
                mResizingBackgroundDrawable = getResizingBackgroundDrawable(
                mResizingBackgroundDrawable = getResizingBackgroundDrawable(
                        getContext(), 0, mWindow.mBackgroundFallbackResource,
                        mWindow.mBackgroundDrawable, mWindow.mBackgroundFallbackDrawable,
                        mWindow.isTranslucent() || mWindow.isShowingWallpaper());
                        mWindow.isTranslucent() || mWindow.isShowingWallpaper());
            }
            }
            if (mResizingBackgroundDrawable != null) {
            if (mResizingBackgroundDrawable != null) {
@@ -1901,9 +1906,9 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind


    private void loadBackgroundDrawablesIfNeeded() {
    private void loadBackgroundDrawablesIfNeeded() {
        if (mResizingBackgroundDrawable == null) {
        if (mResizingBackgroundDrawable == null) {
            mResizingBackgroundDrawable = getResizingBackgroundDrawable(getContext(),
            mResizingBackgroundDrawable = getResizingBackgroundDrawable(mWindow.mBackgroundDrawable,
                    mWindow.mBackgroundResource, mWindow.mBackgroundFallbackResource,
                    mWindow.mBackgroundFallbackDrawable, mWindow.isTranslucent()
                    mWindow.isTranslucent() || mWindow.isShowingWallpaper());
                    || mWindow.isShowingWallpaper());
            if (mResizingBackgroundDrawable == null) {
            if (mResizingBackgroundDrawable == null) {
                // We shouldn't really get here as the background fallback should be always
                // We shouldn't really get here as the background fallback should be always
                // available since it is defaulted by the system.
                // available since it is defaulted by the system.
@@ -2011,21 +2016,15 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
     * Returns the color used to fill areas the app has not rendered content to yet when the
     * Returns the color used to fill areas the app has not rendered content to yet when the
     * user is resizing the window of an activity in multi-window mode.
     * user is resizing the window of an activity in multi-window mode.
     */
     */
    public static Drawable getResizingBackgroundDrawable(Context context, int backgroundRes,
    public static Drawable getResizingBackgroundDrawable(@Nullable Drawable backgroundDrawable,
            int backgroundFallbackRes, boolean windowTranslucent) {
            @Nullable Drawable fallbackDrawable, boolean windowTranslucent) {
        if (backgroundRes != 0) {
        if (backgroundDrawable != null) {
            final Drawable drawable = context.getDrawable(backgroundRes);
            return enforceNonTranslucentBackground(backgroundDrawable, windowTranslucent);
            if (drawable != null) {
                return enforceNonTranslucentBackground(drawable, windowTranslucent);
            }
        }
        }


        if (backgroundFallbackRes != 0) {
            final Drawable fallbackDrawable = context.getDrawable(backgroundFallbackRes);
        if (fallbackDrawable != null) {
        if (fallbackDrawable != null) {
            return enforceNonTranslucentBackground(fallbackDrawable, windowTranslucent);
            return enforceNonTranslucentBackground(fallbackDrawable, windowTranslucent);
        }
        }
        }
        return new ColorDrawable(Color.BLACK);
        return new ColorDrawable(Color.BLACK);
    }
    }


+19 −28
Original line number Original line Diff line number Diff line
@@ -217,10 +217,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {


    private ProgressBar mHorizontalProgressBar;
    private ProgressBar mHorizontalProgressBar;


    int mBackgroundResource = 0;
    Drawable mBackgroundDrawable = null;
    int mBackgroundFallbackResource = 0;
    Drawable mBackgroundFallbackDrawable = null;

    private Drawable mBackgroundDrawable;


    private boolean mLoadElevation = true;
    private boolean mLoadElevation = true;
    private float mElevation;
    private float mElevation;
@@ -1470,14 +1468,14 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {


    @Override
    @Override
    public final void setBackgroundDrawable(Drawable drawable) {
    public final void setBackgroundDrawable(Drawable drawable) {
        if (drawable != mBackgroundDrawable || mBackgroundResource != 0) {
        if (drawable != mBackgroundDrawable) {
            mBackgroundResource = 0;
            mBackgroundDrawable = drawable;
            mBackgroundDrawable = drawable;
            if (mDecor != null) {
            if (mDecor != null) {
                mDecor.setWindowBackground(drawable);
                mDecor.setWindowBackground(drawable);
                if (mBackgroundFallbackDrawable != null) {
                    mDecor.setBackgroundFallback(drawable != null ? null :
                            mBackgroundFallbackDrawable);
                }
                }
            if (mBackgroundFallbackResource != 0) {
                mDecor.setBackgroundFallback(drawable != null ? 0 : mBackgroundFallbackResource);
            }
            }
        }
        }
    }
    }
@@ -2510,19 +2508,18 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        // the values are inherited from our container.
        // the values are inherited from our container.
        if (getContainer() == null) {
        if (getContainer() == null) {
            if (mBackgroundDrawable == null) {
            if (mBackgroundDrawable == null) {
                if (mBackgroundResource == 0) {

                    mBackgroundResource = a.getResourceId(
                            R.styleable.Window_windowBackground, 0);
                }
                if (mFrameResource == 0) {
                if (mFrameResource == 0) {
                    mFrameResource = a.getResourceId(R.styleable.Window_windowFrame, 0);
                    mFrameResource = a.getResourceId(R.styleable.Window_windowFrame, 0);
                }
                }
                mBackgroundFallbackResource = a.getResourceId(

                        R.styleable.Window_windowBackgroundFallback, 0);
                if (a.hasValue(R.styleable.Window_windowBackground)) {
                if (false) {
                    mBackgroundDrawable = a.getDrawable(R.styleable.Window_windowBackground);
                    System.out.println("Background: "
                }
                            + Integer.toHexString(mBackgroundResource) + " Frame: "

                            + Integer.toHexString(mFrameResource));
                if (a.hasValue(R.styleable.Window_windowBackgroundFallback)) {
                    mBackgroundFallbackDrawable =
                            a.getDrawable(R.styleable.Window_windowBackgroundFallback);
                }
                }
            }
            }
            if (mLoadElevation) {
            if (mLoadElevation) {
@@ -2617,13 +2614,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        // Remaining setup -- of background and title -- that only applies
        // Remaining setup -- of background and title -- that only applies
        // to top-level windows.
        // to top-level windows.
        if (getContainer() == null) {
        if (getContainer() == null) {
            final Drawable background;
            mDecor.setWindowBackground(mBackgroundDrawable);
            if (mBackgroundResource != 0) {
                background = getContext().getDrawable(mBackgroundResource);
            } else {
                background = mBackgroundDrawable;
            }
            mDecor.setWindowBackground(background);


            final Drawable frame;
            final Drawable frame;
            if (mFrameResource != 0) {
            if (mFrameResource != 0) {
@@ -2733,8 +2724,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                }
                }
            }
            }


            if (mDecor.getBackground() == null && mBackgroundFallbackResource != 0) {
            if (mDecor.getBackground() == null && mBackgroundFallbackDrawable != null) {
                mDecor.setBackgroundFallback(mBackgroundFallbackResource);
                mDecor.setBackgroundFallback(mBackgroundFallbackDrawable);
            }
            }


            // Only inflate or create a new TransitionManager if the caller hasn't
            // Only inflate or create a new TransitionManager if the caller hasn't
+5 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@


package com.android.internal.widget;
package com.android.internal.widget;


import android.annotation.Nullable;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
@@ -35,6 +36,10 @@ public class BackgroundFallback {
        mBackgroundFallback = d;
        mBackgroundFallback = d;
    }
    }


    public @Nullable Drawable getDrawable() {
        return mBackgroundFallback;
    }

    public boolean hasFallback() {
    public boolean hasFallback() {
        return mBackgroundFallback != null;
        return mBackgroundFallback != null;
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -339,13 +339,13 @@
                  then in code manually set your window's background to
                  then in code manually set your window's background to
                  null so it will not be drawn.
                  null so it will not be drawn.
             </ul> -->
             </ul> -->
        <attr name="windowBackground" format="reference" />
        <attr name="windowBackground" format="reference|color" />
        <!-- Drawable to draw selectively within the inset areas when the windowBackground
        <!-- Drawable to draw selectively within the inset areas when the windowBackground
             has been set to null. This protects against seeing visual garbage in the
             has been set to null. This protects against seeing visual garbage in the
             surface when the app has not drawn any content into this area. One example is
             surface when the app has not drawn any content into this area. One example is
             when the user is resizing a window of an activity that has
             when the user is resizing a window of an activity that has
             {@link android.R.attr#resizeableActivity} set for multi-window mode. -->
             {@link android.R.attr#resizeableActivity} set for multi-window mode. -->
        <attr name="windowBackgroundFallback" format="reference" />
        <attr name="windowBackgroundFallback" format="reference|color" />
        <!-- Drawable to use as a frame around the window. -->
        <!-- Drawable to use as a frame around the window. -->
        <attr name="windowFrame" format="reference" />
        <attr name="windowFrame" format="reference" />
        <!-- Flag indicating whether there should be no title on this window. -->
        <!-- Flag indicating whether there should be no title on this window. -->
+8 −0
Original line number Original line Diff line number Diff line
@@ -31,4 +31,12 @@
    <style name="LayoutInDisplayCutoutModeNever">
    <style name="LayoutInDisplayCutoutModeNever">
        <item name="android:windowLayoutInDisplayCutoutMode">never</item>
        <item name="android:windowLayoutInDisplayCutoutMode">never</item>
    </style>
    </style>
    <style name="WindowBackgroundColorLiteral">
        <item name="android:windowBackground">#00FF00</item>
    </style>
    <style name="WindowBackgroundFallbackColorLiteral">
        <item name="android:windowBackground">@null</item>
        <item name="android:colorBackground">@null</item>
        <item name="android:windowBackgroundFallback">#0000FF</item>
    </style>
</resources>
</resources>
Loading