| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.camera2; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.util.AndroidException; |
| 21 |
|
| 22 |
import java.lang.annotation.Retention; |
| 23 |
import java.lang.annotation.RetentionPolicy; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class CameraAccessException extends AndroidException { |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public static final int CAMERA_IN_USE = 4; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public static final int MAX_CAMERAS_IN_USE = 5; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public static final int CAMERA_DISABLED = 1; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public static final int CAMERA_DISCONNECTED = 2; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public static final int CAMERA_ERROR = 3; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public static final int CAMERA_DEPRECATED_HAL = 1000; |
| 82 |
|
| 83 |
|
| 84 |
@Retention(RetentionPolicy.SOURCE) |
| 85 |
@IntDef(prefix = { "CAMERA_", "MAX_CAMERAS_IN_USE" }, value = { |
| 86 |
CAMERA_IN_USE, |
| 87 |
MAX_CAMERAS_IN_USE, |
| 88 |
CAMERA_DISABLED, |
| 89 |
CAMERA_DISCONNECTED, |
| 90 |
CAMERA_ERROR |
| 91 |
}) |
| 92 |
public @interface AccessError {} |
| 93 |
|
| 94 |
|
| 95 |
private static final long serialVersionUID = 5630338637471475675L; |
| 96 |
|
| 97 |
private final int mReason; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
@AccessError |
| 107 |
public final int getReason() { |
| 108 |
return mReason; |
| 109 |
} |
| 110 |
|
| 111 |
public CameraAccessException(@AccessError int problem) { |
| 112 |
super(getDefaultMessage(problem)); |
| 113 |
mReason = problem; |
| 114 |
} |
| 115 |
|
| 116 |
public CameraAccessException(@AccessError int problem, String message) { |
| 117 |
super(getCombinedMessage(problem, message)); |
| 118 |
mReason = problem; |
| 119 |
} |
| 120 |
|
| 121 |
public CameraAccessException(@AccessError int problem, String message, Throwable cause) { |
| 122 |
super(getCombinedMessage(problem, message), cause); |
| 123 |
mReason = problem; |
| 124 |
} |
| 125 |
|
| 126 |
public CameraAccessException(@AccessError int problem, Throwable cause) { |
| 127 |
super(getDefaultMessage(problem), cause); |
| 128 |
mReason = problem; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public static String getDefaultMessage(@AccessError int problem) { |
| 135 |
switch (problem) { |
| 136 |
case CAMERA_IN_USE: |
| 137 |
return "The camera device is in use already"; |
| 138 |
case MAX_CAMERAS_IN_USE: |
| 139 |
return "The system-wide limit for number of open cameras has been reached, " + |
| 140 |
"and more camera devices cannot be opened until previous instances " + |
| 141 |
"are closed."; |
| 142 |
case CAMERA_DISCONNECTED: |
| 143 |
return "The camera device is removable and has been disconnected from the " + |
| 144 |
"Android device, or the camera service has shut down the connection due " + |
| 145 |
"to a higher-priority access request for the camera device."; |
| 146 |
case CAMERA_DISABLED: |
| 147 |
return "The camera is disabled due to a device policy, and cannot be opened."; |
| 148 |
case CAMERA_ERROR: |
| 149 |
return "The camera device is currently in the error state; " + |
| 150 |
"no further calls to it will succeed."; |
| 151 |
} |
| 152 |
return null; |
| 153 |
} |
| 154 |
|
| 155 |
private static String getCombinedMessage(@AccessError int problem, String message) { |
| 156 |
String problemString = getProblemString(problem); |
| 157 |
return String.format("%s (%d): %s", problemString, problem, message); |
| 158 |
} |
| 159 |
|
| 160 |
private static String getProblemString(int problem) { |
| 161 |
String problemString; |
| 162 |
switch (problem) { |
| 163 |
case CAMERA_IN_USE: |
| 164 |
problemString = "CAMERA_IN_USE"; |
| 165 |
break; |
| 166 |
case MAX_CAMERAS_IN_USE: |
| 167 |
problemString = "MAX_CAMERAS_IN_USE"; |
| 168 |
break; |
| 169 |
case CAMERA_DISCONNECTED: |
| 170 |
problemString = "CAMERA_DISCONNECTED"; |
| 171 |
break; |
| 172 |
case CAMERA_DISABLED: |
| 173 |
problemString = "CAMERA_DISABLED"; |
| 174 |
break; |
| 175 |
case CAMERA_ERROR: |
| 176 |
problemString = "CAMERA_ERROR"; |
| 177 |
break; |
| 178 |
case CAMERA_DEPRECATED_HAL: |
| 179 |
problemString = "CAMERA_DEPRECATED_HAL"; |
| 180 |
break; |
| 181 |
default: |
| 182 |
problemString = "<UNKNOWN ERROR>"; |
| 183 |
} |
| 184 |
return problemString; |
| 185 |
} |
| 186 |
|
| 187 |
} |