blob: a7328cf6f804a92322d85c446f871aba1e6a5586 [file] [log] [blame]
Mathias Agopian65ab4712010-07-14 17:59:35 -07001/*
Ruben Brunkd1176ef2014-02-21 10:51:38 -08002 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Mathias Agopian65ab4712010-07-14 17:59:35 -070016
17#ifndef ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
18#define ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
19
Igor Murashkin634a5152013-02-20 17:15:11 -080020#include <utils/Vector.h>
Ruben Brunkb2119af2014-05-09 19:57:56 -070021#include <utils/KeyedVector.h>
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080022#include <binder/AppOpsManager.h>
Mathias Agopian5462fc92010-07-14 18:41:18 -070023#include <binder/BinderService.h>
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080024#include <binder/IAppOpsCallback.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070025#include <camera/ICameraService.h>
Iliyan Malchev8951a972011-04-14 16:55:59 -070026#include <hardware/camera.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070027
Igor Murashkinc073ba52013-02-26 14:32:34 -080028#include <camera/ICamera.h>
29#include <camera/ICameraClient.h>
30#include <camera/IProCameraUser.h>
31#include <camera/IProCameraCallbacks.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070032#include <camera/camera2/ICameraDeviceUser.h>
33#include <camera/camera2/ICameraDeviceCallbacks.h>
Ruben Brunkd1176ef2014-02-21 10:51:38 -080034#include <camera/VendorTagDescriptor.h>
Jianing Weicb0652e2014-03-12 18:29:36 -070035#include <camera/CaptureResult.h>
Ruben Brunkb2119af2014-05-09 19:57:56 -070036#include <camera/CameraParameters.h>
Igor Murashkinc073ba52013-02-26 14:32:34 -080037
Igor Murashkinbfc99152013-02-27 12:55:20 -080038#include <camera/ICameraServiceListener.h>
39
Mathias Agopian65ab4712010-07-14 17:59:35 -070040/* This needs to be increased if we can have more cameras */
41#define MAX_CAMERAS 2
42
43namespace android {
44
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -070045extern volatile int32_t gLogLevel;
46
Mathias Agopian65ab4712010-07-14 17:59:35 -070047class MemoryHeapBase;
48class MediaPlayer;
49
Mathias Agopian5462fc92010-07-14 18:41:18 -070050class CameraService :
51 public BinderService<CameraService>,
Igor Murashkinecf17e82012-10-02 16:05:11 -070052 public BnCameraService,
Igor Murashkincba2c162013-03-20 15:56:31 -070053 public IBinder::DeathRecipient,
54 public camera_module_callbacks_t
Mathias Agopian65ab4712010-07-14 17:59:35 -070055{
Mathias Agopian5462fc92010-07-14 18:41:18 -070056 friend class BinderService<CameraService>;
Mathias Agopian65ab4712010-07-14 17:59:35 -070057public:
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -070058 class Client;
Igor Murashkin634a5152013-02-20 17:15:11 -080059 class BasicClient;
60
61 // Implementation of BinderService<T>
Mathias Agopian5462fc92010-07-14 18:41:18 -070062 static char const* getServiceName() { return "media.camera"; }
Mathias Agopian65ab4712010-07-14 17:59:35 -070063
64 CameraService();
65 virtual ~CameraService();
66
Igor Murashkin634a5152013-02-20 17:15:11 -080067 /////////////////////////////////////////////////////////////////////
Igor Murashkincba2c162013-03-20 15:56:31 -070068 // HAL Callbacks
69 virtual void onDeviceStatusChanged(int cameraId,
70 int newStatus);
71
72 /////////////////////////////////////////////////////////////////////
Igor Murashkin634a5152013-02-20 17:15:11 -080073 // ICameraService
Mathias Agopian65ab4712010-07-14 17:59:35 -070074 virtual int32_t getNumberOfCameras();
75 virtual status_t getCameraInfo(int cameraId,
76 struct CameraInfo* cameraInfo);
Zhijun He2b59be82013-09-25 10:14:30 -070077 virtual status_t getCameraCharacteristics(int cameraId,
78 CameraMetadata* cameraInfo);
Ruben Brunkd1176ef2014-02-21 10:51:38 -080079 virtual status_t getCameraVendorTagDescriptor(/*out*/ sp<VendorTagDescriptor>& desc);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080080
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070081 virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
82 const String16& clientPackageName, int clientUid,
83 /*out*/
84 sp<ICamera>& device);
85
Zhijun Heb10cdad2014-06-16 16:38:35 -070086 virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
87 int halVersion, const String16& clientPackageName, int clientUid,
88 /*out*/
89 sp<ICamera>& device);
90
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070091 virtual status_t connectPro(const sp<IProCameraCallbacks>& cameraCb,
92 int cameraId, const String16& clientPackageName, int clientUid,
93 /*out*/
94 sp<IProCameraUser>& device);
95
96 virtual status_t connectDevice(
Igor Murashkine7ee7632013-06-11 18:10:18 -070097 const sp<ICameraDeviceCallbacks>& cameraCb,
98 int cameraId,
99 const String16& clientPackageName,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700100 int clientUid,
101 /*out*/
102 sp<ICameraDeviceUser>& device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700103
Igor Murashkinbfc99152013-02-27 12:55:20 -0800104 virtual status_t addListener(const sp<ICameraServiceListener>& listener);
105 virtual status_t removeListener(
106 const sp<ICameraServiceListener>& listener);
107
Igor Murashkin65d14b92014-06-17 12:03:20 -0700108 virtual status_t getLegacyParameters(
109 int cameraId,
110 /*out*/
111 String16* parameters);
112
113 // OK = supports api of that version, -EOPNOTSUPP = does not support
114 virtual status_t supportsCameraApi(
115 int cameraId, int apiVersion);
116
Igor Murashkin634a5152013-02-20 17:15:11 -0800117 // Extra permissions checks
Mathias Agopian65ab4712010-07-14 17:59:35 -0700118 virtual status_t onTransact(uint32_t code, const Parcel& data,
119 Parcel* reply, uint32_t flags);
Igor Murashkin634a5152013-02-20 17:15:11 -0800120
121 virtual status_t dump(int fd, const Vector<String16>& args);
122
123 /////////////////////////////////////////////////////////////////////
124 // Client functionality
125 virtual void removeClientByRemote(const wp<IBinder>& remoteBinder);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700126
127 enum sound_kind {
128 SOUND_SHUTTER = 0,
129 SOUND_RECORDING = 1,
130 NUM_SOUNDS
131 };
132
133 void loadSound();
134 void playSound(sound_kind kind);
135 void releaseSound();
136
Igor Murashkin98e24722013-06-19 19:51:04 -0700137 /////////////////////////////////////////////////////////////////////
138 // CameraDeviceFactory functionality
139 int getDeviceVersion(int cameraId, int* facing = NULL);
140
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700141 /////////////////////////////////////////////////////////////////////
142 // Shared utilities
143 static status_t filterOpenErrorCode(status_t err);
144 static status_t filterGetInfoErrorCode(status_t err);
Igor Murashkin634a5152013-02-20 17:15:11 -0800145
146 /////////////////////////////////////////////////////////////////////
147 // CameraClient functionality
148
149 // returns plain pointer of client. Note that mClientLock should be acquired to
150 // prevent the client from destruction. The result can be NULL.
Igor Murashkine7ee7632013-06-11 18:10:18 -0700151 virtual BasicClient* getClientByIdUnsafe(int cameraId);
Igor Murashkin634a5152013-02-20 17:15:11 -0800152 virtual Mutex* getClientLockById(int cameraId);
153
154 class BasicClient : public virtual RefBase {
155 public:
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700156 virtual status_t initialize(camera_module_t *module) = 0;
157 virtual void disconnect();
Igor Murashkin634a5152013-02-20 17:15:11 -0800158
Igor Murashkine7ee7632013-06-11 18:10:18 -0700159 // because we can't virtually inherit IInterface, which breaks
160 // virtual inheritance
161 virtual sp<IBinder> asBinderWrapper() = 0;
162
Igor Murashkine6800ce2013-03-04 17:25:57 -0800163 // Return the remote callback binder object (e.g. IProCameraCallbacks)
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700164 sp<IBinder> getRemote() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800165 return mRemoteBinder;
Igor Murashkin634a5152013-02-20 17:15:11 -0800166 }
167
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700168 virtual status_t dump(int fd, const Vector<String16>& args) = 0;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700169
Igor Murashkin634a5152013-02-20 17:15:11 -0800170 protected:
171 BasicClient(const sp<CameraService>& cameraService,
172 const sp<IBinder>& remoteCallback,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800173 const String16& clientPackageName,
Igor Murashkin634a5152013-02-20 17:15:11 -0800174 int cameraId,
175 int cameraFacing,
176 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800177 uid_t clientUid,
Igor Murashkin634a5152013-02-20 17:15:11 -0800178 int servicePid);
179
180 virtual ~BasicClient();
181
182 // the instance is in the middle of destruction. When this is set,
183 // the instance should not be accessed from callback.
184 // CameraService's mClientLock should be acquired to access this.
185 // - subclasses should set this to true in their destructors.
186 bool mDestructionStarted;
187
188 // these are initialized in the constructor.
189 sp<CameraService> mCameraService; // immutable after constructor
190 int mCameraId; // immutable after constructor
191 int mCameraFacing; // immutable after constructor
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800192 const String16 mClientPackageName;
Igor Murashkin634a5152013-02-20 17:15:11 -0800193 pid_t mClientPid;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800194 uid_t mClientUid; // immutable after constructor
Igor Murashkin634a5152013-02-20 17:15:11 -0800195 pid_t mServicePid; // immutable after constructor
196
197 // - The app-side Binder interface to receive callbacks from us
Igor Murashkine7ee7632013-06-11 18:10:18 -0700198 sp<IBinder> mRemoteBinder; // immutable after constructor
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800199
200 // permissions management
201 status_t startCameraOps();
202 status_t finishCameraOps();
203
204 // Notify client about a fatal error
Jianing Weicb0652e2014-03-12 18:29:36 -0700205 virtual void notifyError(
206 ICameraDeviceCallbacks::CameraErrorCode errorCode,
207 const CaptureResultExtras& resultExtras) = 0;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800208 private:
209 AppOpsManager mAppOpsManager;
210
211 class OpsCallback : public BnAppOpsCallback {
212 public:
213 OpsCallback(wp<BasicClient> client);
214 virtual void opChanged(int32_t op, const String16& packageName);
215
216 private:
217 wp<BasicClient> mClient;
218
219 }; // class OpsCallback
220
221 sp<OpsCallback> mOpsCallback;
222 // Track whether startCameraOps was called successfully, to avoid
223 // finishing what we didn't start.
224 bool mOpsActive;
225
226 // IAppOpsCallback interface, indirected through opListener
227 virtual void opChanged(int32_t op, const String16& packageName);
228 }; // class BasicClient
Igor Murashkin634a5152013-02-20 17:15:11 -0800229
230 class Client : public BnCamera, public BasicClient
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700231 {
232 public:
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800233 typedef ICameraClient TCamCallbacks;
234
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700235 // ICamera interface (see ICamera for details)
236 virtual void disconnect();
237 virtual status_t connect(const sp<ICameraClient>& client) = 0;
238 virtual status_t lock() = 0;
239 virtual status_t unlock() = 0;
Eino-Ville Talvala1ce7c342013-08-21 13:57:21 -0700240 virtual status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)=0;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700241 virtual void setPreviewCallbackFlag(int flag) = 0;
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700242 virtual status_t setPreviewCallbackTarget(
243 const sp<IGraphicBufferProducer>& callbackProducer) = 0;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700244 virtual status_t startPreview() = 0;
245 virtual void stopPreview() = 0;
246 virtual bool previewEnabled() = 0;
247 virtual status_t storeMetaDataInBuffers(bool enabled) = 0;
248 virtual status_t startRecording() = 0;
249 virtual void stopRecording() = 0;
250 virtual bool recordingEnabled() = 0;
251 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
252 virtual status_t autoFocus() = 0;
253 virtual status_t cancelAutoFocus() = 0;
254 virtual status_t takePicture(int msgType) = 0;
255 virtual status_t setParameters(const String8& params) = 0;
256 virtual String8 getParameters() const = 0;
257 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
258
259 // Interface used by CameraService
260 Client(const sp<CameraService>& cameraService,
261 const sp<ICameraClient>& cameraClient,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800262 const String16& clientPackageName,
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700263 int cameraId,
264 int cameraFacing,
Igor Murashkinecf17e82012-10-02 16:05:11 -0700265 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800266 uid_t clientUid,
Igor Murashkinecf17e82012-10-02 16:05:11 -0700267 int servicePid);
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700268 ~Client();
269
270 // return our camera client
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800271 const sp<ICameraClient>& getRemoteCallback() {
272 return mRemoteCallback;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700273 }
274
Igor Murashkine7ee7632013-06-11 18:10:18 -0700275 virtual sp<IBinder> asBinderWrapper() {
276 return asBinder();
277 }
278
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700279 protected:
280 static Mutex* getClientLockFromCookie(void* user);
281 // convert client from cookie. Client lock should be acquired before getting Client.
282 static Client* getClientFromCookie(void* user);
283
Jianing Weicb0652e2014-03-12 18:29:36 -0700284 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
285 const CaptureResultExtras& resultExtras);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800286
Igor Murashkin634a5152013-02-20 17:15:11 -0800287 // Initialized in constructor
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700288
Igor Murashkin634a5152013-02-20 17:15:11 -0800289 // - The app-side Binder interface to receive callbacks from us
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800290 sp<ICameraClient> mRemoteCallback;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800291
292 }; // class Client
Igor Murashkin634a5152013-02-20 17:15:11 -0800293
294 class ProClient : public BnProCameraUser, public BasicClient {
295 public:
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800296 typedef IProCameraCallbacks TCamCallbacks;
297
Igor Murashkin634a5152013-02-20 17:15:11 -0800298 ProClient(const sp<CameraService>& cameraService,
299 const sp<IProCameraCallbacks>& remoteCallback,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800300 const String16& clientPackageName,
Igor Murashkin634a5152013-02-20 17:15:11 -0800301 int cameraId,
302 int cameraFacing,
303 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800304 uid_t clientUid,
Igor Murashkin634a5152013-02-20 17:15:11 -0800305 int servicePid);
306
307 virtual ~ProClient();
308
309 const sp<IProCameraCallbacks>& getRemoteCallback() {
310 return mRemoteCallback;
311 }
312
Igor Murashkin634a5152013-02-20 17:15:11 -0800313 /***
314 IProCamera implementation
315 ***/
Igor Murashkine6800ce2013-03-04 17:25:57 -0800316 virtual status_t connect(const sp<IProCameraCallbacks>& callbacks)
317 = 0;
318 virtual status_t exclusiveTryLock() = 0;
319 virtual status_t exclusiveLock() = 0;
320 virtual status_t exclusiveUnlock() = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800321
Igor Murashkine6800ce2013-03-04 17:25:57 -0800322 virtual bool hasExclusiveLock() = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800323
324 // Note that the callee gets a copy of the metadata.
325 virtual int submitRequest(camera_metadata_t* metadata,
Igor Murashkine6800ce2013-03-04 17:25:57 -0800326 bool streaming = false) = 0;
327 virtual status_t cancelRequest(int requestId) = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800328
Igor Murashkinbfc99152013-02-27 12:55:20 -0800329 // Callbacks from camera service
Igor Murashkine6800ce2013-03-04 17:25:57 -0800330 virtual void onExclusiveLockStolen() = 0;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800331
Igor Murashkin634a5152013-02-20 17:15:11 -0800332 protected:
Jianing Weicb0652e2014-03-12 18:29:36 -0700333 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
334 const CaptureResultExtras& resultExtras);
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700335
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800336 sp<IProCameraCallbacks> mRemoteCallback;
337 }; // class ProClient
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700338
Mathias Agopian65ab4712010-07-14 17:59:35 -0700339private:
Igor Murashkin634a5152013-02-20 17:15:11 -0800340
341 // Delay-load the Camera HAL module
342 virtual void onFirstRef();
343
Igor Murashkine6800ce2013-03-04 17:25:57 -0800344 // Step 1. Check if we can connect, before we acquire the service lock.
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700345 status_t validateConnect(int cameraId,
Igor Murashkine6800ce2013-03-04 17:25:57 -0800346 /*inout*/
347 int& clientUid) const;
348
349 // Step 2. Check if we can connect, after we acquire the service lock.
350 bool canConnectUnsafe(int cameraId,
351 const String16& clientPackageName,
352 const sp<IBinder>& remoteCallback,
353 /*out*/
Igor Murashkine7ee7632013-06-11 18:10:18 -0700354 sp<BasicClient> &client);
Igor Murashkine6800ce2013-03-04 17:25:57 -0800355
356 // When connection is successful, initialize client and track its death
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700357 status_t connectFinishUnsafe(const sp<BasicClient>& client,
Igor Murashkine7ee7632013-06-11 18:10:18 -0700358 const sp<IBinder>& remoteCallback);
Igor Murashkine6800ce2013-03-04 17:25:57 -0800359
Igor Murashkin634a5152013-02-20 17:15:11 -0800360 virtual sp<BasicClient> getClientByRemote(const wp<IBinder>& cameraClient);
361
Mathias Agopian65ab4712010-07-14 17:59:35 -0700362 Mutex mServiceLock;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700363 // either a Client or CameraDeviceClient
364 wp<BasicClient> mClient[MAX_CAMERAS]; // protected by mServiceLock
Keun young Parkd8973a72012-03-28 14:13:09 -0700365 Mutex mClientLock[MAX_CAMERAS]; // prevent Client destruction inside callbacks
Mathias Agopian65ab4712010-07-14 17:59:35 -0700366 int mNumberOfCameras;
367
Igor Murashkin634a5152013-02-20 17:15:11 -0800368 typedef wp<ProClient> weak_pro_client_ptr;
369 Vector<weak_pro_client_ptr> mProClientList[MAX_CAMERAS];
370
Igor Murashkinecf17e82012-10-02 16:05:11 -0700371 // needs to be called with mServiceLock held
Igor Murashkine7ee7632013-06-11 18:10:18 -0700372 sp<BasicClient> findClientUnsafe(const wp<IBinder>& cameraClient, int& outIndex);
Igor Murashkin634a5152013-02-20 17:15:11 -0800373 sp<ProClient> findProClientUnsafe(
374 const wp<IBinder>& cameraCallbacksRemote);
Igor Murashkinecf17e82012-10-02 16:05:11 -0700375
Mathias Agopian65ab4712010-07-14 17:59:35 -0700376 // atomics to record whether the hardware is allocated to some client.
377 volatile int32_t mBusy[MAX_CAMERAS];
378 void setCameraBusy(int cameraId);
379 void setCameraFree(int cameraId);
380
381 // sounds
Chih-Chung Changff4f55c2011-10-17 19:03:12 +0800382 MediaPlayer* newMediaPlayer(const char *file);
383
Mathias Agopian65ab4712010-07-14 17:59:35 -0700384 Mutex mSoundLock;
385 sp<MediaPlayer> mSoundPlayer[NUM_SOUNDS];
386 int mSoundRef; // reference count (release all MediaPlayer when 0)
387
Iliyan Malchev8951a972011-04-14 16:55:59 -0700388 camera_module_t *mModule;
Igor Murashkinecf17e82012-10-02 16:05:11 -0700389
Igor Murashkinbfc99152013-02-27 12:55:20 -0800390 Vector<sp<ICameraServiceListener> >
391 mListenerList;
392
393 // guard only mStatusList and the broadcasting of ICameraServiceListener
Igor Murashkincba2c162013-03-20 15:56:31 -0700394 mutable Mutex mStatusMutex;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800395 ICameraServiceListener::Status
396 mStatusList[MAX_CAMERAS];
397
Igor Murashkincba2c162013-03-20 15:56:31 -0700398 // Read the current status (locks mStatusMutex)
399 ICameraServiceListener::Status
400 getStatus(int cameraId) const;
401
Igor Murashkin93747b92013-05-01 15:42:20 -0700402 typedef Vector<ICameraServiceListener::Status> StatusVector;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800403 // Broadcast the new status if it changed (locks the service mutex)
404 void updateStatus(
405 ICameraServiceListener::Status status,
Igor Murashkin93747b92013-05-01 15:42:20 -0700406 int32_t cameraId,
407 const StatusVector *rejectSourceStates = NULL);
Igor Murashkinbfc99152013-02-27 12:55:20 -0800408
Igor Murashkinecf17e82012-10-02 16:05:11 -0700409 // IBinder::DeathRecipient implementation
Igor Murashkinbfc99152013-02-27 12:55:20 -0800410 virtual void binderDied(const wp<IBinder> &who);
Igor Murashkin634a5152013-02-20 17:15:11 -0800411
412 // Helpers
Igor Murashkinbfc99152013-02-27 12:55:20 -0800413
414 bool isValidCameraId(int cameraId);
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800415
416 bool setUpVendorTags();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700417
418 /**
419 * A mapping of camera ids to CameraParameters returned by that camera device.
420 *
421 * This cache is used to generate CameraCharacteristic metadata when using
422 * the HAL1 shim.
423 */
424 KeyedVector<int, CameraParameters> mShimParams;
425
426 /**
427 * Initialize and cache the metadata used by the HAL1 shim for a given cameraId.
428 *
429 * Returns OK on success, or a negative error code.
430 */
431 status_t initializeShimMetadata(int cameraId);
432
433 /**
Igor Murashkin65d14b92014-06-17 12:03:20 -0700434 * Get the cached CameraParameters for the camera. If they haven't been
435 * cached yet, then initialize them for the first time.
436 *
437 * Returns OK on success, or a negative error code.
438 */
439 status_t getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters);
440
441 /**
Ruben Brunkb2119af2014-05-09 19:57:56 -0700442 * Generate the CameraCharacteristics metadata required by the Camera2 API
443 * from the available HAL1 CameraParameters and CameraInfo.
444 *
445 * Returns OK on success, or a negative error code.
446 */
447 status_t generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo);
448
449 /**
450 * Connect a new camera client. This should only be used while holding the
451 * mutex for mServiceLock.
452 *
453 * Returns OK on success, or a negative error code.
454 */
Igor Murashkina858ea02014-08-19 14:53:08 -0700455 status_t connectHelperLocked(
456 /*out*/
457 sp<Client>& client,
458 /*in*/
459 const sp<ICameraClient>& cameraClient,
460 int cameraId,
461 const String16& clientPackageName,
462 int clientUid,
463 int callingPid,
464 int halVersion = CAMERA_HAL_API_VERSION_UNSPECIFIED,
465 bool legacyMode = false);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700466};
467
468} // namespace android
469
470#endif