Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb299b85 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Gerrit Code Review
Browse files

Merge "Replace hard-coded errno values with OsConstants"

parents 95f15495 8ea56f68
Loading
Loading
Loading
Loading
+29 −38
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import static android.system.OsConstants.*;

/**
 * The Camera class is used to set image capture settings, start/stop preview,
 * snap pictures, and retrieve frames for encoding for video.  This class is a
@@ -173,13 +175,6 @@ public class Camera {
    private final Object mAutoFocusCallbackLock = new Object();

    private static final int NO_ERROR = 0;
    private static final int EACCESS = -13;
    private static final int ENODEV = -19;
    private static final int EBUSY = -16;
    private static final int EINVAL = -22;
    private static final int ENOSYS = -38;
    private static final int EUSERS = -87;
    private static final int EOPNOTSUPP = -95;

    /**
     * Broadcast Action:  A new picture is taken by the camera, and the entry of
@@ -415,32 +410,30 @@ public class Camera {
    private Camera(int cameraId, int halVersion) {
        int err = cameraInitVersion(cameraId, halVersion);
        if (checkInitErrors(err)) {
            switch(err) {
                case EACCESS:
            if (err == -EACCES) {
                throw new RuntimeException("Fail to connect to camera service");
                case ENODEV:
            } else if (err == -ENODEV) {
                throw new RuntimeException("Camera initialization failed");
                case ENOSYS:
            } else if (err == -ENOSYS) {
                throw new RuntimeException("Camera initialization failed because some methods"
                        + " are not implemented");
                case EOPNOTSUPP:
            } else if (err == -EOPNOTSUPP) {
                throw new RuntimeException("Camera initialization failed because the hal"
                        + " version is not supported by this device");
                case EINVAL:
            } else if (err == -EINVAL) {
                throw new RuntimeException("Camera initialization failed because the input"
                        + " arugments are invalid");
                case EBUSY:
            } else if (err == -EBUSY) {
                throw new RuntimeException("Camera initialization failed because the camera"
                        + " device was already opened");
                case EUSERS:
            } else if (err == -EUSERS) {
                throw new RuntimeException("Camera initialization failed because the max"
                        + " number of camera devices were already opened");
                default:
            }
            // Should never hit this.
            throw new RuntimeException("Unknown camera error");
        }
    }
    }

    private int cameraInitVersion(int cameraId, int halVersion) {
        mShutterCallback = null;
@@ -490,17 +483,15 @@ public class Camera {
    Camera(int cameraId) {
        int err = cameraInitNormal(cameraId);
        if (checkInitErrors(err)) {
            switch(err) {
                case EACCESS:
            if (err == -EACCES) {
                throw new RuntimeException("Fail to connect to camera service");
                case ENODEV:
            } else if (err == -ENODEV) {
                throw new RuntimeException("Camera initialization failed");
                default:
            }
            // Should never hit this.
            throw new RuntimeException("Unknown camera error");
        }
    }
    }


    /**
+23 −12
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ import android.view.Surface;
import java.util.ArrayList;
import java.util.List;

import static android.system.OsConstants.EACCES;
import static android.system.OsConstants.ENODEV;

/**
 * Compatibility implementation of the Camera2 API binder interface.
 *
@@ -88,6 +91,14 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        mSurfaceIdCounter = 0;
    }

    private static int translateErrorsFromCamera1(int errorCode) {
        if (errorCode == -EACCES) {
            return CameraBinderDecorator.PERMISSION_DENIED;
        }

        return errorCode;
    }

    /**
     * Create a separate looper/thread for the camera to run on; open the camera.
     *
@@ -382,7 +393,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot submit request, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        synchronized(mConfigureLock) {
@@ -402,7 +413,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot submit request list, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        synchronized(mConfigureLock) {
@@ -421,7 +432,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot cancel request, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        synchronized(mConfigureLock) {
@@ -442,7 +453,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot begin configure, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        synchronized(mConfigureLock) {
@@ -462,7 +473,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot end configure, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        ArrayList<Surface> surfaces = null;
@@ -490,7 +501,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot delete stream, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        synchronized(mConfigureLock) {
@@ -515,7 +526,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot create stream, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        synchronized(mConfigureLock) {
@@ -552,7 +563,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot create default request, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        CameraMetadataNative template;
@@ -585,7 +596,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot wait until idle, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        synchronized(mConfigureLock) {
@@ -605,7 +616,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot flush, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        synchronized(mConfigureLock) {
@@ -627,7 +638,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot prepare stream, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        // LEGACY doesn't support actual prepare, just signal success right away
@@ -647,7 +658,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
        }
        if (mLegacyDevice.isClosed()) {
            Log.e(TAG, "Cannot tear down stream, device has been closed.");
            return CameraBinderDecorator.ENODEV;
            return -ENODEV;
        }

        // LEGACY doesn't support actual teardown, so just a no-op
+7 −8
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.hardware.camera2.legacy;
import android.hardware.camera2.utils.CameraBinderDecorator;
import android.util.AndroidException;

import static android.system.OsConstants.ENODEV;

/**
 * Utility class containing exception handling used solely by the compatibility mode shim.
 */
