summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Ahan <ahanwu@google.com>2022-01-19 22:15:01 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-01-19 22:15:01 +0000
commit38cd0a81dd465435be5b74836145af4f7d677ddd (patch)
treef33268b69478d759ec581843c5deaf0c3c0023cd
parent7f26a226d1c7132490ad531183bbb3408d40b17b (diff)
parentcc4fe8984ad59ee0e40634f48934545bedd6fb00 (diff)
downloadbase-38cd0a81dd465435be5b74836145af4f7d677ddd.tar.gz
Revert "DO NOT MERGE: Decode the input of both setStream and setResource calls first" am: cc4fe8984a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16631185 Change-Id: I607c675dbd7edd588713d7a07cec625954f5c623
-rw-r--r--core/java/android/app/WallpaperManager.java40
1 files changed, 11 insertions, 29 deletions
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 5990ac724b4b..b1c005c761aa 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -1275,27 +1275,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) {
@@ -1537,22 +1528,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) {