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

Commit b77a2fbe authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Adapt ImageWallpaper to support lockscreen"

parents d40bd156 732de917
Loading
Loading
Loading
Loading
+34 −7
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package com.android.systemui.wallpapers;

import static android.app.WallpaperManager.FLAG_LOCK;
import static android.app.WallpaperManager.FLAG_SYSTEM;
import static android.app.WallpaperManager.SetWallpaperFlags;

import android.app.WallpaperColors;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
@@ -165,7 +169,9 @@ public class ImageWallpaper extends WallpaperService {
            }
            mWallpaperManager = getDisplayContext().getSystemService(WallpaperManager.class);
            mSurfaceHolder = surfaceHolder;
            Rect dimensions = mWallpaperManager.peekBitmapDimensions();
            Rect dimensions = mWallpaperManager.isLockscreenLiveWallpaperEnabled()
                    ? mWallpaperManager.peekBitmapDimensions(getSourceFlag())
                    : mWallpaperManager.peekBitmapDimensions();
            int width = Math.max(MIN_SURFACE_WIDTH, dimensions.width());
            int height = Math.max(MIN_SURFACE_HEIGHT, dimensions.height());
            mSurfaceHolder.setFixedSize(width, height);
@@ -314,7 +320,10 @@ public class ImageWallpaper extends WallpaperService {
            boolean loadSuccess = false;
            Bitmap bitmap;
            try {
                bitmap = mWallpaperManager.getBitmapAsUser(mUserTracker.getUserId(), false);
                bitmap = mWallpaperManager.isLockscreenLiveWallpaperEnabled()
                        ? mWallpaperManager.getBitmapAsUser(
                                mUserTracker.getUserId(), false, getSourceFlag())
                        : mWallpaperManager.getBitmapAsUser(mUserTracker.getUserId(), false);
                if (bitmap != null
                        && bitmap.getByteCount() > RecordingCanvas.MAX_BITMAP_SIZE) {
                    throw new RuntimeException("Wallpaper is too large to draw!");
@@ -325,10 +334,18 @@ public class ImageWallpaper extends WallpaperService {
                // be loaded, we will go into a cycle. Don't do a build where the
                // default wallpaper can't be loaded.
                Log.w(TAG, "Unable to load wallpaper!", exception);
                if (mWallpaperManager.isLockscreenLiveWallpaperEnabled()) {
                    mWallpaperManager.clearWallpaper(getWallpaperFlags(), mUserTracker.getUserId());
                } else {
                    mWallpaperManager.clearWallpaper(
                            WallpaperManager.FLAG_SYSTEM, mUserTracker.getUserId());
                }

                try {
                    bitmap = mWallpaperManager.getBitmapAsUser(mUserTracker.getUserId(), false);
                    bitmap = mWallpaperManager.isLockscreenLiveWallpaperEnabled()
                            ? mWallpaperManager.getBitmapAsUser(
                                    mUserTracker.getUserId(), false, getSourceFlag())
                            : mWallpaperManager.getBitmapAsUser(mUserTracker.getUserId(), false);
                } catch (RuntimeException | OutOfMemoryError e) {
                    Log.w(TAG, "Unable to load default wallpaper!", e);
                    bitmap = null;
@@ -349,8 +366,9 @@ public class ImageWallpaper extends WallpaperService {
                    mBitmap.recycle();
                }
                mBitmap = bitmap;
                mWideColorGamut = mWallpaperManager.wallpaperSupportsWcg(
                        WallpaperManager.FLAG_SYSTEM);
                mWideColorGamut = mWallpaperManager.isLockscreenLiveWallpaperEnabled()
                        ? mWallpaperManager.wallpaperSupportsWcg(getSourceFlag())
                        : mWallpaperManager.wallpaperSupportsWcg(WallpaperManager.FLAG_SYSTEM);

                // +2 usages for the color extraction and the delayed unload.
                mBitmapUsages += 2;
@@ -379,6 +397,15 @@ public class ImageWallpaper extends WallpaperService {
            }
        }

        /**
         * Helper to return the flag from where the source bitmap is from.
         * Similar to {@link #getWallpaperFlags()}, but returns (FLAG_SYSTEM) instead of
         * (FLAG_LOCK | FLAG_SYSTEM) if this engine is used for both lock screen & home screen.
         */
        private @SetWallpaperFlags int getSourceFlag() {
            return getWallpaperFlags() == FLAG_LOCK ? FLAG_LOCK : FLAG_SYSTEM;
        }

        @VisibleForTesting
        void recomputeColorExtractorMiniBitmap() {
            mWallpaperLocalColorExtractor.onBitmapChanged(mBitmap);