@@ -51,19 +53,16 @@ public class LegacyExceptionUtils {
     * exceptions.</p>
     *
     * @param errorFlag error to throw as an exception.
     * @throws {@link BufferQueueAbandonedException} for {@link CameraBinderDecorator#ENODEV}.
     * @throws {@link BufferQueueAbandonedException} for -ENODEV.
     * @throws {@link UnsupportedOperationException} for an unknown negative error code.
     * @return {@code errorFlag} if the value was non-negative, throws otherwise.
     */
    public static int throwOnError(int errorFlag) throws BufferQueueAbandonedException {
        switch (errorFlag) {
            case CameraBinderDecorator.NO_ERROR: {
        if (errorFlag == CameraBinderDecorator.NO_ERROR) {
            return CameraBinderDecorator.NO_ERROR;
            }
            case CameraBinderDecorator.BAD_VALUE: {
        } else if (errorFlag == -ENODEV) {
            throw new BufferQueueAbandonedException();
        }
        }

        if (errorFlag < 0) {
            throw new UnsupportedOperationException("Unknown error " + errorFlag);
+35 −41
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.hardware.camera2.CameraAccessException.CAMERA_IN_USE;
import static android.hardware.camera2.CameraAccessException.CAMERA_ERROR;
import static android.hardware.camera2.CameraAccessException.MAX_CAMERAS_IN_USE;
import static android.hardware.camera2.CameraAccessException.CAMERA_DEPRECATED_HAL;
import static android.system.OsConstants.*;

import android.os.DeadObjectException;
import android.os.RemoteException;
@@ -37,12 +38,12 @@ import java.lang.reflect.Method;
public class CameraBinderDecorator {

    public static final int NO_ERROR = 0;
    public static final int PERMISSION_DENIED = -1;
    public static final int ALREADY_EXISTS = -17;
    public static final int BAD_VALUE = -22;
    public static final int DEAD_OBJECT = -32;
    public static final int INVALID_OPERATION = -38;
    public static final int TIMED_OUT = -110;
    public static final int PERMISSION_DENIED = -EPERM;
    public static final int ALREADY_EXISTS = -EEXIST;
    public static final int BAD_VALUE = -EINVAL;
    public static final int DEAD_OBJECT = -ENOSYS;
    public static final int INVALID_OPERATION = -EPIPE;
    public static final int TIMED_OUT = -ETIMEDOUT;

    /**
     * TODO: add as error codes in Errors.h
@@ -52,12 +53,6 @@ public class CameraBinderDecorator {
     * - NOT_SUPPORTED
     * - TOO_MANY_USERS
     */
    public static final int EACCES = -13;
    public static final int EBUSY = -16;
    public static final int ENODEV = -19;
    public static final int EOPNOTSUPP = -95;
    public static final int EUSERS = -87;


    static class CameraBinderDecoratorListener implements Decorator.DecoratorListener {

@@ -101,33 +96,32 @@ public class CameraBinderDecorator {
     * @param errorFlag error to throw as an exception.
     */
    public static void throwOnError(int errorFlag) {
        switch (errorFlag) {
            case NO_ERROR:
        if (errorFlag == NO_ERROR) {
            return;
            case PERMISSION_DENIED:
        } else if (errorFlag == PERMISSION_DENIED) {
            throw new SecurityException("Lacking privileges to access camera service");
            case ALREADY_EXISTS:
        } else if (errorFlag == 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:
        } else if (errorFlag == BAD_VALUE) {
            throw new IllegalArgumentException("Bad argument passed to camera service");
            case DEAD_OBJECT:
        } else if (errorFlag == DEAD_OBJECT) {
            throw new CameraRuntimeException(CAMERA_DISCONNECTED);
            case TIMED_OUT:
        } else if (errorFlag == TIMED_OUT) {
            throw new CameraRuntimeException(CAMERA_ERROR,
                    "Operation timed out in camera service");
            case EACCES:
        } else if (errorFlag == -EACCES) {
            throw new CameraRuntimeException(CAMERA_DISABLED);
            case EBUSY:
        } else if (errorFlag == -EBUSY) {
            throw new CameraRuntimeException(CAMERA_IN_USE);
            case EUSERS:
        } else if (errorFlag == -EUSERS) {
            throw new CameraRuntimeException(MAX_CAMERAS_IN_USE);
            case ENODEV:
        } else if (errorFlag == -ENODEV) {
            throw new CameraRuntimeException(CAMERA_DISCONNECTED);
            case EOPNOTSUPP:
        } else if (errorFlag == -EOPNOTSUPP) {
            throw new CameraRuntimeException(CAMERA_DEPRECATED_HAL);
            case INVALID_OPERATION:
        } else if (errorFlag == INVALID_OPERATION) {
            throw new CameraRuntimeException(CAMERA_ERROR,
                    "Illegal state encountered in camera service.");
        }
+7 −5
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;

import static android.system.OsConstants.*;

/**
 * The SoundTrigger class provides access via JNI to the native service managing
 * the sound trigger HAL.
@@ -35,11 +37,11 @@ public class SoundTrigger {

    public static final int STATUS_OK = 0;
    public static final int STATUS_ERROR = Integer.MIN_VALUE;
    public static final int STATUS_PERMISSION_DENIED = -1;
    public static final int STATUS_NO_INIT = -19;
    public static final int STATUS_BAD_VALUE = -22;
    public static final int STATUS_DEAD_OBJECT = -32;
    public static final int STATUS_INVALID_OPERATION = -38;
    public static final int STATUS_PERMISSION_DENIED = -EPERM;
    public static final int STATUS_NO_INIT = -ENODEV;
    public static final int STATUS_BAD_VALUE = -EINVAL;
    public static final int STATUS_DEAD_OBJECT = -EPIPE;
    public static final int STATUS_INVALID_OPERATION = -ENOSYS;

    /*****************************************************************************
     * A ModuleProperties describes a given sound trigger hardware module
Loading