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

Commit d6901a95 authored by Selim Cinek's avatar Selim Cinek
Browse files

Catching security exception when activity destroyed

Fixed a bug where an asynctask tried to load an image
even after the activity was destroyed leading to a
security exception since the permission could not be granted anymore.

Bug: 12760267
Change-Id: Ieffb10b1007f349371647512ffe4fe72433344e7
parent fc558d56
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -136,7 +136,21 @@ public class WallpaperCropActivity extends Activity {
        final AsyncTask<Void, Void, Void> loadBitmapTask = new AsyncTask<Void, Void, Void>() {
            protected Void doInBackground(Void...args) {
                if (!isCancelled()) {
                    try {
                        bitmapSource.loadInBackground();
                    } catch (SecurityException securityException) {
                        if (isDestroyed()) {
                            // Temporarily granted permissions are revoked when the activity
                            // finishes, potentially resulting in a SecurityException here.
                            // Even though {@link #isDestroyed} might also return true in different
                            // situations where the configuration changes, we are fine with
                            // catching these cases here as well.
                            cancel(false);
                        } else {
                            // otherwise it had a different cause and we throw it further
                            throw securityException;
                        }
                    }
                }
                return null;
            }