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; 23 import android.hardware.camera2.ICameraInjectionCallback; 24 import android.hardware.camera2.ICameraInjectionSession; 25 import android.hardware.camera2.params.SessionConfiguration; 26 import android.hardware.camera2.params.VendorTagDescriptor; 27 import android.hardware.camera2.params.VendorTagDescriptorCache; 28 import android.hardware.camera2.utils.ConcurrentCameraIdCombination; 29 import android.hardware.camera2.utils.CameraIdAndSessionConfiguration; 30 import android.hardware.camera2.impl.CameraMetadataNative; 31 import android.hardware.ICameraServiceListener; 32 import android.hardware.CameraInfo; 33 import android.hardware.CameraStatus; 34 import android.hardware.CameraExtensionSessionStats; 35 36 /** 37 * Binder interface for the native camera service running in mediaserver. 38 * 39 * @hide 40 */ 41 interface ICameraService 42 { 43 /** 44 * All camera service and device Binder calls may return a 45 * ServiceSpecificException with the following error codes 46 */ 47 const int ERROR_PERMISSION_DENIED = 1; 48 const int ERROR_ALREADY_EXISTS = 2; 49 const int ERROR_ILLEGAL_ARGUMENT = 3; 50 const int ERROR_DISCONNECTED = 4; 51 const int ERROR_TIMED_OUT = 5; 52 const int ERROR_DISABLED = 6; 53 const int ERROR_CAMERA_IN_USE = 7; 54 const int ERROR_MAX_CAMERAS_IN_USE = 8; 55 const int ERROR_DEPRECATED_HAL = 9; 56 const int ERROR_INVALID_OPERATION = 10; 57 58 /** 59 * Types for getNumberOfCameras 60 */ 61 const int CAMERA_TYPE_BACKWARD_COMPATIBLE = 0; 62 const int CAMERA_TYPE_ALL = 1; 63 64 /** 65 * Return the number of camera devices available in the system. 66 * 67 * @param type The type of the camera, can be either CAMERA_TYPE_BACKWARD_COMPATIBLE 68 * or CAMERA_TYPE_ALL. 69 * @param deviceId The device id of the context associated with the caller. 70 * @param devicePolicy The camera policy of the device of the associated context (default 71 * policy for default device context). Only virtual cameras would be exposed 72 * only for custom policy and only real cameras would be exposed for default 73 * policy. 74 */ getNumberOfCameras(int type, int deviceId, int devicePolicy)75 int getNumberOfCameras(int type, int deviceId, int devicePolicy); 76 77 /** 78 * If changed, reflect in 79 * frameworks/base/core/java/android/hardware/camera2/CameraManager.java. 80 * We have an enum here since the decision to override to portrait mode / fetch the 81 * rotationOverride as it exists in CameraManager right now is based on a static system 82 * property and not something that changes based dynamically, say on fold state. As a result, 83 * we can't use just a boolean to differentiate between the case where cameraserver should 84 * override to portrait (sensor orientation is 0, 180) or just rotate the sensor feed (sensor 85 * orientation is 90, 270) 86 */ 87 const int ROTATION_OVERRIDE_NONE = 0; 88 const int ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT = 1; 89 const int ROTATION_OVERRIDE_ROTATION_ONLY = 2; 90 91 /** 92 * Fetch basic camera information for a camera. 93 * 94 * @param cameraId The ID of the camera to fetch information for. 95 * @param rotationOverride Whether to override the sensor orientation information to 96 * correspond to portrait: {@link ICameraService#ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT} 97 * will override the sensor orientation and rotate and crop, while {@link 98 * ICameraService#ROTATION_OVERRIDE_ROTATION_ONLY} will rotate and crop the camera feed 99 * without changing the sensor orientation. 100 * @param deviceId The device id of the context associated with the caller. 101 * @param devicePolicy The camera policy of the device of the associated context (default 102 * policy for default device context). Only virtual cameras would be exposed 103 * only for custom policy and only real cameras would be exposed for default 104 * policy. 105 * @return CameraInfo for the camera. 106 */ getCameraInfo(int cameraId, int rotationOverride, int deviceId, int devicePolicy)107 CameraInfo getCameraInfo(int cameraId, int rotationOverride, int deviceId, 108 int devicePolicy); 109 110 /** 111 * Default UID/PID values for non-privileged callers of 112 * connect() and connectDevice() 113 */ 114 const int USE_CALLING_UID = -1; 115 const int USE_CALLING_PID = -1; 116 117 /** 118 * Open a camera device through the old camera API. 119 * 120 * @param cameraId The ID of the camera to open. 121 * @param opPackageName The package name to report for the app-ops. 122 * @param clientUid UID for the calling client. 123 * @param clientPid PID for the calling client. 124 * @param targetSdkVersion the target sdk level of the application calling this function. 125 * @param rotationOverride Whether to override the sensor orientation information to 126 * correspond to portrait: {@link ICameraService#ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT} 127 * will override the sensor orientation and rotate and crop, while {@link 128 * ICameraService#ROTATION_OVERRIDE_ROTATION_ONLY} will rotate and crop the camera feed 129 * without changing the sensor orientation. 130 * @param forceSlowJpegMode Whether to force slow jpeg mode. 131 * @param deviceId The device id of the context associated with the caller. 132 * @param devicePolicy The camera policy of the device of the associated context (default 133 * policy for default device context). Only virtual cameras would be exposed 134 * only for custom policy and only real cameras would be exposed for default 135 * policy. 136 */ connect(ICameraClient client, int cameraId, @utf8InCpp String opPackageName, int clientUid, int clientPid, int targetSdkVersion, int rotationOverride, boolean forceSlowJpegMode, int deviceId, int devicePolicy)137 ICamera connect(ICameraClient client, 138 int cameraId, 139 @utf8InCpp String opPackageName, 140 int clientUid, int clientPid, 141 int targetSdkVersion, 142 int rotationOverride, 143 boolean forceSlowJpegMode, 144 int deviceId, 145 int devicePolicy); 146 147 /** 148 * Open a camera device through the new camera API. 149 * Only supported for device HAL versions >= 3.2. 150 * 151 * @param cameraId The ID of the camera to open. 152 * @param opPackageName The package name to report for the app-ops. 153 * @param clientUid UID for the calling client. 154 * @param targetSdkVersion the target sdk level of the application calling this function. 155 * @param rotationOverride Whether to override the sensor orientation information to 156 * correspond to portrait: {@link ICameraService#ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT} 157 * will override the sensor orientation and rotate and crop, while {@link 158 * ICameraService#ROTATION_OVERRIDE_ROTATION_ONLY} will rotate and crop the camera feed 159 * without changing the sensor orientation. 160 * @param deviceId The device id of the context associated with the caller. 161 * @param devicePolicy The camera policy of the device of the associated context (default 162 * policy for default device context). Only virtual cameras would be exposed 163 * only for custom policy and only real cameras would be exposed for default 164 * policy. 165 */ connectDevice(ICameraDeviceCallbacks callbacks, @utf8InCpp String cameraId, @utf8InCpp String opPackageName, @nullable @utf8InCpp String featureId, int clientUid, int oomScoreOffset, int targetSdkVersion, int rotationOverride, int deviceId, int devicePolicy)166 ICameraDeviceUser connectDevice(ICameraDeviceCallbacks callbacks, 167 @utf8InCpp String cameraId, 168 @utf8InCpp String opPackageName, 169 @nullable @utf8InCpp String featureId, 170 int clientUid, int oomScoreOffset, 171 int targetSdkVersion, 172 int rotationOverride, 173 int deviceId, 174 int devicePolicy); 175 176 /** 177 * Add listener for changes to camera device and flashlight state. 178 * 179 * Also returns the set of currently-known camera IDs and state of each device. 180 * Adding a listener will trigger the torch status listener to fire for all 181 * devices that have a flash unit. 182 */ addListener(ICameraServiceListener listener)183 CameraStatus[] addListener(ICameraServiceListener listener); 184 185 /** 186 * Get a list of combinations of camera ids which support concurrent streaming. 187 * 188 */ getConcurrentCameraIds()189 ConcurrentCameraIdCombination[] getConcurrentCameraIds(); 190 191 /** 192 * Check whether a particular set of session configurations are concurrently supported by the 193 * corresponding camera ids. 194 * 195 * @param sessions the set of camera id and session configuration pairs to be queried. 196 * @param targetSdkVersion the target sdk level of the application calling this function. 197 * @param deviceId The device id of the context associated with the caller. 198 * @param devicePolicy The camera policy of the device of the associated context (default 199 * policy for default device context). Only virtual cameras would be exposed 200 * only for custom policy and only real cameras would be exposed for default 201 * policy. 202 * @return true - the set of concurrent camera id and stream combinations is supported. 203 * false - the set of concurrent camera id and stream combinations is not supported 204 * OR the method was called with a set of camera ids not returned by 205 * getConcurrentCameraIds(). 206 */ isConcurrentSessionConfigurationSupported( in CameraIdAndSessionConfiguration[] sessions, int targetSdkVersion, int deviceId, int devicePolicy)207 boolean isConcurrentSessionConfigurationSupported( 208 in CameraIdAndSessionConfiguration[] sessions, 209 int targetSdkVersion, int deviceId, int devicePolicy); 210 211 /** 212 * Inject Session Params into an existing camera session. 213 * 214 * @param cameraId the camera id session to inject session params into. Note that 215 * if there is no active session for the input cameraid, this operation 216 * will be a no-op. In addition, future camera sessions for cameraid will 217 * not be affected. 218 * @param sessionParams the session params to override for the existing session. 219 */ injectSessionParams(@tf8InCpp String cameraId, in CameraMetadataNative sessionParams)220 void injectSessionParams(@utf8InCpp String cameraId, 221 in CameraMetadataNative sessionParams); 222 223 /** 224 * Remove listener for changes to camera device and flashlight state. 225 */ removeListener(ICameraServiceListener listener)226 void removeListener(ICameraServiceListener listener); 227 228 /** 229 * Read the static camera metadata for a camera device. 230 * Only supported for device HAL versions >= 3.2 231 * 232 * @param cameraId The ID of the camera to fetch metadata for. 233 * @param targetSdkVersion the target sdk level of the application calling this function. 234 * @param rotationOverride Whether to override the sensor orientation information to 235 * correspond to portrait: {@link ICameraService#ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT} 236 * will override the sensor orientation and rotate and crop, while {@link 237 * ICameraService#ROTATION_OVERRIDE_ROTATION_ONLY} will rotate and crop the camera feed 238 * without changing the sensor orientation. 239 * @param deviceId The device id of the context associated with the caller. 240 * @param devicePolicy The camera policy of the device of the associated context (default 241 * policy for default device context). Only virtual cameras would be exposed 242 * only for custom policy and only real cameras would be exposed for default 243 * policy. 244 * @return Characteristics for the given camera. 245 */ getCameraCharacteristics(@tf8InCpp String cameraId, int targetSdkVersion, int rotationOverride, int deviceId, int devicePolicy)246 CameraMetadataNative getCameraCharacteristics(@utf8InCpp String cameraId, int targetSdkVersion, 247 int rotationOverride, int deviceId, int devicePolicy); 248 249 /** 250 * Read in the vendor tag descriptors from the camera module HAL. 251 * Intended to be used by the native code of CameraMetadataNative to correctly 252 * interpret camera metadata with vendor tags. 253 */ getCameraVendorTagDescriptor()254 VendorTagDescriptor getCameraVendorTagDescriptor(); 255 256 /** 257 * Retrieve the vendor tag descriptor cache which can have multiple vendor 258 * providers. 259 * Intended to be used by the native code of CameraMetadataNative to correctly 260 * interpret camera metadata with vendor tags. 261 */ getCameraVendorTagCache()262 VendorTagDescriptorCache getCameraVendorTagCache(); 263 264 /** 265 * Read the legacy camera1 parameters into a String 266 */ getLegacyParameters(int cameraId)267 @utf8InCpp String getLegacyParameters(int cameraId); 268 269 /** 270 * apiVersion constants for supportsCameraApi 271 */ 272 const int API_VERSION_1 = 1; 273 const int API_VERSION_2 = 2; 274 275 // Determines if a particular API version is supported directly for a cameraId. supportsCameraApi(@tf8InCpp String cameraId, int apiVersion)276 boolean supportsCameraApi(@utf8InCpp String cameraId, int apiVersion); 277 // Determines if a cameraId is a hidden physical camera of a logical multi-camera. isHiddenPhysicalCamera(@tf8InCpp String cameraId)278 boolean isHiddenPhysicalCamera(@utf8InCpp String cameraId); 279 // Inject the external camera to replace the internal camera session. injectCamera(@tf8InCpp String packageName, @utf8InCpp String internalCamId, @utf8InCpp String externalCamId, in ICameraInjectionCallback CameraInjectionCallback)280 ICameraInjectionSession injectCamera(@utf8InCpp String packageName, @utf8InCpp String internalCamId, 281 @utf8InCpp String externalCamId, in ICameraInjectionCallback CameraInjectionCallback); 282 283 /** 284 * Set the torch mode for a camera device. 285 * 286 * @param cameraId The ID of the camera to set torch mode for. 287 * @param deviceId The device id of the context associated with the caller. 288 * @param devicePolicy The camera policy of the device of the associated context (default 289 * policy for default device context). Only virtual cameras would be exposed 290 * only for custom policy and only real cameras would be exposed for default 291 * policy. 292 */ setTorchMode(@tf8InCpp String cameraId, boolean enabled, IBinder clientBinder, int deviceId, int devicePolicy)293 void setTorchMode(@utf8InCpp String cameraId, boolean enabled, IBinder clientBinder, 294 int deviceId, int devicePolicy); 295 296 /** 297 * Change the brightness level of the flash unit associated with cameraId to strengthLevel. 298 * If the torch is in OFF state and strengthLevel > 0 then the torch will also be turned ON. 299 * 300 * @param cameraId The ID of the camera. 301 * @param strengthLevel The torch strength level to set for the camera. 302 * @param deviceId The device id of the context associated with the caller. 303 * @param devicePolicy The camera policy of the device of the associated context (default 304 * policy for default device context). Only virtual cameras would be exposed 305 * only for custom policy and only real cameras would be exposed for default 306 * policy. 307 */ turnOnTorchWithStrengthLevel(@tf8InCpp String cameraId, int strengthLevel, IBinder clientBinder, int deviceId, int devicePolicy)308 void turnOnTorchWithStrengthLevel(@utf8InCpp String cameraId, int strengthLevel, 309 IBinder clientBinder, int deviceId, int devicePolicy); 310 311 /** 312 * Get the brightness level of the flash unit associated with cameraId. 313 * 314 * @param cameraId The ID of the camera. 315 * @param deviceId The device id of the context associated with the caller. 316 * @param devicePolicy The camera policy of the device of the associated context (default 317 * policy for default device context). Only virtual cameras would be exposed 318 * only for custom policy and only real cameras would be exposed for default 319 * policy. 320 * @return Torch strength level for the camera. 321 */ getTorchStrengthLevel(@tf8InCpp String cameraId, int deviceId, int devicePolicy)322 int getTorchStrengthLevel(@utf8InCpp String cameraId, int deviceId, int devicePolicy); 323 324 /** 325 * Notify the camera service of a system event. Should only be called from system_server. 326 * 327 * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission. 328 */ 329 const int EVENT_NONE = 0; 330 const int EVENT_USER_SWITCHED = 1; // The argument is the set of new foreground user IDs. 331 const int EVENT_USB_DEVICE_ATTACHED = 2; // The argument is the deviceId and vendorId 332 const int EVENT_USB_DEVICE_DETACHED = 3; // The argument is the deviceId and vendorId notifySystemEvent(int eventId, in int[] args)333 oneway void notifySystemEvent(int eventId, in int[] args); 334 335 /** 336 * Notify the camera service of a display configuration change. 337 * 338 * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission. 339 */ notifyDisplayConfigurationChange()340 oneway void notifyDisplayConfigurationChange(); 341 342 /** 343 * Notify the camera service of a device physical status change. May only be called from 344 * a privileged process. 345 * 346 * newState is a bitfield consisting of DEVICE_STATE_* values combined together. Valid state 347 * combinations are device-specific. At device startup, the camera service will assume the device 348 * state is NORMAL until otherwise notified. 349 * 350 * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission. 351 */ notifyDeviceStateChange(long newState)352 oneway void notifyDeviceStateChange(long newState); 353 354 /** 355 * Report Extension specific metrics to camera service for logging. This should only be called 356 * by CameraExtensionSession to log extension metrics. All calls after the first must set 357 * CameraExtensionSessionStats.key to the value returned by this function. 358 * 359 * Each subsequent call fully overwrites the existing CameraExtensionSessionStats for the 360 * current session, so the caller is responsible for keeping the stats complete. 361 * 362 * Due to cameraservice and cameraservice_proxy architecture, there is no guarantee that 363 * {@code stats} will be logged immediately (or at all). CameraService will log whatever 364 * extension stats it has at the time of camera session closing which may be before the app 365 * process receives a session/device closed callback; so CameraExtensionSession 366 * should send metrics to the cameraservice preriodically, and cameraservice must handle calls 367 * to this function from sessions that have not been logged yet and from sessions that have 368 * already been closed. 369 * 370 * @return the key that must be used to report updates to previously reported stats. 371 */ reportExtensionSessionStats(in CameraExtensionSessionStats stats)372 @utf8InCpp String reportExtensionSessionStats(in CameraExtensionSessionStats stats); 373 374 // Bitfield constants for notifyDeviceStateChange 375 // All bits >= 32 are for custom vendor states 376 // Written as ints since AIDL does not support long constants. 377 const int DEVICE_STATE_NORMAL = 0; 378 const int DEVICE_STATE_BACK_COVERED = 1; 379 const int DEVICE_STATE_FRONT_COVERED = 2; 380 const int DEVICE_STATE_FOLDED = 4; 381 const int DEVICE_STATE_LAST_FRAMEWORK_BIT = 0x80000000; // 1 << 31; 382 383 /** 384 * Create a CaptureRequest metadata based on template id 385 * 386 * @param cameraId The camera id to create the CaptureRequest for. 387 * @param templateId The template id create the CaptureRequest for. 388 * @param deviceId the device id of the context associated with the caller. 389 * @param devicePolicy The camera policy of the device of the associated context (default 390 * policy for default device context). Only virtual cameras would be exposed 391 * only for custom policy and only real cameras would be exposed for default 392 * policy. 393 * @return Metadata representing the CaptureRequest. 394 */ createDefaultRequest(@tf8InCpp String cameraId, int templateId, int deviceId, int devicePolicy)395 CameraMetadataNative createDefaultRequest(@utf8InCpp String cameraId, int templateId, 396 int deviceId, int devicePolicy); 397 398 /** 399 * Check whether a particular session configuration with optional session parameters 400 * has camera device support. 401 * 402 * @param cameraId The camera id to query session configuration for 403 * @param targetSdkVersion the target sdk level of the application calling this function. 404 * @param sessionConfiguration Specific session configuration to be verified. 405 * @param deviceId The device id of the context associated with the caller. 406 * @param devicePolicy The camera policy of the device of the associated context (default 407 * policy for default device context). Only virtual cameras would be exposed 408 * only for custom policy and only real cameras would be exposed for default 409 * policy. 410 * @return true - in case the stream combination is supported. 411 * false - in case there is no device support. 412 */ isSessionConfigurationWithParametersSupported(@tf8InCpp String cameraId, int targetSdkVersion, in SessionConfiguration sessionConfiguration, int deviceId, int devicePolicy)413 boolean isSessionConfigurationWithParametersSupported(@utf8InCpp String cameraId, 414 int targetSdkVersion, in SessionConfiguration sessionConfiguration, 415 int deviceId, int devicePolicy); 416 417 /** 418 * Get the camera characteristics for a particular session configuration for 419 * the given camera device. 420 * 421 * @param cameraId ID of the device for which the session characteristics must be fetched. 422 * @param targetSdkVersion the target sdk level of the application calling this function. 423 * @param rotationOverride Whether to override the sensor orientation information to 424 * correspond to portrait: {@link ICameraService#ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT} 425 * will override the sensor orientation and rotate and crop, while {@link 426 * ICameraService#ROTATION_OVERRIDE_ROTATION_ONLY} will rotate and crop the camera feed 427 * without changing the sensor orientation. 428 * @param sessionConfiguration Session configuration for which the characteristics 429 * must be fetched. 430 * @param deviceId The device id of the context associated with the caller. 431 * @param devicePolicy The camera policy of the device of the associated context (default 432 * policy for default device context). Only virtual cameras would be exposed 433 * only for custom policy and only real cameras would be exposed for default 434 * policy. 435 * @return Characteristics associated with the given session. 436 */ getSessionCharacteristics(@tf8InCpp String cameraId, int targetSdkVersion, int rotationOverride, in SessionConfiguration sessionConfiguration, int deviceId, int devicePolicy)437 CameraMetadataNative getSessionCharacteristics(@utf8InCpp String cameraId, 438 int targetSdkVersion, 439 int rotationOverride, 440 in SessionConfiguration sessionConfiguration, 441 int deviceId, 442 int devicePolicy); 443 } 444