From: Selim Cinek Date: Tue, 4 Mar 2014 20:29:40 +0000 (+0100) Subject: Catching security exception when activity destroyed X-Git-Tag: android-x86-6.0-r1~508^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=459875d09eca62e9f8511adcf269216a7f8d87ac;p=android-x86%2Fpackages-apps-Launcher3.git 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: I76ee2c0ab268b0ab4bde606706046caf0e39f1e9 --- diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java index 561c4bb6a..bbbd9105c 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java @@ -141,7 +141,21 @@ public class WallpaperCropActivity extends Activity { final AsyncTask loadBitmapTask = new AsyncTask() { protected Void doInBackground(Void...args) { if (!isCancelled()) { - bitmapSource.loadInBackground(); + 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; }