Load wallpaper with correct user id

The CanvasEngine was not using the correct userId to load the wallpaper.
This caused the system wallpaper to be displayed to all the users.

Bug: 255702022
Test: manual
Test: atest ImageWallpaperTest
Change-Id: Id09bf12de3ce491cd8973050dc79d2f52eb6f762
This commit is contained in:
Aurélien Pomini
2022-10-27 10:36:09 +00:00
parent dcc02cbedd
commit 44e56a8190
2 changed files with 9 additions and 5 deletions

View File

@@ -31,6 +31,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.service.wallpaper.WallpaperService;
import android.util.ArraySet;
import android.util.Log;
@@ -738,7 +739,7 @@ public class ImageWallpaper extends WallpaperService {
boolean loadSuccess = false;
Bitmap bitmap;
try {
bitmap = mWallpaperManager.getBitmap(false);
bitmap = mWallpaperManager.getBitmapAsUser(UserHandle.USER_CURRENT, false);
if (bitmap != null
&& bitmap.getByteCount() > RecordingCanvas.MAX_BITMAP_SIZE) {
throw new RuntimeException("Wallpaper is too large to draw!");
@@ -757,7 +758,7 @@ public class ImageWallpaper extends WallpaperService {
}
try {
bitmap = mWallpaperManager.getBitmap(false);
bitmap = mWallpaperManager.getBitmapAsUser(UserHandle.USER_CURRENT, false);
} catch (RuntimeException | OutOfMemoryError e) {
Log.w(TAG, "Unable to load default wallpaper!", e);
bitmap = null;

View File

@@ -26,6 +26,7 @@ import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -44,6 +45,7 @@ import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerGlobal;
import android.os.Handler;
import android.os.UserHandle;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.Display;
@@ -135,9 +137,10 @@ public class ImageWallpaperTest extends SysuiTestCase {
when(mWallpaperBitmap.getHeight()).thenReturn(mBitmapHeight);
// set up wallpaper manager
when(mWallpaperManager.peekBitmapDimensions()).thenReturn(
new Rect(0, 0, mBitmapWidth, mBitmapHeight));
when(mWallpaperManager.getBitmap(false)).thenReturn(mWallpaperBitmap);
when(mWallpaperManager.peekBitmapDimensions())
.thenReturn(new Rect(0, 0, mBitmapWidth, mBitmapHeight));
when(mWallpaperManager.getBitmapAsUser(eq(UserHandle.USER_CURRENT), anyBoolean()))
.thenReturn(mWallpaperBitmap);
when(mMockContext.getSystemService(WallpaperManager.class)).thenReturn(mWallpaperManager);
// set up surface