Merge "camera2: Fix Nakasi crash-on-start when using Camera2 API." into lmp-dev
diff --git a/core/java/android/hardware/camera2/legacy/LegacyFocusStateMapper.java b/core/java/android/hardware/camera2/legacy/LegacyFocusStateMapper.java
index d0a3a3f..d5ec71a 100644
--- a/core/java/android/hardware/camera2/legacy/LegacyFocusStateMapper.java
+++ b/core/java/android/hardware/camera2/legacy/LegacyFocusStateMapper.java
@@ -114,21 +114,24 @@
currentAfRun = mAfRun;
}
- mCamera.setAutoFocusMoveCallback(new Camera.AutoFocusMoveCallback() {
+ Camera.AutoFocusMoveCallback afMoveCallback = new Camera.AutoFocusMoveCallback() {
@Override
public void onAutoFocusMoving(boolean start, Camera camera) {
synchronized (mLock) {
int latestAfRun = mAfRun;
if (VERBOSE) {
- Log.v(TAG, "onAutoFocusMoving - start " + start + " latest AF run " +
- latestAfRun + ", last AF run " + currentAfRun);
+ Log.v(TAG,
+ "onAutoFocusMoving - start " + start + " latest AF run " +
+ latestAfRun + ", last AF run " + currentAfRun
+ );
}
if (currentAfRun != latestAfRun) {
Log.d(TAG,
"onAutoFocusMoving - ignoring move callbacks from old af run"
- + currentAfRun);
+ + currentAfRun
+ );
return;
}
@@ -151,9 +154,19 @@
mAfState = newAfState;
}
}
- });
+ };
+
+ // Only set move callback if we can call autofocus.
+ switch (afMode) {
+ case Parameters.FOCUS_MODE_AUTO:
+ case Parameters.FOCUS_MODE_MACRO:
+ case Parameters.FOCUS_MODE_CONTINUOUS_PICTURE:
+ case Parameters.FOCUS_MODE_CONTINUOUS_VIDEO:
+ mCamera.setAutoFocusMoveCallback(afMoveCallback);
+ }
}
+
// AF Locking
switch (afTrigger) {
case CONTROL_AF_TRIGGER_START:
@@ -167,6 +180,7 @@
case Parameters.FOCUS_MODE_CONTINUOUS_PICTURE:
case Parameters.FOCUS_MODE_CONTINUOUS_VIDEO:
afStateAfterStart = CONTROL_AF_STATE_PASSIVE_SCAN;
+ break;
default:
// EDOF, INFINITY
afStateAfterStart = CONTROL_AF_STATE_INACTIVE;
@@ -183,6 +197,11 @@
"new AF run is " + currentAfRun);
}
+ // Avoid calling autofocus unless we are in a state that supports calling this.
+ if (afStateAfterStart == CONTROL_AF_STATE_INACTIVE) {
+ break;
+ }
+
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
diff --git a/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java b/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java
index 4c4ad0d..42ee4fa 100644
--- a/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java
+++ b/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java
@@ -122,7 +122,10 @@
activeArray, zoomData, aeRegions, maxNumMeteringAreas,
/*regionName*/"AE");
- params.setMeteringAreas(meteringAreaList);
+ // WAR: for b/17252693, some devices can't handle params.setFocusAreas(null).
+ if (maxNumMeteringAreas > 0) {
+ params.setMeteringAreas(meteringAreaList);
+ }
}
// afRegions
@@ -133,7 +136,10 @@
activeArray, zoomData, afRegions, maxNumFocusAreas,
/*regionName*/"AF");
- params.setFocusAreas(focusAreaList);
+ // WAR: for b/17252693, some devices can't handle params.setFocusAreas(null).
+ if (maxNumFocusAreas > 0) {
+ params.setFocusAreas(focusAreaList);
+ }
}
}