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

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

Fix B&R for multi crop

The method findNewCropFromOldCrop was not yet used in the multi-crop
case. Use it to adjust every crop. Also modify the method slightly:
 - Make it work when the target device is wider than source device
 - Prefer adding content to the crop rather than removing some, even if
   we need to add more content on one side. In most cases we'd rather
   break symmetry one one axis than removing content (i.e. zooming)

Also, drop the LANDSCAPE crop hint in restore unless the new device has
a large screen (min width > 600 dpi). We don't really care about the
landscape crop except for tablet devices, and keeping it can lead to
difficult to explain behaviours (e.g. it may affect wallpaper position
on connected displays).

Refactor the logic a bit to mock the display and bitmap sizes to make
the crop logic easily testable (Display and DisplayManager are final).
Then, add a couple test cases. There are way too many possible B&R
combinations; so pick 15 that are realistic and cover more or less all
the logic. These tests expect exact matches but are well commented.

Flag: android.app.fix_wallpaper_crops_on_restore
Test: manual
Test: atest WallpaperBackupAgentTest
Bug: 332937943

Change-Id: I224e52d4804ff7cba993e7ceeb4c9af38c0192e0
parent 724367e8
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -55,3 +55,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "fix_wallpaper_crops_on_restore"
  namespace: "systemui"
  description: "Preserve center for wallpaper crops on restore"
  bug: "332937943"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
 No newline at end of file
+252 −88

File changed.

Preview size limit exceeded, changes collapsed.

+531 −29

File changed.

Preview size limit exceeded, changes collapsed.

+10 −2
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.server.wallpaper;

import static android.app.Flags.fixWallpaperCropsOnRestore;
import static android.app.WallpaperManager.ORIENTATION_LANDSCAPE;
import static android.app.WallpaperManager.ORIENTATION_PORTRAIT;
import static android.app.WallpaperManager.ORIENTATION_UNKNOWN;
import static android.app.WallpaperManager.getOrientation;
import static android.app.WallpaperManager.getRotatedOrientation;
@@ -208,13 +210,19 @@ public class WallpaperCropper {
            return res;
        }


        // Case 5: if the device is a foldable, if we're looking for an unfolded orientation and
        // have the suggested crop of the relative folded orientation, reuse it by adding content.
        int foldedOrientation = defaultDisplayInfo.getFoldedOrientation(orientation);
        suggestedCrop = suggestedCrops.get(foldedOrientation);
        // Exception: don't reuse the suggested crop for landscape if a portrait suggested crop
        // exists. In that case we'd rather go to case 6 and use the portrait suggested crop. This
        // is in order to have a consistent wallpaper position on both SQUARE_PORTRAIT and
        // SQUARE_LANDSCAPE orientations.
        boolean skip = fixWallpaperCropsOnRestore()
                && foldedOrientation == ORIENTATION_LANDSCAPE
                && suggestedCrops.contains(ORIENTATION_PORTRAIT);
        suggestedDisplaySize = defaultDisplayInfo.defaultDisplaySizes.get(foldedOrientation);
        if (suggestedCrop != null) {
        if (suggestedCrop != null && !skip) {
            // only keep the visible part (without parallax)
            Rect adjustedCrop = noParallax(suggestedCrop, suggestedDisplaySize, bitmapSize, rtl);
            return getAdjustedCrop(adjustedCrop, bitmapSize, displaySize, false, rtl, ADD);