From b9a5194e9ef4e5015526167a92933a810fdf23c2 Mon Sep 17 00:00:00 2001 From: Emilian Peev Date: Wed, 14 Mar 2018 17:18:49 +0000 Subject: [PATCH] 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 --- .../camera2/impl/CameraDeviceImpl.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java index b328bb1726e90..5e03a3ec07c8a 100644 --- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java +++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java @@ -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 *

*/ static Executor checkAndWrapHandler(Handler handler) { - return new HandlerExecutor(checkHandler(handler)); + return new CameraHandlerExecutor(checkHandler(handler)); } /**