Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9edf1a71 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "DO NOT MERGE: Decode the input of both setStream and...

Merge "Revert "DO NOT MERGE: Decode the input of both setStream and setResource calls first"" into sc-dev
parents 319336ea 4c5f09ca
Loading
Loading
Loading
Loading
+11 −29
Original line number Diff line number Diff line
@@ -1402,27 +1402,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);
                    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();
                    } else {
                        throw new IllegalArgumentException(
                                "Resource 0x" + Integer.toHexString(resid) + " is invalid");
                    }
                } 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) {
@@ -1664,22 +1655,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);
                    copyStreamToWallpaperFile(bitmapData, fos);
                    fos.close();
                    completion.waitForCompletion();
                    } else {
                        throw new IllegalArgumentException("InputStream is invalid");
                    }
                } finally {
                    IoUtils.closeQuietly(fos);
                    if (tmp != null) {
                        tmp.recycle();
                    }
                }
            }
        } catch (RemoteException e) {