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

Commit 4cb543b9 authored by Santiago Etchebehere's avatar Santiago Etchebehere Committed by Automerger Merge Worker
Browse files

Merge "Send a command to the wallpaper when re-applying it" into rvc-dev am:...

Merge "Send a command to the wallpaper when re-applying it" into rvc-dev am: 9c750b30 am: f34b84ad

Change-Id: I7b5f7758fc16bcb2a6d116421c9309786b0fe10b
parents d70af11c f34b84ad
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -177,6 +177,13 @@ public class WallpaperManager {
     */
    public static final String COMMAND_DROP = "android.home.drop";

    /**
     * Command for {@link #sendWallpaperCommand}: reported when the wallpaper that was already
     * set is re-applied by the user.
     * @hide
     */
    public static final String COMMAND_REAPPLY = "android.wallpaper.reapply";

    /**
     * Extra passed back from setWallpaper() giving the new wallpaper's assigned ID.
     * @hide
+18 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.wallpaper;

import static android.app.WallpaperManager.COMMAND_REAPPLY;
import static android.app.WallpaperManager.FLAG_LOCK;
import static android.app.WallpaperManager.FLAG_SYSTEM;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AUTO;
@@ -1070,7 +1071,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        /**
         * Collect needed info for a display.
         */
        private final class DisplayConnector {
        @VisibleForTesting
        final class DisplayConnector {
            final int mDisplayId;
            final Binder mToken = new Binder();
            IWallpaperEngine mEngine;
@@ -1213,7 +1215,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            }
        }

        private boolean isUsableDisplay(Display display) {
        @VisibleForTesting
        boolean isUsableDisplay(Display display) {
            if (display == null || !display.hasAccess(mClientUid)) {
                return false;
            }
@@ -2583,6 +2586,19 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                if (bindWallpaperComponentLocked(name, false, true, wallpaper, null)) {
                    if (!same) {
                        wallpaper.primaryColors = null;
                    } else {
                        if (wallpaper.connection != null) {
                            wallpaper.connection.forEachDisplayConnector(displayConnector -> {
                                try {
                                    if (displayConnector.mEngine != null) {
                                        displayConnector.mEngine.dispatchWallpaperCommand(
                                                COMMAND_REAPPLY, 0, 0, 0, null);
                                    }
                                } catch (RemoteException e) {
                                    Slog.w(TAG, "Error sending apply message to wallpaper", e);
                                }
                            });
                        }
                    }
                    wallpaper.wallpaperId = makeWallpaperIdLocked();
                    notifyCallbacksLocked(wallpaper);
+32 −3
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.server.wallpaper;

import static android.app.WallpaperManager.COMMAND_REAPPLY;
import static android.app.WallpaperManager.FLAG_SYSTEM;
import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -34,6 +36,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;

import android.app.AppGlobals;
import android.app.AppOpsManager;
@@ -49,6 +52,7 @@ import android.hardware.display.DisplayManager;
import android.os.UserHandle;
import android.platform.test.annotations.Presubmit;
import android.service.wallpaper.IWallpaperConnection;
import android.service.wallpaper.IWallpaperEngine;
import android.service.wallpaper.WallpaperService;
import android.testing.TestableContext;
import android.util.Log;
@@ -110,6 +114,7 @@ public class WallpaperManagerServiceTests {
    public final TemporaryFolder mFolder = new TemporaryFolder();
    private final SparseArray<File> mTempDirs = new SparseArray<>();
    private WallpaperManagerService mService;
    private static IWallpaperConnection.Stub sWallpaperService;

    @BeforeClass
    public static void setUpClass() {
@@ -134,7 +139,7 @@ public class WallpaperManagerServiceTests {
        doNothing().when(sContext).sendBroadcastAsUser(any(), any());

        //Wallpaper components
        final IWallpaperConnection.Stub wallpaperService = mock(IWallpaperConnection.Stub.class);
        sWallpaperService = mock(IWallpaperConnection.Stub.class);
        sImageWallpaperComponentName = ComponentName.unflattenFromString(
                sContext.getResources().getString(R.string.image_wallpaper_component));
        // Mock default wallpaper as image wallpaper if there is no pre-defined default wallpaper.
@@ -145,10 +150,10 @@ public class WallpaperManagerServiceTests {
            doReturn(sImageWallpaperComponentName).when(() ->
                    WallpaperManager.getDefaultWallpaperComponent(any()));
        } else {
            sContext.addMockService(sDefaultWallpaperComponent, wallpaperService);
            sContext.addMockService(sDefaultWallpaperComponent, sWallpaperService);
        }

        sContext.addMockService(sImageWallpaperComponentName, wallpaperService);
        sContext.addMockService(sImageWallpaperComponentName, sWallpaperService);
    }

    @AfterClass
@@ -263,6 +268,30 @@ public class WallpaperManagerServiceTests {
        verifyCurrentSystemData(testUserId);
    }

    /**
     * Tests that when setWallpaperComponent is called with the currently set component, a command
     * is issued to the wallpaper.
     */
    @Test
    public void testSetCurrentComponent() throws Exception {
        final int testUserId = UserHandle.USER_SYSTEM;
        mService.switchUser(testUserId, null);
        verifyLastWallpaperData(testUserId, sDefaultWallpaperComponent);
        verifyCurrentSystemData(testUserId);

        spyOn(mService.mLastWallpaper.connection);
        doReturn(true).when(mService.mLastWallpaper.connection).isUsableDisplay(any());
        mService.mLastWallpaper.connection.attachEngine(mock(IWallpaperEngine.class),
                DEFAULT_DISPLAY);

        WallpaperManagerService.WallpaperConnection.DisplayConnector connector =
                mService.mLastWallpaper.connection.getDisplayConnectorOrCreate(DEFAULT_DISPLAY);
        mService.setWallpaperComponent(sDefaultWallpaperComponent);

        verify(connector.mEngine).dispatchWallpaperCommand(
                eq(COMMAND_REAPPLY), anyInt(), anyInt(), anyInt(), any());
    }

    /**
     * Tests internal data should be correct and no crash after switch user continuously.
     */