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

Commit 23aacbd1 authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Fix failing tests in WallpaperManagerServiceTests

Two tests were failing due to a userId mismatch problem: the tests used
a testUserId = USER_SYSTEM = 0, but in the test setWallpaperComponent was called
with userId = UserHandle.getCallingUserId() = 1, resulting in errors.

Bug: 264533465
Test: atest --iterations 10 FrameworksMockingServicesTests:WallpaperManagerServiceTests
Change-Id: I0fb498aacb03a6b14ece1aae5ea8819ed9c8aa84
parent ffd5aad4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2874,8 +2874,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        setWallpaperComponent(name, UserHandle.getCallingUserId(), FLAG_SYSTEM);
    }

    private void setWallpaperComponent(ComponentName name, @SetWallpaperFlags int which,
            int userId) {
    @VisibleForTesting
    void setWallpaperComponent(ComponentName name, @SetWallpaperFlags int which, int userId) {
        userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId,
                false /* all */, true /* full */, "changing live wallpaper", null /* pkg */);
        checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
+6 −5
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ import android.util.SparseArray;
import android.util.Xml;
import android.view.Display;

import androidx.test.filters.FlakyTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

@@ -89,6 +88,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -110,7 +110,6 @@ import java.nio.charset.StandardCharsets;
 * atest FrameworksMockingServicesTests:WallpaperManagerServiceTests
 */
@Presubmit
@FlakyTest(bugId = 129797242)
@RunWith(AndroidJUnit4.class)
public class WallpaperManagerServiceTests {

@@ -273,8 +272,10 @@ public class WallpaperManagerServiceTests {

    /**
     * Tests setWallpaperComponent and clearWallpaper should work as expected.
     * TODO ignored since the assumption never passes. to be investigated.
     */
    @Test
    @Ignore("b/264533465")
    public void testSetThenClearComponent() {
        // Skip if there is no pre-defined default wallpaper component.
        assumeThat(sDefaultWallpaperComponent,
@@ -285,7 +286,7 @@ public class WallpaperManagerServiceTests {
        verifyLastWallpaperData(testUserId, sDefaultWallpaperComponent);
        verifyCurrentSystemData(testUserId);

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

@@ -312,7 +313,7 @@ public class WallpaperManagerServiceTests {

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

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

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