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, |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 167 | const String16 &clientPackageName, int clientUid, |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 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); |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 175 | data.writeString16(clientPackageName); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 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, |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 190 | const String16 &clientPackageName, int clientUid, |
Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 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); |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 198 | data.writeString16(clientPackageName); |
Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 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, |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 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); |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 237 | data.writeString16(clientPackageName); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 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 | } |
Ruben Brunk | 36597b2 | 2015-03-20 22:15:57 -0700 | [diff] [blame] | 305 | |
| 306 | virtual void notifySystemEvent(int eventId, int arg0) { |
| 307 | Parcel data, reply; |
| 308 | data.writeInt32(eventId); |
| 309 | data.writeInt32(arg0); |
| 310 | remote()->transact(BnCameraService::NOTIFY_SYSTEM_EVENT, data, &reply, |
| 311 | IBinder::FLAG_ONEWAY); |
| 312 | } |
| 313 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); |
| 317 | |
| 318 | // ---------------------------------------------------------------------- |
| 319 | |
| 320 | status_t BnCameraService::onTransact( |
| 321 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 322 | { |
| 323 | switch(code) { |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 324 | case GET_NUMBER_OF_CAMERAS: { |
| 325 | CHECK_INTERFACE(ICameraService, data, reply); |
Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 326 | reply->writeNoException(); |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 327 | reply->writeInt32(getNumberOfCameras()); |
| 328 | return NO_ERROR; |
| 329 | } break; |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 330 | case GET_CAMERA_INFO: { |
| 331 | CHECK_INTERFACE(ICameraService, data, reply); |
Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 332 | CameraInfo cameraInfo = CameraInfo(); |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 333 | memset(&cameraInfo, 0, sizeof(cameraInfo)); |
| 334 | status_t result = getCameraInfo(data.readInt32(), &cameraInfo); |
Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 335 | reply->writeNoException(); |
| 336 | reply->writeInt32(result); |
| 337 | |
| 338 | // Fake a parcelable object here |
| 339 | reply->writeInt32(1); // means the parcelable is included |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 340 | reply->writeInt32(cameraInfo.facing); |
| 341 | reply->writeInt32(cameraInfo.orientation); |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 342 | return NO_ERROR; |
| 343 | } break; |
Zhijun He | 2b59be8 | 2013-09-25 10:14:30 -0700 | [diff] [blame] | 344 | case GET_CAMERA_CHARACTERISTICS: { |
| 345 | CHECK_INTERFACE(ICameraService, data, reply); |
| 346 | CameraMetadata info; |
| 347 | status_t result = getCameraCharacteristics(data.readInt32(), &info); |
| 348 | reply->writeNoException(); |
| 349 | reply->writeInt32(result); |
| 350 | |
| 351 | // out-variables are after exception and return value |
| 352 | reply->writeInt32(1); // means the parcelable is included |
| 353 | info.writeToParcel(reply); |
| 354 | return NO_ERROR; |
| 355 | } break; |
Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 356 | case GET_CAMERA_VENDOR_TAG_DESCRIPTOR: { |
| 357 | CHECK_INTERFACE(ICameraService, data, reply); |
| 358 | sp<VendorTagDescriptor> d; |
| 359 | status_t result = getCameraVendorTagDescriptor(d); |
| 360 | reply->writeNoException(); |
| 361 | reply->writeInt32(result); |
| 362 | |
| 363 | // out-variables are after exception and return value |
Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 364 | if (d == NULL) { |
| 365 | reply->writeInt32(0); |
| 366 | } else { |
Igor Murashkin | e1445da | 2014-03-17 14:00:29 -0700 | [diff] [blame] | 367 | reply->writeInt32(1); // means the parcelable is included |
Ruben Brunk | d1176ef | 2014-02-21 10:51:38 -0800 | [diff] [blame] | 368 | d->writeToParcel(reply); |
| 369 | } |
| 370 | return NO_ERROR; |
| 371 | } break; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 372 | case CONNECT: { |
| 373 | CHECK_INTERFACE(ICameraService, data, reply); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 374 | sp<ICameraClient> cameraClient = |
| 375 | interface_cast<ICameraClient>(data.readStrongBinder()); |
| 376 | int32_t cameraId = data.readInt32(); |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 377 | const String16 clientName = data.readString16(); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 378 | int32_t clientUid = data.readInt32(); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 379 | sp<ICamera> camera; |
| 380 | status_t status = connect(cameraClient, cameraId, |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 381 | clientName, clientUid, /*out*/camera); |
Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 382 | reply->writeNoException(); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 383 | reply->writeInt32(status); |
| 384 | if (camera != NULL) { |
| 385 | reply->writeInt32(1); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 386 | reply->writeStrongBinder(IInterface::asBinder(camera)); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 387 | } else { |
| 388 | reply->writeInt32(0); |
| 389 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 390 | return NO_ERROR; |
| 391 | } break; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 392 | case CONNECT_DEVICE: { |
| 393 | CHECK_INTERFACE(ICameraService, data, reply); |
| 394 | sp<ICameraDeviceCallbacks> cameraClient = |
| 395 | interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder()); |
| 396 | int32_t cameraId = data.readInt32(); |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 397 | const String16 clientName = data.readString16(); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 398 | int32_t clientUid = data.readInt32(); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 399 | sp<ICameraDeviceUser> camera; |
| 400 | status_t status = connectDevice(cameraClient, cameraId, |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 401 | clientName, clientUid, /*out*/camera); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 402 | reply->writeNoException(); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 403 | reply->writeInt32(status); |
| 404 | if (camera != NULL) { |
| 405 | reply->writeInt32(1); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 406 | reply->writeStrongBinder(IInterface::asBinder(camera)); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 407 | } else { |
| 408 | reply->writeInt32(0); |
| 409 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 410 | return NO_ERROR; |
| 411 | } break; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 412 | case ADD_LISTENER: { |
| 413 | CHECK_INTERFACE(ICameraService, data, reply); |
| 414 | sp<ICameraServiceListener> listener = |
| 415 | interface_cast<ICameraServiceListener>(data.readStrongBinder()); |
Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 416 | reply->writeNoException(); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 417 | reply->writeInt32(addListener(listener)); |
| 418 | return NO_ERROR; |
| 419 | } break; |
| 420 | case REMOVE_LISTENER: { |
| 421 | CHECK_INTERFACE(ICameraService, data, reply); |
| 422 | sp<ICameraServiceListener> listener = |
| 423 | interface_cast<ICameraServiceListener>(data.readStrongBinder()); |
Igor Murashkin | bef3f23 | 2013-05-30 17:47:38 -0700 | [diff] [blame] | 424 | reply->writeNoException(); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 425 | reply->writeInt32(removeListener(listener)); |
| 426 | return NO_ERROR; |
| 427 | } break; |
Igor Murashkin | 65d14b9 | 2014-06-17 12:03:20 -0700 | [diff] [blame] | 428 | case GET_LEGACY_PARAMETERS: { |
| 429 | CHECK_INTERFACE(ICameraService, data, reply); |
| 430 | int cameraId = data.readInt32(); |
| 431 | String16 parameters; |
| 432 | |
| 433 | reply->writeNoException(); |
| 434 | // return value |
| 435 | reply->writeInt32(getLegacyParameters(cameraId, ¶meters)); |
| 436 | // out parameters |
| 437 | reply->writeInt32(1); // parameters is always available |
| 438 | reply->writeString16(parameters); |
| 439 | return NO_ERROR; |
| 440 | } break; |
| 441 | case SUPPORTS_CAMERA_API: { |
| 442 | CHECK_INTERFACE(ICameraService, data, reply); |
| 443 | int cameraId = data.readInt32(); |
| 444 | int apiVersion = data.readInt32(); |
| 445 | |
| 446 | reply->writeNoException(); |
| 447 | // return value |
| 448 | reply->writeInt32(supportsCameraApi(cameraId, apiVersion)); |
| 449 | return NO_ERROR; |
| 450 | } break; |
Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 451 | case CONNECT_LEGACY: { |
| 452 | CHECK_INTERFACE(ICameraService, data, reply); |
| 453 | sp<ICameraClient> cameraClient = |
| 454 | interface_cast<ICameraClient>(data.readStrongBinder()); |
| 455 | int32_t cameraId = data.readInt32(); |
| 456 | int32_t halVersion = data.readInt32(); |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 457 | const String16 clientName = data.readString16(); |
Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 458 | int32_t clientUid = data.readInt32(); |
| 459 | sp<ICamera> camera; |
| 460 | status_t status = connectLegacy(cameraClient, cameraId, halVersion, |
Svetoslav Ganov | 280405a | 2015-05-12 02:19:27 +0000 | [diff] [blame] | 461 | clientName, clientUid, /*out*/camera); |
Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 462 | reply->writeNoException(); |
| 463 | reply->writeInt32(status); |
| 464 | if (camera != NULL) { |
| 465 | reply->writeInt32(1); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 466 | reply->writeStrongBinder(IInterface::asBinder(camera)); |
Zhijun He | b10cdad | 2014-06-16 16:38:35 -0700 | [diff] [blame] | 467 | } else { |
| 468 | reply->writeInt32(0); |
| 469 | } |
| 470 | return NO_ERROR; |
| 471 | } break; |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 472 | case SET_TORCH_MODE: { |
| 473 | CHECK_INTERFACE(ICameraService, data, reply); |
| 474 | String16 cameraId = data.readString16(); |
| 475 | bool enabled = data.readInt32() != 0 ? true : false; |
| 476 | const sp<IBinder> clientBinder = data.readStrongBinder(); |
| 477 | status_t status = setTorchMode(cameraId, enabled, clientBinder); |
| 478 | reply->writeNoException(); |
| 479 | reply->writeInt32(status); |
| 480 | return NO_ERROR; |
| 481 | } break; |
Ruben Brunk | 36597b2 | 2015-03-20 22:15:57 -0700 | [diff] [blame] | 482 | case NOTIFY_SYSTEM_EVENT: { |
| 483 | CHECK_INTERFACE(ICameraService, data, reply); |
| 484 | int eventId = data.readInt32(); |
| 485 | int arg0 = data.readInt32(); |
| 486 | notifySystemEvent(eventId, arg0); |
| 487 | return NO_ERROR; |
| 488 | } break; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 489 | default: |
| 490 | return BBinder::onTransact(code, data, reply, flags); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | // ---------------------------------------------------------------------------- |
| 495 | |
| 496 | }; // namespace android |