Skip to content

Commit 2c4a56a

Browse files
Johan AlfvenJohan Redestig
authored andcommitted
Make sure OutOfMemoryError is handled by WallpaperManager
Make sure exception OutOfMemoryError is handled when calling BitmapFactory.decodeFileDescriptor and BitmapFactory.decodeStream to avoid crash in the system server. Change-Id: I954a6388d1225dab86d2617ab0602154b2a7f493
1 parent 75a2ae9 commit 2c4a56a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

core/java/android/app/WallpaperManager.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,13 @@ private Bitmap getCurrentWallpaperLocked(Context context) {
235235
if (width <= 0 || height <= 0) {
236236
// Degenerate case: no size requested, just load
237237
// bitmap as-is.
238-
Bitmap bm = BitmapFactory.decodeFileDescriptor(
239-
fd.getFileDescriptor(), null, null);
238+
Bitmap bm = null;
239+
try {
240+
bm = BitmapFactory.decodeFileDescriptor(
241+
fd.getFileDescriptor(), null, null);
242+
} catch (OutOfMemoryError e) {
243+
Log.w(TAG, "Can't decode file", e);
244+
}
240245
try {
241246
fd.close();
242247
} catch (IOException e) {
@@ -277,7 +282,12 @@ private Bitmap getDefaultWallpaperLocked(Context context) {
277282
if (width <= 0 || height <= 0) {
278283
// Degenerate case: no size requested, just load
279284
// bitmap as-is.
280-
Bitmap bm = BitmapFactory.decodeStream(is, null, null);
285+
Bitmap bm = null;
286+
try {
287+
bm = BitmapFactory.decodeStream(is, null, null);
288+
} catch (OutOfMemoryError e) {
289+
Log.w(TAG, "Can't decode stream", e);
290+
}
281291
try {
282292
is.close();
283293
} catch (IOException e) {

0 commit comments

Comments
 (0)