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

Commit 6ef52546 authored by Steven Ng's avatar Steven Ng Committed by Android (Google) Code Review
Browse files

Merge "Add a config to enable live wallpaper in desktop experience" into main

parents bf37af00 eb122161
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2033,6 +2033,9 @@
    <!-- Class name of WallpaperManagerService. -->
    <string name="config_wallpaperManagerServiceName" translatable="false">com.android.server.wallpaper.WallpaperManagerService</string>

    <!-- True if live wallpapers can be supported in the deskop experience -->
    <bool name="config_isLiveWallpaperSupportedInDesktopExperience">false</bool>

    <!-- Specifies priority of automatic time sources. Suggestions from higher entries in the list
         take precedence over lower ones.
         See com.android.server.timedetector.TimeDetectorStrategy for available sources. -->
+1 −0
Original line number Diff line number Diff line
@@ -2284,6 +2284,7 @@
  <java-symbol type="string" name="heavy_weight_notification_detail" />
  <java-symbol type="string" name="image_wallpaper_component" />
  <java-symbol type="string" name="fallback_wallpaper_component" />
  <java-symbol type="bool" name="config_isLiveWallpaperSupportedInDesktopExperience" />
  <java-symbol type="string" name="input_method_binding_label" />
  <java-symbol type="string" name="input_method_ime_switch_long_click_action_desc" />
  <java-symbol type="string" name="launch_warning_original" />
