summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Ahan <ahanwu@google.com>2022-01-13 14:30:26 +0000
committerXin Li <delphij@google.com>2022-03-02 18:17:47 -0800
commitade248a9bc7797209838d3d780f2ee03cff84d64 (patch)
treee61a8f255a289bdc68c2443d03f7cf1e400b9776
parent589f88b9a9a58959ab77b5375aa4346724f2f2f0 (diff)
downloadbase-ade248a9bc7797209838d3d780f2ee03cff84d64.tar.gz
Revert "Decode the input of both setStream and setResource calls first"
This reverts commit f6a946bbcd024ebcddaf213bd74bd7e57e9d1b49. Reason for revert: will deliver a better fix for that, ag/16580245. (cherry picked from commit aba1d77ff786bb54a578bdc3c86637501e24dfdb) (cherry picked from commit ac8151be84e7adc3ac35f48ce4e98e44217e44e8) Merged-In: I9c401b4cbded8753fc89df25a2c4f88a2fe72087 Change-Id: I9c401b4cbded8753fc89df25a2c4f88a2fe72087
-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 3712caeddaf5..fca4c698c49c 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -1488,27 +1488,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) {
@@ -1750,22 +1741,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) {