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>
20d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk#include <utils/Errors.h>
2165d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin#include <utils/String16.h>
22bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <stdint.h>
243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <sys/types.h>
253cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
263cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/Parcel.h>
273cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/IPCThreadState.h>
283cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/IServiceManager.h>
293cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
303cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <camera/ICameraService.h>
31bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin#include <camera/ICameraServiceListener.h>
32c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin#include <camera/IProCameraUser.h>
33c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin#include <camera/IProCameraCallbacks.h>
34c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin#include <camera/ICamera.h>
35c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin#include <camera/ICameraClient.h>
367b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include <camera/camera2/ICameraDeviceUser.h>
377b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include <camera/camera2/ICameraDeviceCallbacks.h>
382b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He#include <camera/CameraMetadata.h>
39d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk#include <camera/VendorTagDescriptor.h>
403cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
413cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopiannamespace android {
423cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
43bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkinnamespace {
44bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
45bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkinenum {
46bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    EX_SECURITY = -1,
47bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    EX_BAD_PARCELABLE = -2,
48bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    EX_ILLEGAL_ARGUMENT = -3,
49bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    EX_NULL_POINTER = -4,
50bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    EX_ILLEGAL_STATE = -5,
51bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    EX_HAS_REPLY_HEADER = -128,  // special; see below
52bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin};
53bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
54bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkinstatic bool readExceptionCode(Parcel& reply) {
55bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    int32_t exceptionCode = reply.readExceptionCode();
56bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
57bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    if (exceptionCode != 0) {
58bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        const char* errorMsg;
59bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        switch(exceptionCode) {
60bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            case EX_SECURITY:
61bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                errorMsg = "Security";
62bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                break;
63bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            case EX_BAD_PARCELABLE:
64bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                errorMsg = "BadParcelable";
65bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                break;
66bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            case EX_NULL_POINTER:
67bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                errorMsg = "NullPointer";
68bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                break;
69bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            case EX_ILLEGAL_STATE:
70bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                errorMsg = "IllegalState";
71bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                break;
72bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            // Binder should be handling this code inside Parcel::readException
73bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            // but lets have a to-string here anyway just in case.
74bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            case EX_HAS_REPLY_HEADER:
75bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                errorMsg = "HasReplyHeader";
76bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                break;
77bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            default:
78bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                errorMsg = "Unknown";
79bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        }
80bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
81bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        ALOGE("Binder transmission error %s (%d)", errorMsg, exceptionCode);
82bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        return true;
83bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    }
84bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
85bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin    return false;
86bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin}
87bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
88bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin};
89bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
903cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianclass BpCameraService: public BpInterface<ICameraService>
913cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{
923cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianpublic:
933cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    BpCameraService(const sp<IBinder>& impl)
943cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        : BpInterface<ICameraService>(impl)
953cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
963cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
973cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
9835a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang    // get number of cameras available
9935a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang    virtual int32_t getNumberOfCameras()
10035a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang    {
10135a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        Parcel data, reply;
10235a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
10335a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply);
104bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
105bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        if (readExceptionCode(reply)) return 0;
10635a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        return reply.readInt32();
10735a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang    }
10835a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang
109ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang    // get information about a camera
110ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang    virtual status_t getCameraInfo(int cameraId,
111ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang                                   struct CameraInfo* cameraInfo) {
112ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        Parcel data, reply;
113ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
114ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        data.writeInt32(cameraId);
115ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply);
116bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
117bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        if (readExceptionCode(reply)) return -EPROTO;
118bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        status_t result = reply.readInt32();
119bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        if (reply.readInt32() != 0) {
120bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            cameraInfo->facing = reply.readInt32();
121bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            cameraInfo->orientation = reply.readInt32();
122bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        }
123bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        return result;
124ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang    }
125ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang
1262b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He    // get camera characteristics (static metadata)
1272b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He    virtual status_t getCameraCharacteristics(int cameraId,
1282b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He                                              CameraMetadata* cameraInfo) {
1292b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        Parcel data, reply;
1302b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
1312b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        data.writeInt32(cameraId);
1322b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        remote()->transact(BnCameraService::GET_CAMERA_CHARACTERISTICS, data, &reply);
1332b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He
1342b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        if (readExceptionCode(reply)) return -EPROTO;
1352b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        status_t result = reply.readInt32();
1362b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He
1372b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        CameraMetadata out;
1382b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        if (reply.readInt32() != 0) {
1392b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            out.readFromParcel(&reply);
1402b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        }
1412b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He
1422b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        if (cameraInfo != NULL) {
1432b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            cameraInfo->swap(out);
1442b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        }
1452b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He
1462b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        return result;
1472b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He    }
1482b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He
149d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk    // Get enumeration and description of vendor tags for camera
150d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk    virtual status_t getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) {
151d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        Parcel data, reply;
152d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
153d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        remote()->transact(BnCameraService::GET_CAMERA_VENDOR_TAG_DESCRIPTOR, data, &reply);
154d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk
155d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        if (readExceptionCode(reply)) return -EPROTO;
156d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        status_t result = reply.readInt32();
157d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk
158d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        if (reply.readInt32() != 0) {
159d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            sp<VendorTagDescriptor> d;
160d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            if (VendorTagDescriptor::createFromParcel(&reply, /*out*/d) == OK) {
161d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk                desc = d;
162d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            }
163d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        }
164d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        return result;
165d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk    }
166d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk
167e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin    // connect to camera service (android.hardware.Camera)
1680f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk    virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
1690f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                             const String16 &clientPackageName, int clientUid,
1700f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                             /*out*/
1710f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                             sp<ICamera>& device)
1723cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
1733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
1743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
1753cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeStrongBinder(cameraClient->asBinder());
17635a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        data.writeInt32(cameraId);
177ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala        data.writeString16(clientPackageName);
178ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala        data.writeInt32(clientUid);
1793cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(BnCameraService::CONNECT, data, &reply);
180bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
1810f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        if (readExceptionCode(reply)) return -EPROTO;
1820f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        status_t status = reply.readInt32();
1830f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        if (reply.readInt32() != 0) {
1840f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            device = interface_cast<ICamera>(reply.readStrongBinder());
1850f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        }
1860f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        return status;
1873cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
188634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin
189b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He    // connect to camera service (android.hardware.Camera)
190b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He    virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
191b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He                             int halVersion,
192b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He                             const String16 &clientPackageName, int clientUid,
193b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He                             /*out*/sp<ICamera>& device)
194b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He    {
195b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        Parcel data, reply;
196b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
197b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        data.writeStrongBinder(cameraClient->asBinder());
198b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        data.writeInt32(cameraId);
199b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        data.writeInt32(halVersion);
200b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        data.writeString16(clientPackageName);
201b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        data.writeInt32(clientUid);
202b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        remote()->transact(BnCameraService::CONNECT_LEGACY, data, &reply);
203b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He
204b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        if (readExceptionCode(reply)) return -EPROTO;
205b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        status_t status = reply.readInt32();
206b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        if (reply.readInt32() != 0) {
207b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            device = interface_cast<ICamera>(reply.readStrongBinder());
208b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        }
209b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        return status;
210b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He    }
211b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He
212634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin    // connect to camera service (pro client)
2130f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk    virtual status_t connectPro(const sp<IProCameraCallbacks>& cameraCb, int cameraId,
2140f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                                const String16 &clientPackageName, int clientUid,
2150f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                                /*out*/
2160f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                                sp<IProCameraUser>& device)
217634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin    {
218634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin        Parcel data, reply;
219634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
220634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin        data.writeStrongBinder(cameraCb->asBinder());
221634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin        data.writeInt32(cameraId);
222c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin        data.writeString16(clientPackageName);
223c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin        data.writeInt32(clientUid);
224634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin        remote()->transact(BnCameraService::CONNECT_PRO, data, &reply);
225bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
2260f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        if (readExceptionCode(reply)) return -EPROTO;
2270f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        status_t status = reply.readInt32();
2280f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        if (reply.readInt32() != 0) {
2290f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            device = interface_cast<IProCameraUser>(reply.readStrongBinder());
2300f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        }
2310f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        return status;
232634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin    }
233bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin
2347b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala    // connect to camera service (android.hardware.camera2.CameraDevice)
2350f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk    virtual status_t connectDevice(
236e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            const sp<ICameraDeviceCallbacks>& cameraCb,
237e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            int cameraId,
238e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            const String16& clientPackageName,
2390f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            int clientUid,
2400f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            /*out*/
2410f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            sp<ICameraDeviceUser>& device)
242e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin    {
243e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        Parcel data, reply;
244e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
245e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        data.writeStrongBinder(cameraCb->asBinder());
246e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        data.writeInt32(cameraId);
247e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        data.writeString16(clientPackageName);
248e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        data.writeInt32(clientUid);
249e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        remote()->transact(BnCameraService::CONNECT_DEVICE, data, &reply);
250e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin
2510f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        if (readExceptionCode(reply)) return -EPROTO;
2520f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        status_t status = reply.readInt32();
2530f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        if (reply.readInt32() != 0) {
2540f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            device = interface_cast<ICameraDeviceUser>(reply.readStrongBinder());
2550f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        }
2560f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk        return status;
257e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin    }
258e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin
259bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin    virtual status_t addListener(const sp<ICameraServiceListener>& listener)
260bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin    {
261bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        Parcel data, reply;
262bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
263bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        data.writeStrongBinder(listener->asBinder());
264bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        remote()->transact(BnCameraService::ADD_LISTENER, data, &reply);
265bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
266bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        if (readExceptionCode(reply)) return -EPROTO;
267bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        return reply.readInt32();
268bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin    }
269bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin
270bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin    virtual status_t removeListener(const sp<ICameraServiceListener>& listener)
271bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin    {
272bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        Parcel data, reply;
273bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
274bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        data.writeStrongBinder(listener->asBinder());
275bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply);
276bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
277bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        if (readExceptionCode(reply)) return -EPROTO;
278bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        return reply.readInt32();
279bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin    }
28065d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
28165d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin    virtual status_t getLegacyParameters(int cameraId, String16* parameters) {
28265d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        if (parameters == NULL) {
28365d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            ALOGE("%s: parameters must not be null", __FUNCTION__);
28465d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            return BAD_VALUE;
28565d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        }
28665d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
28765d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        Parcel data, reply;
28865d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
28965d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        data.writeInt32(cameraId);
29065d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        remote()->transact(BnCameraService::GET_LEGACY_PARAMETERS, data, &reply);
29165d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        if (readExceptionCode(reply)) return -EPROTO;
29265d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
29365d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        status_t res = data.readInt32();
29465d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        int32_t length = data.readInt32(); // -1 means null
29565d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        if (length > 0) {
29665d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            *parameters = data.readString16();
29765d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        } else {
29865d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            *parameters = String16();
29965d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        }
30065d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
30165d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        return res;
30265d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin    }
30365d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
30465d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin    virtual status_t supportsCameraApi(int cameraId, int apiVersion) {
30565d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        Parcel data, reply;
30665d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
30765d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        data.writeInt32(cameraId);
30865d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        data.writeInt32(apiVersion);
30965d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        remote()->transact(BnCameraService::SUPPORTS_CAMERA_API, data, &reply);
31065d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        if (readExceptionCode(reply)) return -EPROTO;
31165d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
31265d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        status_t res = data.readInt32();
31365d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        return res;
31465d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin    }
3153cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian};
3163cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
3173cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias AgopianIMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
3183cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
3193cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ----------------------------------------------------------------------
3203cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
3213cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianstatus_t BnCameraService::onTransact(
3223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
3233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{
3243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    switch(code) {
32535a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        case GET_NUMBER_OF_CAMERAS: {
32635a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang            CHECK_INTERFACE(ICameraService, data, reply);
327bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeNoException();
32835a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang            reply->writeInt32(getNumberOfCameras());
32935a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang            return NO_ERROR;
33035a055b8bfc6f3cbea409b2897caf936654519cbChih-Chung Chang        } break;
331ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        case GET_CAMERA_INFO: {
332ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            CHECK_INTERFACE(ICameraService, data, reply);
333bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            CameraInfo cameraInfo = CameraInfo();
334ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            memset(&cameraInfo, 0, sizeof(cameraInfo));
335ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
336bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeNoException();
337bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeInt32(result);
338bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin
339bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            // Fake a parcelable object here
340bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeInt32(1); // means the parcelable is included
341ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            reply->writeInt32(cameraInfo.facing);
342ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            reply->writeInt32(cameraInfo.orientation);
343ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang            return NO_ERROR;
344ddbdb35d176266b5ab64c30178f5cb76c5b1b4b4Chih-Chung Chang        } break;
3452b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        case GET_CAMERA_CHARACTERISTICS: {
3462b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            CHECK_INTERFACE(ICameraService, data, reply);
3472b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            CameraMetadata info;
3482b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            status_t result = getCameraCharacteristics(data.readInt32(), &info);
3492b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            reply->writeNoException();
3502b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            reply->writeInt32(result);
3512b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He
3522b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            // out-variables are after exception and return value
3532b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            reply->writeInt32(1); // means the parcelable is included
3542b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            info.writeToParcel(reply);
3552b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He            return NO_ERROR;
3562b59be89dc245b6e2475d9e8b0c5f2392370e71eZhijun He        } break;
357d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        case GET_CAMERA_VENDOR_TAG_DESCRIPTOR: {
358d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            CHECK_INTERFACE(ICameraService, data, reply);
359d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            sp<VendorTagDescriptor> d;
360d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            status_t result = getCameraVendorTagDescriptor(d);
361d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            reply->writeNoException();
362d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            reply->writeInt32(result);
363d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk
364d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            // out-variables are after exception and return value
365d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            if (d == NULL) {
366d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk                reply->writeInt32(0);
367d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            } else {
368e1445da74730473a66a3ae8414e940aebfe6585dIgor Murashkin                reply->writeInt32(1); // means the parcelable is included
369d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk                d->writeToParcel(reply);
370d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            }
371d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk            return NO_ERROR;
372d1176ef16677b6c94fb893edb6a864cdccc0b190Ruben Brunk        } break;
3733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case CONNECT: {
3743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICameraService, data, reply);
375ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala            sp<ICameraClient> cameraClient =
376ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala                    interface_cast<ICameraClient>(data.readStrongBinder());
377ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala            int32_t cameraId = data.readInt32();
378ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala            const String16 clientName = data.readString16();
379ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala            int32_t clientUid = data.readInt32();
3800f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            sp<ICamera> camera;
3810f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            status_t status = connect(cameraClient, cameraId,
382e1445da74730473a66a3ae8414e940aebfe6585dIgor Murashkin                    clientName, clientUid, /*out*/camera);
383bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeNoException();
3840f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            reply->writeInt32(status);
3850f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            if (camera != NULL) {
3860f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeInt32(1);
3870f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeStrongBinder(camera->asBinder());
3880f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            } else {
3890f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeInt32(0);
3900f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            }
3913cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
3923cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
393634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin        case CONNECT_PRO: {
394634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin            CHECK_INTERFACE(ICameraService, data, reply);
395bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            sp<IProCameraCallbacks> cameraClient =
396bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin                interface_cast<IProCameraCallbacks>(data.readStrongBinder());
397c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin            int32_t cameraId = data.readInt32();
398c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin            const String16 clientName = data.readString16();
399c073ba525404f3416c2824c435d3d926a9892f1bIgor Murashkin            int32_t clientUid = data.readInt32();
4000f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            sp<IProCameraUser> camera;
4010f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            status_t status = connectPro(cameraClient, cameraId,
402e1445da74730473a66a3ae8414e940aebfe6585dIgor Murashkin                    clientName, clientUid, /*out*/camera);
403bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeNoException();
4040f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            reply->writeInt32(status);
4050f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            if (camera != NULL) {
4060f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeInt32(1);
4070f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeStrongBinder(camera->asBinder());
4080f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            } else {
4090f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeInt32(0);
4100f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            }
411e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            return NO_ERROR;
412e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        } break;
413e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin        case CONNECT_DEVICE: {
414e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            CHECK_INTERFACE(ICameraService, data, reply);
415e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            sp<ICameraDeviceCallbacks> cameraClient =
416e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin                interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder());
417e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            int32_t cameraId = data.readInt32();
418e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            const String16 clientName = data.readString16();
419e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            int32_t clientUid = data.readInt32();
4200f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            sp<ICameraDeviceUser> camera;
4210f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            status_t status = connectDevice(cameraClient, cameraId,
422e1445da74730473a66a3ae8414e940aebfe6585dIgor Murashkin                    clientName, clientUid, /*out*/camera);
423e7ee7637747371635a85fedd24d2190bb1f38651Igor Murashkin            reply->writeNoException();
4240f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            reply->writeInt32(status);
4250f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            if (camera != NULL) {
4260f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeInt32(1);
4270f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeStrongBinder(camera->asBinder());
4280f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            } else {
4290f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk                reply->writeInt32(0);
4300f61d8f14aa368c9cd7076528e8096e10ed100a0Ruben Brunk            }
431634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin            return NO_ERROR;
432634a51509ee50475f3e9f8ccf897e90fc72ded31Igor Murashkin        } break;
433bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        case ADD_LISTENER: {
434bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin            CHECK_INTERFACE(ICameraService, data, reply);
435bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin            sp<ICameraServiceListener> listener =
436bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin                interface_cast<ICameraServiceListener>(data.readStrongBinder());
437bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeNoException();
438bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin            reply->writeInt32(addListener(listener));
439bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin            return NO_ERROR;
440bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        } break;
441bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        case REMOVE_LISTENER: {
442bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin            CHECK_INTERFACE(ICameraService, data, reply);
443bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin            sp<ICameraServiceListener> listener =
444bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin                interface_cast<ICameraServiceListener>(data.readStrongBinder());
445bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeNoException();
446bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin            reply->writeInt32(removeListener(listener));
447bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin            return NO_ERROR;
448bfc9915f482520eb9676c6d2dbf7f1ac078d937dIgor Murashkin        } break;
44965d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        case GET_LEGACY_PARAMETERS: {
45065d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            CHECK_INTERFACE(ICameraService, data, reply);
45165d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            int cameraId = data.readInt32();
45265d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            String16 parameters;
45365d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
45465d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            reply->writeNoException();
45565d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            // return value
45665d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            reply->writeInt32(getLegacyParameters(cameraId, &parameters));
45765d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            // out parameters
45865d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            reply->writeInt32(1); // parameters is always available
45965d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            reply->writeString16(parameters);
46065d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            return NO_ERROR;
46165d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        } break;
46265d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        case SUPPORTS_CAMERA_API: {
46365d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            CHECK_INTERFACE(ICameraService, data, reply);
46465d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            int cameraId = data.readInt32();
46565d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            int apiVersion = data.readInt32();
46665d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin
46765d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            reply->writeNoException();
46865d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            // return value
46965d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            reply->writeInt32(supportsCameraApi(cameraId, apiVersion));
47065d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin            return NO_ERROR;
47165d14b9825311f9d1847cf282bd0419e71bac666Igor Murashkin        } break;
472b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        case CONNECT_LEGACY: {
473b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            CHECK_INTERFACE(ICameraService, data, reply);
474b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            sp<ICameraClient> cameraClient =
475b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He                    interface_cast<ICameraClient>(data.readStrongBinder());
476b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            int32_t cameraId = data.readInt32();
477b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            int32_t halVersion = data.readInt32();
478b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            const String16 clientName = data.readString16();
479b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            int32_t clientUid = data.readInt32();
480b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            sp<ICamera> camera;
481b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            status_t status = connectLegacy(cameraClient, cameraId, halVersion,
482b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He                    clientName, clientUid, /*out*/camera);
483b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            reply->writeNoException();
484b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            reply->writeInt32(status);
485b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            if (camera != NULL) {
486b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He                reply->writeInt32(1);
487b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He                reply->writeStrongBinder(camera->asBinder());
488b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            } else {
489b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He                reply->writeInt32(0);
490b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            }
491b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He            return NO_ERROR;
492b10cdadf0fb945e23ca77008d4af76584bd0e39aZhijun He        } break;
4933cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        default:
4943cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return BBinder::onTransact(code, data, reply, flags);
4953cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
4963cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}
4973cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
4983cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ----------------------------------------------------------------------------
4993cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
5003cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}; // namespace android
501