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