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

Commit 360a31df authored by Wu Ahan's avatar Wu Ahan Committed by Automerger Merge Worker
Browse files

Merge "Decode the input of both setStream and setResource calls first" into...

Merge "Decode the input of both setStream and setResource calls first" into sc-v2-dev am: c262621e

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

Change-Id: I416db0a66902af55c3086b44f1366c07d6c3f4bf
parents fc9e5611 c262621e
Loading
Loading
Loading
Loading
+29 −11
Original line number Diff line number Diff line
@@ -1488,18 +1488,27 @@ public class WallpaperManager {
                    mContext.getUserId());
            if (fd != null) {
                FileOutputStream fos = null;
                boolean ok = false;
                final Bitmap tmp = BitmapFactory.decodeStream(resources.openRawResource(resid));
                try {
                    // If the stream can't be decoded, treat it as an invalid input.
                    if (tmp != null) {
                        fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                    copyStreamToWallpaperFile(resources.openRawResource(resid), fos);
                        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");
                    }
                } 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) {
@@ -1741,13 +1750,22 @@ 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);
                    copyStreamToWallpaperFile(bitmapData, fos);
                        tmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
                        fos.close();
                        completion.waitForCompletion();
                    } else {
                        throw new IllegalArgumentException("InputStream is invalid");
                    }
                } finally {
                    IoUtils.closeQuietly(fos);
                    if (tmp != null) {
                        tmp.recycle();
                    }
                }
            }
        } catch (RemoteException e) {