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