OSDN Git Service

Avoid crash if user disables Camera while Gallery is open
authorAlan Newberger <alann@google.com>
Wed, 30 Oct 2013 18:42:14 +0000 (11:42 -0700)
committerAlan Newberger <alann@google.com>
Wed, 30 Oct 2013 18:44:13 +0000 (11:44 -0700)
We cache the camera availability check so in the corner case that
a user disables their camera in package manager, avoid crashing.
Not necessary to do more sophisticated handling since this is a
narrow case initiated by user.

Bug: 11435559
Change-Id: I54d5015cdd9b64aec5c9da9a393824d3b41201a1

src/com/android/gallery3d/util/GalleryUtils.java

index d1f8229..8fb926c 100644 (file)
@@ -247,7 +247,13 @@ public class GalleryUtils {
         Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
                 .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                         | Intent.FLAG_ACTIVITY_NEW_TASK);
-        context.startActivity(intent);
+        try {
+            context.startActivity(intent);
+        } catch (ActivityNotFoundException e) {
+            // This will only occur if Camera was disabled while Gallery is open
+            // since we cache our availability check. Just abort the attempt.
+            Log.e(TAG, "Camera activity previously detected but cannot be found", e);
+        }
     }
 
     public static void startGalleryActivity(Context context) {