diff options
| author | Ahan Wu <ahanwu@google.com> | 2021-08-22 22:56:34 -0800 |
|---|---|---|
| committer | Ahan Wu <ahanwu@google.com> | 2021-09-13 18:53:27 +0800 |
| commit | 7af300eea60cd198d49ff59ec49e3329af169d59 (patch) | |
| tree | 8c37dce25d331b12ae40a70ccd857b0f6c9e58f0 /core/java/android/app | |
| parent | 6925a160d0b539dfcc72663fb846b6618ca148d6 (diff) | |
DO NOT MERGE: Fix temporary black after setting a new image wallpaper
Sometimes see temporary black wallpaper after setting a new image
wallpaper because of:
- decode bitmap twice, results in long latency until drawing.
- the set wallpaper apis didn't sync with wallpaper rendering well.
Solutions:
- Only decode bitmap when necessary.
- Make set wallpaper apis wait for image wallpaper rendering finished.
Bug: 194080642
Test: see b/194080642#comment3
Test: atest WallpaperManagerServiceTests --iterations 50
Test: atest SystemUITests
Change-Id: I369eff5195571161cf286b3ec97175481b02eed7
Diffstat (limited to 'core/java/android/app')
| -rw-r--r-- | core/java/android/app/WallpaperManager.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index 8d332ab1d58b..6cfa39cd2337 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -559,6 +559,53 @@ public class WallpaperManager { return null; } + public Rect peekWallpaperDimensions(Context context, boolean returnDefault, int userId) { + if (mService != null) { + try { + if (!mService.isWallpaperSupported(context.getOpPackageName())) { + return new Rect(); + } + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + Rect dimensions = null; + synchronized (this) { + try { + Bundle params = new Bundle(); + // Let's peek user wallpaper first. + ParcelFileDescriptor pfd = mService.getWallpaperWithFeature( + context.getOpPackageName(), context.getAttributionTag(), this, + FLAG_SYSTEM, params, userId); + if (pfd != null) { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeFileDescriptor(pfd.getFileDescriptor(), null, options); + dimensions = new Rect(0, 0, options.outWidth, options.outHeight); + } + } catch (RemoteException ex) { + Log.w(TAG, "peek wallpaper dimensions failed", ex); + } + } + // If user wallpaper is unavailable, may be the default one instead. + if ((dimensions == null || dimensions.width() == 0 || dimensions.height() == 0) + && returnDefault) { + InputStream is = openDefaultWallpaper(context, FLAG_SYSTEM); + if (is != null) { + try { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeStream(is, null, options); + dimensions = new Rect(0, 0, options.outWidth, options.outHeight); + } finally { + IoUtils.closeQuietly(is); + } + } + } + return dimensions; + } + void forgetLoadedWallpaper() { synchronized (this) { mCachedWallpaper = null; @@ -1039,6 +1086,17 @@ public class WallpaperManager { } /** + * Peek the dimensions of system wallpaper of the user without decoding it. + * + * @return the dimensions of system wallpaper + * @hide + */ + public Rect peekBitmapDimensions() { + return sGlobals.peekWallpaperDimensions( + mContext, true /* returnDefault */, mContext.getUserId()); + } + + /** * Get an open, readable file descriptor to the given wallpaper image file. * The caller is responsible for closing the file descriptor when done ingesting the file. * |
