diff options
author | Wu-cheng Li <wuchengli@google.com> | 2011-06-07 14:53:54 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2011-06-07 15:06:39 +0800 |
commit | 03eeea3750b6b540b735e0f4d5d6d76c128cbacb (patch) | |
tree | 3a50c02e7762165992843db5b1d65f12a1c9ff5d | |
parent | 82b1903e5b7f1be665b645835c1eef1d1660fe8e (diff) | |
download | LegacyCamera-03eeea3750b6b540b735e0f4d5d6d76c128cbacb.zip LegacyCamera-03eeea3750b6b540b735e0f4d5d6d76c128cbacb.tar.gz LegacyCamera-03eeea3750b6b540b735e0f4d5d6d76c128cbacb.tar.bz2 |
Fix NPE on launch if camera cannot be opened.
If camera cannot be opened, the app will show a dialog
and finish the acitivty. But if the screen is turned off
and on when the dialog is still there, the app will enter
onResume again.
bug:4556340
Change-Id: Icc331baa14f5e17b178e2022d61e5da55398df40
-rw-r--r-- | src/com/android/camera/Camera.java | 15 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 7 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 36b60a3..d4d2171 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -155,7 +155,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, private ToneGenerator mFocusToneGenerator; private GestureDetector mPopupGestureDetector; private SwitcherSet mSwitcher; - private boolean mStartPreviewFail = false; + private boolean mOpenCameraFail = false; private View mPreviewFrame; // Preview frame area. private View mPreviewBorder; @@ -389,7 +389,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, // Initialize focus UI. mPreviewFrame = findViewById(R.id.camera_preview); mPreviewFrame.setOnTouchListener(this); - mPreviewBorder = (View) findViewById(R.id.preview_border); + mPreviewBorder = findViewById(R.id.preview_border); // Set the length of focus rectangle according to preview frame size. int len = Math.min(mPreviewFrame.getWidth(), mPreviewFrame.getHeight()) / 4; ViewGroup.LayoutParams layout = mFocusRectangle.getLayoutParams(); @@ -998,7 +998,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, Thread startPreviewThread = new Thread(new Runnable() { public void run() { try { - mStartPreviewFail = false; + mOpenCameraFail = false; startPreview(); } catch (CameraHardwareException e) { // In eng build, we throw the exception so that test tool @@ -1006,7 +1006,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, if ("eng".equals(Build.TYPE)) { throw new RuntimeException(e); } - mStartPreviewFail = true; + mOpenCameraFail = true; } } }); @@ -1036,7 +1036,7 @@ public class Camera extends ActivityBase implements View.OnClickListener, // Make sure preview is started. try { startPreviewThread.join(); - if (mStartPreviewFail) { + if (mOpenCameraFail) { showCameraErrorAndFinish(); return; } @@ -1447,15 +1447,16 @@ public class Camera extends ActivityBase implements View.OnClickListener, @Override protected void onResume() { super.onResume(); - mPausing = false; + if (mOpenCameraFail) return; + mJpegPictureCallbackTime = 0; mZoomValue = 0; mReviewImage.setVisibility(View.GONE); // Start the preview if it is not started. - if (mCameraState == PREVIEW_STOPPED && !mStartPreviewFail) { + if (mCameraState == PREVIEW_STOPPED) { resetExposureCompensation(); if (!restartPreview()) return; } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 08ab29a2..e002bf5 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -47,13 +47,14 @@ import android.os.Message; import android.os.ParcelFileDescriptor; import android.os.SystemClock; import android.provider.MediaStore; -import android.provider.Settings; import android.provider.MediaStore.Video; +import android.provider.Settings; import android.util.Log; import android.view.GestureDetector; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; +import android.view.MenuItem.OnMenuItemClickListener; import android.view.MotionEvent; import android.view.OrientationEventListener; import android.view.SurfaceHolder; @@ -62,7 +63,6 @@ import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.view.MenuItem.OnMenuItemClickListener; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.Button; @@ -833,13 +833,14 @@ public class VideoCamera extends ActivityBase protected void onResume() { super.onResume(); mPausing = false; + if (mOpenCameraFail) return; mReviewImage.setVisibility(View.GONE); // Start orientation listener as soon as possible because it takes // some time to get first orientation. mOrientationListener.enable(); - if (!mPreviewing && !mOpenCameraFail) { + if (!mPreviewing) { if (!openCamera()) return; readVideoPreferences(); resizeForPreviewAspectRatio(); |