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

Commit 947b7f49 authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Create and use peekBitmapDimensionsAsUser in ImageWallpaper

Exactly like ImageWallpaper uses WallpaperManager.getBitmapAsUser, it
should specify the userId when peeking the bitmap dimensions. This is
because SystemUI's context.getUserId() returns 0 in HSUM mode, even if
the current user is the user 10, resulting in wrong bitmap dimensions.

This is fixed under flag: without multi-crop, setting an zoomed image on
tablet seems broken regardless of whether this fix is included. Thus, it
felt more logical to include this fix in the multi-crop flag and ignore
the previous version.

Flag: com.android.window.flags.multi_crop
Test: manually verified the HSUM bug
Bug: 358567206
Change-Id: I1e5ca70a0f5331f6bca55baf9c66296531cee5d8
parent 90e48229
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);
    }