Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -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 | |
| 17 | package android.hardware; |
| 18 | |
| 19 | import android.hardware.ICamera; |
| 20 | import android.hardware.ICameraClient; |
| 21 | import android.hardware.camera2.ICameraDeviceUser; |
| 22 | import android.hardware.camera2.ICameraDeviceCallbacks; |
Cliff Wu | d8cae10 | 2021-03-11 01:37:42 +0800 | [diff] [blame] | 23 | import android.hardware.camera2.ICameraInjectionCallback; |
| 24 | import android.hardware.camera2.ICameraInjectionSession; |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 25 | import android.hardware.camera2.params.SessionConfiguration; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 26 | import android.hardware.camera2.params.VendorTagDescriptor; |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 27 | import android.hardware.camera2.params.VendorTagDescriptorCache; |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 28 | import android.hardware.camera2.utils.ConcurrentCameraIdCombination; |
| 29 | import android.hardware.camera2.utils.CameraIdAndSessionConfiguration; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 30 | import android.hardware.camera2.impl.CameraMetadataNative; |
| 31 | import android.hardware.ICameraServiceListener; |
| 32 | import android.hardware.CameraInfo; |
malikakash | 73125c6 | 2023-07-21 22:44:34 +0000 | [diff] [blame] | 33 | import android.hardware.CameraIdRemapping; |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 34 | import android.hardware.CameraStatus; |
Avichal Rakesh | 6e57a2b | 2023-05-01 17:53:37 -0700 | [diff] [blame] | 35 | import android.hardware.CameraExtensionSessionStats; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Binder interface for the native camera service running in mediaserver. |
| 39 | * |
| 40 | * @hide |
| 41 | */ |
| 42 | interface ICameraService |
| 43 | { |
| 44 | /** |
| 45 | * All camera service and device Binder calls may return a |
| 46 | * ServiceSpecificException with the following error codes |
| 47 | */ |
| 48 | const int ERROR_PERMISSION_DENIED = 1; |
| 49 | const int ERROR_ALREADY_EXISTS = 2; |
| 50 | const int ERROR_ILLEGAL_ARGUMENT = 3; |
| 51 | const int ERROR_DISCONNECTED = 4; |
| 52 | const int ERROR_TIMED_OUT = 5; |
| 53 | const int ERROR_DISABLED = 6; |
| 54 | const int ERROR_CAMERA_IN_USE = 7; |
| 55 | const int ERROR_MAX_CAMERAS_IN_USE = 8; |
| 56 | const int ERROR_DEPRECATED_HAL = 9; |
| 57 | const int ERROR_INVALID_OPERATION = 10; |
| 58 | |
| 59 | /** |
| 60 | * Types for getNumberOfCameras |
| 61 | */ |
| 62 | const int CAMERA_TYPE_BACKWARD_COMPATIBLE = 0; |
| 63 | const int CAMERA_TYPE_ALL = 1; |
| 64 | |
| 65 | /** |
| 66 | * Return the number of camera devices available in the system |
| 67 | */ |
| 68 | int getNumberOfCameras(int type); |
| 69 | |
| 70 | /** |
| 71 | * Fetch basic camera information for a camera device |
| 72 | */ |
Austin Borger | 18b30a7 | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 73 | CameraInfo getCameraInfo(int cameraId, boolean overrideToPortrait); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Default UID/PID values for non-privileged callers of |
Eino-Ville Talvala | a976df8 | 2019-06-13 18:01:58 -0700 | [diff] [blame] | 77 | * connect() and connectDevice() |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 78 | */ |
| 79 | const int USE_CALLING_UID = -1; |
| 80 | const int USE_CALLING_PID = -1; |
| 81 | |
| 82 | /** |
| 83 | * Open a camera device through the old camera API |
| 84 | */ |
| 85 | ICamera connect(ICameraClient client, |
| 86 | int cameraId, |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 87 | @utf8InCpp String opPackageName, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 88 | int clientUid, int clientPid, |
Austin Borger | 18b30a7 | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 89 | int targetSdkVersion, |
Chengfei Tao | be683db | 2023-01-31 18:52:49 +0000 | [diff] [blame] | 90 | boolean overrideToPortrait, |
| 91 | boolean forceSlowJpegMode); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Open a camera device through the new camera API |
| 95 | * Only supported for device HAL versions >= 3.2 |
| 96 | */ |
| 97 | ICameraDeviceUser connectDevice(ICameraDeviceCallbacks callbacks, |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 98 | @utf8InCpp String cameraId, |
| 99 | @utf8InCpp String opPackageName, |
| 100 | @nullable @utf8InCpp String featureId, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 101 | int clientUid, int oomScoreOffset, |
Austin Borger | 18b30a7 | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 102 | int targetSdkVersion, |
| 103 | boolean overrideToPortrait); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 104 | |
| 105 | /** |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 106 | * Add listener for changes to camera device and flashlight state. |
| 107 | * |
| 108 | * Also returns the set of currently-known camera IDs and state of each device. |
| 109 | * Adding a listener will trigger the torch status listener to fire for all |
Emilian Peev | 53722fa | 2019-02-22 17:47:20 -0800 | [diff] [blame] | 110 | * devices that have a flash unit. |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 111 | */ |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 112 | CameraStatus[] addListener(ICameraServiceListener listener); |
| 113 | |
| 114 | /** |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 115 | * Get a list of combinations of camera ids which support concurrent streaming. |
| 116 | * |
| 117 | */ |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 118 | ConcurrentCameraIdCombination[] getConcurrentCameraIds(); |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Check whether a particular set of session configurations are concurrently supported by the |
| 122 | * corresponding camera ids. |
| 123 | * |
| 124 | * @param sessions the set of camera id and session configuration pairs to be queried. |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 125 | * @param targetSdkVersion the target sdk level of the application calling this function. |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 126 | * @return true - the set of concurrent camera id and stream combinations is supported. |
| 127 | * false - the set of concurrent camera id and stream combinations is not supported |
| 128 | * OR the method was called with a set of camera ids not returned by |
Jayant Chowdhary | cad23c2 | 2020-03-10 15:04:59 -0700 | [diff] [blame] | 129 | * getConcurrentCameraIds(). |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 130 | */ |
| 131 | boolean isConcurrentSessionConfigurationSupported( |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 132 | in CameraIdAndSessionConfiguration[] sessions, |
| 133 | int targetSdkVersion); |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 134 | |
| 135 | /** |
malikakash | 73125c6 | 2023-07-21 22:44:34 +0000 | [diff] [blame] | 136 | * Remap Camera Ids in the CameraService. |
| 137 | * |
| 138 | * Once this is in effect, all binder calls in the ICameraService that |
| 139 | * use logicalCameraId should consult remapping state to arrive at the |
| 140 | * correct cameraId to perform the operation on. |
| 141 | * |
| 142 | * Note: Before the new cameraIdRemapping state is applied, the previous |
| 143 | * state is cleared. |
| 144 | * |
| 145 | * @param cameraIdRemapping the camera ids to remap. Sending an unpopulated |
| 146 | * cameraIdRemapping object will result in clearing of any previous |
| 147 | * cameraIdRemapping state in the camera service. |
| 148 | */ |
| 149 | void remapCameraIds(in CameraIdRemapping cameraIdRemapping); |
| 150 | |
| 151 | /** |
malikakash | 22af94c | 2023-12-04 18:13:14 +0000 | [diff] [blame] | 152 | * Inject Session Params into an existing camera session. |
| 153 | * |
| 154 | * @param cameraId the camera id session to inject session params into. Note that |
| 155 | * if there is no active session for the input cameraid, this operation |
| 156 | * will be a no-op. In addition, future camera sessions for cameraid will |
| 157 | * not be affected. |
| 158 | * @param sessionParams the session params to override for the existing session. |
| 159 | */ |
| 160 | void injectSessionParams(@utf8InCpp String cameraId, |
| 161 | in CameraMetadataNative sessionParams); |
| 162 | |
| 163 | /** |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 164 | * Remove listener for changes to camera device and flashlight state. |
| 165 | */ |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 166 | void removeListener(ICameraServiceListener listener); |
| 167 | |
| 168 | /** |
| 169 | * Read the static camera metadata for a camera device. |
| 170 | * Only supported for device HAL versions >= 3.2 |
| 171 | */ |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 172 | CameraMetadataNative getCameraCharacteristics(@utf8InCpp String cameraId, int targetSdkVersion, |
Austin Borger | 18b30a7 | 2022-10-27 12:20:29 -0700 | [diff] [blame] | 173 | boolean overrideToPortrait); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * Read in the vendor tag descriptors from the camera module HAL. |
| 177 | * Intended to be used by the native code of CameraMetadataNative to correctly |
| 178 | * interpret camera metadata with vendor tags. |
| 179 | */ |
| 180 | VendorTagDescriptor getCameraVendorTagDescriptor(); |
| 181 | |
| 182 | /** |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 183 | * Retrieve the vendor tag descriptor cache which can have multiple vendor |
| 184 | * providers. |
| 185 | * Intended to be used by the native code of CameraMetadataNative to correctly |
| 186 | * interpret camera metadata with vendor tags. |
| 187 | */ |
| 188 | VendorTagDescriptorCache getCameraVendorTagCache(); |
| 189 | |
| 190 | /** |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 191 | * Read the legacy camera1 parameters into a String |
| 192 | */ |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 193 | @utf8InCpp String getLegacyParameters(int cameraId); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * apiVersion constants for supportsCameraApi |
| 197 | */ |
| 198 | const int API_VERSION_1 = 1; |
| 199 | const int API_VERSION_2 = 2; |
| 200 | |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 201 | // Determines if a particular API version is supported directly for a cameraId. |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 202 | boolean supportsCameraApi(@utf8InCpp String cameraId, int apiVersion); |
Shuzhen Wang | f9d2c02 | 2018-08-21 12:07:35 -0700 | [diff] [blame] | 203 | // Determines if a cameraId is a hidden physical camera of a logical multi-camera. |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 204 | boolean isHiddenPhysicalCamera(@utf8InCpp String cameraId); |
Cliff Wu | d8cae10 | 2021-03-11 01:37:42 +0800 | [diff] [blame] | 205 | // Inject the external camera to replace the internal camera session. |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 206 | ICameraInjectionSession injectCamera(@utf8InCpp String packageName, @utf8InCpp String internalCamId, |
| 207 | @utf8InCpp String externalCamId, in ICameraInjectionCallback CameraInjectionCallback); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 208 | |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 209 | void setTorchMode(@utf8InCpp String cameraId, boolean enabled, IBinder clientBinder); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 210 | |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 211 | // Change the brightness level of the flash unit associated with cameraId to strengthLevel. |
| 212 | // If the torch is in OFF state and strengthLevel > 0 then the torch will also be turned ON. |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 213 | void turnOnTorchWithStrengthLevel(@utf8InCpp String cameraId, int strengthLevel, IBinder clientBinder); |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 214 | |
| 215 | // Get the brightness level of the flash unit associated with cameraId. |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 216 | int getTorchStrengthLevel(@utf8InCpp String cameraId); |
Rucha Katakwar | 3828452 | 2021-11-10 11:25:21 -0800 | [diff] [blame] | 217 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 218 | /** |
| 219 | * Notify the camera service of a system event. Should only be called from system_server. |
| 220 | * |
| 221 | * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission. |
| 222 | */ |
| 223 | const int EVENT_NONE = 0; |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 224 | const int EVENT_USER_SWITCHED = 1; // The argument is the set of new foreground user IDs. |
Valentin Iftime | 29e2e15 | 2021-08-13 15:17:33 +0200 | [diff] [blame] | 225 | const int EVENT_USB_DEVICE_ATTACHED = 2; // The argument is the deviceId and vendorId |
| 226 | const int EVENT_USB_DEVICE_DETACHED = 3; // The argument is the deviceId and vendorId |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 227 | oneway void notifySystemEvent(int eventId, in int[] args); |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 228 | |
| 229 | /** |
Emilian Peev | 8b64f28 | 2021-03-25 16:49:57 -0700 | [diff] [blame] | 230 | * Notify the camera service of a display configuration change. |
| 231 | * |
| 232 | * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission. |
| 233 | */ |
| 234 | oneway void notifyDisplayConfigurationChange(); |
| 235 | |
| 236 | /** |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 237 | * Notify the camera service of a device physical status change. May only be called from |
| 238 | * a privileged process. |
| 239 | * |
| 240 | * newState is a bitfield consisting of DEVICE_STATE_* values combined together. Valid state |
| 241 | * combinations are device-specific. At device startup, the camera service will assume the device |
| 242 | * state is NORMAL until otherwise notified. |
| 243 | * |
| 244 | * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission. |
| 245 | */ |
| 246 | oneway void notifyDeviceStateChange(long newState); |
| 247 | |
Avichal Rakesh | 6e57a2b | 2023-05-01 17:53:37 -0700 | [diff] [blame] | 248 | /** |
| 249 | * Report Extension specific metrics to camera service for logging. This should only be called |
| 250 | * by CameraExtensionSession to log extension metrics. All calls after the first must set |
| 251 | * CameraExtensionSessionStats.key to the value returned by this function. |
| 252 | * |
| 253 | * Each subsequent call fully overwrites the existing CameraExtensionSessionStats for the |
| 254 | * current session, so the caller is responsible for keeping the stats complete. |
| 255 | * |
| 256 | * Due to cameraservice and cameraservice_proxy architecture, there is no guarantee that |
| 257 | * {@code stats} will be logged immediately (or at all). CameraService will log whatever |
| 258 | * extension stats it has at the time of camera session closing which may be before the app |
| 259 | * process receives a session/device closed callback; so CameraExtensionSession |
| 260 | * should send metrics to the cameraservice preriodically, and cameraservice must handle calls |
| 261 | * to this function from sessions that have not been logged yet and from sessions that have |
| 262 | * already been closed. |
| 263 | * |
| 264 | * @return the key that must be used to report updates to previously reported stats. |
| 265 | */ |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 266 | @utf8InCpp String reportExtensionSessionStats(in CameraExtensionSessionStats stats); |
Avichal Rakesh | 6e57a2b | 2023-05-01 17:53:37 -0700 | [diff] [blame] | 267 | |
Eino-Ville Talvala | 63f3611 | 2018-12-06 14:57:03 -0800 | [diff] [blame] | 268 | // Bitfield constants for notifyDeviceStateChange |
| 269 | // All bits >= 32 are for custom vendor states |
| 270 | // Written as ints since AIDL does not support long constants. |
| 271 | const int DEVICE_STATE_NORMAL = 0; |
| 272 | const int DEVICE_STATE_BACK_COVERED = 1; |
| 273 | const int DEVICE_STATE_FRONT_COVERED = 2; |
| 274 | const int DEVICE_STATE_FOLDED = 4; |
| 275 | const int DEVICE_STATE_LAST_FRAMEWORK_BIT = 0x80000000; // 1 << 31; |
| 276 | |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 277 | // Create a CaptureRequest metadata based on template id |
| 278 | CameraMetadataNative createDefaultRequest(@utf8InCpp String cameraId, int templateId); |
| 279 | |
| 280 | /** |
Avichal Rakesh | 3c522e2 | 2024-02-07 16:40:46 -0800 | [diff] [blame] | 281 | * Check whether a particular session configuration with optional session parameters |
| 282 | * has camera device support. |
| 283 | * |
| 284 | * @param cameraId The camera id to query session configuration for |
| 285 | * @param sessionConfiguration Specific session configuration to be verified. |
| 286 | * @return true - in case the stream combination is supported. |
| 287 | * false - in case there is no device support. |
| 288 | */ |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 289 | boolean isSessionConfigurationWithParametersSupported(@utf8InCpp String cameraId, |
| 290 | in SessionConfiguration sessionConfiguration); |
Avichal Rakesh | 3c522e2 | 2024-02-07 16:40:46 -0800 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * Get the camera characteristics for a particular session configuration for |
| 294 | * the given camera device. |
| 295 | * |
| 296 | * @param cameraId ID of the device for which the session characteristics must be fetched. |
| 297 | * @param sessionConfiguration session configuration for which the characteristics |
| 298 | * must be fetched. |
| 299 | * @return - characteristics associated with the given session. |
| 300 | */ |
| 301 | CameraMetadataNative getSessionCharacteristics(@utf8InCpp String cameraId, |
| 302 | int targetSdkVersion, |
| 303 | boolean overrideToPortrait, |
| 304 | in SessionConfiguration sessionConfiguration); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 305 | } |