summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorSai Kumar Sanagavarapu <ssanagav@codeaurora.org>2014-10-30 20:21:14 +0530
committerSai Kumar Sanagavarapu <ssanagav@codeaurora.org>2014-11-03 12:22:31 +0530
commite354e1e5fb21ec7808584a3528e74e0ceb86ead4 (patch)
tree58547131e1dfbf48979554b07d2c49fb9dfb923b /src/com
parente9d99154f779c3e86efdcd6a0d4ebb3730af403f (diff)
downloadandroid_packages_apps_Snap-e354e1e5fb21ec7808584a3528e74e0ceb86ead4.tar.gz
android_packages_apps_Snap-e354e1e5fb21ec7808584a3528e74e0ceb86ead4.tar.bz2
android_packages_apps_Snap-e354e1e5fb21ec7808584a3528e74e0ceb86ead4.zip
SnapdragonCamera: Fix NPE in camera open if UI creation takes time.
Sometimes null pointer exception is seen because open camera thread might try to access photo UI though its not created by that time, due to some timing issues. So, let focus manager initialize without photo UI and later update it when photo UI is ready. Change-Id: I7b4c344586115e45269483a614de1e91e1a6ab81
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/FocusOverlayManager.java8
-rw-r--r--src/com/android/camera/PhotoModule.java38
2 files changed, 37 insertions, 9 deletions
diff --git a/src/com/android/camera/FocusOverlayManager.java b/src/com/android/camera/FocusOverlayManager.java
index 5efbf0178..c5ffef5c5 100644
--- a/src/com/android/camera/FocusOverlayManager.java
+++ b/src/com/android/camera/FocusOverlayManager.java
@@ -146,6 +146,10 @@ public class FocusOverlayManager {
mUI = ui;
}
+ public void setPhotoUI(FocusUI ui) {
+ mUI = ui;
+ }
+
public void setParameters(Parameters parameters) {
// parameters can only be null when onConfigurationChanged is called
// before camera is open. We will just return in this case, because
@@ -530,7 +534,9 @@ public class FocusOverlayManager {
if (!mInitialized) return;
// Put focus indicator to the center. clear reset position
- mUI.clearFocus();
+ if (mUI != null) {
+ mUI.clearFocus();
+ }
// Initialize mFocusArea.
mFocusArea = null;
// Initialize mMeteringArea.
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 823cba69d..44e961e95 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -586,7 +586,7 @@ public class PhotoModule
return;
}
Log.v(TAG, "onPreviewUIReady");
- if (mCameraState == PREVIEW_STOPPED) {
+ if (mCameraState == PREVIEW_STOPPED || mCameraState == INIT) {
startPreview();
} else {
SurfaceTexture st = mUI.getSurfaceTexture();
@@ -624,6 +624,7 @@ public class PhotoModule
Log.v(TAG, "onCameraOpened");
openCameraCommon();
resizeForPreviewAspectRatio();
+ updateFocusManager(mUI);
}
private void switchCamera() {
@@ -2210,12 +2211,22 @@ public class PhotoModule
mInitialParams, this, mMirror,
mActivity.getMainLooper(), mUI);
}
- View root = mUI.getRootView();
- // These depend on camera parameters.
+ }
+
+ private void updateFocusManager(PhotoUI mUI) {
+ // Idea here is to let focus manager create in camera open thread
+ // (in initializeFocusManager) even if photoUI is null by that time so
+ // as to not block start preview process. Once UI creation is done,
+ // we will update focus manager with proper UI.
+ if (mFocusManager != null && mUI != null) {
+ mFocusManager.setPhotoUI(mUI);
- int width = root.getWidth();
- int height = root.getHeight();
- mFocusManager.setPreviewSize(width, height);
+ View root = mUI.getRootView();
+ // These depend on camera parameters.
+ int width = root.getWidth();
+ int height = root.getHeight();
+ mFocusManager.setPreviewSize(width, height);
+ }
}
@Override
@@ -2423,7 +2434,11 @@ public class PhotoModule
mDisplayRotation = CameraUtil.getDisplayRotation(mActivity);
mDisplayOrientation = CameraUtil.getDisplayOrientation(mDisplayRotation, mCameraId);
mCameraDisplayOrientation = mDisplayOrientation;
- mUI.setDisplayOrientation(mDisplayOrientation);
+ // This will be called again in checkDisplayRotation(), so there
+ // should not be any problem even if mUI is null.
+ if (mUI != null) {
+ mUI.setDisplayOrientation(mDisplayOrientation);
+ }
if (mFocusManager != null) {
mFocusManager.setDisplayOrientation(mDisplayOrientation);
}
@@ -2448,7 +2463,14 @@ public class PhotoModule
Log.v(TAG, "startPreview");
- SurfaceTexture st = mUI.getSurfaceTexture();
+ SurfaceTexture st = null;
+ if (mUI != null) {
+ st = mUI.getSurfaceTexture();
+ }
+ // Surfacetexture could be null here, but its still valid and safe to set null
+ // surface before startpreview. This will help in basic preview setup and
+ // surface creation in parallel. Once valid surface is ready in onPreviewUIReady()
+ // we set the surface to camera to actually start preview.
mCameraDevice.setPreviewTexture(st);
if (!mCameraPreviewParamsReady) {