Revert "DO NOT MERGE: Decode the input of both setStream and setResource calls first" am: b6509bdc18

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16630308

Change-Id: I27fbeb2579c5c9ff689b5e20593195bd66cb07de
This commit is contained in:
Wu Ahan
2022-01-19 22:14:40 +00:00
committed by Automerger Merge Worker

View File

@@ -1182,27 +1182,18 @@ public class WallpaperManager {
mContext.getUserId());
if (fd != null) {
FileOutputStream fos = null;
final Bitmap tmp = BitmapFactory.decodeStream(resources.openRawResource(resid));
boolean ok = false;
try {
// If the stream can't be decoded, treat it as an invalid input.
if (tmp != null) {
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
tmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
// The 'close()' is the trigger for any server-side image manipulation,
// so we must do that before waiting for completion.
fos.close();
completion.waitForCompletion();
} else {
throw new IllegalArgumentException(
"Resource 0x" + Integer.toHexString(resid) + " is invalid");
}
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
copyStreamToWallpaperFile(resources.openRawResource(resid), fos);
// The 'close()' is the trigger for any server-side image manipulation,
// so we must do that before waiting for completion.
fos.close();
completion.waitForCompletion();
} finally {
// Might be redundant but completion shouldn't wait unless the write
// succeeded; this is a fallback if it threw past the close+wait.
IoUtils.closeQuietly(fos);
if (tmp != null) {
tmp.recycle();
}
}
}
} catch (RemoteException e) {
@@ -1444,22 +1435,13 @@ public class WallpaperManager {
result, which, completion, mContext.getUserId());
if (fd != null) {
FileOutputStream fos = null;
final Bitmap tmp = BitmapFactory.decodeStream(bitmapData);
try {
// If the stream can't be decoded, treat it as an invalid input.
if (tmp != null) {
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
tmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
completion.waitForCompletion();
} else {
throw new IllegalArgumentException("InputStream is invalid");
}
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
copyStreamToWallpaperFile(bitmapData, fos);
fos.close();
completion.waitForCompletion();
} finally {
IoUtils.closeQuietly(fos);
if (tmp != null) {
tmp.recycle();
}
}
}
} catch (RemoteException e) {