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

Commit 930a66d6 authored by Steven Ng's avatar Steven Ng
Browse files

Delay the creation of WallpaperDefaultDisplayInfo in WallpaperController

Issue: DisplayManagerInternal.getPossibleDisplayInfo returns an empty set DisplayInfo during the initialization of WindowManagerService. This results in an empty FoldableOrientations affecting the wallpaper crop logic.

Test: manually print out the FoldableOrientations in WallpaperController#updateWallpaperOffset on a foldable to confirm the set is not empty.
Flag: EXEMPTED bug fix
Bug: 402306483
Change-Id: I162fc97bfd3aefc276e43b5aef1a2497d1134d0b
parent a17f2afa
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -117,8 +117,11 @@ class WallpaperController {
    private boolean mShouldOffsetWallpaperCenter;

    // This is for WallpaperCropper, which has cropping logic for the default display only.
    // This is lazily initialization by getOrCreateDefaultDisplayInfo. DO NOT use this member
    // variable directly.
    // TODO(b/400685784) make the WallpaperCropper operate on every display independently
    private final WallpaperDefaultDisplayInfo mDefaultDisplayInfo;
    @Nullable
    private WallpaperDefaultDisplayInfo mDefaultDisplayInfo = null;

    private final ToBooleanFunction<WindowState> mFindWallpaperTargetFunction = w -> {
        final ActivityRecord ar = w.mActivityRecord;
@@ -202,14 +205,12 @@ class WallpaperController {
    WallpaperController(WindowManagerService service, DisplayContent displayContent) {
        mService = service;
        mDisplayContent = displayContent;
        WindowManager windowManager = service.mContext.getSystemService(WindowManager.class);
        Resources resources = service.mContext.getResources();
        mMinWallpaperScale =
                resources.getFloat(com.android.internal.R.dimen.config_wallpaperMinScale);
        mMaxWallpaperScale = resources.getFloat(R.dimen.config_wallpaperMaxScale);
        mShouldOffsetWallpaperCenter = resources.getBoolean(
                com.android.internal.R.bool.config_offsetWallpaperToCenterOfLargestDisplay);
        mDefaultDisplayInfo = new WallpaperDefaultDisplayInfo(windowManager, resources);
    }

    void resetLargestDisplay(Display display) {
@@ -358,8 +359,8 @@ class WallpaperController {
                    wallpaperWin.mRequestedWidth, wallpaperWin.mRequestedHeight);
            SparseArray<Rect> cropHints = token.getCropHints();
            wallpaperFrame = bitmapSize.x <= 0 || bitmapSize.y <= 0 ? wallpaperWin.getFrame()
                    : WallpaperCropper.getCrop(screenSize, mDefaultDisplayInfo, bitmapSize,
                            cropHints, wallpaperWin.isRtl());
                    : WallpaperCropper.getCrop(screenSize, getOrCreateDefaultDisplayInfo(),
                            bitmapSize, cropHints, wallpaperWin.isRtl());
            int frameWidth = wallpaperFrame.width();
            int frameHeight = wallpaperFrame.height();
            float frameRatio = (float) frameWidth / frameHeight;
@@ -506,6 +507,16 @@ class WallpaperController {
        return changed;
    }

    private WallpaperDefaultDisplayInfo getOrCreateDefaultDisplayInfo() {
        if (mDefaultDisplayInfo != null) {
            return mDefaultDisplayInfo;
        }
        WindowManager windowManager = mService.mContext.getSystemService(WindowManager.class);
        Resources resources = mService.mContext.getResources();
        mDefaultDisplayInfo = new WallpaperDefaultDisplayInfo(windowManager, resources);
        return mDefaultDisplayInfo;
    }

    /**
     * Get an extra offset if needed ({@link #mShouldOffsetWallpaperCenter} = true, typically on
     * multiple display devices) so that the wallpaper in a smaller display ends up centered at the