From d6901a95d8aabc25fdd108d3605b34f848ab10e0 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Fri, 21 Mar 2014 20:24:55 +0100 Subject: 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 --- .../android/wallpapercropper/WallpaperCropActivity.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'packages/WallpaperCropper') diff --git a/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java b/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java index b9b87b1..4cd797d 100644 --- a/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java +++ b/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java @@ -136,7 +136,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; } -- cgit v1.1