+15 −1
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ import android.os.ResultReceiver;
import android.os.SELinux;
import android.os.ShellCallback;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
@@ -747,13 +748,26 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        if (connection == null) {
            return false;
        }
        boolean isWallpaperDesktopExperienceEnabled = isDeviceEligibleForDesktopExperienceWallpaper(
                mContext);
        boolean isLiveWallpaperSupportedInDesktopExperience =
                SystemProperties.getBoolean("persist.wm.debug.desktop_support_live_wallpaper",
                        mContext.getResources().getBoolean(
                                R.bool.config_isLiveWallpaperSupportedInDesktopExperience)
                );
        // Non image wallpaper.
        if (connection.mInfo != null) {
            if (isWallpaperDesktopExperienceEnabled
                    && !isLiveWallpaperSupportedInDesktopExperience) {
                // Only allow the fallback wallpaper.
                return mFallbackWallpaperComponent != null
                        && mFallbackWallpaperComponent.equals(connection.mInfo.getComponent());
            }
            return connection.mInfo.supportsMultipleDisplays();
        }

        // Image wallpaper
        if (isDeviceEligibleForDesktopExperienceWallpaper(mContext)) {
        if (isWallpaperDesktopExperienceEnabled) {
            return mWallpaperCropper.isWallpaperCompatibleForDisplay(displayId,
                    connection.mWallpaper);
        }
+122 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.graphics.Color;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
@@ -71,6 +72,7 @@ import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
@@ -137,6 +139,8 @@ import java.util.Map;
public class WallpaperManagerServiceTests {

    private static final String TAG = "WallpaperManagerServiceTests";
    private static final String SYS_PROP_LIVE_WALLPAPER_SUPPORT =
            "persist.wm.debug.desktop_support_live_wallpaper";
    private static final int DISPLAY_SIZE_DIMENSION = 100;

    private static final ComponentName TEST_WALLPAPER_COMPONENT = ComponentName.createRelative(
@@ -180,6 +184,7 @@ public class WallpaperManagerServiceTests {
                .spyStatic(LocalServices.class)
                .spyStatic(WallpaperManager.class)
                .spyStatic(DesktopModeHelper.class)
                .spyStatic(SystemProperties.class)
                .startMocking();

        sWindowManagerInternal = mock(WindowManagerInternal.class);
@@ -254,6 +259,9 @@ public class WallpaperManagerServiceTests {
        }).when(() -> WallpaperUtils.getWallpaperDir(anyInt()));
        ExtendedMockito.doAnswer(invocation -> true).when(
                () -> DesktopModeHelper.isDeviceEligibleForDesktopMode(any()));
        ExtendedMockito.doAnswer(invocation -> invocation.getArgument(1)).when(
                () -> SystemProperties.getBoolean(eq(SYS_PROP_LIVE_WALLPAPER_SUPPORT),
                        anyBoolean()));

        sContext.addMockSystemService(DisplayManager.class, mDisplayManager);

@@ -1188,6 +1196,10 @@ public class WallpaperManagerServiceTests {
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
    public void setWallpaperComponent_systemAndLockWallpapers_multiDisplays_shouldHaveExpectedConnections() {
        Resources resources = sContext.getResources();
        spyOn(resources);
        doReturn(true).when(resources).getBoolean(
                R.bool.config_isLiveWallpaperSupportedInDesktopExperience);
        final int incompatibleDisplayId = 2;
        final int compatibleDisplayId = 3;
        setUpDisplays(Map.of(
@@ -1227,6 +1239,116 @@ public class WallpaperManagerServiceTests {
                .isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
    public void isWallpaperCompatibleForDisplay_liveWallpaperSupported_desktopExperienceEnabled_shouldReturnTrue() {
        Resources resources = sContext.getResources();
        spyOn(resources);
        doReturn(true).when(resources).getBoolean(
                R.bool.config_isLiveWallpaperSupportedInDesktopExperience);

        final int displayId = 2;
        setUpDisplays(Map.of(
                DEFAULT_DISPLAY, true,
                displayId, true));
        final int testUserId = USER_SYSTEM;
        mService.switchUser(testUserId, null);
        mService.setWallpaperComponent(TEST_WALLPAPER_COMPONENT, sContext.getOpPackageName(),
                FLAG_SYSTEM | FLAG_LOCK, testUserId);

        assertThat(mService.isWallpaperCompatibleForDisplay(displayId,
                mService.mLastWallpaper.connection)).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
    public void isWallpaperCompatibleForDisplay_liveWallpaperUnsupported_desktopExperienceEnabled_shouldReturnFalse() {
        Resources resources = sContext.getResources();
        spyOn(resources);
        doReturn(false).when(resources).getBoolean(
                R.bool.config_isLiveWallpaperSupportedInDesktopExperience);

        final int displayId = 2;
        setUpDisplays(Map.of(
                DEFAULT_DISPLAY, true,
                displayId, true));
        final int testUserId = USER_SYSTEM;
        mService.switchUser(testUserId, null);
        mService.setWallpaperComponent(TEST_WALLPAPER_COMPONENT, sContext.getOpPackageName(),
                FLAG_SYSTEM | FLAG_LOCK, testUserId);

        assertThat(mService.isWallpaperCompatibleForDisplay(displayId,
                mService.mLastWallpaper.connection)).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
    public void isWallpaperCompatibleForDisplay_liveWallpaperUnsupported_systemOverridden_desktopExperienceEnabled_shouldReturnTrue() {
        ExtendedMockito.doAnswer(invocation -> true).when(
                () -> SystemProperties.getBoolean(eq(SYS_PROP_LIVE_WALLPAPER_SUPPORT),
                        anyBoolean()));
        Resources resources = sContext.getResources();
        spyOn(resources);
        doReturn(false).when(resources).getBoolean(
                R.bool.config_isLiveWallpaperSupportedInDesktopExperience);

        final int displayId = 2;
        setUpDisplays(Map.of(
                DEFAULT_DISPLAY, true,
                displayId, true));
        final int testUserId = USER_SYSTEM;
        mService.switchUser(testUserId, null);
        mService.setWallpaperComponent(TEST_WALLPAPER_COMPONENT, sContext.getOpPackageName(),
                FLAG_SYSTEM | FLAG_LOCK, testUserId);

        assertThat(mService.isWallpaperCompatibleForDisplay(displayId,
                mService.mLastWallpaper.connection)).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
    public void isWallpaperCompatibleForDisplay_liveWallpaperUnsupported_desktopExperienceEnabled_fallbackWallpaper_shouldReturnTrue() {
        Resources resources = sContext.getResources();
        spyOn(resources);
        doReturn(false).when(resources).getBoolean(
                R.bool.config_isLiveWallpaperSupportedInDesktopExperience);

        final int displayId = 2;
        setUpDisplays(Map.of(
                DEFAULT_DISPLAY, true,
                displayId, true));
        final int testUserId = USER_SYSTEM;
        mService.switchUser(testUserId, null);
        mService.setWallpaperComponent(sFallbackWallpaperComponentName, sContext.getOpPackageName(),
                FLAG_SYSTEM | FLAG_LOCK, testUserId);

        assertThat(mService.isWallpaperCompatibleForDisplay(displayId,
                mService.mLastWallpaper.connection)).isTrue();
    }

    @Test
    @DisableFlags(Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_WALLPAPER)
    public void isWallpaperCompatibleForDisplay_liveWallpaperUnsupported_desktopExperienceDisabled_shouldReturnTrue() {
        Resources resources = sContext.getResources();
        spyOn(resources);
        doReturn(false).when(resources).getBoolean(
                R.bool.config_isLiveWallpaperSupportedInDesktopExperience);

        final int displayId = 2;
        setUpDisplays(Map.of(
                DEFAULT_DISPLAY, true,
                displayId, true));
        final int testUserId = USER_SYSTEM;
        mService.switchUser(testUserId, null);
        mService.setWallpaperComponent(TEST_WALLPAPER_COMPONENT, sContext.getOpPackageName(),
                FLAG_SYSTEM | FLAG_LOCK, testUserId);

        // config_isLiveWallpaperSupportedInDesktopExperience is not used if the desktop experience
        // flag for wallpaper is disabled.
        assertThat(mService.isWallpaperCompatibleForDisplay(displayId,
                mService.mLastWallpaper.connection)).isTrue();
    }

    // Verify that after continue switch user from userId 0 to lastUserId, the wallpaper data for
    // non-current user must not bind to wallpaper service.
    private void verifyNoConnectionBeforeLastUser(int lastUserId) {