OSDN Git Service

Protect against destroying uncreated values
authorAlan Newberger <alann@google.com>
Fri, 24 Jul 2015 17:47:55 +0000 (10:47 -0700)
committerAlan Newberger <alann@google.com>
Fri, 24 Jul 2015 17:47:55 +0000 (10:47 -0700)
Though we attempt to minimize lifecycle impact by exiting onCreate
early due to inadequate permissions, we need to protect against
touching fields in onDestroy that we did not initialize in onCreate.

BUG=22718094

Change-Id: I49adcbbed005c4efa785458aa398e61488cfceb0

src/com/android/camera/CameraActivity.java

index 3997705..bf48898 100644 (file)
@@ -2169,16 +2169,26 @@ public class CameraActivity extends QuickActivity
             mCameraController.removeCallbackReceiver();
             mCameraController.setCameraExceptionHandler(null);
         }
-        getContentResolver().unregisterContentObserver(mLocalImagesObserver);
-        getContentResolver().unregisterContentObserver(mLocalVideosObserver);
+        if (mLocalImagesObserver != null) {
+            getContentResolver().unregisterContentObserver(mLocalImagesObserver);
+        }
+        if (mLocalVideosObserver != null) {
+            getContentResolver().unregisterContentObserver(mLocalVideosObserver);
+        }
         getServices().getCaptureSessionManager().removeSessionListener(mSessionListener);
-        mCameraAppUI.onDestroy();
-        mModeListView.setVisibilityChangedListener(null);
+        if (mCameraAppUI != null) {
+            mCameraAppUI.onDestroy();
+        }
+        if (mModeListView != null) {
+            mModeListView.setVisibilityChangedListener(null);
+        }
         mCameraController = null;
         mSettingsManager = null;
         mOrientationManager = null;
         mButtonManager = null;
-        mSoundPlayer.release();
+        if (mSoundPlayer != null) {
+          mSoundPlayer.release();
+        }
         CameraAgentFactory.recycle(CameraAgentFactory.CameraApi.API_1);
         CameraAgentFactory.recycle(CameraAgentFactory.CameraApi.AUTO);
     }