blob: 7c9720faccf69532842b37b8b741f7f0789e241f [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
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080097 // 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 Murashkinbef3f232013-05-30 17:47:38 -0700103
104 if (readExceptionCode(reply)) return 0;
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800105 return reply.readInt32();
106 }
107
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800108 // 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 Murashkinbef3f232013-05-30 17:47:38 -0700115
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 Changddbdb352010-06-10 13:32:16 +0800123 }
124
Zhijun He2b59be82013-09-25 10:14:30 -0700125 // 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 Brunkd1176ef2014-02-21 10:51:38 -0800148 // 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 Murashkine7ee7632013-06-11 18:10:18 -0700166 // connect to camera service (android.hardware.Camera)
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700167 virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000168 const String16 &clientPackageName, int clientUid,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700169 /*out*/
170 sp<ICamera>& device)
Mathias Agopian3cf61352010-02-09 17:46:37 -0800171 {
172 Parcel data, reply;
173 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800174 data.writeStrongBinder(IInterface::asBinder(cameraClient));
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800175 data.writeInt32(cameraId);
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000176 data.writeString16(clientPackageName);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800177 data.writeInt32(clientUid);
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700178
179 status_t status;
180 status = remote()->transact(BnCameraService::CONNECT, data, &reply);
181 if (status != OK) return status;
Igor Murashkinbef3f232013-05-30 17:47:38 -0700182
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700183 if (readExceptionCode(reply)) return -EPROTO;
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700184 status = reply.readInt32();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700185 if (reply.readInt32() != 0) {
186 device = interface_cast<ICamera>(reply.readStrongBinder());
187 }
188 return status;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800189 }
Igor Murashkin634a5152013-02-20 17:15:11 -0800190
Zhijun Heb10cdad2014-06-16 16:38:35 -0700191 // connect to camera service (android.hardware.Camera)
192 virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
193 int halVersion,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000194 const String16 &clientPackageName, int clientUid,
Zhijun Heb10cdad2014-06-16 16:38:35 -0700195 /*out*/sp<ICamera>& device)
196 {
197 Parcel data, reply;
198 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800199 data.writeStrongBinder(IInterface::asBinder(cameraClient));
Zhijun Heb10cdad2014-06-16 16:38:35 -0700200 data.writeInt32(cameraId);
201 data.writeInt32(halVersion);
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000202 data.writeString16(clientPackageName);
Zhijun Heb10cdad2014-06-16 16:38:35 -0700203 data.writeInt32(clientUid);
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700204
205 status_t status;
206 status = remote()->transact(BnCameraService::CONNECT_LEGACY, data, &reply);
207 if (status != OK) return status;
Zhijun Heb10cdad2014-06-16 16:38:35 -0700208
209 if (readExceptionCode(reply)) return -EPROTO;
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700210 status = reply.readInt32();
Zhijun Heb10cdad2014-06-16 16:38:35 -0700211 if (reply.readInt32() != 0) {
212 device = interface_cast<ICamera>(reply.readStrongBinder());
213 }
214 return status;
215 }
216
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800217 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 Talvala7b82efe2013-07-25 17:12:35 -0700231 // connect to camera service (android.hardware.camera2.CameraDevice)
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700232 virtual status_t connectDevice(
Igor Murashkine7ee7632013-06-11 18:10:18 -0700233 const sp<ICameraDeviceCallbacks>& cameraCb,
234 int cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000235 const String16& clientPackageName,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700236 int clientUid,
237 /*out*/
238 sp<ICameraDeviceUser>& device)
Igor Murashkine7ee7632013-06-11 18:10:18 -0700239 {
240 Parcel data, reply;
241 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800242 data.writeStrongBinder(IInterface::asBinder(cameraCb));
Igor Murashkine7ee7632013-06-11 18:10:18 -0700243 data.writeInt32(cameraId);
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000244 data.writeString16(clientPackageName);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700245 data.writeInt32(clientUid);
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700246
247 status_t status;
248 status = remote()->transact(BnCameraService::CONNECT_DEVICE, data, &reply);
249 if (status != OK) return status;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700250
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700251 if (readExceptionCode(reply)) return -EPROTO;
Eino-Ville Talvalae3afb2c2015-06-03 16:03:30 -0700252 status = reply.readInt32();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700253 if (reply.readInt32() != 0) {
254 device = interface_cast<ICameraDeviceUser>(reply.readStrongBinder());
255 }
256 return status;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700257 }
258
Igor Murashkinbfc99152013-02-27 12:55:20 -0800259 virtual status_t addListener(const sp<ICameraServiceListener>& listener)
260 {
261 Parcel data, reply;
262 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800263 data.writeStrongBinder(IInterface::asBinder(listener));
Igor Murashkinbfc99152013-02-27 12:55:20 -0800264 remote()->transact(BnCameraService::ADD_LISTENER, data, &reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700265
266 if (readExceptionCode(reply)) return -EPROTO;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800267 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 Nelissen06b46062014-11-14 07:58:25 -0800274 data.writeStrongBinder(IInterface::asBinder(listener));
Igor Murashkinbfc99152013-02-27 12:55:20 -0800275 remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700276
277 if (readExceptionCode(reply)) return -EPROTO;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800278 return reply.readInt32();
279 }
Igor Murashkin65d14b92014-06-17 12:03:20 -0700280
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;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700288 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Igor Murashkin65d14b92014-06-17 12:03:20 -0700289
290 data.writeInt32(cameraId);
291 remote()->transact(BnCameraService::GET_LEGACY_PARAMETERS, data, &reply);
292 if (readExceptionCode(reply)) return -EPROTO;
293
294 status_t res = data.readInt32();
295 int32_t length = data.readInt32(); // -1 means null
296 if (length > 0) {
297 *parameters = data.readString16();
298 } else {
299 *parameters = String16();
300 }
301
302 return res;
303 }
304
305 virtual status_t supportsCameraApi(int cameraId, int apiVersion) {
306 Parcel data, reply;
307
Ruben Brunk3450ba72015-06-16 11:00:37 -0700308 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Igor Murashkin65d14b92014-06-17 12:03:20 -0700309 data.writeInt32(cameraId);
310 data.writeInt32(apiVersion);
311 remote()->transact(BnCameraService::SUPPORTS_CAMERA_API, data, &reply);
312 if (readExceptionCode(reply)) return -EPROTO;
313
314 status_t res = data.readInt32();
315 return res;
316 }
Ruben Brunk36597b22015-03-20 22:15:57 -0700317
Ruben Brunk6267b532015-04-30 17:44:07 -0700318 virtual void notifySystemEvent(int32_t eventId, const int32_t* args, size_t len) {
Ruben Brunk36597b22015-03-20 22:15:57 -0700319 Parcel data, reply;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700320 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
Ruben Brunk36597b22015-03-20 22:15:57 -0700321 data.writeInt32(eventId);
Ruben Brunk6267b532015-04-30 17:44:07 -0700322 data.writeInt32Array(len, args);
Ruben Brunk36597b22015-03-20 22:15:57 -0700323 remote()->transact(BnCameraService::NOTIFY_SYSTEM_EVENT, data, &reply,
324 IBinder::FLAG_ONEWAY);
325 }
326
Mathias Agopian3cf61352010-02-09 17:46:37 -0800327};
328
329IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
330
331// ----------------------------------------------------------------------
332
333status_t BnCameraService::onTransact(
334 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
335{
336 switch(code) {
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800337 case GET_NUMBER_OF_CAMERAS: {
338 CHECK_INTERFACE(ICameraService, data, reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700339 reply->writeNoException();
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800340 reply->writeInt32(getNumberOfCameras());
341 return NO_ERROR;
342 } break;
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800343 case GET_CAMERA_INFO: {
344 CHECK_INTERFACE(ICameraService, data, reply);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700345 CameraInfo cameraInfo = CameraInfo();
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800346 memset(&cameraInfo, 0, sizeof(cameraInfo));
347 status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700348 reply->writeNoException();
349 reply->writeInt32(result);
350
351 // Fake a parcelable object here
352 reply->writeInt32(1); // means the parcelable is included
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800353 reply->writeInt32(cameraInfo.facing);
354 reply->writeInt32(cameraInfo.orientation);
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800355 return NO_ERROR;
356 } break;
Zhijun He2b59be82013-09-25 10:14:30 -0700357 case GET_CAMERA_CHARACTERISTICS: {
358 CHECK_INTERFACE(ICameraService, data, reply);
359 CameraMetadata info;
360 status_t result = getCameraCharacteristics(data.readInt32(), &info);
361 reply->writeNoException();
362 reply->writeInt32(result);
363
364 // out-variables are after exception and return value
365 reply->writeInt32(1); // means the parcelable is included
366 info.writeToParcel(reply);
367 return NO_ERROR;
368 } break;
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800369 case GET_CAMERA_VENDOR_TAG_DESCRIPTOR: {
370 CHECK_INTERFACE(ICameraService, data, reply);
371 sp<VendorTagDescriptor> d;
372 status_t result = getCameraVendorTagDescriptor(d);
373 reply->writeNoException();
374 reply->writeInt32(result);
375
376 // out-variables are after exception and return value
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800377 if (d == NULL) {
378 reply->writeInt32(0);
379 } else {
Igor Murashkine1445da2014-03-17 14:00:29 -0700380 reply->writeInt32(1); // means the parcelable is included
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800381 d->writeToParcel(reply);
382 }
383 return NO_ERROR;
384 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800385 case CONNECT: {
386 CHECK_INTERFACE(ICameraService, data, reply);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800387 sp<ICameraClient> cameraClient =
388 interface_cast<ICameraClient>(data.readStrongBinder());
389 int32_t cameraId = data.readInt32();
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000390 const String16 clientName = data.readString16();
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800391 int32_t clientUid = data.readInt32();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700392 sp<ICamera> camera;
393 status_t status = connect(cameraClient, cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000394 clientName, clientUid, /*out*/camera);
Igor Murashkinbef3f232013-05-30 17:47:38 -0700395 reply->writeNoException();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700396 reply->writeInt32(status);
397 if (camera != NULL) {
398 reply->writeInt32(1);
Marco Nelissen06b46062014-11-14 07:58:25 -0800399 reply->writeStrongBinder(IInterface::asBinder(camera));
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700400 } else {
401 reply->writeInt32(0);
402 }
Mathias Agopian3cf61352010-02-09 17:46:37 -0800403 return NO_ERROR;
404 } break;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700405 case CONNECT_DEVICE: {
406 CHECK_INTERFACE(ICameraService, data, reply);
407 sp<ICameraDeviceCallbacks> cameraClient =
408 interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder());
409 int32_t cameraId = data.readInt32();
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000410 const String16 clientName = data.readString16();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700411 int32_t clientUid = data.readInt32();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700412 sp<ICameraDeviceUser> camera;
413 status_t status = connectDevice(cameraClient, cameraId,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000414 clientName, clientUid, /*out*/camera);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700415 reply->writeNoException();
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700416 reply->writeInt32(status);
417 if (camera != NULL) {
418 reply->writeInt32(1);
Marco Nelissen06b46062014-11-14 07:58:25 -0800419 reply->writeStrongBinder(IInterface::asBinder(camera));
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700420 } else {
421 reply->writeInt32(0);
422 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700423 return NO_ERROR;
424 } break;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800425 case ADD_LISTENER: {
426 CHECK_INTERFACE(ICameraService, data, reply);
427 sp<ICameraServiceListener> listener =
428 interface_cast<ICameraServiceListener>(data.readStrongBinder());
Igor Murashkinbef3f232013-05-30 17:47:38 -0700429 reply->writeNoException();
Igor Murashkinbfc99152013-02-27 12:55:20 -0800430 reply->writeInt32(addListener(listener));
431 return NO_ERROR;
432 } break;
433 case REMOVE_LISTENER: {
434 CHECK_INTERFACE(ICameraService, data, reply);
435 sp<ICameraServiceListener> listener =
436 interface_cast<ICameraServiceListener>(data.readStrongBinder());
Igor Murashkinbef3f232013-05-30 17:47:38 -0700437 reply->writeNoException();
Igor Murashkinbfc99152013-02-27 12:55:20 -0800438 reply->writeInt32(removeListener(listener));
439 return NO_ERROR;
440 } break;
Igor Murashkin65d14b92014-06-17 12:03:20 -0700441 case GET_LEGACY_PARAMETERS: {
442 CHECK_INTERFACE(ICameraService, data, reply);
443 int cameraId = data.readInt32();
444 String16 parameters;
445
446 reply->writeNoException();
447 // return value
448 reply->writeInt32(getLegacyParameters(cameraId, &parameters));
449 // out parameters
450 reply->writeInt32(1); // parameters is always available
451 reply->writeString16(parameters);
452 return NO_ERROR;
453 } break;
454 case SUPPORTS_CAMERA_API: {
455 CHECK_INTERFACE(ICameraService, data, reply);
456 int cameraId = data.readInt32();
457 int apiVersion = data.readInt32();
458
459 reply->writeNoException();
460 // return value
461 reply->writeInt32(supportsCameraApi(cameraId, apiVersion));
462 return NO_ERROR;
463 } break;
Zhijun Heb10cdad2014-06-16 16:38:35 -0700464 case CONNECT_LEGACY: {
465 CHECK_INTERFACE(ICameraService, data, reply);
466 sp<ICameraClient> cameraClient =
467 interface_cast<ICameraClient>(data.readStrongBinder());
468 int32_t cameraId = data.readInt32();
469 int32_t halVersion = data.readInt32();
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000470 const String16 clientName = data.readString16();
Zhijun Heb10cdad2014-06-16 16:38:35 -0700471 int32_t clientUid = data.readInt32();
472 sp<ICamera> camera;
473 status_t status = connectLegacy(cameraClient, cameraId, halVersion,
Svetoslav Ganov280405a2015-05-12 02:19:27 +0000474 clientName, clientUid, /*out*/camera);
Zhijun Heb10cdad2014-06-16 16:38:35 -0700475 reply->writeNoException();
476 reply->writeInt32(status);
477 if (camera != NULL) {
478 reply->writeInt32(1);
Marco Nelissen06b46062014-11-14 07:58:25 -0800479 reply->writeStrongBinder(IInterface::asBinder(camera));
Zhijun Heb10cdad2014-06-16 16:38:35 -0700480 } else {
481 reply->writeInt32(0);
482 }
483 return NO_ERROR;
484 } break;
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800485 case SET_TORCH_MODE: {
486 CHECK_INTERFACE(ICameraService, data, reply);
487 String16 cameraId = data.readString16();
488 bool enabled = data.readInt32() != 0 ? true : false;
489 const sp<IBinder> clientBinder = data.readStrongBinder();
490 status_t status = setTorchMode(cameraId, enabled, clientBinder);
491 reply->writeNoException();
492 reply->writeInt32(status);
493 return NO_ERROR;
494 } break;
Ruben Brunk36597b22015-03-20 22:15:57 -0700495 case NOTIFY_SYSTEM_EVENT: {
496 CHECK_INTERFACE(ICameraService, data, reply);
Ruben Brunk6267b532015-04-30 17:44:07 -0700497 int32_t eventId = data.readInt32();
498 int32_t len = data.readInt32();
499 if (len < 0) {
500 ALOGE("%s: Received poorly formatted length in binder request: notifySystemEvent.",
501 __FUNCTION__);
502 return FAILED_TRANSACTION;
503 }
504 if (len > 512) {
505 ALOGE("%s: Length %" PRIi32 " too long in binder request: notifySystemEvent.",
506 __FUNCTION__, len);
507 return FAILED_TRANSACTION;
508 }
Chih-Hung Hsieh8eddd882015-05-18 15:51:54 -0700509 int32_t events[len];
510 memset(events, 0, sizeof(int32_t) * len);
Ruben Brunk6267b532015-04-30 17:44:07 -0700511 status_t status = data.read(events, sizeof(int32_t) * len);
512 if (status != NO_ERROR) {
513 ALOGE("%s: Received poorly formatted binder request: notifySystemEvent.",
514 __FUNCTION__);
515 return FAILED_TRANSACTION;
516 }
517 notifySystemEvent(eventId, events, len);
Ruben Brunk36597b22015-03-20 22:15:57 -0700518 return NO_ERROR;
519 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800520 default:
521 return BBinder::onTransact(code, data, reply, flags);
522 }
523}
524
525// ----------------------------------------------------------------------------
526
527}; // namespace android