Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 1 | /* |
| 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 Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 26 | #include <camera/IProCameraUser.h> |
| 27 | #include <camera/IProCameraCallbacks.h> |
| 28 | #include <camera/ICamera.h> |
| 29 | #include <camera/ICameraClient.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | class BpCameraService: public BpInterface<ICameraService> |
| 34 | { |
| 35 | public: |
| 36 | BpCameraService(const sp<IBinder>& impl) |
| 37 | : BpInterface<ICameraService>(impl) |
| 38 | { |
| 39 | } |
| 40 | |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 41 | // 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 Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 50 | // 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 Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 62 | // connect to camera service |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 63 | virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId, |
| 64 | const String16 &clientPackageName, int clientUid) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 65 | { |
| 66 | Parcel data, reply; |
| 67 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); |
| 68 | data.writeStrongBinder(cameraClient->asBinder()); |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 69 | data.writeInt32(cameraId); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 70 | data.writeString16(clientPackageName); |
| 71 | data.writeInt32(clientUid); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 72 | remote()->transact(BnCameraService::CONNECT, data, &reply); |
| 73 | return interface_cast<ICamera>(reply.readStrongBinder()); |
| 74 | } |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 75 | |
| 76 | // connect to camera service (pro client) |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 77 | virtual sp<IProCameraUser> connect(const sp<IProCameraCallbacks>& cameraCb, int cameraId, |
| 78 | const String16 &clientPackageName, int clientUid) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 79 | { |
| 80 | Parcel data, reply; |
| 81 | data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); |
| 82 | data.writeStrongBinder(cameraCb->asBinder()); |
| 83 | data.writeInt32(cameraId); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 84 | data.writeString16(clientPackageName); |
| 85 | data.writeInt32(clientUid); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 86 | remote()->transact(BnCameraService::CONNECT_PRO, data, &reply); |
| 87 | return interface_cast<IProCameraUser>(reply.readStrongBinder()); |
| 88 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); |
| 92 | |
| 93 | // ---------------------------------------------------------------------- |
| 94 | |
| 95 | status_t BnCameraService::onTransact( |
| 96 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 97 | { |
| 98 | switch(code) { |
Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 99 | case GET_NUMBER_OF_CAMERAS: { |
| 100 | CHECK_INTERFACE(ICameraService, data, reply); |
| 101 | reply->writeInt32(getNumberOfCameras()); |
| 102 | return NO_ERROR; |
| 103 | } break; |
Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 104 | 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 Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 114 | case CONNECT: { |
| 115 | CHECK_INTERFACE(ICameraService, data, reply); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 116 | 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 Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 123 | reply->writeStrongBinder(camera->asBinder()); |
| 124 | return NO_ERROR; |
| 125 | } break; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 126 | case CONNECT_PRO: { |
| 127 | CHECK_INTERFACE(ICameraService, data, reply); |
| 128 | sp<IProCameraCallbacks> cameraClient = interface_cast<IProCameraCallbacks>(data.readStrongBinder()); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 129 | 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 Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 134 | reply->writeStrongBinder(camera->asBinder()); |
| 135 | return NO_ERROR; |
| 136 | } break; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 137 | default: |
| 138 | return BBinder::onTransact(code, data, reply, flags); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // ---------------------------------------------------------------------------- |
| 143 | |
| 144 | }; // namespace android |