• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // Determines if a cameraId is a hidden physical camera of a logical multi-camera.
isHiddenPhysicalCamera(@tf8InCpp String cameraId)265     boolean isHiddenPhysicalCamera(@utf8InCpp String cameraId);
266     // Inject the external camera to replace the internal camera session.
injectCamera(@tf8InCpp String packageName, @utf8InCpp String internalCamId, @utf8InCpp String externalCamId, in ICameraInjectionCallback CameraInjectionCallback)267     ICameraInjectionSession injectCamera(@utf8InCpp String packageName, @utf8InCpp String internalCamId,
268             @utf8InCpp String externalCamId, in ICameraInjectionCallback CameraInjectionCallback);
269 
270     /**
271      * Set the torch mode for a camera device.
272      *
273      * @param cameraId The ID of the camera to set torch mode for.
274      * @param clientAttribution The AttributionSource of the client.
275      * @param devicePolicy The camera policy of the device of the associated context (default
276      *                     policy for default device context). Only virtual cameras would be exposed
277      *                     only for custom policy and only real cameras would be exposed for default
278      *                     policy.
279      */
setTorchMode(@tf8InCpp String cameraId, boolean enabled, IBinder clientBinder, in AttributionSourceState clientAttribution, int devicePolicy)280     void setTorchMode(@utf8InCpp String cameraId, boolean enabled, IBinder clientBinder,
281             in AttributionSourceState clientAttribution, int devicePolicy);
282 
283     /**
284      * Change the brightness level of the flash unit associated with cameraId to strengthLevel.
285      * If the torch is in OFF state and strengthLevel > 0 then the torch will also be turned ON.
286      *
287      * @param cameraId The ID of the camera.
288      * @param strengthLevel The torch strength level to set for the camera.
289      * @param clientAttribution The AttributionSource of the client.
290      * @param devicePolicy The camera policy of the device of the associated context (default
291      *                     policy for default device context). Only virtual cameras would be exposed
292      *                     only for custom policy and only real cameras would be exposed for default
293      *                     policy.
294      */
turnOnTorchWithStrengthLevel(@tf8InCpp String cameraId, int strengthLevel, IBinder clientBinder, in AttributionSourceState clientAttribution, int devicePolicy)295     void turnOnTorchWithStrengthLevel(@utf8InCpp String cameraId, int strengthLevel,
296             IBinder clientBinder, in AttributionSourceState clientAttribution, int devicePolicy);
297 
298     /**
299      * Get the brightness level of the flash unit associated with cameraId.
300      *
301      * @param cameraId The ID of the camera.
302      * @param clientAttribution The AttributionSource of the client.
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      * @return Torch strength level for the camera.
308      */
getTorchStrengthLevel(@tf8InCpp String cameraId, in AttributionSourceState clientAttribution, int devicePolicy)309     int getTorchStrengthLevel(@utf8InCpp String cameraId,
310             in AttributionSourceState clientAttribution, int devicePolicy);
311 
312     /**
313      * Notify the camera service of a system event.  Should only be called from system_server.
314      *
315      * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission.
316      */
317     const int EVENT_NONE = 0;
318     const int EVENT_USER_SWITCHED = 1; // The argument is the set of new foreground user IDs.
319     const int EVENT_USB_DEVICE_ATTACHED = 2; // The argument is the deviceId and vendorId
320     const int EVENT_USB_DEVICE_DETACHED = 3; // The argument is the deviceId and vendorId
notifySystemEvent(int eventId, in int[] args)321     oneway void notifySystemEvent(int eventId, in int[] args);
322 
323     /**
324      * Notify the camera service of a display configuration change.
325      *
326      * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission.
327      */
notifyDisplayConfigurationChange()328     oneway void notifyDisplayConfigurationChange();
329 
330     /**
331      * Notify the camera service of a device physical status change. May only be called from
332      * a privileged process.
333      *
334      * newState is a bitfield consisting of DEVICE_STATE_* values combined together. Valid state
335      * combinations are device-specific. At device startup, the camera service will assume the device
336      * state is NORMAL until otherwise notified.
337      *
338      * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission.
339      */
notifyDeviceStateChange(long newState)340     oneway void notifyDeviceStateChange(long newState);
341 
342     /**
343      * Report Extension specific metrics to camera service for logging. This should only be called
344      * by CameraExtensionSession to log extension metrics. All calls after the first must set
345      * CameraExtensionSessionStats.key to the value returned by this function.
346      *
347      * Each subsequent call fully overwrites the existing CameraExtensionSessionStats for the
348      * current session, so the caller is responsible for keeping the stats complete.
349      *
350      * Due to cameraservice and cameraservice_proxy architecture, there is no guarantee that
351      * {@code stats} will be logged immediately (or at all). CameraService will log whatever
352      * extension stats it has at the time of camera session closing which may be before the app
353      * process receives a session/device closed callback; so CameraExtensionSession
354      * should send metrics to the cameraservice preriodically, and cameraservice must handle calls
355      * to this function from sessions that have not been logged yet and from sessions that have
356      * already been closed.
357      *
358      * @return the key that must be used to report updates to previously reported stats.
359      */
reportExtensionSessionStats(in CameraExtensionSessionStats stats)360     @utf8InCpp String reportExtensionSessionStats(in CameraExtensionSessionStats stats);
361 
362     // Bitfield constants for notifyDeviceStateChange
363     // All bits >= 32 are for custom vendor states
364     // Written as ints since AIDL does not support long constants.
365     const int DEVICE_STATE_NORMAL = 0;
366     const int DEVICE_STATE_BACK_COVERED = 1;
367     const int DEVICE_STATE_FRONT_COVERED = 2;
368     const int DEVICE_STATE_FOLDED = 4;
369     const int DEVICE_STATE_LAST_FRAMEWORK_BIT = 0x80000000; // 1 << 31;
370 
371     /**
372      * Create a CaptureRequest metadata based on template id
373      *
374      * @param cameraId The camera id to create the CaptureRequest for.
375      * @param templateId The template id create the CaptureRequest for.
376      * @param clientAttribution The AttributionSource of the client.
377      * @param devicePolicy The camera policy of the device of the associated context (default
378      *                     policy for default device context). Only virtual cameras would be exposed
379      *                     only for custom policy and only real cameras would be exposed for default
380      *                     policy.
381      * @return Metadata representing the CaptureRequest.
382      */
createDefaultRequest(@tf8InCpp String cameraId, int templateId, in AttributionSourceState clientAttribution, int devicePolicy)383     CameraMetadataNative createDefaultRequest(@utf8InCpp String cameraId, int templateId,
384             in AttributionSourceState clientAttribution, int devicePolicy);
385 
386     /**
387      * Check whether a particular session configuration with optional session parameters
388      * has camera device support.
389      *
390      * @param cameraId The camera id to query session configuration for
391      * @param targetSdkVersion the target sdk level of the application calling this function.
392      * @param sessionConfiguration Specific session configuration to be verified.
393      * @param clientAttribution The AttributionSource of the client.
394      * @param devicePolicy The camera policy of the device of the associated context (default
395      *                     policy for default device context). Only virtual cameras would be exposed
396      *                     only for custom policy and only real cameras would be exposed for default
397      *                     policy.
398      * @return true  - in case the stream combination is supported.
399      *         false - in case there is no device support.
400      */
isSessionConfigurationWithParametersSupported(@tf8InCpp String cameraId, int targetSdkVersion, in SessionConfiguration sessionConfiguration, in AttributionSourceState clientAttribution, int devicePolicy)401     boolean isSessionConfigurationWithParametersSupported(@utf8InCpp String cameraId,
402             int targetSdkVersion, in SessionConfiguration sessionConfiguration,
403             in AttributionSourceState clientAttribution, int devicePolicy);
404 
405     /**
406      * Get the camera characteristics for a particular session configuration for
407      * the given camera device.
408      *
409      * @param cameraId ID of the device for which the session characteristics must be fetched.
410      * @param targetSdkVersion the target sdk level of the application calling this function.
411      * @param rotationOverride Whether to override the sensor orientation information to
412      *        correspond to portrait: {@link ICameraService#ROTATION_OVERRIDE_OVERRIDE_TO_PORTRAIT}
413      *        will override the sensor orientation and rotate and crop, while {@link
414      *        ICameraService#ROTATION_OVERRIDE_ROTATION_ONLY} will rotate and crop the camera feed
415      *        without changing the sensor orientation.
416      * @param sessionConfiguration Session configuration for which the characteristics
417      *                             must be fetched.
418      * @param clientAttribution The AttributionSource of the client.
419      * @param devicePolicy The camera policy of the device of the associated context (default
420      *                     policy for default device context). Only virtual cameras would be exposed
421      *                     only for custom policy and only real cameras would be exposed for default
422      *                     policy.
423      * @return Characteristics associated with the given session.
424      */
getSessionCharacteristics(@tf8InCpp String cameraId, int targetSdkVersion, int rotationOverride, in SessionConfiguration sessionConfiguration, in AttributionSourceState clientAttribution, int devicePolicy)425     CameraMetadataNative getSessionCharacteristics(@utf8InCpp String cameraId,
426             int targetSdkVersion,
427             int rotationOverride,
428             in SessionConfiguration sessionConfiguration,
429             in AttributionSourceState clientAttribution,
430             int devicePolicy);
431 }
432