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

Commit edb3c9e7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

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

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

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

Change-Id: I8776eeb1756d32d748596c6d1da914c21c559ece
parents 5fd5d007 613dfbf4
Loading
Loading
Loading
Loading
+11 −29
Original line number Original line Diff line number Diff line
@@ -1488,27 +1488,18 @@ public class WallpaperManager {
                    mContext.getUserId());
                    mContext.getUserId());
            if (fd != null) {
            if (fd != null) {
                FileOutputStream fos = null;
                FileOutputStream fos = null;
                final Bitmap tmp = BitmapFactory.decodeStream(resources.openRawResource(resid));
                boolean ok = false;
                try {
                try {
                    // If the stream can't be decoded, treat it as an invalid input.
                    if (tmp != null) {
                    fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                    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,
                    // The 'close()' is the trigger for any server-side image manipulation,
                    // so we must do that before waiting for completion.
                    // so we must do that before waiting for completion.
                    fos.close();
                    fos.close();
                    completion.waitForCompletion();
                    completion.waitForCompletion();
                    } else {
                        throw new IllegalArgumentException(
                                "Resource 0x" + Integer.toHexString(resid) + " is invalid");
                    }
                } finally {
                } finally {
                    // Might be redundant but completion shouldn't wait unless the write
                    // Might be redundant but completion shouldn't wait unless the write
                    // succeeded; this is a fallback if it threw past the close+wait.
                    // succeeded; this is a fallback if it threw past the close+wait.
                    IoUtils.closeQuietly(fos);
                    IoUtils.closeQuietly(fos);
                    if (tmp != null) {
                        tmp.recycle();
                    }
                }
                }
            }
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
@@ -1750,22 +1741,13 @@ public class WallpaperManager {
                    result, which, completion, mContext.getUserId());
                    result, which, completion, mContext.getUserId());
            if (fd != null) {
            if (fd != null) {
                FileOutputStream fos = null;
                FileOutputStream fos = null;
                final Bitmap tmp = BitmapFactory.decodeStream(bitmapData);
                try {
                try {
                    // If the stream can't be decoded, treat it as an invalid input.
                    if (tmp != null) {
                    fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                    fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
                        tmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
                    copyStreamToWallpaperFile(bitmapData, fos);
                    fos.close();
                    fos.close();
                    completion.waitForCompletion();
                    completion.waitForCompletion();
                    } else {
                        throw new IllegalArgumentException("InputStream is invalid");
                    }
                } finally {
                } finally {
                    IoUtils.closeQuietly(fos);
                    IoUtils.closeQuietly(fos);
                    if (tmp != null) {
                        tmp.recycle();
                    }
                }
                }
            }
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {