blob: 91ef6cae22950760707c7dfdbaea73c1699ceec9 [file] [log] [blame]
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08001/*
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
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -070017package android.hardware.camera2;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080018
Igor Murashkine363fbb2013-06-25 20:26:06 +000019import android.util.AndroidException;
20
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080021/**
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 */
Igor Murashkine363fbb2013-06-25 20:26:06 +000029public class CameraAccessException extends AndroidException {
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080030 /**
31 * The camera device is in use already
Igor Murashkin5c9eaf62013-09-10 19:35:24 -070032 * @hide
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080033 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -070034 public static final int CAMERA_IN_USE = 4;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080035
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.
Igor Murashkin5c9eaf62013-09-10 19:35:24 -070040 * @hide
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080041 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -070042 public static final int MAX_CAMERAS_IN_USE = 5;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080043
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 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -070049 public static final int CAMERA_DISABLED = 1;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080050
51 /**
52 * The camera device is removable and has been disconnected from the Android
Ruben Brunk66ef6452013-08-08 13:05:30 -070053 * 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
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080055 * higher-priority access request for the camera device.
56 */
Igor Murashkin5c9eaf62013-09-10 19:35:24 -070057 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
Eino-Ville Talvalafd887432014-09-04 13:07:40 -070064 * {@link CameraDevice.StateCallback#onError} for the exact
Igor Murashkin5c9eaf62013-09-10 19:35:24 -070065 * 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;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080074
Ruben Brunk66ef6452013-08-08 13:05:30 -070075 /**
76 * A deprecated HAL version is in use.
77 * @hide
78 */
79 public static final int CAMERA_DEPRECATED_HAL = 1000;
80
Igor Murashkine363fbb2013-06-25 20:26:06 +000081 // Make the eclipse warning about serializable exceptions go away
82 private static final long serialVersionUID = 5630338637471475675L; // randomly generated
83
84 private final int mReason;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080085
86 /**
87 * The reason for the failure to access the camera.
88 *
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080089 * @see #CAMERA_DISABLED
90 * @see #CAMERA_DISCONNECTED
Igor Murashkin5c9eaf62013-09-10 19:35:24 -070091 * @see #CAMERA_ERROR
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080092 */
93 public final int getReason() {
94 return mReason;
95 }
96
97 public CameraAccessException(int problem) {
Igor Murashkine363fbb2013-06-25 20:26:06 +000098 super(getDefaultMessage(problem));
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080099 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) {
Igor Murashkine363fbb2013-06-25 20:26:06 +0000113 super(getDefaultMessage(problem), cause);
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800114 mReason = problem;
115 }
Igor Murashkine363fbb2013-06-25 20:26:06 +0000116
Ruben Brunkb6a78102014-05-22 06:45:59 -0700117 /**
118 * @hide
119 */
120 public static String getDefaultMessage(int problem) {
Igor Murashkine363fbb2013-06-25 20:26:06 +0000121 switch (problem) {
122 case CAMERA_IN_USE:
123 return "The camera device is in use already";
124 case MAX_CAMERAS_IN_USE:
125 return "The system-wide limit for number of open cameras has been reached, " +
126 "and more camera devices cannot be opened until previous instances " +
127 "are closed.";
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700128 case CAMERA_DISCONNECTED:
129 return "The camera device is removable and has been disconnected from the " +
130 "Android device, or the camera service has shut down the connection due " +
131 "to a higher-priority access request for the camera device.";
Igor Murashkine363fbb2013-06-25 20:26:06 +0000132 case CAMERA_DISABLED:
133 return "The camera is disabled due to a device policy, and cannot be opened.";
Igor Murashkin5c9eaf62013-09-10 19:35:24 -0700134 case CAMERA_ERROR:
135 return "The camera device is currently in the error state; " +
136 "no further calls to it will succeed.";
Igor Murashkine363fbb2013-06-25 20:26:06 +0000137 }
138 return null;
139 }
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800140}