1 /*
2  * Copyright (C) 2008 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 #ifndef ANDROID_HARDWARE_ICAMERASERVICE_H
18 #define ANDROID_HARDWARE_ICAMERASERVICE_H
19 
20 #include <utils/RefBase.h>
21 #include <binder/IInterface.h>
22 #include <binder/Parcel.h>
23 
24 namespace android {
25 
26 class ICamera;
27 class ICameraClient;
28 class ICameraServiceListener;
29 class ICameraDeviceUser;
30 class ICameraDeviceCallbacks;
31 class CameraMetadata;
32 class VendorTagDescriptor;
33 class String16;
34 
35 class ICameraService : public IInterface
36 {
37 public:
38     /**
39      * Keep up-to-date with ICameraService.aidl in frameworks/base
40      */
41     enum {
42         GET_NUMBER_OF_CAMERAS = IBinder::FIRST_CALL_TRANSACTION,
43         GET_CAMERA_INFO,
44         CONNECT,
45         CONNECT_DEVICE,
46         ADD_LISTENER,
47         REMOVE_LISTENER,
48         GET_CAMERA_CHARACTERISTICS,
49         GET_CAMERA_VENDOR_TAG_DESCRIPTOR,
50         GET_LEGACY_PARAMETERS,
51         SUPPORTS_CAMERA_API,
52         CONNECT_LEGACY,
53         SET_TORCH_MODE,
54         NOTIFY_SYSTEM_EVENT,
55     };
56 
57     enum {
58         USE_CALLING_UID = -1
59     };
60 
61     enum {
62         API_VERSION_1 = 1,
63         API_VERSION_2 = 2,
64     };
65 
66     enum {
67         CAMERA_TYPE_BACKWARD_COMPATIBLE = 0,
68         CAMERA_TYPE_ALL = 1,
69     };
70 
71     enum {
72         CAMERA_HAL_API_VERSION_UNSPECIFIED = -1
73     };
74 
75     /**
76      * Keep up-to-date with declarations in
77      * frameworks/base/services/core/java/com/android/server/camera/CameraService.java
78      *
79      * These event codes are intended to be used with the notifySystemEvent call.
80      */
81     enum {
82         NO_EVENT = 0,
83         USER_SWITCHED,
84     };
85 
86 public:
87     DECLARE_META_INTERFACE(CameraService);
88 
89     // Get the number of cameras that support basic color camera operation
90     // (type CAMERA_TYPE_BACKWARD_COMPATIBLE)
91     virtual int32_t  getNumberOfCameras() = 0;
92     // Get the number of cameras of the specified type, one of CAMERA_TYPE_*
93     // enums
94     virtual int32_t  getNumberOfCameras(int cameraType) = 0;
95     virtual status_t getCameraInfo(int cameraId,
96             /*out*/
97             struct CameraInfo* cameraInfo) = 0;
98 
99     virtual status_t getCameraCharacteristics(int cameraId,
100             /*out*/
101             CameraMetadata* cameraInfo) = 0;
102 
103     virtual status_t getCameraVendorTagDescriptor(
104             /*out*/
105             sp<VendorTagDescriptor>& desc) = 0;
106 
107     // Returns 'OK' if operation succeeded
108     // - Errors: ALREADY_EXISTS if the listener was already added
109     virtual status_t addListener(const sp<ICameraServiceListener>& listener)
110                                                                             = 0;
111     // Returns 'OK' if operation succeeded
112     // - Errors: BAD_VALUE if specified listener was not in the listener list
113     virtual status_t removeListener(const sp<ICameraServiceListener>& listener)
114                                                                             = 0;
115     /**
116      * clientPackageName and clientUid are used for permissions checking.  if
117      * clientUid == USE_CALLING_UID, then the calling UID is used instead. Only
118      * trusted callers can set a clientUid other than USE_CALLING_UID.
119      */
120     virtual status_t connect(const sp<ICameraClient>& cameraClient,
121             int cameraId,
122             const String16& clientPackageName,
123             int clientUid,
124             /*out*/
125             sp<ICamera>& device) = 0;
126 
127     virtual status_t connectDevice(
128             const sp<ICameraDeviceCallbacks>& cameraCb,
129             int cameraId,
130             const String16& clientPackageName,
131             int clientUid,
132             /*out*/
133             sp<ICameraDeviceUser>& device) = 0;
134 
135     virtual status_t getLegacyParameters(
136             int cameraId,
137             /*out*/
138             String16* parameters) = 0;
139 
140     /**
141      * Returns OK if device supports camera2 api,
142      * returns -EOPNOTSUPP if it doesn't.
143      */
144     virtual status_t supportsCameraApi(
145             int cameraId, int apiVersion) = 0;
146 
147     /**
148      * Connect the device as a legacy device for a given HAL version.
149      * For halVersion, use CAMERA_API_DEVICE_VERSION_* for a particular
150      * version, or CAMERA_HAL_API_VERSION_UNSPECIFIED for a service-selected version.
151      */
152     virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient,
153             int cameraId, int halVersion,
154             const String16& clientPackageName,
155             int clientUid,
156             /*out*/
157             sp<ICamera>& device) = 0;
158 
159     /**
160      * Turn on or off a camera's torch mode. Torch mode will be turned off by
161      * camera service if the lastest client binder that turns it on dies.
162      *
163      * return values:
164      * 0:       on a successful operation.
165      * -ENOSYS: the camera device doesn't support this operation. It it returned
166      *          if and only if android.flash.into.available is false.
167      * -EBUSY:  the camera device is opened.
168      * -EINVAL: camera_id is invalid or clientBinder is NULL when enabling a
169      *          torch mode.
170      */
171     virtual status_t setTorchMode(const String16& cameraId, bool enabled,
172             const sp<IBinder>& clientBinder) = 0;
173 
174     /**
175      * Notify the camera service of a system event.  Should only be called from system_server.
176      */
177     virtual void notifySystemEvent(int32_t eventId, const int32_t* args, size_t length) = 0;
178 };
179 
180 // ----------------------------------------------------------------------------
181 
182 class BnCameraService: public BnInterface<ICameraService>
183 {
184 public:
185     virtual status_t    onTransact( uint32_t code,
186                                     const Parcel& data,
187                                     Parcel* reply,
188                                     uint32_t flags = 0);
189 };
190 
191 }; // namespace android
192 
193 #endif
194