Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 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 | |
Eino-Ville Talvala | 2f1a2e4 | 2013-07-25 17:12:05 -0700 | [diff] [blame] | 17 | package android.hardware.camera2; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 18 | |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 19 | import android.util.AndroidException; |
| 20 | |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 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 | */ |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 29 | public class CameraAccessException extends AndroidException { |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 30 | /** |
| 31 | * The camera device is in use already |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 32 | * @hide |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 33 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 34 | public static final int CAMERA_IN_USE = 4; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 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. |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 40 | * @hide |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 41 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 42 | public static final int MAX_CAMERAS_IN_USE = 5; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 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 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 49 | public static final int CAMERA_DISABLED = 1; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * The camera device is removable and has been disconnected from the Android |
Ruben Brunk | 66ef645 | 2013-08-08 13:05:30 -0700 | [diff] [blame] | 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 |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 55 | * higher-priority access request for the camera device. |
| 56 | */ |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 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 |
Eino-Ville Talvala | fd88743 | 2014-09-04 13:07:40 -0700 | [diff] [blame] | 64 | * {@link CameraDevice.StateCallback#onError} for the exact |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 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; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 74 | |
Ruben Brunk | 66ef645 | 2013-08-08 13:05:30 -0700 | [diff] [blame] | 75 | /** |
| 76 | * A deprecated HAL version is in use. |
| 77 | * @hide |
| 78 | */ |
| 79 | public static final int CAMERA_DEPRECATED_HAL = 1000; |
| 80 | |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 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; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * The reason for the failure to access the camera. |
| 88 | * |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 89 | * @see #CAMERA_DISABLED |
| 90 | * @see #CAMERA_DISCONNECTED |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 91 | * @see #CAMERA_ERROR |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 92 | */ |
| 93 | public final int getReason() { |
| 94 | return mReason; |
| 95 | } |
| 96 | |
| 97 | public CameraAccessException(int problem) { |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 98 | super(getDefaultMessage(problem)); |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 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) { |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 113 | super(getDefaultMessage(problem), cause); |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 114 | mReason = problem; |
| 115 | } |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 116 | |
Ruben Brunk | b6a7810 | 2014-05-22 06:45:59 -0700 | [diff] [blame] | 117 | /** |
| 118 | * @hide |
| 119 | */ |
| 120 | public static String getDefaultMessage(int problem) { |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 121 | 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 Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 128 | 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 Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 132 | case CAMERA_DISABLED: |
| 133 | return "The camera is disabled due to a device policy, and cannot be opened."; |
Igor Murashkin | 5c9eaf6 | 2013-09-10 19:35:24 -0700 | [diff] [blame] | 134 | case CAMERA_ERROR: |
| 135 | return "The camera device is currently in the error state; " + |
| 136 | "no further calls to it will succeed."; |
Igor Murashkin | e363fbb | 2013-06-25 20:26:06 +0000 | [diff] [blame] | 137 | } |
| 138 | return null; |
| 139 | } |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 140 | } |