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

Commit 09af2b3b authored by Eric Rahm's avatar Eric Rahm
Browse files

Improve comparison of default wallpapers

This adds handling of the cases when comparing a null wallpaper
component to the default wallpaper component should be considered
equivalent. This will avoid changing wallpapers when resetting to the
default wallpaper if the default wallpaper is already configured.

Bug: 296508731
Test: atest WallpaperManagerTest
Change-Id: I723cd3f07caf3e7035ba01361f76fbc9a2183950
parent 020c3b85
Loading
Loading
Loading
Loading
+19 −7
Original line number Original line Diff line number Diff line
@@ -3494,15 +3494,24 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        }
        }
    }
    }


    /**
     * Determines if the given component name is the default component. Note: a null name can be
     * used to represent the default component.
     * @param name The component name to check.
     * @return True if the component name matches the default wallpaper component.
     */
    private boolean isDefaultComponent(ComponentName name) {
        return name == null || name.equals(mDefaultWallpaperComponent);
    }

    private boolean changingToSame(ComponentName componentName, WallpaperData wallpaper) {
    private boolean changingToSame(ComponentName componentName, WallpaperData wallpaper) {
        if (wallpaper.connection != null) {
        if (wallpaper.connection != null) {
            if (wallpaper.wallpaperComponent == null) {
            final ComponentName wallpaperName = wallpaper.wallpaperComponent;
                if (componentName == null) {
            if (isDefaultComponent(componentName) && isDefaultComponent(wallpaperName)) {
                if (DEBUG) Slog.v(TAG, "changingToSame: still using default");
                if (DEBUG) Slog.v(TAG, "changingToSame: still using default");
                // Still using default wallpaper.
                // Still using default wallpaper.
                return true;
                return true;
                }
            } else if (wallpaperName != null && wallpaperName.equals(componentName)) {
            } else if (wallpaper.wallpaperComponent.equals(componentName)) {
                // Changing to same wallpaper.
                // Changing to same wallpaper.
                if (DEBUG) Slog.v(TAG, "same wallpaper");
                if (DEBUG) Slog.v(TAG, "same wallpaper");
                return true;
                return true;
@@ -3519,6 +3528,9 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        // Has the component changed?
        // Has the component changed?
        if (!force && changingToSame(componentName, wallpaper)) {
        if (!force && changingToSame(componentName, wallpaper)) {
            try {
            try {
                if (DEBUG_LIVE) {
                    Slog.v(TAG, "Changing to the same component, ignoring");
                }
                if (reply != null) reply.sendResult(null);
                if (reply != null) reply.sendResult(null);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to send callback", e);
                Slog.e(TAG, "Failed to send callback", e);