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