Fields Summary |
---|
private static final String | TAG |
private static final boolean | VERBOSE |
private final CameraDevice.StateCallback | mProxy |
private final Object | mLock |
private boolean | mWaiting |
private final LinkedBlockingQueue | mRecentStates |
private static final String[] | mStateNames |
public static final int | STATE_UNINITIALIZEDDevice has not reported any state yet |
public static final int | STATE_OPENEDDevice is in the first-opened state (transitory) |
public static final int | STATE_CLOSEDDevice is closed |
public static final int | STATE_DISCONNECTEDDevice is disconnected |
public static final int | STATE_ERRORDevice has encountered a fatal error |
private static int | NUM_STATESTotal number of reachable states |
Methods Summary |
---|
public static void | appendStates(java.lang.StringBuilder s, java.util.Collection states)Append all states to string
boolean start = true;
for (Integer state: states) {
if (!start) s.append(" ");
s.append(stateToString(state));
start = false;
}
|
public void | onClosed(android.hardware.camera2.CameraDevice camera)
if (mProxy != null) mProxy.onClosed(camera);
setCurrentState(STATE_CLOSED);
|
public void | onDisconnected(android.hardware.camera2.CameraDevice camera)
if (mProxy != null) mProxy.onDisconnected(camera);
setCurrentState(STATE_DISCONNECTED);
|
public void | onError(android.hardware.camera2.CameraDevice camera, int error)
if (mProxy != null) mProxy.onError(camera, error);
setCurrentState(STATE_ERROR);
|
public void | onOpened(android.hardware.camera2.CameraDevice camera)
if (mProxy != null) mProxy.onOpened(camera);
setCurrentState(STATE_OPENED);
|
private void | setCurrentState(int state)
if (VERBOSE) Log.v(TAG, "Camera device state now " + stateToString(state));
try {
mRecentStates.put(state);
} catch(InterruptedException e) {
throw new RuntimeException("Unable to set device state", e);
}
|
public static java.lang.String | stateToString(int state)Convert state integer to a String
return mStateNames[state + 1];
|
public int | waitForAnyOfStates(java.util.Collection states, long timeout)Wait until the one of the desired states is observed, checking all
state transitions since the last state that was waited on.
Note: Only one waiter allowed at a time!
synchronized(mLock) {
if (mWaiting) throw new IllegalStateException("Only one waiter allowed at a time");
mWaiting = true;
}
if (VERBOSE) {
StringBuilder s = new StringBuilder("Waiting for state(s) ");
appendStates(s, states);
Log.v(TAG, s.toString());
}
Integer nextState = null;
long timeoutLeft = timeout;
long startMs = SystemClock.elapsedRealtime();
try {
while ((nextState = mRecentStates.poll(timeoutLeft, TimeUnit.MILLISECONDS))
!= null) {
if (VERBOSE) {
Log.v(TAG, " Saw transition to " + stateToString(nextState));
}
if (states.contains(nextState)) break;
long endMs = SystemClock.elapsedRealtime();
timeoutLeft -= (endMs - startMs);
startMs = endMs;
}
} catch (InterruptedException e) {
throw new UnsupportedOperationException("Does not support interrupts on waits", e);
}
synchronized(mLock) {
mWaiting = false;
}
if (!states.contains(nextState)) {
StringBuilder s = new StringBuilder("Timed out after ");
s.append(timeout);
s.append(" ms waiting for state(s) ");
appendStates(s, states);
throw new TimeoutRuntimeException(s.toString());
}
return nextState;
|
public void | waitForState(int state, long timeout)Wait until the desired state is observed, checking all state
transitions since the last state that was waited on.
Note: Only one waiter allowed at a time!
Integer[] stateArray = { state };
waitForAnyOfStates(Arrays.asList(stateArray), timeout);
|