blob: 134f7f0cb40bdc7092f486319c4fc8b31d271d94 [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include <stdint.h>
19#include <sys/types.h>
20
21#include <binder/Parcel.h>
22#include <binder/IPCThreadState.h>
23#include <binder/IServiceManager.h>
24
25#include <camera/ICameraService.h>
Igor Murashkinbfc99152013-02-27 12:55:20 -080026#include <camera/ICameraServiceListener.h>
Igor Murashkinc073ba52013-02-26 14:32:34 -080027#include <camera/IProCameraUser.h>
28#include <camera/IProCameraCallbacks.h>
29#include <camera/ICamera.h>
30#include <camera/ICameraClient.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080031
32namespace android {
33
34class BpCameraService: public BpInterface<ICameraService>
35{
36public:
37 BpCameraService(const sp<IBinder>& impl)
38 : BpInterface<ICameraService>(impl)
39 {
40 }
41
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080042 // get number of cameras available
43 virtual int32_t getNumberOfCameras()
44 {
45 Parcel data, reply;
46 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
47 remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply);
48 return reply.readInt32();
49 }
50
Chih-Chung Changddbdb352010-06-10 13:32:16 +080051 // get information about a camera
52 virtual status_t getCameraInfo(int cameraId,
53 struct CameraInfo* cameraInfo) {
54 Parcel data, reply;
55 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
56 data.writeInt32(cameraId);
57 remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply);
58 cameraInfo->facing = reply.readInt32();
59 cameraInfo->orientation = reply.readInt32();
60 return reply.readInt32();
61 }
62
Mathias Agopian3cf61352010-02-09 17:46:37 -080063 // connect to camera service
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080064 virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId,
65 const String16 &clientPackageName, int clientUid)
Mathias Agopian3cf61352010-02-09 17:46:37 -080066 {
67 Parcel data, reply;
68 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
69 data.writeStrongBinder(cameraClient->asBinder());
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080070 data.writeInt32(cameraId);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080071 data.writeString16(clientPackageName);
72 data.writeInt32(clientUid);
Mathias Agopian3cf61352010-02-09 17:46:37 -080073 remote()->transact(BnCameraService::CONNECT, data, &reply);
74 return interface_cast<ICamera>(reply.readStrongBinder());
75 }
Igor Murashkin634a5152013-02-20 17:15:11 -080076
77 // connect to camera service (pro client)
Igor Murashkinc073ba52013-02-26 14:32:34 -080078 virtual sp<IProCameraUser> connect(const sp<IProCameraCallbacks>& cameraCb, int cameraId,
79 const String16 &clientPackageName, int clientUid)
Igor Murashkin634a5152013-02-20 17:15:11 -080080 {
81 Parcel data, reply;
82 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
83 data.writeStrongBinder(cameraCb->asBinder());
84 data.writeInt32(cameraId);
Igor Murashkinc073ba52013-02-26 14:32:34 -080085 data.writeString16(clientPackageName);
86 data.writeInt32(clientUid);
Igor Murashkin634a5152013-02-20 17:15:11 -080087 remote()->transact(BnCameraService::CONNECT_PRO, data, &reply);
88 return interface_cast<IProCameraUser>(reply.readStrongBinder());
89 }
Igor Murashkinbfc99152013-02-27 12:55:20 -080090
91 virtual status_t addListener(const sp<ICameraServiceListener>& listener)
92 {
93 Parcel data, reply;
94 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
95 data.writeStrongBinder(listener->asBinder());
96 remote()->transact(BnCameraService::ADD_LISTENER, data, &reply);
97 return reply.readInt32();
98 }
99
100 virtual status_t removeListener(const sp<ICameraServiceListener>& listener)
101 {
102 Parcel data, reply;
103 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
104 data.writeStrongBinder(listener->asBinder());
105 remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply);
106 return reply.readInt32();
107 }
Mathias Agopian3cf61352010-02-09 17:46:37 -0800108};
109
110IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
111
112// ----------------------------------------------------------------------
113
114status_t BnCameraService::onTransact(
115 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
116{
117 switch(code) {
Chih-Chung Chang35a055b2010-05-06 16:36:58 +0800118 case GET_NUMBER_OF_CAMERAS: {
119 CHECK_INTERFACE(ICameraService, data, reply);
120 reply->writeInt32(getNumberOfCameras());
121 return NO_ERROR;
122 } break;
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800123 case GET_CAMERA_INFO: {
124 CHECK_INTERFACE(ICameraService, data, reply);
125 CameraInfo cameraInfo;
126 memset(&cameraInfo, 0, sizeof(cameraInfo));
127 status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
128 reply->writeInt32(cameraInfo.facing);
129 reply->writeInt32(cameraInfo.orientation);
130 reply->writeInt32(result);
131 return NO_ERROR;
132 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800133 case CONNECT: {
134 CHECK_INTERFACE(ICameraService, data, reply);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800135 sp<ICameraClient> cameraClient =
136 interface_cast<ICameraClient>(data.readStrongBinder());
137 int32_t cameraId = data.readInt32();
138 const String16 clientName = data.readString16();
139 int32_t clientUid = data.readInt32();
140 sp<ICamera> camera = connect(cameraClient, cameraId,
141 clientName, clientUid);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800142 reply->writeStrongBinder(camera->asBinder());
143 return NO_ERROR;
144 } break;
Igor Murashkin634a5152013-02-20 17:15:11 -0800145 case CONNECT_PRO: {
146 CHECK_INTERFACE(ICameraService, data, reply);
147 sp<IProCameraCallbacks> cameraClient = interface_cast<IProCameraCallbacks>(data.readStrongBinder());
Igor Murashkinc073ba52013-02-26 14:32:34 -0800148 int32_t cameraId = data.readInt32();
149 const String16 clientName = data.readString16();
150 int32_t clientUid = data.readInt32();
151 sp<IProCameraUser> camera = connect(cameraClient, cameraId,
152 clientName, clientUid);
Igor Murashkin634a5152013-02-20 17:15:11 -0800153 reply->writeStrongBinder(camera->asBinder());
154 return NO_ERROR;
155 } break;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800156 case ADD_LISTENER: {
157 CHECK_INTERFACE(ICameraService, data, reply);
158 sp<ICameraServiceListener> listener =
159 interface_cast<ICameraServiceListener>(data.readStrongBinder());
160 reply->writeInt32(addListener(listener));
161 return NO_ERROR;
162 } break;
163 case REMOVE_LISTENER: {
164 CHECK_INTERFACE(ICameraService, data, reply);
165 sp<ICameraServiceListener> listener =
166 interface_cast<ICameraServiceListener>(data.readStrongBinder());
167 reply->writeInt32(removeListener(listener));
168 return NO_ERROR;
169 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800170 default:
171 return BBinder::onTransact(code, data, reply, flags);
172 }
173}
174
175// ----------------------------------------------------------------------------
176
177}; // namespace android