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

Commit 7053f3cf authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Create and use peekBitmapDimensionsAsUser in ImageWallpaper" into main

parents efc0ca9c 947b7f49
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -1571,11 +1571,28 @@ public class WallpaperManager {
     */
    @Nullable
    public Rect peekBitmapDimensions(@SetWallpaperFlags int which, boolean returnDefault) {
        if (multiCrop()) {
            return peekBitmapDimensionsAsUser(which, returnDefault, mContext.getUserId());
        }
        checkExactlyOneWallpaperFlagSet(which);
        return sGlobals.peekWallpaperDimensions(mContext, returnDefault, which,
                mContext.getUserId());
    }

    /**
     * Overload of {@link #peekBitmapDimensions(int, boolean)} with a userId argument.
     * TODO(b/360120606): remove the SuppressWarnings
     * @hide
     */
    @SuppressWarnings("AndroidFrameworkContextUserId")
    @FlaggedApi(FLAG_MULTI_CROP)
    @Nullable
    public Rect peekBitmapDimensionsAsUser(@SetWallpaperFlags int which, boolean returnDefault,
            int userId) {
        checkExactlyOneWallpaperFlagSet(which);
        return sGlobals.peekWallpaperDimensions(mContext, returnDefault, which, userId);
    }

    /**
     * For the current user, given a list of display sizes, return a list of rectangles representing
     * the area of the current wallpaper that would be shown for each of these sizes.
+5 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.WallpaperManager.FLAG_SYSTEM;
import static android.app.WallpaperManager.SetWallpaperFlags;

import static com.android.systemui.Flags.fixImageWallpaperCrashSurfaceAlreadyReleased;
import static com.android.window.flags.Flags.multiCrop;
import static com.android.window.flags.Flags.offloadColorExtraction;

import android.annotation.Nullable;
@@ -190,7 +191,10 @@ public class ImageWallpaper extends WallpaperService {
            }
            mWallpaperManager = getDisplayContext().getSystemService(WallpaperManager.class);
            mSurfaceHolder = surfaceHolder;
            Rect dimensions = mWallpaperManager.peekBitmapDimensions(getSourceFlag(), true);
            Rect dimensions = !multiCrop()
                    ? mWallpaperManager.peekBitmapDimensions(getSourceFlag(), true)
                    : mWallpaperManager.peekBitmapDimensionsAsUser(getSourceFlag(), true,
                    mUserTracker.getUserId());
            int width = Math.max(MIN_SURFACE_WIDTH, dimensions.width());
            int height = Math.max(MIN_SURFACE_HEIGHT, dimensions.height());
            mSurfaceHolder.setFixedSize(width, height);
+3 −0
Original line number Diff line number Diff line
@@ -223,8 +223,11 @@ public class ImageWallpaperTest extends SysuiTestCase {
    }

    private void setBitmapDimensions(int bitmapWidth, int bitmapHeight) {
        // TODO(b/281648899) remove the when(mWallpaperManager.peekBitmapDimensions(...))
        when(mWallpaperManager.peekBitmapDimensions(anyInt(), anyBoolean()))
                .thenReturn(new Rect(0, 0, bitmapWidth, bitmapHeight));
        when(mWallpaperManager.peekBitmapDimensionsAsUser(anyInt(), anyBoolean(), anyInt()))
                .thenReturn(new Rect(0, 0, bitmapWidth, bitmapHeight));
        when(mWallpaperBitmap.getWidth()).thenReturn(bitmapWidth);
        when(mWallpaperBitmap.getHeight()).thenReturn(bitmapHeight);
    }