blob: b359f5720fc3a6a459f0ea2e83ec315c4d872458 [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
Ruben Brunk9efdf952015-03-18 23:11:57 -07005** 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 Agopian3cf61352010-02-09 17:46:37 -08008**
Ruben Brunk9efdf952015-03-18 23:11:57 -07009** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopian3cf61352010-02-09 17:46:37 -080010**
Ruben Brunk9efdf952015-03-18 23:11:57 -070011** 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 Agopian3cf61352010-02-09 17:46:37 -080015** limitations under the License.
16*/
17
Igor Murashkinbef3f232013-05-30 17:47:38 -070018#define LOG_TAG "BpCameraService"
19#include <utils/Log.h>
Ruben Brunkd1176ef2014-02-21 10:51:38 -080020#include <utils/Errors.h>
Igor Murashkin65d14b92014-06-17 12:03:20 -070021#include <utils/String16.h>
Igor Murashkinbef3f232013-05-30 17:47:38 -070022
Ruben Brunk6267b532015-04-30 17:44:07 -070023#include <inttypes.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080024#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 Murashkinbfc99152013-02-27 12:55:20 -080032#include <camera/ICameraServiceListener.h>
Igor Murashkinc073ba52013-02-26 14:32:34 -080033#include <camera/ICamera.h>
34#include <camera/ICameraClient.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070035#include <camera/camera2/ICameraDeviceUser.h>
36#include <camera/camera2/ICameraDeviceCallbacks.h>
Zhijun He2b59be82013-09-25 10:14:30 -070037#include <camera/CameraMetadata.h>
Ruben Brunkd1176ef2014-02-21 10:51:38 -080038#include <camera/VendorTagDescriptor.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080039
40namespace android {
41
Igor Murashkinbef3f232013-05-30 17:47:38 -070042namespace {
43
44enum {
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
53static 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 Agopian3cf61352010-02-09 17:46:37 -080089class BpCameraService: public BpInterface<ICameraService>
90{
91public:
92 BpCameraService(const sp<IBinder>& impl)
93 : BpInterface<ICameraService>(impl)
94 {
95 }
96
Eino-Ville Talvalabad43582015-08-14 13:12:32 -070097 // get number of cameras available that support standard camera operations
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080098 virtual int32_t getNumberOfCameras()
99 {
Eino-Ville Talvalabad43582015-08-14 13:12:32 -0700100 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 Chang35a055b2010-05-06 16:36:58 +0800106 Parcel data, reply;
107 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Eino-Ville Talvalabad43582015-08-14 13:12:32 -0700108 data.writeInt32(type);
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800109 remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700110
111 if (readExceptionCode(reply)) return 0;
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800112 return reply.readInt32();
113 }
114
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800115 // 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 Murashkinbef3f232013-05-30 17:47:38 -0700122
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 Changddbdb352010-06-10 13:32:16 +0800130 }
131
Zhijun He2b59be82013-09-25 10:14:30 -0700132 // 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 Brunkd1176ef2014-02-21 10:51:38 -0800155 // 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 Murashkine7ee7632013-06-11 18:10:18 -0700173 // connect to camera service (android.hardware.Camera)
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700174 virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000175 const String16 &clientPackageName, int clientUid,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700176 /*out*/
177 sp<ICamera>& device)
Mathias Agopian3cf61352010-02-09 17:46:37 -0800178 {
179 Parcel data, reply;
180 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800181 data.writeStrongBinder(IInterface::asBinder(cameraClient));
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800182 data.writeInt32(cameraId);
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000183 data.writeString16(clientPackageName);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800184 data.writeInt32(clientUid);
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700185
186 status_t status;
187 status = remote()->transact(BnCameraService::CONNECT, data, &reply);
188 if (status != OK) return status;
Igor Murashkinbef3f232013-05-30 17:47:38 -0700189
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700190 if (readExceptionCode(reply)) return -EPROTO;
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700191 status = reply.readInt32();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700192 if (reply.readInt32() != 0) {
193 device = interface_cast<ICamera>(reply.readStrongBinder());
194 }
195 return status;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800196 }
Igor Murashkin634a5152013-02-20 17:15:11 -0800197
Zhijun Heb10cdad2014-06-16 16:38:35 -0700198 // connect to camera service (android.hardware.Camera)
199 virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
200 int halVersion,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000201 const String16 &clientPackageName, int clientUid,
Zhijun Heb10cdad2014-06-16 16:38:35 -0700202 /*out*/sp<ICamera>& device)
203 {
204 Parcel data, reply;
205 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800206 data.writeStrongBinder(IInterface::asBinder(cameraClient));
Zhijun Heb10cdad2014-06-16 16:38:35 -0700207 data.writeInt32(cameraId);
208 data.writeInt32(halVersion);
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000209 data.writeString16(clientPackageName);
Zhijun Heb10cdad2014-06-16 16:38:35 -0700210 data.writeInt32(clientUid);
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700211
212 status_t status;
213 status = remote()->transact(BnCameraService::CONNECT_LEGACY, data, &reply);
214 if (status != OK) return status;
Zhijun Heb10cdad2014-06-16 16:38:35 -0700215
216 if (readExceptionCode(reply)) return -EPROTO;
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700217 status = reply.readInt32();
Zhijun Heb10cdad2014-06-16 16:38:35 -0700218 if (reply.readInt32() != 0) {
219 device = interface_cast<ICamera>(reply.readStrongBinder());
220 }
221 return status;
222 }
223
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800224 virtual status_t setTorchMode(const String16& cameraId, bool enabled,
225 const sp<IBinder>& clientBinder)
226 {
227 Parcel data, reply;
228 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
229 data.writeString16(cameraId);
230 data.writeInt32(enabled ? 1 : 0);
231 data.writeStrongBinder(clientBinder);
232 remote()->transact(BnCameraService::SET_TORCH_MODE, data, &reply);
233
234 if (readExceptionCode(reply)) return -EPROTO;
235 return reply.readInt32();
236 }
237
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700238 // connect to camera service (android.hardware.camera2.CameraDevice)
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700239 virtual status_t connectDevice(
Igor Murashkine7ee7632013-06-11 18:10:18 -0700240 const sp<ICameraDeviceCallbacks>& cameraCb,
241 int cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000242 const String16& clientPackageName,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700243 int clientUid,
244 /*out*/
245 sp<ICameraDeviceUser>& device)
Igor Murashkine7ee7632013-06-11 18:10:18 -0700246 {
247 Parcel data, reply;
248 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800249 data.writeStrongBinder(IInterface::asBinder(cameraCb));
Igor Murashkine7ee7632013-06-11 18:10:18 -0700250 data.writeInt32(cameraId);
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000251 data.writeString16(clientPackageName);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700252 data.writeInt32(clientUid);
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700253
254 status_t status;
255 status = remote()->transact(BnCameraService::CONNECT_DEVICE, data, &reply);
256 if (status != OK) return status;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700257
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700258 if (readExceptionCode(reply)) return -EPROTO;
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700259 status = reply.readInt32();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700260 if (reply.readInt32() != 0) {
261 device = interface_cast<ICameraDeviceUser>(reply.readStrongBinder());
262 }
263 return status;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700264 }
265
Igor Murashkinbfc99152013-02-27 12:55:20 -0800266 virtual status_t addListener(const sp<ICameraServiceListener>& listener)
267 {
268 Parcel data, reply;
269 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800270 data.writeStrongBinder(IInterface::asBinder(listener));
Igor Murashkinbfc99152013-02-27 12:55:20 -0800271 remote()->transact(BnCameraService::ADD_LISTENER, data, &reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700272
273 if (readExceptionCode(reply)) return -EPROTO;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800274 return reply.readInt32();
275 }
276
277 virtual status_t removeListener(const sp<ICameraServiceListener>& listener)
278 {
279 Parcel data, reply;
280 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800281 data.writeStrongBinder(IInterface::asBinder(listener));
Igor Murashkinbfc99152013-02-27 12:55:20 -0800282 remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700283
284 if (readExceptionCode(reply)) return -EPROTO;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800285 return reply.readInt32();
286 }
Igor Murashkin65d14b92014-06-17 12:03:20 -0700287
288 virtual status_t getLegacyParameters(int cameraId, String16* parameters) {
289 if (parameters == NULL) {
290 ALOGE("%s: parameters must not be null", __FUNCTION__);
291 return BAD_VALUE;
292 }
293
294 Parcel data, reply;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700295 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Igor Murashkin65d14b92014-06-17 12:03:20 -0700296
297 data.writeInt32(cameraId);
298 remote()->transact(BnCameraService::GET_LEGACY_PARAMETERS, data, &reply);
299 if (readExceptionCode(reply)) return -EPROTO;
300
301 status_t res = data.readInt32();
302 int32_t length = data.readInt32(); // -1 means null
303 if (length > 0) {
304 *parameters = data.readString16();
305 } else {
306 *parameters = String16();
307 }
308
309 return res;
310 }
311
312 virtual status_t supportsCameraApi(int cameraId, int apiVersion) {
313 Parcel data, reply;
314
Ruben Brunk3450ba72015-06-16 11:00:37 -0700315 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Igor Murashkin65d14b92014-06-17 12:03:20 -0700316 data.writeInt32(cameraId);
317 data.writeInt32(apiVersion);
318 remote()->transact(BnCameraService::SUPPORTS_CAMERA_API, data, &reply);
319 if (readExceptionCode(reply)) return -EPROTO;
320
321 status_t res = data.readInt32();
322 return res;
323 }
Ruben Brunk36597b22015-03-20 22:15:57 -0700324
Ruben Brunk6267b532015-04-30 17:44:07 -0700325 virtual void notifySystemEvent(int32_t eventId, const int32_t* args, size_t len) {
Ruben Brunk36597b22015-03-20 22:15:57 -0700326 Parcel data, reply;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700327 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Ruben Brunk36597b22015-03-20 22:15:57 -0700328 data.writeInt32(eventId);
Ruben Brunk6267b532015-04-30 17:44:07 -0700329 data.writeInt32Array(len, args);
Ruben Brunk36597b22015-03-20 22:15:57 -0700330 remote()->transact(BnCameraService::NOTIFY_SYSTEM_EVENT, data, &reply,
331 IBinder::FLAG_ONEWAY);
332 }
333
Mathias Agopian3cf61352010-02-09 17:46:37 -0800334};
335
336IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
337
338// ----------------------------------------------------------------------
339
340status_t BnCameraService::onTransact(
341 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
342{
343 switch(code) {
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800344 case GET_NUMBER_OF_CAMERAS: {
345 CHECK_INTERFACE(ICameraService, data, reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700346 reply->writeNoException();
Eino-Ville Talvalabad43582015-08-14 13:12:32 -0700347 reply->writeInt32(getNumberOfCameras(data.readInt32()));
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800348 return NO_ERROR;
349 } break;
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800350 case GET_CAMERA_INFO: {
351 CHECK_INTERFACE(ICameraService, data, reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700352 CameraInfo cameraInfo = CameraInfo();
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800353 memset(&cameraInfo, 0, sizeof(cameraInfo));
354 status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700355 reply->writeNoException();
356 reply->writeInt32(result);
357
358 // Fake a parcelable object here
359 reply->writeInt32(1); // means the parcelable is included
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800360 reply->writeInt32(cameraInfo.facing);
361 reply->writeInt32(cameraInfo.orientation);
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800362 return NO_ERROR;
363 } break;
Zhijun He2b59be82013-09-25 10:14:30 -0700364 case GET_CAMERA_CHARACTERISTICS: {
365 CHECK_INTERFACE(ICameraService, data, reply);
366 CameraMetadata info;
367 status_t result = getCameraCharacteristics(data.readInt32(), &info);
368 reply->writeNoException();
369 reply->writeInt32(result);
370
371 // out-variables are after exception and return value
372 reply->writeInt32(1); // means the parcelable is included
373 info.writeToParcel(reply);
374 return NO_ERROR;
375 } break;
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800376 case GET_CAMERA_VENDOR_TAG_DESCRIPTOR: {
377 CHECK_INTERFACE(ICameraService, data, reply);
378 sp<VendorTagDescriptor> d;
379 status_t result = getCameraVendorTagDescriptor(d);
380 reply->writeNoException();
381 reply->writeInt32(result);
382
383 // out-variables are after exception and return value
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800384 if (d == NULL) {
385 reply->writeInt32(0);
386 } else {
Igor Murashkine1445da2014-03-17 14:00:29 -0700387 reply->writeInt32(1); // means the parcelable is included
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800388 d->writeToParcel(reply);
389 }
390 return NO_ERROR;
391 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800392 case CONNECT: {
393 CHECK_INTERFACE(ICameraService, data, reply);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800394 sp<ICameraClient> cameraClient =
395 interface_cast<ICameraClient>(data.readStrongBinder());
396 int32_t cameraId = data.readInt32();
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000397 const String16 clientName = data.readString16();
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800398 int32_t clientUid = data.readInt32();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700399 sp<ICamera> camera;
400 status_t status = connect(cameraClient, cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000401 clientName, clientUid, /*out*/camera);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700402 reply->writeNoException();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700403 reply->writeInt32(status);
404 if (camera != NULL) {
405 reply->writeInt32(1);
Marco Nelissen06b46062014-11-14 07:58:25 -0800406 reply->writeStrongBinder(IInterface::asBinder(camera));
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700407 } else {
408 reply->writeInt32(0);
409 }
Mathias Agopian3cf61352010-02-09 17:46:37 -0800410 return NO_ERROR;
411 } break;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700412 case CONNECT_DEVICE: {
413 CHECK_INTERFACE(ICameraService, data, reply);
414 sp<ICameraDeviceCallbacks> cameraClient =
415 interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder());
416 int32_t cameraId = data.readInt32();
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000417 const String16 clientName = data.readString16();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700418 int32_t clientUid = data.readInt32();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700419 sp<ICameraDeviceUser> camera;
420 status_t status = connectDevice(cameraClient, cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000421 clientName, clientUid, /*out*/camera);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700422 reply->writeNoException();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700423 reply->writeInt32(status);
424 if (camera != NULL) {
425 reply->writeInt32(1);
Marco Nelissen06b46062014-11-14 07:58:25 -0800426 reply->writeStrongBinder(IInterface::asBinder(camera));
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700427 } else {
428 reply->writeInt32(0);
429 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700430 return NO_ERROR;
431 } break;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800432 case ADD_LISTENER: {
433 CHECK_INTERFACE(ICameraService, data, reply);
434 sp<ICameraServiceListener> listener =
435 interface_cast<ICameraServiceListener>(data.readStrongBinder());
Igor Murashkinbef3f232013-05-30 17:47:38 -0700436 reply->writeNoException();
Igor Murashkinbfc99152013-02-27 12:55:20 -0800437 reply->writeInt32(addListener(listener));
438 return NO_ERROR;
439 } break;
440 case REMOVE_LISTENER: {
441 CHECK_INTERFACE(ICameraService, data, reply);
442 sp<ICameraServiceListener> listener =
443 interface_cast<ICameraServiceListener>(data.readStrongBinder());
Igor Murashkinbef3f232013-05-30 17:47:38 -0700444 reply->writeNoException();
Igor Murashkinbfc99152013-02-27 12:55:20 -0800445 reply->writeInt32(removeListener(listener));
446 return NO_ERROR;
447 } break;
Igor Murashkin65d14b92014-06-17 12:03:20 -0700448 case GET_LEGACY_PARAMETERS: {
449 CHECK_INTERFACE(ICameraService, data, reply);
450 int cameraId = data.readInt32();
451 String16 parameters;
452
453 reply->writeNoException();
454 // return value
455 reply->writeInt32(getLegacyParameters(cameraId, &parameters));
456 // out parameters
457 reply->writeInt32(1); // parameters is always available
458 reply->writeString16(parameters);
459 return NO_ERROR;
460 } break;
461 case SUPPORTS_CAMERA_API: {
462 CHECK_INTERFACE(ICameraService, data, reply);
463 int cameraId = data.readInt32();
464 int apiVersion = data.readInt32();
465
466 reply->writeNoException();
467 // return value
468 reply->writeInt32(supportsCameraApi(cameraId, apiVersion));
469 return NO_ERROR;
470 } break;
Zhijun Heb10cdad2014-06-16 16:38:35 -0700471 case CONNECT_LEGACY: {
472 CHECK_INTERFACE(ICameraService, data, reply);
473 sp<ICameraClient> cameraClient =
474 interface_cast<ICameraClient>(data.readStrongBinder());
475 int32_t cameraId = data.readInt32();
476 int32_t halVersion = data.readInt32();
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000477 const String16 clientName = data.readString16();
Zhijun Heb10cdad2014-06-16 16:38:35 -0700478 int32_t clientUid = data.readInt32();
479 sp<ICamera> camera;
480 status_t status = connectLegacy(cameraClient, cameraId, halVersion,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000481 clientName, clientUid, /*out*/camera);
Zhijun Heb10cdad2014-06-16 16:38:35 -0700482 reply->writeNoException();
483 reply->writeInt32(status);
484 if (camera != NULL) {
485 reply->writeInt32(1);
Marco Nelissen06b46062014-11-14 07:58:25 -0800486 reply->writeStrongBinder(IInterface::asBinder(camera));
Zhijun Heb10cdad2014-06-16 16:38:35 -0700487 } else {
488 reply->writeInt32(0);
489 }
490 return NO_ERROR;
491 } break;
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800492 case SET_TORCH_MODE: {
493 CHECK_INTERFACE(ICameraService, data, reply);
494 String16 cameraId = data.readString16();
495 bool enabled = data.readInt32() != 0 ? true : false;
496 const sp<IBinder> clientBinder = data.readStrongBinder();
497 status_t status = setTorchMode(cameraId, enabled, clientBinder);
498 reply->writeNoException();
499 reply->writeInt32(status);
500 return NO_ERROR;
501 } break;
Ruben Brunk36597b22015-03-20 22:15:57 -0700502 case NOTIFY_SYSTEM_EVENT: {
503 CHECK_INTERFACE(ICameraService, data, reply);
Ruben Brunk6267b532015-04-30 17:44:07 -0700504 int32_t eventId = data.readInt32();
505 int32_t len = data.readInt32();
506 if (len < 0) {
507 ALOGE("%s: Received poorly formatted length in binder request: notifySystemEvent.",
508 __FUNCTION__);
509 return FAILED_TRANSACTION;
510 }
511 if (len > 512) {
512 ALOGE("%s: Length %" PRIi32 " too long in binder request: notifySystemEvent.",
513 __FUNCTION__, len);
514 return FAILED_TRANSACTION;
515 }
Chih-Hung Hsieh8eddd882015-05-18 15:51:54 -0700516 int32_t events[len];
517 memset(events, 0, sizeof(int32_t) * len);
Ruben Brunk6267b532015-04-30 17:44:07 -0700518 status_t status = data.read(events, sizeof(int32_t) * len);
519 if (status != NO_ERROR) {
520 ALOGE("%s: Received poorly formatted binder request: notifySystemEvent.",
521 __FUNCTION__);
522 return FAILED_TRANSACTION;
523 }
524 notifySystemEvent(eventId, events, len);
Ruben Brunk36597b22015-03-20 22:15:57 -0700525 return NO_ERROR;
526 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800527 default:
528 return BBinder::onTransact(code, data, reply, flags);
529 }
530}
531
532// ----------------------------------------------------------------------------
533
534}; // namespace android