diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java index 44f6d03207b16..ad97ef4a79bc1 100644 --- a/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java +++ b/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java @@ -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; @@ -598,7 +599,6 @@ public class ImageWallpaper extends WallpaperService { getDisplayContext().getSystemService(DisplayManager.class) .unregisterDisplayListener(this); mWallpaperLocalColorExtractor.cleanUp(); - unloadBitmap(); } @Override @@ -676,9 +676,14 @@ public class ImageWallpaper extends WallpaperService { void drawFrameOnCanvas(Bitmap bitmap) { Trace.beginSection("ImageWallpaper.CanvasEngine#drawFrame"); Surface surface = mSurfaceHolder.getSurface(); - Canvas canvas = mWideColorGamut - ? surface.lockHardwareWideColorGamutCanvas() - : surface.lockHardwareCanvas(); + Canvas canvas = null; + try { + canvas = mWideColorGamut + ? surface.lockHardwareWideColorGamutCanvas() + : surface.lockHardwareCanvas(); + } catch (IllegalStateException e) { + Log.w(TAG, "Unable to lock canvas", e); + } if (canvas != null) { Rect dest = mSurfaceHolder.getSurfaceFrame(); try { @@ -709,17 +714,6 @@ public class ImageWallpaper extends WallpaperService { } } - private void unloadBitmap() { - mBackgroundExecutor.execute(this::unloadBitmapSynchronized); - } - - private void unloadBitmapSynchronized() { - synchronized (mLock) { - mBitmapUsages = 0; - unloadBitmapInternal(); - } - } - private void unloadBitmapInternal() { Trace.beginSection("ImageWallpaper.CanvasEngine#unloadBitmap"); if (mBitmap != null) { @@ -738,7 +732,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 +751,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; @@ -770,9 +764,6 @@ public class ImageWallpaper extends WallpaperService { Log.e(TAG, "Attempt to load a recycled bitmap"); } else if (mBitmap == bitmap) { Log.e(TAG, "Loaded a bitmap that was already loaded"); - } else if (bitmap.getWidth() < 1 || bitmap.getHeight() < 1) { - Log.e(TAG, "Attempt to load an invalid wallpaper of length " - + bitmap.getWidth() + "x" + bitmap.getHeight()); } else { // at this point, loading is done correctly. loadSuccess = true; diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java index c2543589bfb82..379bb28ae0322 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java @@ -26,8 +26,8 @@ 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; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -44,6 +44,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 +136,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 @@ -286,9 +288,6 @@ public class ImageWallpaperTest extends SysuiTestCase { testMinSurfaceHelper(8, 8); testMinSurfaceHelper(100, 2000); testMinSurfaceHelper(200, 1); - testMinSurfaceHelper(0, 1); - testMinSurfaceHelper(1, 0); - testMinSurfaceHelper(0, 0); } private void testMinSurfaceHelper(int bitmapWidth, int bitmapHeight) { @@ -306,28 +305,6 @@ public class ImageWallpaperTest extends SysuiTestCase { intThat(greaterThanOrEqualTo(ImageWallpaper.CanvasEngine.MIN_SURFACE_HEIGHT))); } - @Test - public void testZeroBitmap() { - // test that a frame is never drawn with a 0 bitmap - testZeroBitmapHelper(0, 1); - testZeroBitmapHelper(1, 0); - testZeroBitmapHelper(0, 0); - } - - private void testZeroBitmapHelper(int bitmapWidth, int bitmapHeight) { - - clearInvocations(mSurfaceHolder); - setBitmapDimensions(bitmapWidth, bitmapHeight); - - ImageWallpaper imageWallpaper = createImageWallpaperCanvas(); - ImageWallpaper.CanvasEngine engine = - (ImageWallpaper.CanvasEngine) imageWallpaper.onCreateEngine(); - ImageWallpaper.CanvasEngine spyEngine = spy(engine); - spyEngine.onCreate(mSurfaceHolder); - spyEngine.onSurfaceRedrawNeeded(mSurfaceHolder); - verify(spyEngine, never()).drawFrameOnCanvas(any()); - } - @Test public void testLoadDrawAndUnloadBitmap() { setBitmapDimensions(LOW_BMP_WIDTH, LOW_BMP_HEIGHT);