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