Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright (C) 2008, The Android Open Source Project |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef ANDROID_SERVERS_CAMERA_CAMERASERVICE_H |
| 19 | #define ANDROID_SERVERS_CAMERA_CAMERASERVICE_H |
| 20 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 21 | #include <utils/Vector.h> |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 22 | #include <binder/AppOpsManager.h> |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 23 | #include <binder/BinderService.h> |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 24 | #include <binder/IAppOpsCallback.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 25 | #include <camera/ICameraService.h> |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 26 | #include <hardware/camera.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 27 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 28 | #include <camera/ICamera.h> |
| 29 | #include <camera/ICameraClient.h> |
| 30 | #include <camera/IProCameraUser.h> |
| 31 | #include <camera/IProCameraCallbacks.h> |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame^] | 32 | #include <camera/camera2/ICameraDeviceUser.h> |
| 33 | #include <camera/camera2/ICameraDeviceCallbacks.h> |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 34 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 35 | #include <camera/ICameraServiceListener.h> |
| 36 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 37 | /* This needs to be increased if we can have more cameras */ |
| 38 | #define MAX_CAMERAS 2 |
| 39 | |
| 40 | namespace android { |
| 41 | |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 42 | extern volatile int32_t gLogLevel; |
| 43 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 44 | class MemoryHeapBase; |
| 45 | class MediaPlayer; |
| 46 | |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 47 | class CameraService : |
| 48 | public BinderService<CameraService>, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 49 | public BnCameraService, |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 50 | public IBinder::DeathRecipient, |
| 51 | public camera_module_callbacks_t |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 52 | { |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 53 | friend class BinderService<CameraService>; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 54 | public: |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 55 | class Client; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 56 | class BasicClient; |
| 57 | |
| 58 | // Implementation of BinderService<T> |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 59 | static char const* getServiceName() { return "media.camera"; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 60 | |
| 61 | CameraService(); |
| 62 | virtual ~CameraService(); |
| 63 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 64 | ///////////////////////////////////////////////////////////////////// |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 65 | // HAL Callbacks |
| 66 | virtual void onDeviceStatusChanged(int cameraId, |
| 67 | int newStatus); |
| 68 | |
| 69 | ///////////////////////////////////////////////////////////////////// |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 70 | // ICameraService |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 71 | virtual int32_t getNumberOfCameras(); |
| 72 | virtual status_t getCameraInfo(int cameraId, |
| 73 | struct CameraInfo* cameraInfo); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 74 | |
| 75 | virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId, |
| 76 | const String16& clientPackageName, int clientUid); |
| 77 | virtual sp<IProCameraUser> connect(const sp<IProCameraCallbacks>& cameraCb, |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 78 | int cameraId, const String16& clientPackageName, int clientUid); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 79 | virtual sp<ICameraDeviceUser> connect( |
| 80 | const sp<ICameraDeviceCallbacks>& cameraCb, |
| 81 | int cameraId, |
| 82 | const String16& clientPackageName, |
| 83 | int clientUid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 84 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 85 | virtual status_t addListener(const sp<ICameraServiceListener>& listener); |
| 86 | virtual status_t removeListener( |
| 87 | const sp<ICameraServiceListener>& listener); |
| 88 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 89 | // Extra permissions checks |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 90 | virtual status_t onTransact(uint32_t code, const Parcel& data, |
| 91 | Parcel* reply, uint32_t flags); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 92 | |
| 93 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 94 | |
| 95 | ///////////////////////////////////////////////////////////////////// |
| 96 | // Client functionality |
| 97 | virtual void removeClientByRemote(const wp<IBinder>& remoteBinder); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 98 | |
| 99 | enum sound_kind { |
| 100 | SOUND_SHUTTER = 0, |
| 101 | SOUND_RECORDING = 1, |
| 102 | NUM_SOUNDS |
| 103 | }; |
| 104 | |
| 105 | void loadSound(); |
| 106 | void playSound(sound_kind kind); |
| 107 | void releaseSound(); |
| 108 | |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 109 | ///////////////////////////////////////////////////////////////////// |
| 110 | // CameraDeviceFactory functionality |
| 111 | int getDeviceVersion(int cameraId, int* facing = NULL); |
| 112 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 113 | |
| 114 | ///////////////////////////////////////////////////////////////////// |
| 115 | // CameraClient functionality |
| 116 | |
| 117 | // returns plain pointer of client. Note that mClientLock should be acquired to |
| 118 | // prevent the client from destruction. The result can be NULL. |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 119 | virtual BasicClient* getClientByIdUnsafe(int cameraId); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 120 | virtual Mutex* getClientLockById(int cameraId); |
| 121 | |
| 122 | class BasicClient : public virtual RefBase { |
| 123 | public: |
| 124 | virtual status_t initialize(camera_module_t *module) = 0; |
| 125 | |
| 126 | virtual void disconnect() = 0; |
| 127 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 128 | // because we can't virtually inherit IInterface, which breaks |
| 129 | // virtual inheritance |
| 130 | virtual sp<IBinder> asBinderWrapper() = 0; |
| 131 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 132 | // Return the remote callback binder object (e.g. IProCameraCallbacks) |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 133 | sp<IBinder> getRemote() { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 134 | return mRemoteBinder; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 137 | virtual status_t dump(int fd, const Vector<String16>& args) = 0; |
| 138 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 139 | protected: |
| 140 | BasicClient(const sp<CameraService>& cameraService, |
| 141 | const sp<IBinder>& remoteCallback, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 142 | const String16& clientPackageName, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 143 | int cameraId, |
| 144 | int cameraFacing, |
| 145 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 146 | uid_t clientUid, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 147 | int servicePid); |
| 148 | |
| 149 | virtual ~BasicClient(); |
| 150 | |
| 151 | // the instance is in the middle of destruction. When this is set, |
| 152 | // the instance should not be accessed from callback. |
| 153 | // CameraService's mClientLock should be acquired to access this. |
| 154 | // - subclasses should set this to true in their destructors. |
| 155 | bool mDestructionStarted; |
| 156 | |
| 157 | // these are initialized in the constructor. |
| 158 | sp<CameraService> mCameraService; // immutable after constructor |
| 159 | int mCameraId; // immutable after constructor |
| 160 | int mCameraFacing; // immutable after constructor |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 161 | const String16 mClientPackageName; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 162 | pid_t mClientPid; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 163 | uid_t mClientUid; // immutable after constructor |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 164 | pid_t mServicePid; // immutable after constructor |
| 165 | |
| 166 | // - The app-side Binder interface to receive callbacks from us |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 167 | sp<IBinder> mRemoteBinder; // immutable after constructor |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 168 | |
| 169 | // permissions management |
| 170 | status_t startCameraOps(); |
| 171 | status_t finishCameraOps(); |
| 172 | |
| 173 | // Notify client about a fatal error |
| 174 | virtual void notifyError() = 0; |
| 175 | private: |
| 176 | AppOpsManager mAppOpsManager; |
| 177 | |
| 178 | class OpsCallback : public BnAppOpsCallback { |
| 179 | public: |
| 180 | OpsCallback(wp<BasicClient> client); |
| 181 | virtual void opChanged(int32_t op, const String16& packageName); |
| 182 | |
| 183 | private: |
| 184 | wp<BasicClient> mClient; |
| 185 | |
| 186 | }; // class OpsCallback |
| 187 | |
| 188 | sp<OpsCallback> mOpsCallback; |
| 189 | // Track whether startCameraOps was called successfully, to avoid |
| 190 | // finishing what we didn't start. |
| 191 | bool mOpsActive; |
| 192 | |
| 193 | // IAppOpsCallback interface, indirected through opListener |
| 194 | virtual void opChanged(int32_t op, const String16& packageName); |
| 195 | }; // class BasicClient |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 196 | |
| 197 | class Client : public BnCamera, public BasicClient |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 198 | { |
| 199 | public: |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 200 | typedef ICameraClient TCamCallbacks; |
| 201 | |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 202 | // ICamera interface (see ICamera for details) |
| 203 | virtual void disconnect(); |
| 204 | virtual status_t connect(const sp<ICameraClient>& client) = 0; |
| 205 | virtual status_t lock() = 0; |
| 206 | virtual status_t unlock() = 0; |
| 207 | virtual status_t setPreviewDisplay(const sp<Surface>& surface) = 0; |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 208 | virtual status_t setPreviewTexture(const sp<IGraphicBufferProducer>& bufferProducer)=0; |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 209 | virtual void setPreviewCallbackFlag(int flag) = 0; |
Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 210 | virtual status_t setPreviewCallbackTarget( |
| 211 | const sp<IGraphicBufferProducer>& callbackProducer) = 0; |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 212 | virtual status_t startPreview() = 0; |
| 213 | virtual void stopPreview() = 0; |
| 214 | virtual bool previewEnabled() = 0; |
| 215 | virtual status_t storeMetaDataInBuffers(bool enabled) = 0; |
| 216 | virtual status_t startRecording() = 0; |
| 217 | virtual void stopRecording() = 0; |
| 218 | virtual bool recordingEnabled() = 0; |
| 219 | virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0; |
| 220 | virtual status_t autoFocus() = 0; |
| 221 | virtual status_t cancelAutoFocus() = 0; |
| 222 | virtual status_t takePicture(int msgType) = 0; |
| 223 | virtual status_t setParameters(const String8& params) = 0; |
| 224 | virtual String8 getParameters() const = 0; |
| 225 | virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0; |
| 226 | |
| 227 | // Interface used by CameraService |
| 228 | Client(const sp<CameraService>& cameraService, |
| 229 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 230 | const String16& clientPackageName, |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 231 | int cameraId, |
| 232 | int cameraFacing, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 233 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 234 | uid_t clientUid, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 235 | int servicePid); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 236 | ~Client(); |
| 237 | |
| 238 | // return our camera client |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 239 | const sp<ICameraClient>& getRemoteCallback() { |
| 240 | return mRemoteCallback; |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 243 | virtual sp<IBinder> asBinderWrapper() { |
| 244 | return asBinder(); |
| 245 | } |
| 246 | |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 247 | protected: |
| 248 | static Mutex* getClientLockFromCookie(void* user); |
| 249 | // convert client from cookie. Client lock should be acquired before getting Client. |
| 250 | static Client* getClientFromCookie(void* user); |
| 251 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 252 | virtual void notifyError(); |
| 253 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 254 | // Initialized in constructor |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 255 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 256 | // - The app-side Binder interface to receive callbacks from us |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 257 | sp<ICameraClient> mRemoteCallback; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 258 | |
| 259 | }; // class Client |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 260 | |
| 261 | class ProClient : public BnProCameraUser, public BasicClient { |
| 262 | public: |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 263 | typedef IProCameraCallbacks TCamCallbacks; |
| 264 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 265 | ProClient(const sp<CameraService>& cameraService, |
| 266 | const sp<IProCameraCallbacks>& remoteCallback, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 267 | const String16& clientPackageName, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 268 | int cameraId, |
| 269 | int cameraFacing, |
| 270 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 271 | uid_t clientUid, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 272 | int servicePid); |
| 273 | |
| 274 | virtual ~ProClient(); |
| 275 | |
| 276 | const sp<IProCameraCallbacks>& getRemoteCallback() { |
| 277 | return mRemoteCallback; |
| 278 | } |
| 279 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 280 | /*** |
| 281 | IProCamera implementation |
| 282 | ***/ |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 283 | virtual status_t connect(const sp<IProCameraCallbacks>& callbacks) |
| 284 | = 0; |
| 285 | virtual status_t exclusiveTryLock() = 0; |
| 286 | virtual status_t exclusiveLock() = 0; |
| 287 | virtual status_t exclusiveUnlock() = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 288 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 289 | virtual bool hasExclusiveLock() = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 290 | |
| 291 | // Note that the callee gets a copy of the metadata. |
| 292 | virtual int submitRequest(camera_metadata_t* metadata, |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 293 | bool streaming = false) = 0; |
| 294 | virtual status_t cancelRequest(int requestId) = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 295 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 296 | // Callbacks from camera service |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 297 | virtual void onExclusiveLockStolen() = 0; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 298 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 299 | protected: |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 300 | virtual void notifyError(); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 301 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 302 | sp<IProCameraCallbacks> mRemoteCallback; |
| 303 | }; // class ProClient |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 304 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 305 | private: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 306 | |
| 307 | // Delay-load the Camera HAL module |
| 308 | virtual void onFirstRef(); |
| 309 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 310 | // Step 1. Check if we can connect, before we acquire the service lock. |
| 311 | bool validateConnect(int cameraId, |
| 312 | /*inout*/ |
| 313 | int& clientUid) const; |
| 314 | |
| 315 | // Step 2. Check if we can connect, after we acquire the service lock. |
| 316 | bool canConnectUnsafe(int cameraId, |
| 317 | const String16& clientPackageName, |
| 318 | const sp<IBinder>& remoteCallback, |
| 319 | /*out*/ |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 320 | sp<BasicClient> &client); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 321 | |
| 322 | // When connection is successful, initialize client and track its death |
| 323 | bool connectFinishUnsafe(const sp<BasicClient>& client, |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 324 | const sp<IBinder>& remoteCallback); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 325 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 326 | virtual sp<BasicClient> getClientByRemote(const wp<IBinder>& cameraClient); |
| 327 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 328 | Mutex mServiceLock; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 329 | // either a Client or CameraDeviceClient |
| 330 | wp<BasicClient> mClient[MAX_CAMERAS]; // protected by mServiceLock |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 331 | Mutex mClientLock[MAX_CAMERAS]; // prevent Client destruction inside callbacks |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 332 | int mNumberOfCameras; |
| 333 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 334 | typedef wp<ProClient> weak_pro_client_ptr; |
| 335 | Vector<weak_pro_client_ptr> mProClientList[MAX_CAMERAS]; |
| 336 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 337 | // needs to be called with mServiceLock held |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 338 | sp<BasicClient> findClientUnsafe(const wp<IBinder>& cameraClient, int& outIndex); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 339 | sp<ProClient> findProClientUnsafe( |
| 340 | const wp<IBinder>& cameraCallbacksRemote); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 341 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 342 | // atomics to record whether the hardware is allocated to some client. |
| 343 | volatile int32_t mBusy[MAX_CAMERAS]; |
| 344 | void setCameraBusy(int cameraId); |
| 345 | void setCameraFree(int cameraId); |
| 346 | |
| 347 | // sounds |
Chih-Chung Chang | ff4f55c | 2011-10-17 19:03:12 +0800 | [diff] [blame] | 348 | MediaPlayer* newMediaPlayer(const char *file); |
| 349 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 350 | Mutex mSoundLock; |
| 351 | sp<MediaPlayer> mSoundPlayer[NUM_SOUNDS]; |
| 352 | int mSoundRef; // reference count (release all MediaPlayer when 0) |
| 353 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 354 | camera_module_t *mModule; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 355 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 356 | Vector<sp<ICameraServiceListener> > |
| 357 | mListenerList; |
| 358 | |
| 359 | // guard only mStatusList and the broadcasting of ICameraServiceListener |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 360 | mutable Mutex mStatusMutex; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 361 | ICameraServiceListener::Status |
| 362 | mStatusList[MAX_CAMERAS]; |
| 363 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 364 | // Read the current status (locks mStatusMutex) |
| 365 | ICameraServiceListener::Status |
| 366 | getStatus(int cameraId) const; |
| 367 | |
Igor Murashkin | 93747b9 | 2013-05-01 15:42:20 -0700 | [diff] [blame] | 368 | typedef Vector<ICameraServiceListener::Status> StatusVector; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 369 | // Broadcast the new status if it changed (locks the service mutex) |
| 370 | void updateStatus( |
| 371 | ICameraServiceListener::Status status, |
Igor Murashkin | 93747b9 | 2013-05-01 15:42:20 -0700 | [diff] [blame] | 372 | int32_t cameraId, |
| 373 | const StatusVector *rejectSourceStates = NULL); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 374 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 375 | // IBinder::DeathRecipient implementation |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 376 | virtual void binderDied(const wp<IBinder> &who); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 377 | |
| 378 | // Helpers |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 379 | |
| 380 | bool isValidCameraId(int cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 381 | }; |
| 382 | |
| 383 | } // namespace android |
| 384 | |
| 385 | #endif |