Merge "DO NOT MERGE: Don't do heavy operation while in the synchronized block" into tm-dev

This commit is contained in:
Wu Ahan
2022-04-15 10:49:21 +00:00
committed by Android (Google) Code Review

View File

@@ -67,7 +67,6 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.StrictMode; import android.os.StrictMode;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.service.wallpaper.WallpaperService;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.ArraySet; import android.util.ArraySet;
@@ -559,23 +558,26 @@ public class WallpaperManager {
} }
mCachedWallpaper = null; mCachedWallpaper = null;
mCachedWallpaperUserId = 0; mCachedWallpaperUserId = 0;
try { }
mCachedWallpaper = getCurrentWallpaperLocked( try {
context, userId, hardware, cmProxy); Bitmap currentWallpaper = getCurrentWallpaperLocked(
mCachedWallpaperUserId = userId; context, userId, hardware, cmProxy);
} catch (OutOfMemoryError e) { if (currentWallpaper != null) {
Log.w(TAG, "Out of memory loading the current wallpaper: " + e); synchronized (this) {
} catch (SecurityException e) { mCachedWallpaper = currentWallpaper;
if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.O_MR1) { mCachedWallpaperUserId = userId;
Log.w(TAG, "No permission to access wallpaper, suppressing" return mCachedWallpaper;
+ " exception to avoid crashing legacy app.");
} else {
// Post-O apps really most sincerely need the permission.
throw e;
} }
} }
if (mCachedWallpaper != null) { } catch (OutOfMemoryError e) {
return mCachedWallpaper; Log.w(TAG, "Out of memory loading the current wallpaper: " + e);
} catch (SecurityException e) {
if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.O_MR1) {
Log.w(TAG, "No permission to access wallpaper, suppressing"
+ " exception to avoid crashing legacy app.");
} else {
// Post-O apps really most sincerely need the permission.
throw e;
} }
} }
if (returnDefault) { if (returnDefault) {
@@ -2472,7 +2474,7 @@ public class WallpaperManager {
* *
* @param colors Wallpaper color info, {@code null} when not available. * @param colors Wallpaper color info, {@code null} when not available.
* @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM} * @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM}
* @see WallpaperService.Engine#onComputeColors() * @see android.service.wallpaper.WallpaperService.Engine#onComputeColors()
*/ */
void onColorsChanged(@Nullable WallpaperColors colors, int which); void onColorsChanged(@Nullable WallpaperColors colors, int which);
@@ -2484,7 +2486,7 @@ public class WallpaperManager {
* @param colors Wallpaper color info, {@code null} when not available. * @param colors Wallpaper color info, {@code null} when not available.
* @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM} * @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM}
* @param userId Owner of the wallpaper * @param userId Owner of the wallpaper
* @see WallpaperService.Engine#onComputeColors() * @see android.service.wallpaper.WallpaperService.Engine#onComputeColors()
* @hide * @hide
*/ */
default void onColorsChanged(@Nullable WallpaperColors colors, int which, int userId) { default void onColorsChanged(@Nullable WallpaperColors colors, int which, int userId) {