Loading services/core/java/com/android/server/wallpaper/WallpaperCropper.java +7 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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); Loading services/core/java/com/android/server/wallpaper/WallpaperDisplayHelper.java +8 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading services/tests/mockingservicestests/src/com/android/server/wallpaper/WallpaperCropperTest.java +18 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(); Loading Loading
services/core/java/com/android/server/wallpaper/WallpaperCropper.java +7 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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); Loading
services/core/java/com/android/server/wallpaper/WallpaperDisplayHelper.java +8 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading
services/tests/mockingservicestests/src/com/android/server/wallpaper/WallpaperCropperTest.java +18 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(); Loading