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

Commit 849b7a44 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: b136d698

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



Change-Id: Iab93bc77da981007597b9c1ef54daa63e0146685
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1c020406 b136d698
Loading
Loading
Loading
Loading
+17 −12
Original line number Original line 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) {
        synchronized (mLock) {
            if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which));
            if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which));
            WallpaperData wallpaper;
            WallpaperData wallpaper;
@@ -3066,7 +3063,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                    wallpaper.mSystemWasBoth = systemIsBoth;
                    wallpaper.mSystemWasBoth = systemIsBoth;
                    wallpaper.mWhich = which;
                    wallpaper.mWhich = which;
                    wallpaper.setComplete = completion;
                    wallpaper.setComplete = completion;
                    wallpaper.fromForegroundApp = fromForegroundApp;
                    wallpaper.fromForegroundApp = isFromForegroundApp(callingPackage);
                    wallpaper.cropHint.set(cropHint);
                    wallpaper.cropHint.set(cropHint);
                    wallpaper.allowBackup = allowBackup;
                    wallpaper.allowBackup = allowBackup;
                    wallpaper.mWallpaperDimAmount = getWallpaperDimAmount();
                    wallpaper.mWallpaperDimAmount = getWallpaperDimAmount();
@@ -3153,27 +3150,28 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            @SetWallpaperFlags int which, int userId) {
            @SetWallpaperFlags int which, int userId) {


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


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


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


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


    // TODO(b/266818039) Remove this method
    // TODO(b/266818039) Remove this method
    private void setWallpaperComponentInternalLegacy(ComponentName name,
    private void setWallpaperComponentInternalLegacy(ComponentName name, String callingPackage,
            @SetWallpaperFlags int which, int userId) {
            @SetWallpaperFlags int which, int userId) {
        userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId,
        userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId,
                false /* all */, true /* full */, "changing live wallpaper", null /* pkg */);
                false /* all */, true /* full */, "changing live wallpaper", null /* pkg */);
@@ -3320,6 +3319,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            try {
            try {
                wallpaper.imageWallpaperPending = false;
                wallpaper.imageWallpaperPending = false;
                wallpaper.mWhich = which;
                wallpaper.mWhich = which;
                wallpaper.fromForegroundApp = isFromForegroundApp(callingPackage);
                boolean same = changingToSame(name, wallpaper);
                boolean same = changingToSame(name, wallpaper);
                if (bindWallpaperComponentLocked(name, false, true, wallpaper, null)) {
                if (bindWallpaperComponentLocked(name, false, true, wallpaper, null)) {
                    if (!same) {
                    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
     * Certain user types do not support wallpapers (e.g. managed profiles). The check is
     * implemented through through the OP_WRITE_WALLPAPER AppOp.
     * implemented through through the OP_WRITE_WALLPAPER AppOp.
+6 −3
Original line number Original line Diff line number Diff line
@@ -292,7 +292,8 @@ public class WallpaperManagerServiceTests {
        verifyLastWallpaperData(testUserId, sDefaultWallpaperComponent);
        verifyLastWallpaperData(testUserId, sDefaultWallpaperComponent);
        verifyCurrentSystemData(testUserId);
        verifyCurrentSystemData(testUserId);


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


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


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


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


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