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