DO NOT MERGE: Don't do heavy operation while in the synchronized block
We read the wallpaper within the synchronized block, this is a long time operation, might block the other thread who is going to obtain the lock. So we have to move the operation beyond the synchronized block. Bug: 228435216 Test: atest WallpaperManagerTest#testPeekWallpaperNotBlockingOtherThread Change-Id: Ic2a947b473710ffe68db436586769858950588a4
This commit is contained in:
@@ -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,10 +558,17 @@ public class WallpaperManager {
|
|||||||
}
|
}
|
||||||
mCachedWallpaper = null;
|
mCachedWallpaper = null;
|
||||||
mCachedWallpaperUserId = 0;
|
mCachedWallpaperUserId = 0;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
mCachedWallpaper = getCurrentWallpaperLocked(
|
Bitmap currentWallpaper = getCurrentWallpaperLocked(
|
||||||
context, userId, hardware, cmProxy);
|
context, userId, hardware, cmProxy);
|
||||||
|
if (currentWallpaper != null) {
|
||||||
|
synchronized (this) {
|
||||||
|
mCachedWallpaper = currentWallpaper;
|
||||||
mCachedWallpaperUserId = userId;
|
mCachedWallpaperUserId = userId;
|
||||||
|
return mCachedWallpaper;
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
Log.w(TAG, "Out of memory loading the current wallpaper: " + e);
|
Log.w(TAG, "Out of memory loading the current wallpaper: " + e);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
@@ -574,10 +580,6 @@ public class WallpaperManager {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mCachedWallpaper != null) {
|
|
||||||
return mCachedWallpaper;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (returnDefault) {
|
if (returnDefault) {
|
||||||
Bitmap defaultWallpaper = mDefaultWallpaper;
|
Bitmap defaultWallpaper = mDefaultWallpaper;
|
||||||
if (defaultWallpaper == null || defaultWallpaper.isRecycled()) {
|
if (defaultWallpaper == null || defaultWallpaper.isRecycled()) {
|
||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user