| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | ** | 
|  | 3 | ** Copyright 2008, The Android Open Source Project | 
|  | 4 | ** | 
| Ruben Brunk | 9efdf95 | 2015-03-18 23:11:57 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 6 | ** you may not use this file except in compliance with the License. | 
|  | 7 | ** You may obtain a copy of the License at | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 8 | ** | 
| Ruben Brunk | 9efdf95 | 2015-03-18 23:11:57 -0700 | [diff] [blame] | 9 | **     http://www.apache.org/licenses/LICENSE-2.0 | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 10 | ** | 
| Ruben Brunk | 9efdf95 | 2015-03-18 23:11:57 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software | 
|  | 12 | ** distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 14 | ** See the License for the specific language governing permissions and | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 15 | ** limitations under the License. | 
|  | 16 | */ | 
|  | 17 |  | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 18 | #define LOG_TAG "BpCameraService" | 
|  | 19 | #include <utils/Log.h> | 
| Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 20 | #include <utils/Errors.h> | 
| Igor Murashkin | 65d14b9 | 2014-06-17 12:03:20 -0700 | [diff] [blame] | 21 | #include <utils/String16.h> | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 22 |  | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 23 | #include <stdint.h> | 
|  | 24 | #include <sys/types.h> | 
|  | 25 |  | 
|  | 26 | #include <binder/Parcel.h> | 
|  | 27 | #include <binder/IPCThreadState.h> | 
|  | 28 | #include <binder/IServiceManager.h> | 
|  | 29 |  | 
|  | 30 | #include <camera/ICameraService.h> | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 31 | #include <camera/ICameraServiceListener.h> | 
| Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 32 | #include <camera/ICamera.h> | 
|  | 33 | #include <camera/ICameraClient.h> | 
| Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 34 | #include <camera/camera2/ICameraDeviceUser.h> | 
|  | 35 | #include <camera/camera2/ICameraDeviceCallbacks.h> | 
| Zhijun He | 2b59be8 | 2013-09-25 10:14:30 -0700 | [diff] [blame] | 36 | #include <camera/CameraMetadata.h> | 
| Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 37 | #include <camera/VendorTagDescriptor.h> | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 38 |  | 
|  | 39 | namespace android { | 
|  | 40 |  | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 41 | namespace { | 
|  | 42 |  | 
|  | 43 | enum { | 
|  | 44 | EX_SECURITY = -1, | 
|  | 45 | EX_BAD_PARCELABLE = -2, | 
|  | 46 | EX_ILLEGAL_ARGUMENT = -3, | 
|  | 47 | EX_NULL_POINTER = -4, | 
|  | 48 | EX_ILLEGAL_STATE = -5, | 
|  | 49 | EX_HAS_REPLY_HEADER = -128,  // special; see below | 
|  | 50 | }; | 
|  | 51 |  | 
|  | 52 | static bool readExceptionCode(Parcel& reply) { | 
|  | 53 | int32_t exceptionCode = reply.readExceptionCode(); | 
|  | 54 |  | 
|  | 55 | if (exceptionCode != 0) { | 
|  | 56 | const char* errorMsg; | 
|  | 57 | switch(exceptionCode) { | 
|  | 58 | case EX_SECURITY: | 
|  | 59 | errorMsg = "Security"; | 
|  | 60 | break; | 
|  | 61 | case EX_BAD_PARCELABLE: | 
|  | 62 | errorMsg = "BadParcelable"; | 
|  | 63 | break; | 
|  | 64 | case EX_NULL_POINTER: | 
|  | 65 | errorMsg = "NullPointer"; | 
|  | 66 | break; | 
|  | 67 | case EX_ILLEGAL_STATE: | 
|  | 68 | errorMsg = "IllegalState"; | 
|  | 69 | break; | 
|  | 70 | // Binder should be handling this code inside Parcel::readException | 
|  | 71 | // but lets have a to-string here anyway just in case. | 
|  | 72 | case EX_HAS_REPLY_HEADER: | 
|  | 73 | errorMsg = "HasReplyHeader"; | 
|  | 74 | break; | 
|  | 75 | default: | 
|  | 76 | errorMsg = "Unknown"; | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | ALOGE("Binder transmission error %s (%d)", errorMsg, exceptionCode); | 
|  | 80 | return true; | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | return false; | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | }; | 
|  | 87 |  | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 88 | class BpCameraService: public BpInterface<ICameraService> | 
|  | 89 | { | 
|  | 90 | public: | 
|  | 91 | BpCameraService(const sp<IBinder>& impl) | 
|  | 92 | : BpInterface<ICameraService>(impl) | 
|  | 93 | { | 
|  | 94 | } | 
|  | 95 |  | 
| Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 96 | // get number of cameras available | 
|  | 97 | virtual int32_t getNumberOfCameras() | 
|  | 98 | { | 
|  | 99 | Parcel data, reply; | 
|  | 100 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
|  | 101 | remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 102 |  | 
|  | 103 | if (readExceptionCode(reply)) return 0; | 
| Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 104 | return reply.readInt32(); | 
|  | 105 | } | 
|  | 106 |  | 
| Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 107 | // get information about a camera | 
|  | 108 | virtual status_t getCameraInfo(int cameraId, | 
|  | 109 | struct CameraInfo* cameraInfo) { | 
|  | 110 | Parcel data, reply; | 
|  | 111 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
|  | 112 | data.writeInt32(cameraId); | 
|  | 113 | remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 114 |  | 
|  | 115 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 116 | status_t result = reply.readInt32(); | 
|  | 117 | if (reply.readInt32() != 0) { | 
|  | 118 | cameraInfo->facing = reply.readInt32(); | 
|  | 119 | cameraInfo->orientation = reply.readInt32(); | 
|  | 120 | } | 
|  | 121 | return result; | 
| Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 122 | } | 
|  | 123 |  | 
| Zhijun He | 2b59be8 | 2013-09-25 10:14:30 -0700 | [diff] [blame] | 124 | // get camera characteristics (static metadata) | 
|  | 125 | virtual status_t getCameraCharacteristics(int cameraId, | 
|  | 126 | CameraMetadata* cameraInfo) { | 
|  | 127 | Parcel data, reply; | 
|  | 128 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
|  | 129 | data.writeInt32(cameraId); | 
|  | 130 | remote()->transact(BnCameraService::GET_CAMERA_CHARACTERISTICS, data, &reply); | 
|  | 131 |  | 
|  | 132 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 133 | status_t result = reply.readInt32(); | 
|  | 134 |  | 
|  | 135 | CameraMetadata out; | 
|  | 136 | if (reply.readInt32() != 0) { | 
|  | 137 | out.readFromParcel(&reply); | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | if (cameraInfo != NULL) { | 
|  | 141 | cameraInfo->swap(out); | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | return result; | 
|  | 145 | } | 
|  | 146 |  | 
| Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 147 | // Get enumeration and description of vendor tags for camera | 
|  | 148 | virtual status_t getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) { | 
|  | 149 | Parcel data, reply; | 
|  | 150 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
|  | 151 | remote()->transact(BnCameraService::GET_CAMERA_VENDOR_TAG_DESCRIPTOR, data, &reply); | 
|  | 152 |  | 
|  | 153 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 154 | status_t result = reply.readInt32(); | 
|  | 155 |  | 
|  | 156 | if (reply.readInt32() != 0) { | 
|  | 157 | sp<VendorTagDescriptor> d; | 
|  | 158 | if (VendorTagDescriptor::createFromParcel(&reply, /*out*/d) == OK) { | 
|  | 159 | desc = d; | 
|  | 160 | } | 
|  | 161 | } | 
|  | 162 | return result; | 
|  | 163 | } | 
|  | 164 |  | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 165 | // connect to camera service (android.hardware.Camera) | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 166 | virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId, | 
|  | 167 | const String16 &clientPackageName, int clientUid, | 
|  | 168 | /*out*/ | 
|  | 169 | sp<ICamera>& device) | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 170 | { | 
|  | 171 | Parcel data, reply; | 
|  | 172 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 173 | data.writeStrongBinder(IInterface::asBinder(cameraClient)); | 
| Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 174 | data.writeInt32(cameraId); | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 175 | data.writeString16(clientPackageName); | 
|  | 176 | data.writeInt32(clientUid); | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 177 | remote()->transact(BnCameraService::CONNECT, data, &reply); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 178 |  | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 179 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 180 | status_t status = reply.readInt32(); | 
|  | 181 | if (reply.readInt32() != 0) { | 
|  | 182 | device = interface_cast<ICamera>(reply.readStrongBinder()); | 
|  | 183 | } | 
|  | 184 | return status; | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 185 | } | 
| Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 186 |  | 
| Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 187 | // connect to camera service (android.hardware.Camera) | 
|  | 188 | virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId, | 
|  | 189 | int halVersion, | 
|  | 190 | const String16 &clientPackageName, int clientUid, | 
|  | 191 | /*out*/sp<ICamera>& device) | 
|  | 192 | { | 
|  | 193 | Parcel data, reply; | 
|  | 194 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 195 | data.writeStrongBinder(IInterface::asBinder(cameraClient)); | 
| Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 196 | data.writeInt32(cameraId); | 
|  | 197 | data.writeInt32(halVersion); | 
|  | 198 | data.writeString16(clientPackageName); | 
|  | 199 | data.writeInt32(clientUid); | 
|  | 200 | remote()->transact(BnCameraService::CONNECT_LEGACY, data, &reply); | 
|  | 201 |  | 
|  | 202 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 203 | status_t status = reply.readInt32(); | 
|  | 204 | if (reply.readInt32() != 0) { | 
|  | 205 | device = interface_cast<ICamera>(reply.readStrongBinder()); | 
|  | 206 | } | 
|  | 207 | return status; | 
|  | 208 | } | 
|  | 209 |  | 
| Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 210 | virtual status_t setTorchMode(const String16& cameraId, bool enabled, | 
|  | 211 | const sp<IBinder>& clientBinder) | 
|  | 212 | { | 
|  | 213 | Parcel data, reply; | 
|  | 214 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
|  | 215 | data.writeString16(cameraId); | 
|  | 216 | data.writeInt32(enabled ? 1 : 0); | 
|  | 217 | data.writeStrongBinder(clientBinder); | 
|  | 218 | remote()->transact(BnCameraService::SET_TORCH_MODE, data, &reply); | 
|  | 219 |  | 
|  | 220 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 221 | return reply.readInt32(); | 
|  | 222 | } | 
|  | 223 |  | 
| Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 224 | // connect to camera service (android.hardware.camera2.CameraDevice) | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 225 | virtual status_t connectDevice( | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 226 | const sp<ICameraDeviceCallbacks>& cameraCb, | 
|  | 227 | int cameraId, | 
|  | 228 | const String16& clientPackageName, | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 229 | int clientUid, | 
|  | 230 | /*out*/ | 
|  | 231 | sp<ICameraDeviceUser>& device) | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 232 | { | 
|  | 233 | Parcel data, reply; | 
|  | 234 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 235 | data.writeStrongBinder(IInterface::asBinder(cameraCb)); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 236 | data.writeInt32(cameraId); | 
|  | 237 | data.writeString16(clientPackageName); | 
|  | 238 | data.writeInt32(clientUid); | 
|  | 239 | remote()->transact(BnCameraService::CONNECT_DEVICE, data, &reply); | 
|  | 240 |  | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 241 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 242 | status_t status = reply.readInt32(); | 
|  | 243 | if (reply.readInt32() != 0) { | 
|  | 244 | device = interface_cast<ICameraDeviceUser>(reply.readStrongBinder()); | 
|  | 245 | } | 
|  | 246 | return status; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 247 | } | 
|  | 248 |  | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 249 | virtual status_t addListener(const sp<ICameraServiceListener>& listener) | 
|  | 250 | { | 
|  | 251 | Parcel data, reply; | 
|  | 252 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 253 | data.writeStrongBinder(IInterface::asBinder(listener)); | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 254 | remote()->transact(BnCameraService::ADD_LISTENER, data, &reply); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 255 |  | 
|  | 256 | if (readExceptionCode(reply)) return -EPROTO; | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 257 | return reply.readInt32(); | 
|  | 258 | } | 
|  | 259 |  | 
|  | 260 | virtual status_t removeListener(const sp<ICameraServiceListener>& listener) | 
|  | 261 | { | 
|  | 262 | Parcel data, reply; | 
|  | 263 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 264 | data.writeStrongBinder(IInterface::asBinder(listener)); | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 265 | remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 266 |  | 
|  | 267 | if (readExceptionCode(reply)) return -EPROTO; | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 268 | return reply.readInt32(); | 
|  | 269 | } | 
| Igor Murashkin | 65d14b9 | 2014-06-17 12:03:20 -0700 | [diff] [blame] | 270 |  | 
|  | 271 | virtual status_t getLegacyParameters(int cameraId, String16* parameters) { | 
|  | 272 | if (parameters == NULL) { | 
|  | 273 | ALOGE("%s: parameters must not be null", __FUNCTION__); | 
|  | 274 | return BAD_VALUE; | 
|  | 275 | } | 
|  | 276 |  | 
|  | 277 | Parcel data, reply; | 
|  | 278 |  | 
|  | 279 | data.writeInt32(cameraId); | 
|  | 280 | remote()->transact(BnCameraService::GET_LEGACY_PARAMETERS, data, &reply); | 
|  | 281 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 282 |  | 
|  | 283 | status_t res = data.readInt32(); | 
|  | 284 | int32_t length = data.readInt32(); // -1 means null | 
|  | 285 | if (length > 0) { | 
|  | 286 | *parameters = data.readString16(); | 
|  | 287 | } else { | 
|  | 288 | *parameters = String16(); | 
|  | 289 | } | 
|  | 290 |  | 
|  | 291 | return res; | 
|  | 292 | } | 
|  | 293 |  | 
|  | 294 | virtual status_t supportsCameraApi(int cameraId, int apiVersion) { | 
|  | 295 | Parcel data, reply; | 
|  | 296 |  | 
|  | 297 | data.writeInt32(cameraId); | 
|  | 298 | data.writeInt32(apiVersion); | 
|  | 299 | remote()->transact(BnCameraService::SUPPORTS_CAMERA_API, data, &reply); | 
|  | 300 | if (readExceptionCode(reply)) return -EPROTO; | 
|  | 301 |  | 
|  | 302 | status_t res = data.readInt32(); | 
|  | 303 | return res; | 
|  | 304 | } | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 305 | }; | 
|  | 306 |  | 
|  | 307 | IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); | 
|  | 308 |  | 
|  | 309 | // ---------------------------------------------------------------------- | 
|  | 310 |  | 
|  | 311 | status_t BnCameraService::onTransact( | 
|  | 312 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 313 | { | 
|  | 314 | switch(code) { | 
| Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 315 | case GET_NUMBER_OF_CAMERAS: { | 
|  | 316 | CHECK_INTERFACE(ICameraService, data, reply); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 317 | reply->writeNoException(); | 
| Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 318 | reply->writeInt32(getNumberOfCameras()); | 
|  | 319 | return NO_ERROR; | 
|  | 320 | } break; | 
| Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 321 | case GET_CAMERA_INFO: { | 
|  | 322 | CHECK_INTERFACE(ICameraService, data, reply); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 323 | CameraInfo cameraInfo = CameraInfo(); | 
| Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 324 | memset(&cameraInfo, 0, sizeof(cameraInfo)); | 
|  | 325 | status_t result = getCameraInfo(data.readInt32(), &cameraInfo); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 326 | reply->writeNoException(); | 
|  | 327 | reply->writeInt32(result); | 
|  | 328 |  | 
|  | 329 | // Fake a parcelable object here | 
|  | 330 | reply->writeInt32(1); // means the parcelable is included | 
| Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 331 | reply->writeInt32(cameraInfo.facing); | 
|  | 332 | reply->writeInt32(cameraInfo.orientation); | 
| Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 333 | return NO_ERROR; | 
|  | 334 | } break; | 
| Zhijun He | 2b59be8 | 2013-09-25 10:14:30 -0700 | [diff] [blame] | 335 | case GET_CAMERA_CHARACTERISTICS: { | 
|  | 336 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 337 | CameraMetadata info; | 
|  | 338 | status_t result = getCameraCharacteristics(data.readInt32(), &info); | 
|  | 339 | reply->writeNoException(); | 
|  | 340 | reply->writeInt32(result); | 
|  | 341 |  | 
|  | 342 | // out-variables are after exception and return value | 
|  | 343 | reply->writeInt32(1); // means the parcelable is included | 
|  | 344 | info.writeToParcel(reply); | 
|  | 345 | return NO_ERROR; | 
|  | 346 | } break; | 
| Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 347 | case GET_CAMERA_VENDOR_TAG_DESCRIPTOR: { | 
|  | 348 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 349 | sp<VendorTagDescriptor> d; | 
|  | 350 | status_t result = getCameraVendorTagDescriptor(d); | 
|  | 351 | reply->writeNoException(); | 
|  | 352 | reply->writeInt32(result); | 
|  | 353 |  | 
|  | 354 | // out-variables are after exception and return value | 
| Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 355 | if (d == NULL) { | 
|  | 356 | reply->writeInt32(0); | 
|  | 357 | } else { | 
| Igor Murashkin | e1445da | 2014-03-17 14:00:29 -0700 | [diff] [blame] | 358 | reply->writeInt32(1); // means the parcelable is included | 
| Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 359 | d->writeToParcel(reply); | 
|  | 360 | } | 
|  | 361 | return NO_ERROR; | 
|  | 362 | } break; | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 363 | case CONNECT: { | 
|  | 364 | CHECK_INTERFACE(ICameraService, data, reply); | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 365 | sp<ICameraClient> cameraClient = | 
|  | 366 | interface_cast<ICameraClient>(data.readStrongBinder()); | 
|  | 367 | int32_t cameraId = data.readInt32(); | 
|  | 368 | const String16 clientName = data.readString16(); | 
|  | 369 | int32_t clientUid = data.readInt32(); | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 370 | sp<ICamera> camera; | 
|  | 371 | status_t status = connect(cameraClient, cameraId, | 
| Igor Murashkin | e1445da | 2014-03-17 14:00:29 -0700 | [diff] [blame] | 372 | clientName, clientUid, /*out*/camera); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 373 | reply->writeNoException(); | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 374 | reply->writeInt32(status); | 
|  | 375 | if (camera != NULL) { | 
|  | 376 | reply->writeInt32(1); | 
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 377 | reply->writeStrongBinder(IInterface::asBinder(camera)); | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 378 | } else { | 
|  | 379 | reply->writeInt32(0); | 
|  | 380 | } | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 381 | return NO_ERROR; | 
|  | 382 | } break; | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 383 | case CONNECT_DEVICE: { | 
|  | 384 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 385 | sp<ICameraDeviceCallbacks> cameraClient = | 
|  | 386 | interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder()); | 
|  | 387 | int32_t cameraId = data.readInt32(); | 
|  | 388 | const String16 clientName = data.readString16(); | 
|  | 389 | int32_t clientUid = data.readInt32(); | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 390 | sp<ICameraDeviceUser> camera; | 
|  | 391 | status_t status = connectDevice(cameraClient, cameraId, | 
| Igor Murashkin | e1445da | 2014-03-17 14:00:29 -0700 | [diff] [blame] | 392 | clientName, clientUid, /*out*/camera); | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 393 | reply->writeNoException(); | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 394 | reply->writeInt32(status); | 
|  | 395 | if (camera != NULL) { | 
|  | 396 | reply->writeInt32(1); | 
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 397 | reply->writeStrongBinder(IInterface::asBinder(camera)); | 
| Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 398 | } else { | 
|  | 399 | reply->writeInt32(0); | 
|  | 400 | } | 
| Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 401 | return NO_ERROR; | 
|  | 402 | } break; | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 403 | case ADD_LISTENER: { | 
|  | 404 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 405 | sp<ICameraServiceListener> listener = | 
|  | 406 | interface_cast<ICameraServiceListener>(data.readStrongBinder()); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 407 | reply->writeNoException(); | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 408 | reply->writeInt32(addListener(listener)); | 
|  | 409 | return NO_ERROR; | 
|  | 410 | } break; | 
|  | 411 | case REMOVE_LISTENER: { | 
|  | 412 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 413 | sp<ICameraServiceListener> listener = | 
|  | 414 | interface_cast<ICameraServiceListener>(data.readStrongBinder()); | 
| Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 415 | reply->writeNoException(); | 
| Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 416 | reply->writeInt32(removeListener(listener)); | 
|  | 417 | return NO_ERROR; | 
|  | 418 | } break; | 
| Igor Murashkin | 65d14b9 | 2014-06-17 12:03:20 -0700 | [diff] [blame] | 419 | case GET_LEGACY_PARAMETERS: { | 
|  | 420 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 421 | int cameraId = data.readInt32(); | 
|  | 422 | String16 parameters; | 
|  | 423 |  | 
|  | 424 | reply->writeNoException(); | 
|  | 425 | // return value | 
|  | 426 | reply->writeInt32(getLegacyParameters(cameraId, ¶meters)); | 
|  | 427 | // out parameters | 
|  | 428 | reply->writeInt32(1); // parameters is always available | 
|  | 429 | reply->writeString16(parameters); | 
|  | 430 | return NO_ERROR; | 
|  | 431 | } break; | 
|  | 432 | case SUPPORTS_CAMERA_API: { | 
|  | 433 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 434 | int cameraId = data.readInt32(); | 
|  | 435 | int apiVersion = data.readInt32(); | 
|  | 436 |  | 
|  | 437 | reply->writeNoException(); | 
|  | 438 | // return value | 
|  | 439 | reply->writeInt32(supportsCameraApi(cameraId, apiVersion)); | 
|  | 440 | return NO_ERROR; | 
|  | 441 | } break; | 
| Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 442 | case CONNECT_LEGACY: { | 
|  | 443 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 444 | sp<ICameraClient> cameraClient = | 
|  | 445 | interface_cast<ICameraClient>(data.readStrongBinder()); | 
|  | 446 | int32_t cameraId = data.readInt32(); | 
|  | 447 | int32_t halVersion = data.readInt32(); | 
|  | 448 | const String16 clientName = data.readString16(); | 
|  | 449 | int32_t clientUid = data.readInt32(); | 
|  | 450 | sp<ICamera> camera; | 
|  | 451 | status_t status = connectLegacy(cameraClient, cameraId, halVersion, | 
|  | 452 | clientName, clientUid, /*out*/camera); | 
|  | 453 | reply->writeNoException(); | 
|  | 454 | reply->writeInt32(status); | 
|  | 455 | if (camera != NULL) { | 
|  | 456 | reply->writeInt32(1); | 
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 457 | reply->writeStrongBinder(IInterface::asBinder(camera)); | 
| Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 458 | } else { | 
|  | 459 | reply->writeInt32(0); | 
|  | 460 | } | 
|  | 461 | return NO_ERROR; | 
|  | 462 | } break; | 
| Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 463 | case SET_TORCH_MODE: { | 
|  | 464 | CHECK_INTERFACE(ICameraService, data, reply); | 
|  | 465 | String16 cameraId = data.readString16(); | 
|  | 466 | bool enabled = data.readInt32() != 0 ? true : false; | 
|  | 467 | const sp<IBinder> clientBinder = data.readStrongBinder(); | 
|  | 468 | status_t status = setTorchMode(cameraId, enabled, clientBinder); | 
|  | 469 | reply->writeNoException(); | 
|  | 470 | reply->writeInt32(status); | 
|  | 471 | return NO_ERROR; | 
|  | 472 | } break; | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 473 | default: | 
|  | 474 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 475 | } | 
|  | 476 | } | 
|  | 477 |  | 
|  | 478 | // ---------------------------------------------------------------------------- | 
|  | 479 |  | 
|  | 480 | }; // namespace android |