| 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> | 
 | 26 |  | 
 | 27 | namespace android { | 
 | 28 |  | 
 | 29 | class BpCameraService: public BpInterface<ICameraService> | 
 | 30 | { | 
 | 31 | public: | 
 | 32 |     BpCameraService(const sp<IBinder>& impl) | 
 | 33 |         : BpInterface<ICameraService>(impl) | 
 | 34 |     { | 
 | 35 |     } | 
 | 36 |  | 
| Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 37 |     // get number of cameras available | 
 | 38 |     virtual int32_t getNumberOfCameras() | 
 | 39 |     { | 
 | 40 |         Parcel data, reply; | 
 | 41 |         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
 | 42 |         remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply); | 
 | 43 |         return reply.readInt32(); | 
 | 44 |     } | 
 | 45 |  | 
| Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 46 |     // get information about a camera | 
 | 47 |     virtual status_t getCameraInfo(int cameraId, | 
 | 48 |                                    struct CameraInfo* cameraInfo) { | 
 | 49 |         Parcel data, reply; | 
 | 50 |         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
 | 51 |         data.writeInt32(cameraId); | 
 | 52 |         remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply); | 
 | 53 |         cameraInfo->facing = reply.readInt32(); | 
 | 54 |         cameraInfo->orientation = reply.readInt32(); | 
 | 55 |         return reply.readInt32(); | 
 | 56 |     } | 
 | 57 |  | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 58 |     // connect to camera service | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame^] | 59 |     virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId, | 
 | 60 |                                 const String16 &clientPackageName, int clientUid) | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 61 |     { | 
 | 62 |         Parcel data, reply; | 
 | 63 |         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
 | 64 |         data.writeStrongBinder(cameraClient->asBinder()); | 
| Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 65 |         data.writeInt32(cameraId); | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame^] | 66 |         data.writeString16(clientPackageName); | 
 | 67 |         data.writeInt32(clientUid); | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 68 |         remote()->transact(BnCameraService::CONNECT, data, &reply); | 
 | 69 |         return interface_cast<ICamera>(reply.readStrongBinder()); | 
 | 70 |     } | 
| Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 71 |  | 
 | 72 |     // connect to camera service (pro client) | 
 | 73 |     virtual sp<IProCameraUser> connect(const sp<IProCameraCallbacks>& cameraCb, int cameraId) | 
 | 74 |     { | 
 | 75 |         Parcel data, reply; | 
 | 76 |         data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); | 
 | 77 |         data.writeStrongBinder(cameraCb->asBinder()); | 
 | 78 |         data.writeInt32(cameraId); | 
 | 79 |         remote()->transact(BnCameraService::CONNECT_PRO, data, &reply); | 
 | 80 |         return interface_cast<IProCameraUser>(reply.readStrongBinder()); | 
 | 81 |     } | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 82 | }; | 
 | 83 |  | 
 | 84 | IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); | 
 | 85 |  | 
 | 86 | // ---------------------------------------------------------------------- | 
 | 87 |  | 
 | 88 | status_t BnCameraService::onTransact( | 
 | 89 |     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
 | 90 | { | 
 | 91 |     switch(code) { | 
| Chih-Chung Chang | 35a055b | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 92 |         case GET_NUMBER_OF_CAMERAS: { | 
 | 93 |             CHECK_INTERFACE(ICameraService, data, reply); | 
 | 94 |             reply->writeInt32(getNumberOfCameras()); | 
 | 95 |             return NO_ERROR; | 
 | 96 |         } break; | 
| Chih-Chung Chang | ddbdb35 | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 97 |         case GET_CAMERA_INFO: { | 
 | 98 |             CHECK_INTERFACE(ICameraService, data, reply); | 
 | 99 |             CameraInfo cameraInfo; | 
 | 100 |             memset(&cameraInfo, 0, sizeof(cameraInfo)); | 
 | 101 |             status_t result = getCameraInfo(data.readInt32(), &cameraInfo); | 
 | 102 |             reply->writeInt32(cameraInfo.facing); | 
 | 103 |             reply->writeInt32(cameraInfo.orientation); | 
 | 104 |             reply->writeInt32(result); | 
 | 105 |             return NO_ERROR; | 
 | 106 |         } break; | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 107 |         case CONNECT: { | 
 | 108 |             CHECK_INTERFACE(ICameraService, data, reply); | 
| Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame^] | 109 |             sp<ICameraClient> cameraClient = | 
 | 110 |                     interface_cast<ICameraClient>(data.readStrongBinder()); | 
 | 111 |             int32_t cameraId = data.readInt32(); | 
 | 112 |             const String16 clientName = data.readString16(); | 
 | 113 |             int32_t clientUid = data.readInt32(); | 
 | 114 |             sp<ICamera> camera = connect(cameraClient, cameraId, | 
 | 115 |                     clientName, clientUid); | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 116 |             reply->writeStrongBinder(camera->asBinder()); | 
 | 117 |             return NO_ERROR; | 
 | 118 |         } break; | 
| Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 119 |         case CONNECT_PRO: { | 
 | 120 |             CHECK_INTERFACE(ICameraService, data, reply); | 
 | 121 |             sp<IProCameraCallbacks> cameraClient = interface_cast<IProCameraCallbacks>(data.readStrongBinder()); | 
 | 122 |             sp<IProCameraUser> camera = connect(cameraClient, data.readInt32()); | 
 | 123 |             reply->writeStrongBinder(camera->asBinder()); | 
 | 124 |             return NO_ERROR; | 
 | 125 |         } break; | 
| Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 126 |         default: | 
 | 127 |             return BBinder::onTransact(code, data, reply, flags); | 
 | 128 |     } | 
 | 129 | } | 
 | 130 |  | 
 | 131 | // ---------------------------------------------------------------------------- | 
 | 132 |  | 
 | 133 | }; // namespace android |