ICameraService.cpp revision 2b59be89dc245b6e2475d9e8b0c5f2392370e71e
13cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian/* 23cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 33cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Copyright 2008, The Android Open Source Project 43cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 53cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License"); 63cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** you may not use this file except in compliance with the License. 73cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** You may obtain a copy of the License at 83cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 93cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** http://www.apache.org/licenses/LICENSE-2.0 103cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** 113cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Unless required by applicable law or agreed to in writing, software 123cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS, 133cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 143cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** See the License for the specific language governing permissions and 153cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** limitations under the License. 163cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian*/ 173cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 18bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin#define LOG_TAG "BpCameraService" 19bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin#include <utils/Log.h> 20bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 213cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <stdint.h> 223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <sys/types.h> 233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/Parcel.h> 253cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/IPCThreadState.h> 263cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/IServiceManager.h> 273cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 283cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <camera/ICameraService.h> 29bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin#include <camera/ICameraServiceListener.h> 30c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin#include <camera/IProCameraUser.h> 31c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin#include <camera/IProCameraCallbacks.h> 32c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin#include <camera/ICamera.h> 33c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin#include <camera/ICameraClient.h> 347b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include <camera/camera2/ICameraDeviceUser.h> 357b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include <camera/camera2/ICameraDeviceCallbacks.h> 362b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He#include <camera/CameraMetadata.h> 373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 383cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopiannamespace android { 393cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 40bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkinnamespace { 41bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 42bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkinenum { 43bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin EX_SECURITY = -1, 44bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin EX_BAD_PARCELABLE = -2, 45bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin EX_ILLEGAL_ARGUMENT = -3, 46bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin EX_NULL_POINTER = -4, 47bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin EX_ILLEGAL_STATE = -5, 48bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin EX_HAS_REPLY_HEADER = -128, // special; see below 49bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin}; 50bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 51bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkinstatic bool readExceptionCode(Parcel& reply) { 52bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin int32_t exceptionCode = reply.readExceptionCode(); 53bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 54bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin if (exceptionCode != 0) { 55bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin const char* errorMsg; 56bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin switch(exceptionCode) { 57bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin case EX_SECURITY: 58bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin errorMsg = "Security"; 59bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin break; 60bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin case EX_BAD_PARCELABLE: 61bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin errorMsg = "BadParcelable"; 62bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin break; 63bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin case EX_NULL_POINTER: 64bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin errorMsg = "NullPointer"; 65bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin break; 66bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin case EX_ILLEGAL_STATE: 67bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin errorMsg = "IllegalState"; 68bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin break; 69bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin // Binder should be handling this code inside Parcel::readException 70bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin // but lets have a to-string here anyway just in case. 71bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin case EX_HAS_REPLY_HEADER: 72bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin errorMsg = "HasReplyHeader"; 73bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin break; 74bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin default: 75bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin errorMsg = "Unknown"; 76bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin } 77bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 78bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin ALOGE("Binder transmission error %s (%d)", errorMsg, exceptionCode); 79bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin return true; 80bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin } 81bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 82bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin return false; 83bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin} 84bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 85bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin}; 86bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 873cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianclass BpCameraService: public BpInterface<ICameraService> 883cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{ 893cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianpublic: 903cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian BpCameraService(const sp<IBinder>& impl) 913cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian : BpInterface<ICameraService>(impl) 923cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian { 933cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 943cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 9535a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang // get number of cameras available 9635a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang virtual int32_t getNumberOfCameras() 9735a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang { 9835a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang Parcel data, reply; 9935a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 10035a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply); 101bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 102bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin if (readExceptionCode(reply)) return 0; 10335a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang return reply.readInt32(); 10435a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang } 10535a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang 106ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang // get information about a camera 107ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang virtual status_t getCameraInfo(int cameraId, 108ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang struct CameraInfo* cameraInfo) { 109ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang Parcel data, reply; 110ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 111ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang data.writeInt32(cameraId); 112ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply); 113bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 114bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin if (readExceptionCode(reply)) return -EPROTO; 115bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin status_t result = reply.readInt32(); 116bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin if (reply.readInt32() != 0) { 117bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin cameraInfo->facing = reply.readInt32(); 118bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin cameraInfo->orientation = reply.readInt32(); 119bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin } 120bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin return result; 121ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang } 122ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang 1232b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He // get camera characteristics (static metadata) 1242b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He virtual status_t getCameraCharacteristics(int cameraId, 1252b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He CameraMetadata* cameraInfo) { 1262b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He Parcel data, reply; 1272b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 1282b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He data.writeInt32(cameraId); 1292b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He remote()->transact(BnCameraService::GET_CAMERA_CHARACTERISTICS, data, &reply); 1302b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He 1312b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He if (readExceptionCode(reply)) return -EPROTO; 1322b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He status_t result = reply.readInt32(); 1332b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He 1342b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He CameraMetadata out; 1352b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He if (reply.readInt32() != 0) { 1362b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He out.readFromParcel(&reply); 1372b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He } 1382b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He 1392b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He if (cameraInfo != NULL) { 1402b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He cameraInfo->swap(out); 1412b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He } 1422b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He 1432b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He return result; 1442b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He } 1452b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He 146e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin // connect to camera service (android.hardware.Camera) 1470f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId, 1480f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk const String16 &clientPackageName, int clientUid, 1490f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk /*out*/ 1500f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk sp<ICamera>& device) 1513cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian { 1523cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian Parcel data, reply; 1533cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 1543cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian data.writeStrongBinder(cameraClient->asBinder()); 15535a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang data.writeInt32(cameraId); 156ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala data.writeString16(clientPackageName); 157ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala data.writeInt32(clientUid); 1583cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian remote()->transact(BnCameraService::CONNECT, data, &reply); 159bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 1600f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (readExceptionCode(reply)) return -EPROTO; 1610f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk status_t status = reply.readInt32(); 1620f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (reply.readInt32() != 0) { 1630f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk device = interface_cast<ICamera>(reply.readStrongBinder()); 1640f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } 1650f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk return status; 1663cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 167634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin 168634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin // connect to camera service (pro client) 1690f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk virtual status_t connectPro(const sp<IProCameraCallbacks>& cameraCb, int cameraId, 1700f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk const String16 &clientPackageName, int clientUid, 1710f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk /*out*/ 1720f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk sp<IProCameraUser>& device) 173634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin { 174634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin Parcel data, reply; 175634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 176634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin data.writeStrongBinder(cameraCb->asBinder()); 177634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin data.writeInt32(cameraId); 178c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin data.writeString16(clientPackageName); 179c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin data.writeInt32(clientUid); 180634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin remote()->transact(BnCameraService::CONNECT_PRO, data, &reply); 181bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 1820f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (readExceptionCode(reply)) return -EPROTO; 1830f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk status_t status = reply.readInt32(); 1840f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (reply.readInt32() != 0) { 1850f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk device = interface_cast<IProCameraUser>(reply.readStrongBinder()); 1860f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } 1870f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk return status; 188634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin } 189bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin 1907b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala // connect to camera service (android.hardware.camera2.CameraDevice) 1910f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk virtual status_t connectDevice( 192e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin const sp<ICameraDeviceCallbacks>& cameraCb, 193e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin int cameraId, 194e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin const String16& clientPackageName, 1950f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk int clientUid, 1960f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk /*out*/ 1970f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk sp<ICameraDeviceUser>& device) 198e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin { 199e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin Parcel data, reply; 200e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 201e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin data.writeStrongBinder(cameraCb->asBinder()); 202e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin data.writeInt32(cameraId); 203e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin data.writeString16(clientPackageName); 204e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin data.writeInt32(clientUid); 205e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin remote()->transact(BnCameraService::CONNECT_DEVICE, data, &reply); 206e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin 2070f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (readExceptionCode(reply)) return -EPROTO; 2080f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk status_t status = reply.readInt32(); 2090f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (reply.readInt32() != 0) { 2100f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk device = interface_cast<ICameraDeviceUser>(reply.readStrongBinder()); 2110f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } 2120f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk return status; 213e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin } 214e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin 215bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin virtual status_t addListener(const sp<ICameraServiceListener>& listener) 216bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin { 217bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin Parcel data, reply; 218bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 219bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin data.writeStrongBinder(listener->asBinder()); 220bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin remote()->transact(BnCameraService::ADD_LISTENER, data, &reply); 221bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 222bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin if (readExceptionCode(reply)) return -EPROTO; 223bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin return reply.readInt32(); 224bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin } 225bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin 226bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin virtual status_t removeListener(const sp<ICameraServiceListener>& listener) 227bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin { 228bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin Parcel data, reply; 229bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); 230bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin data.writeStrongBinder(listener->asBinder()); 231bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply); 232bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 233bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin if (readExceptionCode(reply)) return -EPROTO; 234bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin return reply.readInt32(); 235bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin } 2363cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; 2373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 2383cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias AgopianIMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService"); 2393cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 2403cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ---------------------------------------------------------------------- 2413cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 2423cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianstatus_t BnCameraService::onTransact( 2433cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 2443cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{ 2453cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian switch(code) { 24635a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang case GET_NUMBER_OF_CAMERAS: { 24735a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang CHECK_INTERFACE(ICameraService, data, reply); 248bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin reply->writeNoException(); 24935a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang reply->writeInt32(getNumberOfCameras()); 25035a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang return NO_ERROR; 25135a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang } break; 252ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang case GET_CAMERA_INFO: { 253ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang CHECK_INTERFACE(ICameraService, data, reply); 254bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin CameraInfo cameraInfo = CameraInfo(); 255ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang memset(&cameraInfo, 0, sizeof(cameraInfo)); 256ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang status_t result = getCameraInfo(data.readInt32(), &cameraInfo); 257bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin reply->writeNoException(); 258bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin reply->writeInt32(result); 259bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin 260bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin // Fake a parcelable object here 261bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin reply->writeInt32(1); // means the parcelable is included 262ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang reply->writeInt32(cameraInfo.facing); 263ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang reply->writeInt32(cameraInfo.orientation); 264ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang return NO_ERROR; 265ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang } break; 2662b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He case GET_CAMERA_CHARACTERISTICS: { 2672b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He CHECK_INTERFACE(ICameraService, data, reply); 2682b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He CameraMetadata info; 2692b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He status_t result = getCameraCharacteristics(data.readInt32(), &info); 2702b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He reply->writeNoException(); 2712b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He reply->writeInt32(result); 2722b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He 2732b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He // out-variables are after exception and return value 2742b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He reply->writeInt32(1); // means the parcelable is included 2752b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He info.writeToParcel(reply); 2762b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He return NO_ERROR; 2772b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He } break; 2783cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian case CONNECT: { 2793cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian CHECK_INTERFACE(ICameraService, data, reply); 280ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala sp<ICameraClient> cameraClient = 281ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala interface_cast<ICameraClient>(data.readStrongBinder()); 282ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala int32_t cameraId = data.readInt32(); 283ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala const String16 clientName = data.readString16(); 284ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala int32_t clientUid = data.readInt32(); 2850f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk sp<ICamera> camera; 2860f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk status_t status = connect(cameraClient, cameraId, 2870f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk clientName, clientUid, /*out*/ camera); 288bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin reply->writeNoException(); 2890f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(status); 2900f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (camera != NULL) { 2910f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(1); 2920f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeStrongBinder(camera->asBinder()); 2930f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } else { 2940f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(0); 2950f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } 2963cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return NO_ERROR; 2973cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } break; 298634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin case CONNECT_PRO: { 299634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin CHECK_INTERFACE(ICameraService, data, reply); 300bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin sp<IProCameraCallbacks> cameraClient = 301bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin interface_cast<IProCameraCallbacks>(data.readStrongBinder()); 302c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin int32_t cameraId = data.readInt32(); 303c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin const String16 clientName = data.readString16(); 304c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin int32_t clientUid = data.readInt32(); 3050f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk sp<IProCameraUser> camera; 3060f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk status_t status = connectPro(cameraClient, cameraId, 3070f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk clientName, clientUid, /*out*/ camera); 308bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin reply->writeNoException(); 3090f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(status); 3100f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (camera != NULL) { 3110f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(1); 3120f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeStrongBinder(camera->asBinder()); 3130f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } else { 3140f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(0); 3150f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } 316e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin return NO_ERROR; 317e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin } break; 318e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin case CONNECT_DEVICE: { 319e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin CHECK_INTERFACE(ICameraService, data, reply); 320e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin sp<ICameraDeviceCallbacks> cameraClient = 321e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder()); 322e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin int32_t cameraId = data.readInt32(); 323e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin const String16 clientName = data.readString16(); 324e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin int32_t clientUid = data.readInt32(); 3250f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk sp<ICameraDeviceUser> camera; 3260f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk status_t status = connectDevice(cameraClient, cameraId, 3270f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk clientName, clientUid, /*out*/ camera); 328e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin reply->writeNoException(); 3290f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(status); 3300f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk if (camera != NULL) { 3310f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(1); 3320f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeStrongBinder(camera->asBinder()); 3330f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } else { 3340f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk reply->writeInt32(0); 3350f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk } 336634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin return NO_ERROR; 337634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin } break; 338bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin case ADD_LISTENER: { 339bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin CHECK_INTERFACE(ICameraService, data, reply); 340bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin sp<ICameraServiceListener> listener = 341bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin interface_cast<ICameraServiceListener>(data.readStrongBinder()); 342bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin reply->writeNoException(); 343bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin reply->writeInt32(addListener(listener)); 344bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin return NO_ERROR; 345bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin } break; 346bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin case REMOVE_LISTENER: { 347bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin CHECK_INTERFACE(ICameraService, data, reply); 348bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin sp<ICameraServiceListener> listener = 349bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin interface_cast<ICameraServiceListener>(data.readStrongBinder()); 350bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin reply->writeNoException(); 351bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin reply->writeInt32(removeListener(listener)); 352bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin return NO_ERROR; 353bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin } break; 3543cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian default: 3553cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian return BBinder::onTransact(code, data, reply, flags); 3563cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian } 3573cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian} 3583cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 3593cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ---------------------------------------------------------------------------- 3603cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian 3613cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; // namespace android 362