DO NOT MERGE: Decode the input of both setStream and setResource calls first am: 4d91b5aa0b
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16379915 Change-Id: Id96d35b0fe3a31764221a584faed10dd8780f849
This commit is contained in:
@@ -1182,18 +1182,27 @@ public class WallpaperManager {
|
|||||||
mContext.getUserId());
|
mContext.getUserId());
|
||||||
if (fd != null) {
|
if (fd != null) {
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
boolean ok = false;
|
final Bitmap tmp = BitmapFactory.decodeStream(resources.openRawResource(resid));
|
||||||
try {
|
try {
|
||||||
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
|
// If the stream can't be decoded, treat it as an invalid input.
|
||||||
copyStreamToWallpaperFile(resources.openRawResource(resid), fos);
|
if (tmp != null) {
|
||||||
// The 'close()' is the trigger for any server-side image manipulation,
|
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
|
||||||
// so we must do that before waiting for completion.
|
tmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||||||
fos.close();
|
// The 'close()' is the trigger for any server-side image manipulation,
|
||||||
completion.waitForCompletion();
|
// so we must do that before waiting for completion.
|
||||||
|
fos.close();
|
||||||
|
completion.waitForCompletion();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Resource 0x" + Integer.toHexString(resid) + " is invalid");
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Might be redundant but completion shouldn't wait unless the write
|
// Might be redundant but completion shouldn't wait unless the write
|
||||||
// succeeded; this is a fallback if it threw past the close+wait.
|
// succeeded; this is a fallback if it threw past the close+wait.
|
||||||
IoUtils.closeQuietly(fos);
|
IoUtils.closeQuietly(fos);
|
||||||
|
if (tmp != null) {
|
||||||
|
tmp.recycle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -1435,13 +1444,22 @@ public class WallpaperManager {
|
|||||||
result, which, completion, mContext.getUserId());
|
result, which, completion, mContext.getUserId());
|
||||||
if (fd != null) {
|
if (fd != null) {
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
|
final Bitmap tmp = BitmapFactory.decodeStream(bitmapData);
|
||||||
try {
|
try {
|
||||||
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
|
// If the stream can't be decoded, treat it as an invalid input.
|
||||||
copyStreamToWallpaperFile(bitmapData, fos);
|
if (tmp != null) {
|
||||||
fos.close();
|
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
|
||||||
completion.waitForCompletion();
|
tmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||||||
|
fos.close();
|
||||||
|
completion.waitForCompletion();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("InputStream is invalid");
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
IoUtils.closeQuietly(fos);
|
IoUtils.closeQuietly(fos);
|
||||||
|
if (tmp != null) {
|
||||||
|
tmp.recycle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user