FileDocCategorySizeDatePackage
CameraBinderDecorator.javaAPI DocAndroid 5.1 API6359Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.utils

CameraBinderDecorator

public class CameraBinderDecorator extends Object
Translate camera device status_t return values into exceptions.
see
android.hardware.camera2.utils.CameraBinderDecorator#newInstance
hide

Fields Summary
public static final int
NO_ERROR
public static final int
PERMISSION_DENIED
public static final int
ALREADY_EXISTS
public static final int
BAD_VALUE
public static final int
DEAD_OBJECT
public static final int
INVALID_OPERATION
public static final int
TIMED_OUT
public static final int
EACCES
TODO: add as error codes in Errors.h - POLICY_PROHIBITS - RESOURCE_BUSY - NO_SUCH_DEVICE - NOT_SUPPORTED - TOO_MANY_USERS
public static final int
EBUSY
public static final int
ENODEV
public static final int
EOPNOTSUPP
public static final int
EUSERS
Constructors Summary
Methods Summary
public static TnewInstance(T obj)

Wraps the type T with a proxy that will check 'status_t' return codes from the native side of the camera service, and throw Java exceptions automatically based on the code.

In addition it also rewrites binder's RemoteException into either a CameraAccessException or an UnsupportedOperationException.

As a result of calling any method on the proxy, RemoteException is guaranteed never to be thrown.

param
obj object that will serve as the target for all method calls
param
the type of the element you want to wrap. This must be an interface.
return
a proxy that will intercept all invocations to obj

        return Decorator.<T> newInstance(obj, new CameraBinderDecoratorListener());
    
public static voidthrowOnError(int errorFlag)
Throw error codes returned by the camera service as exceptions.

param
errorFlag error to throw as an exception.

        switch (errorFlag) {
            case NO_ERROR:
                return;
            case PERMISSION_DENIED:
                throw new SecurityException("Lacking privileges to access camera service");
            case ALREADY_EXISTS:
                // This should be handled at the call site. Typically this isn't bad,
                // just means we tried to do an operation that already completed.
                return;
            case BAD_VALUE:
                throw new IllegalArgumentException("Bad argument passed to camera service");
            case DEAD_OBJECT:
                throw new CameraRuntimeException(CAMERA_DISCONNECTED);
            case TIMED_OUT:
                throw new CameraRuntimeException(CAMERA_ERROR,
                        "Operation timed out in camera service");
            case EACCES:
                throw new CameraRuntimeException(CAMERA_DISABLED);
            case EBUSY:
                throw new CameraRuntimeException(CAMERA_IN_USE);
            case EUSERS:
                throw new CameraRuntimeException(MAX_CAMERAS_IN_USE);
            case ENODEV:
                throw new CameraRuntimeException(CAMERA_DISCONNECTED);
            case EOPNOTSUPP:
                throw new CameraRuntimeException(CAMERA_DEPRECATED_HAL);
            case INVALID_OPERATION:
                throw new CameraRuntimeException(CAMERA_ERROR,
                        "Illegal state encountered in camera service.");
        }

        /**
         * Trap the rest of the negative return values. If we have known
         * error codes i.e. ALREADY_EXISTS that aren't really runtime
         * errors, then add them to the top switch statement
         */
        if (errorFlag < 0) {
            throw new UnsupportedOperationException(String.format("Unknown error %d",
                    errorFlag));
        }