Merge "Camera: fix race in onRepeatingRequestError callback" into oc-mr1-dev am: f23334869d
am: 811029f71d
Change-Id: Ib156c92bde8571cad70b1fe2cef0f03d9eae54b4
diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
index 0d5c5e3..bfeb14d 100644
--- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
@@ -1769,7 +1769,7 @@
}
@Override
- public void onRepeatingRequestError(long lastFrameNumber) {
+ public void onRepeatingRequestError(long lastFrameNumber, int repeatingRequestId) {
if (DEBUG) {
Log.d(TAG, "Repeating request error received. Last frame number is " +
lastFrameNumber);
@@ -1782,7 +1782,10 @@
}
checkEarlyTriggerSequenceComplete(mRepeatingRequestId, lastFrameNumber);
- mRepeatingRequestId = REQUEST_ID_NONE;
+ // Check if there is already a new repeating request
+ if (mRepeatingRequestId == repeatingRequestId) {
+ mRepeatingRequestId = REQUEST_ID_NONE;
+ }
}
}
diff --git a/core/java/android/hardware/camera2/legacy/CameraDeviceState.java b/core/java/android/hardware/camera2/legacy/CameraDeviceState.java
index 135d92b..89ecd5f 100644
--- a/core/java/android/hardware/camera2/legacy/CameraDeviceState.java
+++ b/core/java/android/hardware/camera2/legacy/CameraDeviceState.java
@@ -77,7 +77,7 @@
void onCaptureStarted(RequestHolder holder, long timestamp);
void onCaptureResult(CameraMetadataNative result, RequestHolder holder);
void onRequestQueueEmpty();
- void onRepeatingRequestError(long lastFrameNumber);
+ void onRepeatingRequestError(long lastFrameNumber, int repeatingRequestId);
}
/**
@@ -208,12 +208,14 @@
* <p>Repeating request has been stopped due to an error such as abandoned output surfaces.</p>
*
* @param lastFrameNumber Frame number of the last repeating request before it is stopped.
+ * @param repeatingRequestId The ID of the repeating request being stopped
*/
- public synchronized void setRepeatingRequestError(final long lastFrameNumber) {
+ public synchronized void setRepeatingRequestError(final long lastFrameNumber,
+ final int repeatingRequestId) {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
- mCurrentListener.onRepeatingRequestError(lastFrameNumber);
+ mCurrentListener.onRepeatingRequestError(lastFrameNumber, repeatingRequestId);
}
});
}
diff --git a/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java b/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
index d8df9a0..49d4096 100644
--- a/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
+++ b/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
@@ -264,10 +264,10 @@
}
@Override
- public void onRepeatingRequestError(long lastFrameNumber) {
+ public void onRepeatingRequestError(long lastFrameNumber, int repeatingRequestId) {
+ Object[] objArray = new Object[] { lastFrameNumber, repeatingRequestId };
Message msg = getHandler().obtainMessage(REPEATING_REQUEST_ERROR,
- /*arg1*/ (int) (lastFrameNumber & 0xFFFFFFFFL),
- /*arg2*/ (int) ( (lastFrameNumber >> 32) & 0xFFFFFFFFL));
+ /*obj*/ objArray);
getHandler().sendMessage(msg);
}
@@ -329,9 +329,10 @@
break;
}
case REPEATING_REQUEST_ERROR: {
- long lastFrameNumber = msg.arg2 & 0xFFFFFFFFL;
- lastFrameNumber = (lastFrameNumber << 32) | (msg.arg1 & 0xFFFFFFFFL);
- mCallbacks.onRepeatingRequestError(lastFrameNumber);
+ Object[] objArray = (Object[]) msg.obj;
+ long lastFrameNumber = (Long) objArray[0];
+ int repeatingRequestId = (Integer) objArray[1];
+ mCallbacks.onRepeatingRequestError(lastFrameNumber, repeatingRequestId);
break;
}
case REQUEST_QUEUE_EMPTY: {
diff --git a/core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java b/core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java
index 621ea84..cb59fd1 100644
--- a/core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java
+++ b/core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java
@@ -263,7 +263,8 @@
}
@Override
- public void onRepeatingRequestError(final long lastFrameNumber) {
+ public void onRepeatingRequestError(final long lastFrameNumber,
+ final int repeatingRequestId) {
mResultHandler.post(new Runnable() {
@Override
public void run() {
@@ -271,7 +272,8 @@
Log.d(TAG, "doing onRepeatingRequestError callback.");
}
try {
- mDeviceCallbacks.onRepeatingRequestError(lastFrameNumber);
+ mDeviceCallbacks.onRepeatingRequestError(lastFrameNumber,
+ repeatingRequestId);
} catch (RemoteException e) {
throw new IllegalStateException(
"Received remote exception during onRepeatingRequestError " +
diff --git a/core/java/android/hardware/camera2/legacy/RequestThreadManager.java b/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
index 565a43e..aaf07e6 100644
--- a/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
+++ b/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
@@ -939,7 +939,8 @@
Log.d(TAG, "Stopped repeating request. Last frame number is " +
lastFrameNumber);
}
- mDeviceState.setRepeatingRequestError(lastFrameNumber);
+ mDeviceState.setRepeatingRequestError(lastFrameNumber,
+ burstHolder.getRequestId());
}
if (DEBUG) {
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
index fcb861c..cf5882f 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
@@ -271,7 +271,7 @@
* @see android.hardware.camera2.ICameraDeviceCallbacks#onRepeatingRequestError()
*/
@Override
- public void onRepeatingRequestError(long lastFrameNumber) {
+ public void onRepeatingRequestError(long lastFrameNumber, int repeatingRequestId) {
// TODO Auto-generated method stub
}
}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
index 476f016..e628b68 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
@@ -161,7 +161,7 @@
* @see android.hardware.camera2.ICameraDeviceCallbacks#onRepeatingRequestError()
*/
@Override
- public void onRepeatingRequestError(long lastFrameNumber) {
+ public void onRepeatingRequestError(long lastFrameNumber, int repeatingRequestId) {
// TODO Auto-generated method stub
}
}