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

Commit 6184be8d authored by Aaron Knobloch's avatar Aaron Knobloch Committed by Android (Google) Code Review
Browse files

Merge "Add configurable scaling for wallpaper zoom" into main

parents f97c6019 8a71682a
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ import android.app.Service;
import android.app.WallpaperColors;
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Intent;
@@ -194,6 +197,18 @@ public abstract class WallpaperService extends Service {
    // TODO (b/287037772) remove this flag and the forceReport argument in reportVisibility
    private boolean mIsWearOs;

    /**
     * Wear products currently force a slight scaling transition to wallpapers
     * when the QSS is opened. However, on Wear 6 (SDK 35) and above, 1P watch faces
     * will be expected to either implement their own scaling, or to override this
     * method to allow the WallpaperController to continue to scale for them.
     *
     * @hide
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    public static final long WEAROS_WALLPAPER_HANDLES_SCALING = 272527315L;

    static final class WallpaperCommand {
        String action;
        int x;
@@ -601,7 +616,7 @@ public abstract class WallpaperService extends Service {
         * @hide
         */
        public boolean shouldZoomOutWallpaper() {
            return false;
            return mIsWearOs && !CompatChanges.isChangeEnabled(WEAROS_WALLPAPER_HANDLES_SCALING);
        }

        /**
+1 −0
Original line number Diff line number Diff line
@@ -4454,6 +4454,7 @@

  <java-symbol type="string" name="notification_history_title_placeholder" />

  <java-symbol type="dimen" name="config_wallpaperMinScale"/>
  <!-- The max scale for the wallpaper when it's zoomed in -->
  <java-symbol type="dimen" name="config_wallpaperMaxScale"/>

+22 −7
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.view.WindowManager;
import android.view.animation.Animation;
import android.window.ScreenCapture;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.ProtoLogImpl;
import com.android.internal.protolog.common.ProtoLog;
@@ -91,10 +92,12 @@ class WallpaperController {
    private float mLastWallpaperZoomOut = 0;
    private int mLastWallpaperDisplayOffsetX = Integer.MIN_VALUE;
    private int mLastWallpaperDisplayOffsetY = Integer.MIN_VALUE;
    private final float mMaxWallpaperScale;
    // Whether COMMAND_FREEZE was dispatched.
    private boolean mLastFrozen = false;

    private float mMinWallpaperScale;
    private float mMaxWallpaperScale;

    // This is set when we are waiting for a wallpaper to tell us it is done
    // changing its scroll position.
    private WindowState mWaitingOnWallpaper;
@@ -240,14 +243,16 @@ class WallpaperController {
    WallpaperController(WindowManagerService service, DisplayContent displayContent) {
        mService = service;
        mDisplayContent = displayContent;
        mIsLockscreenLiveWallpaperEnabled =
                SystemProperties.getBoolean("persist.wm.debug.lockscreen_live_wallpaper", true);

        Resources resources = service.mContext.getResources();
        mMaxWallpaperScale =
                resources.getFloat(com.android.internal.R.dimen.config_wallpaperMaxScale);
        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);
        mIsLockscreenLiveWallpaperEnabled =
                SystemProperties.getBoolean("persist.wm.debug.lockscreen_live_wallpaper", true);
    }

    void resetLargestDisplay(Display display) {
@@ -256,6 +261,16 @@ class WallpaperController {
        }
    }

    @VisibleForTesting
    void setMinWallpaperScale(float minScale) {
        mMinWallpaperScale = minScale;
    }

    @VisibleForTesting
    void setMaxWallpaperScale(float maxScale) {
        mMaxWallpaperScale = maxScale;
    }

    @VisibleForTesting void setShouldOffsetWallpaperCenter(boolean shouldOffset) {
        mShouldOffsetWallpaperCenter = shouldOffset;
    }
@@ -1010,8 +1025,8 @@ class WallpaperController {
        }
    }

    private float zoomOutToScale(float zoom) {
        return MathUtils.lerp(1, mMaxWallpaperScale, 1 - zoom);
    private float zoomOutToScale(float zoomOut) {
        return MathUtils.lerp(mMinWallpaperScale, mMaxWallpaperScale, 1 - zoomOut);
    }

    void dump(PrintWriter pw, String prefix) {
+18 −13
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ import static org.mockito.Mockito.verify;

import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.IBinder;
import android.os.RemoteException;
@@ -65,9 +64,9 @@ import android.view.WindowManager;

import androidx.test.filters.SmallTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.AdditionalMatchers;

import java.util.List;

@@ -85,14 +84,6 @@ public class WallpaperControllerTests extends WindowTestsBase {
    private static final int INITIAL_HEIGHT = 900;
    private static final int SECOND_WIDTH = 300;

    @Before
    public void setup() {
        Resources resources = mWm.mContext.getResources();
        spyOn(resources);
        doReturn(false).when(resources).getBoolean(
                com.android.internal.R.bool.config_offsetWallpaperToCenterOfLargestDisplay);
    }

    @Test
    public void testWallpaperScreenshot() {
        WindowSurfaceController windowSurfaceController = mock(WindowSurfaceController.class);
@@ -190,16 +181,24 @@ public class WallpaperControllerTests extends WindowTestsBase {

        spyOn(dc.mWallpaperController);
        doReturn(true).when(dc.mWallpaperController).isWallpaperVisible();

        dc.mWallpaperController.setMinWallpaperScale(.6f);
        dc.mWallpaperController.setMaxWallpaperScale(1.2f);
        dc.mWallpaperController.adjustWallpaperWindows();

        spyOn(wallpaperWindow);
        spyOn(wallpaperWindow.mClient);

        float zoom = .5f;
        float zoomScale = .9f;
        wallpaperWindow.mShouldScaleWallpaper = true;

        dc.mWallpaperController.setWallpaperZoomOut(homeWindow, zoom);
        assertEquals(zoom, wallpaperWindow.mWallpaperZoomOut, .01f);
        verify(wallpaperWindow.mClient).dispatchWallpaperOffsets(anyFloat(), anyFloat(), anyFloat(),
                anyFloat(), eq(zoom), anyBoolean());
        verify(wallpaperWindow.mClient)
                .dispatchWallpaperOffsets(
                        anyFloat(), anyFloat(), anyFloat(), anyFloat(), eq(zoom), anyBoolean());
        verify(wallpaperWindow)
                .setWallpaperOffset(anyInt(), anyInt(), AdditionalMatchers.eq(zoomScale, .01f));
    }

    @Test
@@ -213,9 +212,12 @@ public class WallpaperControllerTests extends WindowTestsBase {

        spyOn(dc.mWallpaperController);
        doReturn(true).when(dc.mWallpaperController).isWallpaperVisible();
        dc.mWallpaperController.setMinWallpaperScale(.6f);
        dc.mWallpaperController.setMaxWallpaperScale(1.2f);

        dc.mWallpaperController.adjustWallpaperWindows();

        spyOn(wallpaperWindow);
        spyOn(wallpaperWindow.mClient);

        float newZoom = .5f;
@@ -227,6 +229,9 @@ public class WallpaperControllerTests extends WindowTestsBase {
        assertEquals(1f, wallpaperWindow.mWallpaperScale, .01f);
        verify(wallpaperWindow.mClient).dispatchWallpaperOffsets(anyFloat(), anyFloat(), anyFloat(),
                anyFloat(), eq(newZoom), anyBoolean());
        // As the expected scale is .9 with a zoom of .5f and min and max scale of .6 and 1.2,
        // if it's passing a scale of 1 it's not scaling the wallpaper.
        verify(wallpaperWindow).setWallpaperOffset(anyInt(), anyInt(), eq(1f));
    }

    @Test