From 662082d70ce8dc5f679a25322a00c2733f0339f2 Mon Sep 17 00:00:00 2001 From: Alan Newberger Date: Mon, 12 Jan 2015 11:27:30 -0800 Subject: [PATCH] Remove exception when releasing a requested, not yet opened camera From monkey tests, we see a spike in an exception from new device which is likely due to slow close performance. If we camera B is open, and we request camera A, B will be closed then A opened. If we release A during this process but B is not yet closed, don't crash, just let the pending underlying open of A happen and release the request. Preserve the exception for application errors where truly unrequested cameras are released. Bug: 17975345 Change-Id: I9aa3b0575e130f516cea6a3df120e4812df55bce --- src/com/android/camera/app/CameraController.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/com/android/camera/app/CameraController.java b/src/com/android/camera/app/CameraController.java index c6f5d62e9..5eba88bd2 100644 --- a/src/com/android/camera/app/CameraController.java +++ b/src/com/android/camera/app/CameraController.java @@ -266,8 +266,16 @@ public class CameraController implements CameraAgent.CameraOpenCallback, CameraP mRequestingCameraId = EMPTY_REQUEST; return; } - if (mCameraProxy.getCameraId() != id) { - throw new IllegalStateException("Trying to release an unopened camera."); + int currentId = mCameraProxy.getCameraId(); + if (currentId != id) { + if (mRequestingCameraId == id) { + Log.w(TAG, "Releasing camera which was requested but not yet " + + "opened (current:requested): " + currentId + ":" + id); + } else { + throw new IllegalStateException("Trying to release a camera neither opened" + + "nor requested (current:requested:for-release): " + + currentId + ":" + mRequestingCameraId + ":" + id); + } } mRequestingCameraId = EMPTY_REQUEST; } -- 2.11.0