blob: b54d63f5e4baed40b1a701af4256e9fe7fee856c [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 Murashkinc073ba52013-02-26 14:32:34 -080026#include <camera/IProCameraUser.h>
27#include <camera/IProCameraCallbacks.h>
28#include <camera/ICamera.h>
29#include <camera/ICameraClient.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080030
31namespace android {
32
33class BpCameraService: public BpInterface<ICameraService>
34{
35public:
36 BpCameraService(const sp<IBinder>& impl)
37 : BpInterface<ICameraService>(impl)
38 {
39 }
40
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080041 // get number of cameras available
42 virtual int32_t getNumberOfCameras()
43 {
44 Parcel data, reply;
45 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
46 remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply);
47 return reply.readInt32();
48 }
49
Chih-Chung Changddbdb352010-06-10 13:32:16 +080050 // get information about a camera
51 virtual status_t getCameraInfo(int cameraId,
52 struct CameraInfo* cameraInfo) {
53 Parcel data, reply;
54 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
55 data.writeInt32(cameraId);
56 remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply);
57 cameraInfo->facing = reply.readInt32();
58 cameraInfo->orientation = reply.readInt32();
59 return reply.readInt32();
60 }
61
Mathias Agopian3cf61352010-02-09 17:46:37 -080062 // connect to camera service
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080063 virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId,
64 const String16 &clientPackageName, int clientUid)
Mathias Agopian3cf61352010-02-09 17:46:37 -080065 {
66 Parcel data, reply;
67 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
68 data.writeStrongBinder(cameraClient->asBinder());
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080069 data.writeInt32(cameraId);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080070 data.writeString16(clientPackageName);
71 data.writeInt32(clientUid);
Mathias Agopian3cf61352010-02-09 17:46:37 -080072 remote()->transact(BnCameraService::CONNECT, data, &reply);
73 return interface_cast<ICamera>(reply.readStrongBinder());
74 }
Igor Murashkin634a5152013-02-20 17:15:11 -080075
76 // connect to camera service (pro client)
Igor Murashkinc073ba52013-02-26 14:32:34 -080077 virtual sp<IProCameraUser> connect(const sp<IProCameraCallbacks>& cameraCb, int cameraId,
78 const String16 &clientPackageName, int clientUid)
Igor Murashkin634a5152013-02-20 17:15:11 -080079 {
80 Parcel data, reply;
81 data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
82 data.writeStrongBinder(cameraCb->asBinder());
83 data.writeInt32(cameraId);
Igor Murashkinc073ba52013-02-26 14:32:34 -080084 data.writeString16(clientPackageName);
85 data.writeInt32(clientUid);
Igor Murashkin634a5152013-02-20 17:15:11 -080086 remote()->transact(BnCameraService::CONNECT_PRO, data, &reply);
87 return interface_cast<IProCameraUser>(reply.readStrongBinder());
88 }
Mathias Agopian3cf61352010-02-09 17:46:37 -080089};
90
91IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
92
93// ----------------------------------------------------------------------
94
95status_t BnCameraService::onTransact(
96 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
97{
98 switch(code) {
Chih-Chung Chang35a055b2010-05-06 16:36:58 +080099 case GET_NUMBER_OF_CAMERAS: {
100 CHECK_INTERFACE(ICameraService, data, reply);
101 reply->writeInt32(getNumberOfCameras());
102 return NO_ERROR;
103 } break;
Chih-Chung Changddbdb352010-06-10 13:32:16 +0800104 case GET_CAMERA_INFO: {
105 CHECK_INTERFACE(ICameraService, data, reply);
106 CameraInfo cameraInfo;
107 memset(&cameraInfo, 0, sizeof(cameraInfo));
108 status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
109 reply->writeInt32(cameraInfo.facing);
110 reply->writeInt32(cameraInfo.orientation);
111 reply->writeInt32(result);
112 return NO_ERROR;
113 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800114 case CONNECT: {
115 CHECK_INTERFACE(ICameraService, data, reply);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800116 sp<ICameraClient> cameraClient =
117 interface_cast<ICameraClient>(data.readStrongBinder());
118 int32_t cameraId = data.readInt32();
119 const String16 clientName = data.readString16();
120 int32_t clientUid = data.readInt32();
121 sp<ICamera> camera = connect(cameraClient, cameraId,
122 clientName, clientUid);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800123 reply->writeStrongBinder(camera->asBinder());
124 return NO_ERROR;
125 } break;
Igor Murashkin634a5152013-02-20 17:15:11 -0800126 case CONNECT_PRO: {
127 CHECK_INTERFACE(ICameraService, data, reply);
128 sp<IProCameraCallbacks> cameraClient = interface_cast<IProCameraCallbacks>(data.readStrongBinder());
Igor Murashkinc073ba52013-02-26 14:32:34 -0800129 int32_t cameraId = data.readInt32();
130 const String16 clientName = data.readString16();
131 int32_t clientUid = data.readInt32();
132 sp<IProCameraUser> camera = connect(cameraClient, cameraId,
133 clientName, clientUid);
Igor Murashkin634a5152013-02-20 17:15:11 -0800134 reply->writeStrongBinder(camera->asBinder());
135 return NO_ERROR;
136 } break;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800137 default:
138 return BBinder::onTransact(code, data, reply, flags);
139 }
140}
141
142// ----------------------------------------------------------------------------
143
144}; // namespace android