Camera: Camera shouldn't throw 'RejectedExecutionException'

In case the camera client registers a valid callback but the
respective handler looper exits a 'RejectedExecutionException'
could be thrown by the 'HandlerExecutor' implementation once it
detects that the 'post' method is failing. This exception is not
mentioned in the current camera API and deviates from the usual
behavior where the post status is ignored. To avoid possible
issues with camera clients a new camera specific handler executor
is used which will also ignore the 'post' method return value.

Bug: 74605221
Test: Camera CTS
Change-Id: I2d947ba9cebfc9b4b2a7c88ace6a4060ff7c175e
This commit is contained in:
Emilian Peev
2018-03-14 17:18:49 +00:00
parent 77ca866b53
commit b9a5194e9e

View File

@@ -18,6 +18,7 @@ package android.hardware.camera2.impl;
import static com.android.internal.util.function.pooled.PooledLambda.obtainRunnable;
import android.annotation.NonNull;
import android.hardware.ICameraService;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
@@ -38,7 +39,6 @@ import android.hardware.camera2.utils.SurfaceUtils;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
@@ -49,6 +49,8 @@ import android.util.Size;
import android.util.SparseArray;
import android.view.Surface;
import com.android.internal.util.Preconditions;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Collection;
@@ -2292,6 +2294,27 @@ public class CameraDeviceImpl extends CameraDevice
} // public class CameraDeviceCallbacks
/**
* A camera specific adapter {@link Executor} that posts all executed tasks onto the given
* {@link Handler}.
*
* @hide
*/
private static class CameraHandlerExecutor implements Executor {
private final Handler mHandler;
public CameraHandlerExecutor(@NonNull Handler handler) {
mHandler = Preconditions.checkNotNull(handler);
}
@Override
public void execute(Runnable command) {
// Return value of 'post()' will be ignored in order to keep the
// same camera behavior. For further details see b/74605221 .
mHandler.post(command);
}
}
/**
* Instantiate a new Executor.
*
@@ -2304,7 +2327,7 @@ public class CameraDeviceImpl extends CameraDevice
}
if (handler != null) {
return new HandlerExecutor(handler);
return new CameraHandlerExecutor(handler);
}
return null;
@@ -2320,7 +2343,7 @@ public class CameraDeviceImpl extends CameraDevice
* </p>
*/
static Executor checkAndWrapHandler(Handler handler) {
return new HandlerExecutor(checkHandler(handler));
return new CameraHandlerExecutor(checkHandler(handler));
}
/**