blob: fac5086faa5cefbbe18324b6efe2081ee1f4c0cc [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
17package android.hardware.photography;
18
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
32 */
33 public static final int CAMERA_IN_USE = 1;
34
35 /**
36 * The system-wide limit for number of open cameras has been reached,
37 * and more camera devices cannot be opened until previous instances are
38 * closed.
39 */
40 public static final int MAX_CAMERAS_IN_USE = 2;
41
42 /**
43 * The camera is disabled due to a device policy, and cannot be opened.
44 *
45 * @see android.app.admin.DevicePolicyManager#setCameraDisabled(android.content.ComponentName, boolean)
46 */
47 public static final int CAMERA_DISABLED = 3;
48
49 /**
50 * The camera device is removable and has been disconnected from the Android
51 * device, or the camera service has shut down the connection due to a
52 * higher-priority access request for the camera device.
53 */
54 public static final int CAMERA_DISCONNECTED = 4;
55
Igor Murashkine363fbb2013-06-25 20:26:06 +000056 // Make the eclipse warning about serializable exceptions go away
57 private static final long serialVersionUID = 5630338637471475675L; // randomly generated
58
59 private final int mReason;
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080060
61 /**
62 * The reason for the failure to access the camera.
63 *
64 * @see #CAMERA_IN_USE
65 * @see #MAX_CAMERAS_IN_USE
66 * @see #CAMERA_DISABLED
67 * @see #CAMERA_DISCONNECTED
68 */
69 public final int getReason() {
70 return mReason;
71 }
72
73 public CameraAccessException(int problem) {
Igor Murashkine363fbb2013-06-25 20:26:06 +000074 super(getDefaultMessage(problem));
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080075 mReason = problem;
76 }
77
78 public CameraAccessException(int problem, String message) {
79 super(message);
80 mReason = problem;
81 }
82
83 public CameraAccessException(int problem, String message, Throwable cause) {
84 super(message, cause);
85 mReason = problem;
86 }
87
88 public CameraAccessException(int problem, Throwable cause) {
Igor Murashkine363fbb2013-06-25 20:26:06 +000089 super(getDefaultMessage(problem), cause);
Eino-Ville Talvalab2675542012-12-12 13:29:45 -080090 mReason = problem;
91 }
Igor Murashkine363fbb2013-06-25 20:26:06 +000092
93 private static String getDefaultMessage(int problem) {
94 switch (problem) {
95 case CAMERA_IN_USE:
96 return "The camera device is in use already";
97 case MAX_CAMERAS_IN_USE:
98 return "The system-wide limit for number of open cameras has been reached, " +
99 "and more camera devices cannot be opened until previous instances " +
100 "are closed.";
101 case CAMERA_DISABLED:
102 return "The camera is disabled due to a device policy, and cannot be opened.";
103 case CAMERA_DISCONNECTED:
104 return "The camera device is removable and has been disconnected from the Android" +
105 " device, or the camera service has shut down the connection due to a " +
106 "higher-priority access request for the camera device.";
107 }
108 return null;
109 }
Eino-Ville Talvalab2675542012-12-12 13:29:45 -0800110}