Home | History | Annotate | Download | only in camera2
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.hardware.camera2;
     18 
     19 import android.util.AndroidException;
     20 
     21 /**
     22  * <p><code>CameraAccessException</code> is thrown if a camera device could not
     23  * be queried or opened by the {@link CameraManager}, or if the connection to an
     24  * opened {@link CameraDevice} is no longer valid.</p>
     25  *
     26  * @see CameraManager
     27  * @see CameraDevice
     28  */
     29 public class CameraAccessException extends AndroidException {
     30     /**
     31      * The camera device is in use already
     32      * @hide
     33      */
     34     public static final int CAMERA_IN_USE = 4;
     35 
     36     /**
     37      * The system-wide limit for number of open cameras has been reached,
     38      * and more camera devices cannot be opened until previous instances are
     39      * closed.
     40      * @hide
     41      */
     42     public static final int MAX_CAMERAS_IN_USE = 5;
     43 
     44     /**
     45      * The camera is disabled due to a device policy, and cannot be opened.
     46      *
     47      * @see android.app.admin.DevicePolicyManager#setCameraDisabled(android.content.ComponentName, boolean)
     48      */
     49     public static final int CAMERA_DISABLED = 1;
     50 
     51     /**
     52      * The camera device is removable and has been disconnected from the Android
     53      * device, or the camera id used with {@link android.hardware.camera2.CameraManager#openCamera}
     54      * is no longer valid, or the camera service has shut down the connection due to a
     55      * higher-priority access request for the camera device.
     56      */
     57     public static final int CAMERA_DISCONNECTED = 2;
     58 
     59     /**
     60      * The camera device is currently in the error state.
     61      *
     62      * <p>The camera has failed to open or has failed at a later time
     63      * as a result of some non-user interaction. Refer to
     64      * {@link CameraDevice.StateListener#onError} for the exact
     65      * nature of the error.</p>
     66      *
     67      * <p>No further calls to the camera will succeed. Clean up
     68      * the camera with {@link CameraDevice#close} and try
     69      * handling the error in order to successfully re-open the camera.
     70      * </p>
     71      *
     72      */
     73     public static final int CAMERA_ERROR = 3;
     74 
     75     /**
     76      * A deprecated HAL version is in use.
     77      * @hide
     78      */
     79     public static final int CAMERA_DEPRECATED_HAL = 1000;
     80 
     81     // Make the eclipse warning about serializable exceptions go away
     82     private static final long serialVersionUID = 5630338637471475675L; // randomly generated
     83 
     84     private final int mReason;
     85 
     86     /**
     87      * The reason for the failure to access the camera.
     88      *
     89      * @see #CAMERA_DISABLED
     90      * @see #CAMERA_DISCONNECTED
     91      * @see #CAMERA_ERROR
     92      */
     93     public final int getReason() {
     94         return mReason;
     95     }
     96 
     97     public CameraAccessException(int problem) {
     98         super(getDefaultMessage(problem));
     99         mReason = problem;
    100     }
    101 
    102     public CameraAccessException(int problem, String message) {
    103         super(message);
    104         mReason = problem;
    105     }
    106 
    107     public CameraAccessException(int problem, String message, Throwable cause) {
    108         super(message, cause);
    109         mReason = problem;
    110     }
    111 
    112     public CameraAccessException(int problem, Throwable cause) {
    113         super(getDefaultMessage(problem), cause);
    114         mReason = problem;
    115     }
    116 
    117     private static String getDefaultMessage(int problem) {
    118         switch (problem) {
    119             case CAMERA_IN_USE:
    120                 return "The camera device is in use already";
    121             case MAX_CAMERAS_IN_USE:
    122                 return "The system-wide limit for number of open cameras has been reached, " +
    123                        "and more camera devices cannot be opened until previous instances " +
    124                        "are closed.";
    125             case CAMERA_DISCONNECTED:
    126                 return "The camera device is removable and has been disconnected from the " +
    127                         "Android device, or the camera service has shut down the connection due " +
    128                         "to a higher-priority access request for the camera device.";
    129             case CAMERA_DISABLED:
    130                 return "The camera is disabled due to a device policy, and cannot be opened.";
    131             case CAMERA_ERROR:
    132                 return "The camera device is currently in the error state; " +
    133                        "no further calls to it will succeed.";
    134         }
    135         return null;
    136     }
    137 }
    138