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

Commit e1e51762 authored by Chris Poultney's avatar Chris Poultney Committed by Automerger Merge Worker
Browse files

Merge "Fixes lives wallpaper preview and colors not updating after setting"...

Merge "Fixes lives wallpaper preview and colors not updating after setting" into udc-dev am: 8e1a7a94 am: 48638f85

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23217402



Change-Id: I581620ac06bb2aec6d6b8bd54738ed09b33c9cf2
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d87edb7a 48638f85
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -3031,9 +3031,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            }
        }

        final boolean fromForegroundApp = Binder.withCleanCallingIdentity(() ->
                mActivityManager.getPackageImportance(callingPackage) == IMPORTANCE_FOREGROUND);

        synchronized (mLock) {
            if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which));
            WallpaperData wallpaper;
@@ -3066,7 +3063,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                    wallpaper.mSystemWasBoth = systemIsBoth;
                    wallpaper.mWhich = which;
                    wallpaper.setComplete = completion;
                    wallpaper.fromForegroundApp = fromForegroundApp;
                    wallpaper.fromForegroundApp = isFromForegroundApp(callingPackage);
                    wallpaper.cropHint.set(cropHint);
                    wallpaper.allowBackup = allowBackup;
                    wallpaper.mWallpaperDimAmount = getWallpaperDimAmount();
@@ -3153,27 +3150,28 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            @SetWallpaperFlags int which, int userId) {

        if (isWallpaperSupported(callingPackage) && isSetWallpaperAllowed(callingPackage)) {
            setWallpaperComponent(name, which, userId);
            setWallpaperComponent(name, callingPackage, which, userId);
        }
    }

    // ToDo: Remove this version of the function
    @Override
    public void setWallpaperComponent(ComponentName name) {
        setWallpaperComponent(name, UserHandle.getCallingUserId(), FLAG_SYSTEM);
        setWallpaperComponent(name, "", UserHandle.getCallingUserId(), FLAG_SYSTEM);
    }

    @VisibleForTesting
    void setWallpaperComponent(ComponentName name, @SetWallpaperFlags int which, int userId) {
    void setWallpaperComponent(ComponentName name, String callingPackage,
            @SetWallpaperFlags int which, int userId) {
        if (mIsLockscreenLiveWallpaperEnabled) {
            setWallpaperComponentInternal(name, which, userId);
            setWallpaperComponentInternal(name, callingPackage, which, userId);
        } else {
            setWallpaperComponentInternalLegacy(name, which, userId);
            setWallpaperComponentInternalLegacy(name, callingPackage, which, userId);
        }
    }

    private void setWallpaperComponentInternal(ComponentName name, @SetWallpaperFlags int which,
            int userIdIn) {
    private void setWallpaperComponentInternal(ComponentName name, String callingPackage,
            @SetWallpaperFlags int which, int userIdIn) {
        if (DEBUG) {
            Slog.v(TAG, "Setting new live wallpaper: which=" + which + ", component: " + name);
        }
@@ -3209,6 +3207,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                newWallpaper.imageWallpaperPending = false;
                newWallpaper.mWhich = which;
                newWallpaper.mSystemWasBoth = systemIsBoth;
                newWallpaper.fromForegroundApp = isFromForegroundApp(callingPackage);
                final WallpaperDestinationChangeHandler
                        liveSync = new WallpaperDestinationChangeHandler(
                        newWallpaper);
@@ -3280,7 +3279,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
    }

    // TODO(b/266818039) Remove this method
    private void setWallpaperComponentInternalLegacy(ComponentName name,
    private void setWallpaperComponentInternalLegacy(ComponentName name, String callingPackage,
            @SetWallpaperFlags int which, int userId) {
        userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId,
                false /* all */, true /* full */, "changing live wallpaper", null /* pkg */);
@@ -3320,6 +3319,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            try {
                wallpaper.imageWallpaperPending = false;
                wallpaper.mWhich = which;
                wallpaper.fromForegroundApp = isFromForegroundApp(callingPackage);
                boolean same = changingToSame(name, wallpaper);
                if (bindWallpaperComponentLocked(name, false, true, wallpaper, null)) {
                    if (!same) {
@@ -3679,6 +3679,11 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        }
    }

    private boolean isFromForegroundApp(String callingPackage) {
        return Binder.withCleanCallingIdentity(() ->
                mActivityManager.getPackageImportance(callingPackage) == IMPORTANCE_FOREGROUND);
    }

    /**
     * Certain user types do not support wallpapers (e.g. managed profiles). The check is
     * implemented through through the OP_WRITE_WALLPAPER AppOp.
+6 −3
Original line number Diff line number Diff line
@@ -292,7 +292,8 @@ public class WallpaperManagerServiceTests {
        verifyLastWallpaperData(testUserId, sDefaultWallpaperComponent);
        verifyCurrentSystemData(testUserId);

        mService.setWallpaperComponent(sImageWallpaperComponentName, FLAG_SYSTEM, testUserId);
        mService.setWallpaperComponent(sImageWallpaperComponentName, sContext.getOpPackageName(),
                FLAG_SYSTEM, testUserId);
        verifyLastWallpaperData(testUserId, sImageWallpaperComponentName);
        verifyCurrentSystemData(testUserId);

@@ -321,7 +322,8 @@ public class WallpaperManagerServiceTests {

        WallpaperManagerService.DisplayConnector connector =
                mService.mLastWallpaper.connection.getDisplayConnectorOrCreate(DEFAULT_DISPLAY);
        mService.setWallpaperComponent(sDefaultWallpaperComponent, FLAG_SYSTEM, testUserId);
        mService.setWallpaperComponent(sDefaultWallpaperComponent, sContext.getOpPackageName(),
                FLAG_SYSTEM, testUserId);

        verify(connector.mEngine).dispatchWallpaperCommand(
                eq(COMMAND_REAPPLY), anyInt(), anyInt(), anyInt(), any());
@@ -465,7 +467,8 @@ public class WallpaperManagerServiceTests {
    public void testGetAdjustedWallpaperColorsOnDimming() throws RemoteException {
        final int testUserId = USER_SYSTEM;
        mService.switchUser(testUserId, null);
        mService.setWallpaperComponent(sDefaultWallpaperComponent, FLAG_SYSTEM, testUserId);
        mService.setWallpaperComponent(sDefaultWallpaperComponent, sContext.getOpPackageName(),
                FLAG_SYSTEM, testUserId);
        WallpaperData wallpaper = mService.getCurrentWallpaperData(FLAG_SYSTEM, testUserId);

        // Mock a wallpaper data with color hints that support dark text and dark theme