blob: 22afc8cc774fa4f1cb78ff2fca0f63c9e5d2599b [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>
Chien-Yu Chen3068d732015-02-09 13:29:57 -080039#include "CameraFlashlight.h"
40
Igor Murashkinbfc99152013-02-27 12:55:20 -080041
Yin-Chia Yehe074a932015-01-30 10:29:02 -080042#include "common/CameraModule.h"
43
Mathias Agopian65ab4712010-07-14 17:59:35 -070044/* This needs to be increased if we can have more cameras */
45#define MAX_CAMERAS 2
46
47namespace android {
48
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -070049extern volatile int32_t gLogLevel;
50
Mathias Agopian65ab4712010-07-14 17:59:35 -070051class MemoryHeapBase;
52class MediaPlayer;
53
Mathias Agopian5462fc92010-07-14 18:41:18 -070054class CameraService :
55 public BinderService<CameraService>,
Igor Murashkinecf17e82012-10-02 16:05:11 -070056 public BnCameraService,
Igor Murashkincba2c162013-03-20 15:56:31 -070057 public IBinder::DeathRecipient,
58 public camera_module_callbacks_t
Mathias Agopian65ab4712010-07-14 17:59:35 -070059{
Mathias Agopian5462fc92010-07-14 18:41:18 -070060 friend class BinderService<CameraService>;
Mathias Agopian65ab4712010-07-14 17:59:35 -070061public:
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -070062 class Client;
Igor Murashkin634a5152013-02-20 17:15:11 -080063 class BasicClient;
64
65 // Implementation of BinderService<T>
Mathias Agopian5462fc92010-07-14 18:41:18 -070066 static char const* getServiceName() { return "media.camera"; }
Mathias Agopian65ab4712010-07-14 17:59:35 -070067
68 CameraService();
69 virtual ~CameraService();
70
Igor Murashkin634a5152013-02-20 17:15:11 -080071 /////////////////////////////////////////////////////////////////////
Igor Murashkincba2c162013-03-20 15:56:31 -070072 // HAL Callbacks
73 virtual void onDeviceStatusChanged(int cameraId,
74 int newStatus);
Chien-Yu Chen88da5262015-02-17 13:56:46 -080075 virtual void onTorchStatusChanged(const String8& cameraId,
Chien-Yu Chen3068d732015-02-09 13:29:57 -080076 ICameraServiceListener::TorchStatus
77 newStatus);
Igor Murashkincba2c162013-03-20 15:56:31 -070078
79 /////////////////////////////////////////////////////////////////////
Igor Murashkin634a5152013-02-20 17:15:11 -080080 // ICameraService
Mathias Agopian65ab4712010-07-14 17:59:35 -070081 virtual int32_t getNumberOfCameras();
82 virtual status_t getCameraInfo(int cameraId,
83 struct CameraInfo* cameraInfo);
Zhijun He2b59be82013-09-25 10:14:30 -070084 virtual status_t getCameraCharacteristics(int cameraId,
85 CameraMetadata* cameraInfo);
Ruben Brunkd1176ef2014-02-21 10:51:38 -080086 virtual status_t getCameraVendorTagDescriptor(/*out*/ sp<VendorTagDescriptor>& desc);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -080087
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070088 virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
89 const String16& clientPackageName, int clientUid,
90 /*out*/
91 sp<ICamera>& device);
92
Zhijun Heb10cdad2014-06-16 16:38:35 -070093 virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
94 int halVersion, const String16& clientPackageName, int clientUid,
95 /*out*/
96 sp<ICamera>& device);
97
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070098 virtual status_t connectPro(const sp<IProCameraCallbacks>& cameraCb,
99 int cameraId, const String16& clientPackageName, int clientUid,
100 /*out*/
101 sp<IProCameraUser>& device);
102
103 virtual status_t connectDevice(
Igor Murashkine7ee7632013-06-11 18:10:18 -0700104 const sp<ICameraDeviceCallbacks>& cameraCb,
105 int cameraId,
106 const String16& clientPackageName,
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700107 int clientUid,
108 /*out*/
109 sp<ICameraDeviceUser>& device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700110
Igor Murashkinbfc99152013-02-27 12:55:20 -0800111 virtual status_t addListener(const sp<ICameraServiceListener>& listener);
112 virtual status_t removeListener(
113 const sp<ICameraServiceListener>& listener);
114
Igor Murashkin65d14b92014-06-17 12:03:20 -0700115 virtual status_t getLegacyParameters(
116 int cameraId,
117 /*out*/
118 String16* parameters);
119
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800120 virtual status_t setTorchMode(const String16& cameraId, bool enabled,
121 const sp<IBinder>& clientBinder);
122
Igor Murashkin65d14b92014-06-17 12:03:20 -0700123 // OK = supports api of that version, -EOPNOTSUPP = does not support
124 virtual status_t supportsCameraApi(
125 int cameraId, int apiVersion);
126
Igor Murashkin634a5152013-02-20 17:15:11 -0800127 // Extra permissions checks
Mathias Agopian65ab4712010-07-14 17:59:35 -0700128 virtual status_t onTransact(uint32_t code, const Parcel& data,
129 Parcel* reply, uint32_t flags);
Igor Murashkin634a5152013-02-20 17:15:11 -0800130
131 virtual status_t dump(int fd, const Vector<String16>& args);
132
133 /////////////////////////////////////////////////////////////////////
134 // Client functionality
135 virtual void removeClientByRemote(const wp<IBinder>& remoteBinder);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700136
137 enum sound_kind {
138 SOUND_SHUTTER = 0,
139 SOUND_RECORDING = 1,
140 NUM_SOUNDS
141 };
142
143 void loadSound();
144 void playSound(sound_kind kind);
145 void releaseSound();
146
Igor Murashkin98e24722013-06-19 19:51:04 -0700147 /////////////////////////////////////////////////////////////////////
148 // CameraDeviceFactory functionality
149 int getDeviceVersion(int cameraId, int* facing = NULL);
150
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700151 /////////////////////////////////////////////////////////////////////
152 // Shared utilities
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700153 static status_t filterGetInfoErrorCode(status_t err);
Igor Murashkin634a5152013-02-20 17:15:11 -0800154
155 /////////////////////////////////////////////////////////////////////
156 // CameraClient functionality
157
158 // returns plain pointer of client. Note that mClientLock should be acquired to
159 // prevent the client from destruction. The result can be NULL.
Igor Murashkine7ee7632013-06-11 18:10:18 -0700160 virtual BasicClient* getClientByIdUnsafe(int cameraId);
Igor Murashkin634a5152013-02-20 17:15:11 -0800161 virtual Mutex* getClientLockById(int cameraId);
162
163 class BasicClient : public virtual RefBase {
164 public:
Yin-Chia Yehe074a932015-01-30 10:29:02 -0800165 virtual status_t initialize(CameraModule *module) = 0;
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700166 virtual void disconnect();
Igor Murashkin634a5152013-02-20 17:15:11 -0800167
Igor Murashkine7ee7632013-06-11 18:10:18 -0700168 // because we can't virtually inherit IInterface, which breaks
169 // virtual inheritance
170 virtual sp<IBinder> asBinderWrapper() = 0;
171
Igor Murashkine6800ce2013-03-04 17:25:57 -0800172 // Return the remote callback binder object (e.g. IProCameraCallbacks)
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700173 sp<IBinder> getRemote() {
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800174 return mRemoteBinder;
Igor Murashkin634a5152013-02-20 17:15:11 -0800175 }
176
Eino-Ville Talvalaf67e23e2014-07-23 17:17:59 -0700177 virtual status_t dump(int fd, const Vector<String16>& args) = 0;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700178
Igor Murashkin634a5152013-02-20 17:15:11 -0800179 protected:
180 BasicClient(const sp<CameraService>& cameraService,
181 const sp<IBinder>& remoteCallback,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800182 const String16& clientPackageName,
Igor Murashkin634a5152013-02-20 17:15:11 -0800183 int cameraId,
184 int cameraFacing,
185 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800186 uid_t clientUid,
Igor Murashkin634a5152013-02-20 17:15:11 -0800187 int servicePid);
188
189 virtual ~BasicClient();
190
191 // the instance is in the middle of destruction. When this is set,
192 // the instance should not be accessed from callback.
193 // CameraService's mClientLock should be acquired to access this.
194 // - subclasses should set this to true in their destructors.
195 bool mDestructionStarted;
196
197 // these are initialized in the constructor.
198 sp<CameraService> mCameraService; // immutable after constructor
199 int mCameraId; // immutable after constructor
200 int mCameraFacing; // immutable after constructor
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800201 const String16 mClientPackageName;
Igor Murashkin634a5152013-02-20 17:15:11 -0800202 pid_t mClientPid;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800203 uid_t mClientUid; // immutable after constructor
Igor Murashkin634a5152013-02-20 17:15:11 -0800204 pid_t mServicePid; // immutable after constructor
205
206 // - The app-side Binder interface to receive callbacks from us
Igor Murashkine7ee7632013-06-11 18:10:18 -0700207 sp<IBinder> mRemoteBinder; // immutable after constructor
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800208
209 // permissions management
210 status_t startCameraOps();
211 status_t finishCameraOps();
212
213 // Notify client about a fatal error
Jianing Weicb0652e2014-03-12 18:29:36 -0700214 virtual void notifyError(
215 ICameraDeviceCallbacks::CameraErrorCode errorCode,
216 const CaptureResultExtras& resultExtras) = 0;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800217 private:
218 AppOpsManager mAppOpsManager;
219
220 class OpsCallback : public BnAppOpsCallback {
221 public:
222 OpsCallback(wp<BasicClient> client);
223 virtual void opChanged(int32_t op, const String16& packageName);
224
225 private:
226 wp<BasicClient> mClient;
227
228 }; // class OpsCallback
229
230 sp<OpsCallback> mOpsCallback;
231 // Track whether startCameraOps was called successfully, to avoid
232 // finishing what we didn't start.
233 bool mOpsActive;
234
235 // IAppOpsCallback interface, indirected through opListener
236 virtual void opChanged(int32_t op, const String16& packageName);
237 }; // class BasicClient
Igor Murashkin634a5152013-02-20 17:15:11 -0800238
239 class Client : public BnCamera, public BasicClient
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700240 {
241 public:
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800242 typedef ICameraClient TCamCallbacks;
243
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700244 // ICamera interface (see ICamera for details)
245 virtual void disconnect();
246 virtual status_t connect(const sp<ICameraClient>& client) = 0;
247 virtual status_t lock() = 0;
248 virtual status_t unlock() = 0;
Eino-Ville Talvala1ce7c342013-08-21 13:57:21 -0700249 virtual status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)=0;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700250 virtual void setPreviewCallbackFlag(int flag) = 0;
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700251 virtual status_t setPreviewCallbackTarget(
252 const sp<IGraphicBufferProducer>& callbackProducer) = 0;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700253 virtual status_t startPreview() = 0;
254 virtual void stopPreview() = 0;
255 virtual bool previewEnabled() = 0;
256 virtual status_t storeMetaDataInBuffers(bool enabled) = 0;
257 virtual status_t startRecording() = 0;
258 virtual void stopRecording() = 0;
259 virtual bool recordingEnabled() = 0;
260 virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;
261 virtual status_t autoFocus() = 0;
262 virtual status_t cancelAutoFocus() = 0;
263 virtual status_t takePicture(int msgType) = 0;
264 virtual status_t setParameters(const String8& params) = 0;
265 virtual String8 getParameters() const = 0;
266 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
267
268 // Interface used by CameraService
269 Client(const sp<CameraService>& cameraService,
270 const sp<ICameraClient>& cameraClient,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800271 const String16& clientPackageName,
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700272 int cameraId,
273 int cameraFacing,
Igor Murashkinecf17e82012-10-02 16:05:11 -0700274 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800275 uid_t clientUid,
Igor Murashkinecf17e82012-10-02 16:05:11 -0700276 int servicePid);
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700277 ~Client();
278
279 // return our camera client
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800280 const sp<ICameraClient>& getRemoteCallback() {
281 return mRemoteCallback;
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700282 }
283
Igor Murashkine7ee7632013-06-11 18:10:18 -0700284 virtual sp<IBinder> asBinderWrapper() {
Marco Nelissen06b46062014-11-14 07:58:25 -0800285 return asBinder(this);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700286 }
287
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700288 protected:
289 static Mutex* getClientLockFromCookie(void* user);
290 // convert client from cookie. Client lock should be acquired before getting Client.
291 static Client* getClientFromCookie(void* user);
292
Jianing Weicb0652e2014-03-12 18:29:36 -0700293 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
294 const CaptureResultExtras& resultExtras);
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800295
Igor Murashkin634a5152013-02-20 17:15:11 -0800296 // Initialized in constructor
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700297
Igor Murashkin634a5152013-02-20 17:15:11 -0800298 // - The app-side Binder interface to receive callbacks from us
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800299 sp<ICameraClient> mRemoteCallback;
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800300
301 }; // class Client
Igor Murashkin634a5152013-02-20 17:15:11 -0800302
303 class ProClient : public BnProCameraUser, public BasicClient {
304 public:
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800305 typedef IProCameraCallbacks TCamCallbacks;
306
Igor Murashkin634a5152013-02-20 17:15:11 -0800307 ProClient(const sp<CameraService>& cameraService,
308 const sp<IProCameraCallbacks>& remoteCallback,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800309 const String16& clientPackageName,
Igor Murashkin634a5152013-02-20 17:15:11 -0800310 int cameraId,
311 int cameraFacing,
312 int clientPid,
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800313 uid_t clientUid,
Igor Murashkin634a5152013-02-20 17:15:11 -0800314 int servicePid);
315
316 virtual ~ProClient();
317
318 const sp<IProCameraCallbacks>& getRemoteCallback() {
319 return mRemoteCallback;
320 }
321
Igor Murashkin634a5152013-02-20 17:15:11 -0800322 /***
323 IProCamera implementation
324 ***/
Igor Murashkine6800ce2013-03-04 17:25:57 -0800325 virtual status_t connect(const sp<IProCameraCallbacks>& callbacks)
326 = 0;
327 virtual status_t exclusiveTryLock() = 0;
328 virtual status_t exclusiveLock() = 0;
329 virtual status_t exclusiveUnlock() = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800330
Igor Murashkine6800ce2013-03-04 17:25:57 -0800331 virtual bool hasExclusiveLock() = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800332
333 // Note that the callee gets a copy of the metadata.
334 virtual int submitRequest(camera_metadata_t* metadata,
Igor Murashkine6800ce2013-03-04 17:25:57 -0800335 bool streaming = false) = 0;
336 virtual status_t cancelRequest(int requestId) = 0;
Igor Murashkin634a5152013-02-20 17:15:11 -0800337
Igor Murashkinbfc99152013-02-27 12:55:20 -0800338 // Callbacks from camera service
Igor Murashkine6800ce2013-03-04 17:25:57 -0800339 virtual void onExclusiveLockStolen() = 0;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800340
Igor Murashkin634a5152013-02-20 17:15:11 -0800341 protected:
Jianing Weicb0652e2014-03-12 18:29:36 -0700342 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
343 const CaptureResultExtras& resultExtras);
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700344
Eino-Ville Talvalaceb388d2013-02-19 10:40:14 -0800345 sp<IProCameraCallbacks> mRemoteCallback;
346 }; // class ProClient
Eino-Ville Talvala5e08d602012-05-16 14:59:25 -0700347
Mathias Agopian65ab4712010-07-14 17:59:35 -0700348private:
Igor Murashkin634a5152013-02-20 17:15:11 -0800349
350 // Delay-load the Camera HAL module
351 virtual void onFirstRef();
352
Igor Murashkine6800ce2013-03-04 17:25:57 -0800353 // Step 1. Check if we can connect, before we acquire the service lock.
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700354 status_t validateConnect(int cameraId,
Igor Murashkine6800ce2013-03-04 17:25:57 -0800355 /*inout*/
356 int& clientUid) const;
357
358 // Step 2. Check if we can connect, after we acquire the service lock.
359 bool canConnectUnsafe(int cameraId,
360 const String16& clientPackageName,
361 const sp<IBinder>& remoteCallback,
362 /*out*/
Igor Murashkine7ee7632013-06-11 18:10:18 -0700363 sp<BasicClient> &client);
Igor Murashkine6800ce2013-03-04 17:25:57 -0800364
365 // When connection is successful, initialize client and track its death
Ruben Brunk0f61d8f2013-08-08 13:07:18 -0700366 status_t connectFinishUnsafe(const sp<BasicClient>& client,
Igor Murashkine7ee7632013-06-11 18:10:18 -0700367 const sp<IBinder>& remoteCallback);
Igor Murashkine6800ce2013-03-04 17:25:57 -0800368
Igor Murashkin634a5152013-02-20 17:15:11 -0800369 virtual sp<BasicClient> getClientByRemote(const wp<IBinder>& cameraClient);
370
Mathias Agopian65ab4712010-07-14 17:59:35 -0700371 Mutex mServiceLock;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700372 // either a Client or CameraDeviceClient
373 wp<BasicClient> mClient[MAX_CAMERAS]; // protected by mServiceLock
Keun young Parkd8973a72012-03-28 14:13:09 -0700374 Mutex mClientLock[MAX_CAMERAS]; // prevent Client destruction inside callbacks
Mathias Agopian65ab4712010-07-14 17:59:35 -0700375 int mNumberOfCameras;
376
Igor Murashkin634a5152013-02-20 17:15:11 -0800377 typedef wp<ProClient> weak_pro_client_ptr;
378 Vector<weak_pro_client_ptr> mProClientList[MAX_CAMERAS];
379
Igor Murashkinecf17e82012-10-02 16:05:11 -0700380 // needs to be called with mServiceLock held
Igor Murashkine7ee7632013-06-11 18:10:18 -0700381 sp<BasicClient> findClientUnsafe(const wp<IBinder>& cameraClient, int& outIndex);
Igor Murashkin634a5152013-02-20 17:15:11 -0800382 sp<ProClient> findProClientUnsafe(
383 const wp<IBinder>& cameraCallbacksRemote);
Igor Murashkinecf17e82012-10-02 16:05:11 -0700384
Mathias Agopian65ab4712010-07-14 17:59:35 -0700385 // atomics to record whether the hardware is allocated to some client.
386 volatile int32_t mBusy[MAX_CAMERAS];
387 void setCameraBusy(int cameraId);
388 void setCameraFree(int cameraId);
389
390 // sounds
Chih-Chung Changff4f55c2011-10-17 19:03:12 +0800391 MediaPlayer* newMediaPlayer(const char *file);
392
Mathias Agopian65ab4712010-07-14 17:59:35 -0700393 Mutex mSoundLock;
394 sp<MediaPlayer> mSoundPlayer[NUM_SOUNDS];
395 int mSoundRef; // reference count (release all MediaPlayer when 0)
396
Yin-Chia Yehe074a932015-01-30 10:29:02 -0800397 CameraModule* mModule;
Igor Murashkinecf17e82012-10-02 16:05:11 -0700398
Igor Murashkinbfc99152013-02-27 12:55:20 -0800399 Vector<sp<ICameraServiceListener> >
400 mListenerList;
401
402 // guard only mStatusList and the broadcasting of ICameraServiceListener
Igor Murashkincba2c162013-03-20 15:56:31 -0700403 mutable Mutex mStatusMutex;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800404 ICameraServiceListener::Status
405 mStatusList[MAX_CAMERAS];
406
Igor Murashkincba2c162013-03-20 15:56:31 -0700407 // Read the current status (locks mStatusMutex)
408 ICameraServiceListener::Status
409 getStatus(int cameraId) const;
410
Igor Murashkin93747b92013-05-01 15:42:20 -0700411 typedef Vector<ICameraServiceListener::Status> StatusVector;
Igor Murashkinbfc99152013-02-27 12:55:20 -0800412 // Broadcast the new status if it changed (locks the service mutex)
413 void updateStatus(
414 ICameraServiceListener::Status status,
Igor Murashkin93747b92013-05-01 15:42:20 -0700415 int32_t cameraId,
416 const StatusVector *rejectSourceStates = NULL);
Igor Murashkinbfc99152013-02-27 12:55:20 -0800417
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800418 // flashlight control
419 sp<CameraFlashlight> mFlashlight;
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800420 // guard mTorchStatusMap
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800421 Mutex mTorchStatusMutex;
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800422 // guard mTorchClientMap
423 Mutex mTorchClientMapMutex;
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800424 // camera id -> torch status
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800425 KeyedVector<String8, ICameraServiceListener::TorchStatus> mTorchStatusMap;
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800426 // camera id -> torch client binder
427 // only store the last client that turns on each camera's torch mode
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800428 KeyedVector<String8, sp<IBinder> > mTorchClientMap;
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800429
430 // check and handle if torch client's process has died
431 void handleTorchClientBinderDied(const wp<IBinder> &who);
432
433 // handle torch mode status change and invoke callbacks. mTorchStatusMutex
434 // should be locked.
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800435 void onTorchStatusChangedLocked(const String8& cameraId,
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800436 ICameraServiceListener::TorchStatus newStatus);
437
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800438 // validate the camera id for use of setting a torch mode.
439 bool validCameraIdForSetTorchMode(const String8& cameraId);
440
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800441 // get a camera's torch status. mTorchStatusMutex should be locked.
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800442 status_t getTorchStatusLocked(const String8 &cameraId,
443 ICameraServiceListener::TorchStatus *status) const;
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800444
445 // set a camera's torch status. mTorchStatusMutex should be locked.
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800446 status_t setTorchStatusLocked(const String8 &cameraId,
Chien-Yu Chen3068d732015-02-09 13:29:57 -0800447 ICameraServiceListener::TorchStatus status);
448
Igor Murashkinecf17e82012-10-02 16:05:11 -0700449 // IBinder::DeathRecipient implementation
Igor Murashkinbfc99152013-02-27 12:55:20 -0800450 virtual void binderDied(const wp<IBinder> &who);
Igor Murashkin634a5152013-02-20 17:15:11 -0800451
452 // Helpers
Igor Murashkinbfc99152013-02-27 12:55:20 -0800453
454 bool isValidCameraId(int cameraId);
Ruben Brunkd1176ef2014-02-21 10:51:38 -0800455
456 bool setUpVendorTags();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700457
458 /**
459 * A mapping of camera ids to CameraParameters returned by that camera device.
460 *
461 * This cache is used to generate CameraCharacteristic metadata when using
462 * the HAL1 shim.
463 */
464 KeyedVector<int, CameraParameters> mShimParams;
465
466 /**
467 * Initialize and cache the metadata used by the HAL1 shim for a given cameraId.
468 *
469 * Returns OK on success, or a negative error code.
470 */
471 status_t initializeShimMetadata(int cameraId);
472
473 /**
Igor Murashkin65d14b92014-06-17 12:03:20 -0700474 * Get the cached CameraParameters for the camera. If they haven't been
475 * cached yet, then initialize them for the first time.
476 *
477 * Returns OK on success, or a negative error code.
478 */
479 status_t getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters);
480
481 /**
Ruben Brunkb2119af2014-05-09 19:57:56 -0700482 * Generate the CameraCharacteristics metadata required by the Camera2 API
483 * from the available HAL1 CameraParameters and CameraInfo.
484 *
485 * Returns OK on success, or a negative error code.
486 */
487 status_t generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo);
488
489 /**
490 * Connect a new camera client. This should only be used while holding the
491 * mutex for mServiceLock.
492 *
493 * Returns OK on success, or a negative error code.
494 */
Igor Murashkina858ea02014-08-19 14:53:08 -0700495 status_t connectHelperLocked(
496 /*out*/
497 sp<Client>& client,
498 /*in*/
499 const sp<ICameraClient>& cameraClient,
500 int cameraId,
501 const String16& clientPackageName,
502 int clientUid,
503 int callingPid,
504 int halVersion = CAMERA_HAL_API_VERSION_UNSPECIFIED,
505 bool legacyMode = false);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700506};
507
508} // namespace android
509
510#endif