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

Commit 3b825ec4 authored by Lucas Dupin's avatar Lucas Dupin Committed by Automerger Merge Worker
Browse files

Merge "Dim wallpaper by setting wallpaper layer transparency." into sc-dev am:...

Merge "Dim wallpaper by setting wallpaper layer transparency." into sc-dev am: 76fda9db am: 74d1b5f9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14486205

Change-Id: I3ee0a5d3d851a7af9583122b908dba533a781754
parents 8b161547 74d1b5f9
Loading
Loading
Loading
Loading
+50 −1
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.util.ArraySet;
import android.util.Log;
@@ -155,6 +156,9 @@ public abstract class WallpaperService extends Service {

    private static final int NOTIFY_COLORS_RATE_LIMIT_MS = 1000;

    private static final boolean ENABLE_WALLPAPER_DIMMING =
            SystemProperties.getBoolean("persist.debug.enable_wallpaper_dimming", false);

    private final ArrayList<Engine> mActiveEngines
            = new ArrayList<Engine>();

@@ -202,6 +206,7 @@ public abstract class WallpaperService extends Service {
        boolean mDrawingAllowed;
        boolean mOffsetsChanged;
        boolean mFixedSizeAllowed;
        boolean mShouldDim;
        int mWidth;
        int mHeight;
        int mFormat;
@@ -253,6 +258,7 @@ public abstract class WallpaperService extends Service {
        private Display mDisplay;
        private Context mDisplayContext;
        private int mDisplayState;
        private float mWallpaperDimAmount = 0.05f;

        SurfaceControl mSurfaceControl = new SurfaceControl();
        SurfaceControl mBbqSurfaceControl;
@@ -783,6 +789,42 @@ public abstract class WallpaperService extends Service {
                    throw new RuntimeException(e);
                }
            }
            WallpaperColors primaryColors = mIWallpaperEngine.mWallpaperManager
                    .getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
            setPrimaryWallpaperColors(primaryColors);
        }

        private void setPrimaryWallpaperColors(WallpaperColors colors) {
            if (colors == null) {
                return;
            }
            int colorHints = colors.getColorHints();
            boolean shouldDim = ((colorHints & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) == 0
                    && (colorHints & WallpaperColors.HINT_SUPPORTS_DARK_THEME) == 0);
            if (shouldDim != mShouldDim) {
                mShouldDim = shouldDim;
                updateSurfaceDimming();
                updateSurface(false, false, true);
            }
        }

        private void updateSurfaceDimming() {
            if (!ENABLE_WALLPAPER_DIMMING || mBbqSurfaceControl == null) {
                return;
            }
            // TODO: apply the dimming to preview as well once surface transparency works in
            // preview mode.
            if (!isPreview() && mShouldDim) {
                Log.v(TAG, "Setting wallpaper dimming: " + mWallpaperDimAmount);
                new SurfaceControl.Transaction()
                        .setAlpha(mBbqSurfaceControl, 1 - mWallpaperDimAmount)
                        .apply();
            } else {
                Log.v(TAG, "Setting wallpaper dimming: " + 0);
                new SurfaceControl.Transaction()
                        .setAlpha(mBbqSurfaceControl, 1.0f)
                        .apply();
            }
        }

        /**
@@ -986,6 +1028,7 @@ public abstract class WallpaperService extends Service {
                                    .setParent(mSurfaceControl)
                                    .setCallsite("Wallpaper#relayout")
                                    .build();
                            updateSurfaceDimming();
                        }
                        Surface blastSurface = getOrCreateBLASTSurface(mSurfaceSize.x,
                                mSurfaceSize.y, mFormat);
@@ -1222,6 +1265,8 @@ public abstract class WallpaperService extends Service {
            // Use window context of TYPE_WALLPAPER so client can access UI resources correctly.
            mDisplayContext = createDisplayContext(mDisplay)
                    .createWindowContext(TYPE_WALLPAPER, null /* options */);
            mWallpaperDimAmount = mDisplayContext.getResources().getFloat(
                    com.android.internal.R.dimen.config_wallpaperDimAmount);
            mDisplayState = mDisplay.getState();

            if (DEBUG) Log.v(TAG, "onCreate(): " + this);
@@ -1908,6 +1953,7 @@ public abstract class WallpaperService extends Service {
        final int mDisplayId;
        final DisplayManager mDisplayManager;
        final Display mDisplay;
        final WallpaperManager mWallpaperManager;
        private final AtomicBoolean mDetached = new AtomicBoolean();

        Engine mEngine;
@@ -1916,6 +1962,7 @@ public abstract class WallpaperService extends Service {
                IWallpaperConnection conn, IBinder windowToken,
                int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding,
                int displayId) {
            mWallpaperManager = getSystemService(WallpaperManager.class);
            mCaller = new HandlerCaller(context, context.getMainLooper(), this, true);
            mConnection = conn;
            mWindowToken = windowToken;
@@ -2133,7 +2180,9 @@ public abstract class WallpaperService extends Service {
                        break;
                    }
                    try {
                        mConnection.onWallpaperColorsChanged(mEngine.onComputeColors(), mDisplayId);
                        WallpaperColors colors = mEngine.onComputeColors();
                        mEngine.setPrimaryWallpaperColors(colors);
                        mConnection.onWallpaperColorsChanged(colors, mDisplayId);
                    } catch (RemoteException e) {
                        // Connection went away, nothing to do in here.
                    }
+4 −0
Original line number Diff line number Diff line
@@ -4972,4 +4972,8 @@

    <!-- List containing the allowed install sources for accessibility service. -->
    <string-array name="config_accessibility_allowed_install_source" translatable="false"/>

    <!-- The amount of dimming to apply to wallpapers with mid range luminance. 0 displays
         the wallpaper at full brightness. 1 displays the wallpaper as fully black. -->
    <item name="config_wallpaperDimAmount" format="float" type="dimen">0.05</item>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -4392,4 +4392,6 @@

  <java-symbol type="dimen" name="starting_surface_icon_size" />
  <java-symbol type="dimen" name="starting_surface_default_icon_size" />

  <java-symbol type="dimen" name="config_wallpaperDimAmount" />
</resources>