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

Commit b7df50aa authored by Steven Ng's avatar Steven Ng Committed by Android (Google) Code Review
Browse files

Merge "Make WallpaperDisplayHelper#getDisplayInfo returns nullable DisplayInfo" into main

parents f54fcb71 8b214d0e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -476,6 +476,9 @@ public class WallpaperCropper {
        final WallpaperDisplayHelper.DisplayData wpData =
                mWallpaperDisplayHelper.getDisplayDataOrCreate(DEFAULT_DISPLAY);
        final DisplayInfo displayInfo = mWallpaperDisplayHelper.getDisplayInfo(DEFAULT_DISPLAY);
        if (displayInfo == null) {
            Slog.w(TAG, "Null display info for the default display");
        }

        // Analyse the source; needed in multiple cases
        BitmapFactory.Options options = new BitmapFactory.Options();
@@ -844,6 +847,10 @@ public class WallpaperCropper {
        }

        DisplayInfo displayInfo = mWallpaperDisplayHelper.getDisplayInfo(displayId);
        if (displayInfo == null) {
            Slog.w(TAG, "Null display. Wallpaper unsupported for display " + displayId);
            return false;
        }
        Point displaySize = new Point(displayInfo.logicalWidth, displayInfo.logicalHeight);
        int displayOrientation = WallpaperManager.getOrientation(displaySize);

+8 −1
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.view.Display;
import android.view.DisplayInfo;
import android.view.WindowManager;

import androidx.annotation.Nullable;

import com.android.server.wm.WindowManagerInternal;

import java.util.function.Consumer;
@@ -125,9 +127,14 @@ class WallpaperDisplayHelper {
        return mDisplayManager.getDisplays();
    }

    @Nullable
    DisplayInfo getDisplayInfo(int displayId) {
        final DisplayInfo displayInfo = new DisplayInfo();
        mDisplayManager.getDisplay(displayId).getDisplayInfo(displayInfo);
        Display display = mDisplayManager.getDisplay(displayId);
        if (display == null) {
            return null;
        }
        display.getDisplayInfo(displayInfo);
        return displayInfo;
    }

+18 −1
Original line number Diff line number Diff line
@@ -759,6 +759,23 @@ public class WallpaperCropperTest {
                displayId, wallpaperData)).isTrue();
    }

    // Test isWallpaperCompatibleForDisplay always return false if the display info is null.
    @Test
    public void isWallpaperCompatibleForDisplay_nullDisplayInfo_returnFalse()
            throws Exception {
        final int displayId = 2;
        DisplayInfo displayInfo = new DisplayInfo();
        displayInfo.logicalWidth = 2560;
        displayInfo.logicalHeight = 1044;
        setUpWithDisplays(List.of(new Point(displayInfo.logicalWidth, displayInfo.logicalHeight)));
        doReturn(null).when(mWallpaperDisplayHelper).getDisplayInfo(eq(displayId));
        WallpaperData wallpaperData = createWallpaperData(/* isStockWallpaper = */ false,
                new Point(100, 100));

        assertThat(new WallpaperCropper(mWallpaperDisplayHelper).isWallpaperCompatibleForDisplay(
                displayId, wallpaperData)).isFalse();
    }

    // Test isWallpaperCompatibleForDisplay wallpaper is suitable for the display and wallpaper
    // aspect ratio meets the hard-coded aspect ratio.
    @Test
@@ -807,7 +824,7 @@ public class WallpaperCropperTest {
        setUpWithDisplays(List.of(new Point(displayInfo.logicalWidth, displayInfo.logicalHeight)));
        doReturn(displayInfo).when(mWallpaperDisplayHelper).getDisplayInfo(eq(displayId));
        WallpaperData wallpaperData = createWallpaperData(/* isStockWallpaper = */ false,
                new Point(2000, 800));
                new Point(1500, 800));

        assertThat(new WallpaperCropper(mWallpaperDisplayHelper).isWallpaperCompatibleForDisplay(
                displayId, wallpaperData)).isFalse();