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 | #define LOG_TAG "CameraService" |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <pthread.h> |
| 24 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 25 | #include <binder/AppOpsManager.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 26 | #include <binder/IPCThreadState.h> |
| 27 | #include <binder/IServiceManager.h> |
| 28 | #include <binder/MemoryBase.h> |
| 29 | #include <binder/MemoryHeapBase.h> |
| 30 | #include <cutils/atomic.h> |
Nipun Kwatra | b5ca461 | 2010-09-11 19:31:10 -0700 | [diff] [blame] | 31 | #include <cutils/properties.h> |
Mathias Agopian | df712ea | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 32 | #include <gui/Surface.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 33 | #include <hardware/hardware.h> |
| 34 | #include <media/AudioSystem.h> |
| 35 | #include <media/mediaplayer.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 36 | #include <utils/Errors.h> |
| 37 | #include <utils/Log.h> |
| 38 | #include <utils/String16.h> |
| 39 | |
| 40 | #include "CameraService.h" |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 41 | #include "CameraClient.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 42 | #include "Camera2Client.h" |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 43 | #include "ProCamera2Client.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 44 | |
| 45 | namespace android { |
| 46 | |
| 47 | // ---------------------------------------------------------------------------- |
| 48 | // Logging support -- this is for debugging only |
| 49 | // Use "adb shell dumpsys media.camera -v 1" to change it. |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 50 | volatile int32_t gLogLevel = 0; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 51 | |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 52 | #define LOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__); |
| 53 | #define LOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 54 | |
| 55 | static void setLogLevel(int level) { |
| 56 | android_atomic_write(level, &gLogLevel); |
| 57 | } |
| 58 | |
| 59 | // ---------------------------------------------------------------------------- |
| 60 | |
| 61 | static int getCallingPid() { |
| 62 | return IPCThreadState::self()->getCallingPid(); |
| 63 | } |
| 64 | |
| 65 | static int getCallingUid() { |
| 66 | return IPCThreadState::self()->getCallingUid(); |
| 67 | } |
| 68 | |
| 69 | // ---------------------------------------------------------------------------- |
| 70 | |
| 71 | // This is ugly and only safe if we never re-create the CameraService, but |
| 72 | // should be ok for now. |
| 73 | static CameraService *gCameraService; |
| 74 | |
| 75 | CameraService::CameraService() |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 76 | :mSoundRef(0), mModule(0) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 77 | { |
Steve Block | df64d15 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 78 | ALOGI("CameraService started (pid=%d)", getpid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 79 | gCameraService = this; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 80 | |
| 81 | for (size_t i = 0; i < MAX_CAMERAS; ++i) { |
| 82 | mStatusList[i] = ICameraServiceListener::STATUS_AVAILABLE; |
| 83 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 86 | void CameraService::onFirstRef() |
| 87 | { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 88 | LOG1("CameraService::onFirstRef"); |
| 89 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 90 | BnCameraService::onFirstRef(); |
| 91 | |
| 92 | if (hw_get_module(CAMERA_HARDWARE_MODULE_ID, |
| 93 | (const hw_module_t **)&mModule) < 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 94 | ALOGE("Could not load camera HAL module"); |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 95 | mNumberOfCameras = 0; |
| 96 | } |
| 97 | else { |
Alex Ray | c0dd54f | 2013-02-20 13:39:37 -0800 | [diff] [blame] | 98 | ALOGI("Loaded \"%s\" camera module", mModule->common.name); |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 99 | mNumberOfCameras = mModule->get_number_of_cameras(); |
| 100 | if (mNumberOfCameras > MAX_CAMERAS) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 101 | ALOGE("Number of cameras(%d) > MAX_CAMERAS(%d).", |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 102 | mNumberOfCameras, MAX_CAMERAS); |
| 103 | mNumberOfCameras = MAX_CAMERAS; |
| 104 | } |
| 105 | for (int i = 0; i < mNumberOfCameras; i++) { |
| 106 | setCameraFree(i); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 111 | CameraService::~CameraService() { |
| 112 | for (int i = 0; i < mNumberOfCameras; i++) { |
| 113 | if (mBusy[i]) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 114 | ALOGE("camera %d is still in use in destructor!", i); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
| 118 | gCameraService = NULL; |
| 119 | } |
| 120 | |
| 121 | int32_t CameraService::getNumberOfCameras() { |
| 122 | return mNumberOfCameras; |
| 123 | } |
| 124 | |
| 125 | status_t CameraService::getCameraInfo(int cameraId, |
| 126 | struct CameraInfo* cameraInfo) { |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 127 | if (!mModule) { |
| 128 | return NO_INIT; |
| 129 | } |
| 130 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 131 | if (cameraId < 0 || cameraId >= mNumberOfCameras) { |
| 132 | return BAD_VALUE; |
| 133 | } |
| 134 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 135 | struct camera_info info; |
| 136 | status_t rc = mModule->get_camera_info(cameraId, &info); |
| 137 | cameraInfo->facing = info.facing; |
| 138 | cameraInfo->orientation = info.orientation; |
| 139 | return rc; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 142 | int CameraService::getDeviceVersion(int cameraId, int* facing) { |
| 143 | struct camera_info info; |
| 144 | if (mModule->get_camera_info(cameraId, &info) != OK) { |
| 145 | return -1; |
| 146 | } |
| 147 | |
| 148 | int deviceVersion; |
| 149 | if (mModule->common.module_api_version >= CAMERA_MODULE_API_VERSION_2_0) { |
| 150 | deviceVersion = info.device_version; |
| 151 | } else { |
| 152 | deviceVersion = CAMERA_DEVICE_API_VERSION_1_0; |
| 153 | } |
| 154 | |
| 155 | if (facing) { |
| 156 | *facing = info.facing; |
| 157 | } |
| 158 | |
| 159 | return deviceVersion; |
| 160 | } |
| 161 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 162 | bool CameraService::isValidCameraId(int cameraId) { |
| 163 | int facing; |
| 164 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
| 165 | |
| 166 | switch(deviceVersion) { |
| 167 | case CAMERA_DEVICE_API_VERSION_1_0: |
| 168 | case CAMERA_DEVICE_API_VERSION_2_0: |
| 169 | case CAMERA_DEVICE_API_VERSION_2_1: |
| 170 | case CAMERA_DEVICE_API_VERSION_3_0: |
| 171 | return true; |
| 172 | default: |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | return false; |
| 177 | } |
| 178 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 179 | bool CameraService::validateConnect(int cameraId, |
| 180 | /*inout*/ |
| 181 | int& clientUid) const { |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 182 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 183 | int callingPid = getCallingPid(); |
Tyler Luu | 5861a9a | 2011-10-06 00:00:03 -0500 | [diff] [blame] | 184 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 185 | if (clientUid == USE_CALLING_UID) { |
| 186 | clientUid = getCallingUid(); |
| 187 | } else { |
| 188 | // We only trust our own process to forward client UIDs |
| 189 | if (callingPid != getpid()) { |
| 190 | ALOGE("CameraService::connect X (pid %d) rejected (don't trust clientUid)", |
| 191 | callingPid); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 192 | return false; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 193 | } |
| 194 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 195 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 196 | if (!mModule) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 197 | ALOGE("Camera HAL module not loaded"); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 198 | return false; |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 201 | if (cameraId < 0 || cameraId >= mNumberOfCameras) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 202 | ALOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).", |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 203 | callingPid, cameraId); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 204 | return false; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Wu-cheng Li | a335543 | 2011-05-20 14:54:25 +0800 | [diff] [blame] | 207 | char value[PROPERTY_VALUE_MAX]; |
| 208 | property_get("sys.secpolicy.camera.disabled", value, "0"); |
| 209 | if (strcmp(value, "1") == 0) { |
| 210 | // Camera is disabled by DevicePolicyManager. |
Steve Block | df64d15 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 211 | ALOGI("Camera is disabled. connect X (pid %d) rejected", callingPid); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 212 | return false; |
Wu-cheng Li | a335543 | 2011-05-20 14:54:25 +0800 | [diff] [blame] | 213 | } |
| 214 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 215 | return true; |
| 216 | } |
| 217 | |
| 218 | bool CameraService::canConnectUnsafe(int cameraId, |
| 219 | const String16& clientPackageName, |
| 220 | const sp<IBinder>& remoteCallback, |
| 221 | sp<Client> &client) { |
| 222 | String8 clientName8(clientPackageName); |
| 223 | int callingPid = getCallingPid(); |
| 224 | |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 225 | if (mClient[cameraId] != 0) { |
| 226 | client = mClient[cameraId].promote(); |
| 227 | if (client != 0) { |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 228 | if (remoteCallback == client->getRemoteCallback()->asBinder()) { |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 229 | LOG1("CameraService::connect X (pid %d) (the same client)", |
| 230 | callingPid); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 231 | return true; |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 232 | } else { |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 233 | // TODOSC: need to support 1 regular client, |
| 234 | // multiple shared clients here |
| 235 | ALOGW("CameraService::connect X (pid %d) rejected" |
| 236 | " (existing client).", callingPid); |
| 237 | return false; |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 238 | } |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 239 | } |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 240 | mClient[cameraId].clear(); |
| 241 | } |
| 242 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 243 | /* |
| 244 | mBusy is set to false as the last step of the Client destructor, |
| 245 | after which it is guaranteed that the Client destructor has finished ( |
| 246 | including any inherited destructors) |
| 247 | |
| 248 | We only need this for a Client subclasses since we don't allow |
| 249 | multiple Clents to be opened concurrently, but multiple BasicClient |
| 250 | would be fine |
| 251 | */ |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 252 | if (mBusy[cameraId]) { |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 253 | ALOGW("CameraService::connect X (pid %d, \"%s\") rejected" |
| 254 | " (camera %d is still busy).", callingPid, |
| 255 | clientName8.string(), cameraId); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 256 | return false; |
| 257 | } |
| 258 | |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | sp<ICamera> CameraService::connect( |
| 263 | const sp<ICameraClient>& cameraClient, |
| 264 | int cameraId, |
| 265 | const String16& clientPackageName, |
| 266 | int clientUid) { |
| 267 | |
| 268 | String8 clientName8(clientPackageName); |
| 269 | int callingPid = getCallingPid(); |
| 270 | |
| 271 | LOG1("CameraService::connect E (pid %d \"%s\", id %d)", callingPid, |
| 272 | clientName8.string(), cameraId); |
| 273 | |
| 274 | if (!validateConnect(cameraId, /*inout*/clientUid)) { |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 275 | return NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 278 | sp<Client> client; |
| 279 | |
| 280 | Mutex::Autolock lock(mServiceLock); |
| 281 | if (!canConnectUnsafe(cameraId, clientPackageName, |
| 282 | cameraClient->asBinder(), |
| 283 | /*out*/client)) { |
| 284 | return NULL; |
| 285 | } else if (client.get() != NULL) { |
| 286 | return client; |
| 287 | } |
| 288 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 289 | int facing = -1; |
| 290 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 291 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 292 | // If there are other non-exclusive users of the camera, |
| 293 | // this will tear them down before we can reuse the camera |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 294 | if (isValidCameraId(cameraId)) { |
| 295 | updateStatus(ICameraServiceListener::STATUS_NOT_AVAILABLE, cameraId); |
| 296 | } |
| 297 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 298 | switch(deviceVersion) { |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 299 | case CAMERA_DEVICE_API_VERSION_1_0: |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 300 | client = new CameraClient(this, cameraClient, |
| 301 | clientPackageName, cameraId, |
| 302 | facing, callingPid, clientUid, getpid()); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 303 | break; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 304 | case CAMERA_DEVICE_API_VERSION_2_0: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 305 | case CAMERA_DEVICE_API_VERSION_2_1: |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 306 | case CAMERA_DEVICE_API_VERSION_3_0: |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 307 | client = new Camera2Client(this, cameraClient, |
| 308 | clientPackageName, cameraId, |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 309 | facing, callingPid, clientUid, getpid(), |
| 310 | deviceVersion); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 311 | break; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 312 | case -1: |
| 313 | ALOGE("Invalid camera id %d", cameraId); |
| 314 | return NULL; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 315 | default: |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 316 | ALOGE("Unknown camera device HAL version: %d", deviceVersion); |
Tyler Luu | 5861a9a | 2011-10-06 00:00:03 -0500 | [diff] [blame] | 317 | return NULL; |
| 318 | } |
| 319 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 320 | if (!connectFinishUnsafe(client, client->asBinder())) { |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 321 | // this is probably not recoverable.. but maybe the client can try again |
| 322 | updateStatus(ICameraServiceListener::STATUS_AVAILABLE, cameraId); |
| 323 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 324 | return NULL; |
| 325 | } |
| 326 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 327 | mClient[cameraId] = client; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 328 | LOG1("CameraService::connect X (id %d, this pid is %d)", cameraId, getpid()); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 329 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 330 | return client; |
| 331 | } |
| 332 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 333 | bool CameraService::connectFinishUnsafe(const sp<BasicClient>& client, |
| 334 | const sp<IBinder>& clientBinder) { |
| 335 | if (client->initialize(mModule) != OK) { |
| 336 | return false; |
| 337 | } |
| 338 | |
| 339 | clientBinder->linkToDeath(this); |
| 340 | |
| 341 | return true; |
| 342 | } |
| 343 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 344 | sp<IProCameraUser> CameraService::connect( |
| 345 | const sp<IProCameraCallbacks>& cameraCb, |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 346 | int cameraId, |
| 347 | const String16& clientPackageName, |
| 348 | int clientUid) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 349 | { |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 350 | String8 clientName8(clientPackageName); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 351 | int callingPid = getCallingPid(); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 352 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 353 | LOG1("CameraService::connectPro E (pid %d \"%s\", id %d)", callingPid, |
| 354 | clientName8.string(), cameraId); |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 355 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 356 | if (!validateConnect(cameraId, /*inout*/clientUid)) { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 357 | return NULL; |
| 358 | } |
| 359 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 360 | Mutex::Autolock lock(mServiceLock); |
| 361 | { |
| 362 | sp<Client> client; |
| 363 | if (!canConnectUnsafe(cameraId, clientPackageName, |
| 364 | cameraCb->asBinder(), |
| 365 | /*out*/client)) { |
| 366 | return NULL; |
| 367 | } |
| 368 | } |
| 369 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 370 | sp<ProClient> client; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 371 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 372 | int facing = -1; |
| 373 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
| 374 | |
| 375 | switch(deviceVersion) { |
| 376 | case CAMERA_DEVICE_API_VERSION_1_0: |
| 377 | ALOGE("Camera id %d uses HALv1, doesn't support ProCamera", cameraId); |
| 378 | return NULL; |
| 379 | break; |
| 380 | case CAMERA_DEVICE_API_VERSION_2_0: |
Igor Murashkin | 985fd30 | 2013-02-20 18:24:43 -0800 | [diff] [blame] | 381 | case CAMERA_DEVICE_API_VERSION_2_1: |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 382 | client = new ProCamera2Client(this, cameraCb, String16(), |
| 383 | cameraId, facing, callingPid, USE_CALLING_UID, getpid()); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 384 | break; |
| 385 | case -1: |
| 386 | ALOGE("Invalid camera id %d", cameraId); |
| 387 | return NULL; |
| 388 | default: |
| 389 | ALOGE("Unknown camera device HAL version: %d", deviceVersion); |
| 390 | return NULL; |
| 391 | } |
| 392 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 393 | if (!connectFinishUnsafe(client, client->asBinder())) { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 394 | return NULL; |
| 395 | } |
| 396 | |
| 397 | mProClientList[cameraId].push(client); |
| 398 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 399 | LOG1("CameraService::connectPro X (id %d, this pid is %d)", cameraId, |
| 400 | getpid()); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 401 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 402 | return client; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 403 | } |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 404 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 405 | status_t CameraService::addListener( |
| 406 | const sp<ICameraServiceListener>& listener) { |
| 407 | ALOGV("%s: Add listener %p", __FUNCTION__, listener.get()); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 408 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 409 | Mutex::Autolock lock(mServiceLock); |
| 410 | |
| 411 | Vector<sp<ICameraServiceListener> >::iterator it, end; |
| 412 | for (it = mListenerList.begin(); it != mListenerList.end(); ++it) { |
| 413 | if ((*it)->asBinder() == listener->asBinder()) { |
| 414 | ALOGW("%s: Tried to add listener %p which was already subscribed", |
| 415 | __FUNCTION__, listener.get()); |
| 416 | return ALREADY_EXISTS; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | mListenerList.push_back(listener); |
| 421 | |
| 422 | return OK; |
| 423 | } |
| 424 | status_t CameraService::removeListener( |
| 425 | const sp<ICameraServiceListener>& listener) { |
| 426 | ALOGV("%s: Remove listener %p", __FUNCTION__, listener.get()); |
| 427 | |
| 428 | Mutex::Autolock lock(mServiceLock); |
| 429 | |
| 430 | Vector<sp<ICameraServiceListener> >::iterator it; |
| 431 | for (it = mListenerList.begin(); it != mListenerList.end(); ++it) { |
| 432 | if ((*it)->asBinder() == listener->asBinder()) { |
| 433 | mListenerList.erase(it); |
| 434 | return OK; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | ALOGW("%s: Tried to remove a listener %p which was not subscribed", |
| 439 | __FUNCTION__, listener.get()); |
| 440 | |
| 441 | return BAD_VALUE; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | void CameraService::removeClientByRemote(const wp<IBinder>& remoteBinder) { |
| 445 | int callingPid = getCallingPid(); |
| 446 | LOG1("CameraService::removeClientByRemote E (pid %d)", callingPid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 447 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 448 | // Declare this before the lock to make absolutely sure the |
| 449 | // destructor won't be called with the lock held. |
| 450 | Mutex::Autolock lock(mServiceLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 451 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 452 | int outIndex; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 453 | sp<Client> client = findClientUnsafe(remoteBinder, outIndex); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 454 | |
| 455 | if (client != 0) { |
| 456 | // Found our camera, clear and leave. |
| 457 | LOG1("removeClient: clear camera %d", outIndex); |
| 458 | mClient[outIndex].clear(); |
| 459 | |
| 460 | client->unlinkToDeath(this); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 461 | } else { |
| 462 | |
| 463 | sp<ProClient> clientPro = findProClientUnsafe(remoteBinder); |
| 464 | |
| 465 | if (clientPro != NULL) { |
| 466 | // Found our camera, clear and leave. |
| 467 | LOG1("removeClient: clear pro %p", clientPro.get()); |
| 468 | |
| 469 | clientPro->getRemoteCallback()->asBinder()->unlinkToDeath(this); |
| 470 | } |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 473 | LOG1("CameraService::removeClientByRemote X (pid %d)", callingPid); |
| 474 | } |
| 475 | |
| 476 | sp<CameraService::ProClient> CameraService::findProClientUnsafe( |
| 477 | const wp<IBinder>& cameraCallbacksRemote) |
| 478 | { |
| 479 | sp<ProClient> clientPro; |
| 480 | |
| 481 | for (int i = 0; i < mNumberOfCameras; ++i) { |
| 482 | Vector<size_t> removeIdx; |
| 483 | |
| 484 | for (size_t j = 0; j < mProClientList[i].size(); ++j) { |
| 485 | wp<ProClient> cl = mProClientList[i][j]; |
| 486 | |
| 487 | sp<ProClient> clStrong = cl.promote(); |
| 488 | if (clStrong != NULL && clStrong->getRemote() == cameraCallbacksRemote) { |
| 489 | clientPro = clStrong; |
| 490 | break; |
| 491 | } else if (clStrong == NULL) { |
| 492 | // mark to clean up dead ptr |
| 493 | removeIdx.push(j); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | // remove stale ptrs (in reverse so the indices dont change) |
| 498 | for (ssize_t j = (ssize_t)removeIdx.size() - 1; j >= 0; --j) { |
| 499 | mProClientList[i].removeAt(removeIdx[j]); |
| 500 | } |
| 501 | |
| 502 | } |
| 503 | |
| 504 | return clientPro; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | sp<CameraService::Client> CameraService::findClientUnsafe( |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 508 | const wp<IBinder>& cameraClient, int& outIndex) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 509 | sp<Client> client; |
| 510 | |
| 511 | for (int i = 0; i < mNumberOfCameras; i++) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 512 | |
| 513 | // This happens when we have already disconnected (or this is |
| 514 | // just another unused camera). |
| 515 | if (mClient[i] == 0) continue; |
| 516 | |
| 517 | // Promote mClient. It can fail if we are called from this path: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 518 | // Client::~Client() -> disconnect() -> removeClientByRemote(). |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 519 | client = mClient[i].promote(); |
| 520 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 521 | // Clean up stale client entry |
| 522 | if (client == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 523 | mClient[i].clear(); |
| 524 | continue; |
| 525 | } |
| 526 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 527 | if (cameraClient == client->getRemoteCallback()->asBinder()) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 528 | // Found our camera |
| 529 | outIndex = i; |
| 530 | return client; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 534 | outIndex = -1; |
| 535 | return NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 538 | CameraService::Client* CameraService::getClientByIdUnsafe(int cameraId) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 539 | if (cameraId < 0 || cameraId >= mNumberOfCameras) return NULL; |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 540 | return mClient[cameraId].unsafe_get(); |
| 541 | } |
| 542 | |
| 543 | Mutex* CameraService::getClientLockById(int cameraId) { |
| 544 | if (cameraId < 0 || cameraId >= mNumberOfCameras) return NULL; |
| 545 | return &mClientLock[cameraId]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 548 | sp<CameraService::BasicClient> CameraService::getClientByRemote( |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 549 | const wp<IBinder>& cameraClient) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 550 | |
| 551 | // Declare this before the lock to make absolutely sure the |
| 552 | // destructor won't be called with the lock held. |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 553 | sp<BasicClient> client; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 554 | |
| 555 | Mutex::Autolock lock(mServiceLock); |
| 556 | |
| 557 | int outIndex; |
| 558 | client = findClientUnsafe(cameraClient, outIndex); |
| 559 | |
| 560 | return client; |
| 561 | } |
| 562 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 563 | status_t CameraService::onTransact( |
| 564 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 565 | // Permission checks |
| 566 | switch (code) { |
| 567 | case BnCameraService::CONNECT: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 568 | case BnCameraService::CONNECT_PRO: |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 569 | const int pid = getCallingPid(); |
| 570 | const int self_pid = getpid(); |
| 571 | if (pid != self_pid) { |
| 572 | // we're called from a different process, do the real check |
| 573 | if (!checkCallingPermission( |
| 574 | String16("android.permission.CAMERA"))) { |
| 575 | const int uid = getCallingUid(); |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 576 | ALOGE("Permission Denial: " |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 577 | "can't use the camera pid=%d, uid=%d", pid, uid); |
| 578 | return PERMISSION_DENIED; |
| 579 | } |
| 580 | } |
| 581 | break; |
| 582 | } |
| 583 | |
| 584 | return BnCameraService::onTransact(code, data, reply, flags); |
| 585 | } |
| 586 | |
| 587 | // The reason we need this busy bit is a new CameraService::connect() request |
| 588 | // may come in while the previous Client's destructor has not been run or is |
| 589 | // still running. If the last strong reference of the previous Client is gone |
| 590 | // but the destructor has not been finished, we should not allow the new Client |
| 591 | // to be created because we need to wait for the previous Client to tear down |
| 592 | // the hardware first. |
| 593 | void CameraService::setCameraBusy(int cameraId) { |
| 594 | android_atomic_write(1, &mBusy[cameraId]); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 595 | |
| 596 | ALOGV("setCameraBusy cameraId=%d", cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | void CameraService::setCameraFree(int cameraId) { |
| 600 | android_atomic_write(0, &mBusy[cameraId]); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 601 | |
| 602 | ALOGV("setCameraFree cameraId=%d", cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | // We share the media players for shutter and recording sound for all clients. |
| 606 | // A reference count is kept to determine when we will actually release the |
| 607 | // media players. |
| 608 | |
Chih-Chung Chang | ff4f55c | 2011-10-17 19:03:12 +0800 | [diff] [blame] | 609 | MediaPlayer* CameraService::newMediaPlayer(const char *file) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 610 | MediaPlayer* mp = new MediaPlayer(); |
| 611 | if (mp->setDataSource(file, NULL) == NO_ERROR) { |
Eino-Ville Talvala | 60a78ac | 2012-01-05 15:34:53 -0800 | [diff] [blame] | 612 | mp->setAudioStreamType(AUDIO_STREAM_ENFORCED_AUDIBLE); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 613 | mp->prepare(); |
| 614 | } else { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 615 | ALOGE("Failed to load CameraService sounds: %s", file); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 616 | return NULL; |
| 617 | } |
| 618 | return mp; |
| 619 | } |
| 620 | |
| 621 | void CameraService::loadSound() { |
| 622 | Mutex::Autolock lock(mSoundLock); |
| 623 | LOG1("CameraService::loadSound ref=%d", mSoundRef); |
| 624 | if (mSoundRef++) return; |
| 625 | |
| 626 | mSoundPlayer[SOUND_SHUTTER] = newMediaPlayer("/system/media/audio/ui/camera_click.ogg"); |
| 627 | mSoundPlayer[SOUND_RECORDING] = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg"); |
| 628 | } |
| 629 | |
| 630 | void CameraService::releaseSound() { |
| 631 | Mutex::Autolock lock(mSoundLock); |
| 632 | LOG1("CameraService::releaseSound ref=%d", mSoundRef); |
| 633 | if (--mSoundRef) return; |
| 634 | |
| 635 | for (int i = 0; i < NUM_SOUNDS; i++) { |
| 636 | if (mSoundPlayer[i] != 0) { |
| 637 | mSoundPlayer[i]->disconnect(); |
| 638 | mSoundPlayer[i].clear(); |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | void CameraService::playSound(sound_kind kind) { |
| 644 | LOG1("playSound(%d)", kind); |
| 645 | Mutex::Autolock lock(mSoundLock); |
| 646 | sp<MediaPlayer> player = mSoundPlayer[kind]; |
| 647 | if (player != 0) { |
Chih-Chung Chang | 8888a75 | 2011-10-20 10:47:26 +0800 | [diff] [blame] | 648 | player->seekTo(0); |
| 649 | player->start(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | |
| 653 | // ---------------------------------------------------------------------------- |
| 654 | |
| 655 | CameraService::Client::Client(const sp<CameraService>& cameraService, |
Wu-cheng Li | b7a6794 | 2010-08-17 15:45:37 -0700 | [diff] [blame] | 656 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 657 | const String16& clientPackageName, |
| 658 | int cameraId, int cameraFacing, |
| 659 | int clientPid, uid_t clientUid, |
| 660 | int servicePid) : |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 661 | CameraService::BasicClient(cameraService, cameraClient->asBinder(), |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 662 | clientPackageName, |
| 663 | cameraId, cameraFacing, |
| 664 | clientPid, clientUid, |
| 665 | servicePid) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 666 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 667 | int callingPid = getCallingPid(); |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 668 | LOG1("Client::Client E (pid %d, id %d)", callingPid, cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 669 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 670 | mRemoteCallback = cameraClient; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 671 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 672 | cameraService->setCameraBusy(cameraId); |
| 673 | cameraService->loadSound(); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 674 | |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 675 | LOG1("Client::Client X (pid %d, id %d)", callingPid, cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 678 | // tear down the client |
| 679 | CameraService::Client::~Client() { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 680 | mDestructionStarted = true; |
| 681 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 682 | mCameraService->releaseSound(); |
Igor Murashkin | 036bc3e | 2012-10-08 15:09:46 -0700 | [diff] [blame] | 683 | // unconditionally disconnect. function is idempotent |
| 684 | Client::disconnect(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 687 | CameraService::BasicClient::BasicClient(const sp<CameraService>& cameraService, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 688 | const sp<IBinder>& remoteCallback, |
| 689 | const String16& clientPackageName, |
| 690 | int cameraId, int cameraFacing, |
| 691 | int clientPid, uid_t clientUid, |
| 692 | int servicePid): |
| 693 | mClientPackageName(clientPackageName) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 694 | { |
| 695 | mCameraService = cameraService; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 696 | mRemoteBinder = remoteCallback; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 697 | mCameraId = cameraId; |
| 698 | mCameraFacing = cameraFacing; |
| 699 | mClientPid = clientPid; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 700 | mClientUid = clientUid; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 701 | mServicePid = servicePid; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 702 | mOpsActive = false; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 703 | mDestructionStarted = false; |
| 704 | } |
| 705 | |
| 706 | CameraService::BasicClient::~BasicClient() { |
| 707 | mDestructionStarted = true; |
| 708 | } |
| 709 | |
| 710 | void CameraService::BasicClient::disconnect() { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 711 | mCameraService->removeClientByRemote(mRemoteBinder); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 714 | status_t CameraService::BasicClient::startCameraOps() { |
| 715 | int32_t res; |
| 716 | |
| 717 | mOpsCallback = new OpsCallback(this); |
| 718 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 719 | { |
| 720 | ALOGV("%s: Start camera ops, package name = %s, client UID = %d", |
| 721 | __FUNCTION__, String8(mClientPackageName).string(), mClientUid); |
| 722 | } |
| 723 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 724 | mAppOpsManager.startWatchingMode(AppOpsManager::OP_CAMERA, |
| 725 | mClientPackageName, mOpsCallback); |
| 726 | res = mAppOpsManager.startOp(AppOpsManager::OP_CAMERA, |
| 727 | mClientUid, mClientPackageName); |
| 728 | |
| 729 | if (res != AppOpsManager::MODE_ALLOWED) { |
| 730 | ALOGI("Camera %d: Access for \"%s\" has been revoked", |
| 731 | mCameraId, String8(mClientPackageName).string()); |
| 732 | return PERMISSION_DENIED; |
| 733 | } |
| 734 | mOpsActive = true; |
| 735 | return OK; |
| 736 | } |
| 737 | |
| 738 | status_t CameraService::BasicClient::finishCameraOps() { |
| 739 | if (mOpsActive) { |
| 740 | mAppOpsManager.finishOp(AppOpsManager::OP_CAMERA, mClientUid, |
| 741 | mClientPackageName); |
| 742 | mOpsActive = false; |
| 743 | } |
| 744 | mAppOpsManager.stopWatchingMode(mOpsCallback); |
| 745 | mOpsCallback.clear(); |
| 746 | |
| 747 | return OK; |
| 748 | } |
| 749 | |
| 750 | void CameraService::BasicClient::opChanged(int32_t op, const String16& packageName) { |
| 751 | String8 name(packageName); |
| 752 | String8 myName(mClientPackageName); |
| 753 | |
| 754 | if (op != AppOpsManager::OP_CAMERA) { |
| 755 | ALOGW("Unexpected app ops notification received: %d", op); |
| 756 | return; |
| 757 | } |
| 758 | |
| 759 | int32_t res; |
| 760 | res = mAppOpsManager.checkOp(AppOpsManager::OP_CAMERA, |
| 761 | mClientUid, mClientPackageName); |
| 762 | ALOGV("checkOp returns: %d, %s ", res, |
| 763 | res == AppOpsManager::MODE_ALLOWED ? "ALLOWED" : |
| 764 | res == AppOpsManager::MODE_IGNORED ? "IGNORED" : |
| 765 | res == AppOpsManager::MODE_ERRORED ? "ERRORED" : |
| 766 | "UNKNOWN"); |
| 767 | |
| 768 | if (res != AppOpsManager::MODE_ALLOWED) { |
| 769 | ALOGI("Camera %d: Access for \"%s\" revoked", mCameraId, |
| 770 | myName.string()); |
| 771 | // Reset the client PID to allow server-initiated disconnect, |
| 772 | // and to prevent further calls by client. |
| 773 | mClientPid = getCallingPid(); |
| 774 | notifyError(); |
| 775 | disconnect(); |
| 776 | } |
| 777 | } |
| 778 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 779 | // ---------------------------------------------------------------------------- |
| 780 | |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 781 | Mutex* CameraService::Client::getClientLockFromCookie(void* user) { |
| 782 | return gCameraService->getClientLockById((int) user); |
| 783 | } |
| 784 | |
| 785 | // Provide client pointer for callbacks. Client lock returned from getClientLockFromCookie should |
| 786 | // be acquired for this to be safe |
| 787 | CameraService::Client* CameraService::Client::getClientFromCookie(void* user) { |
| 788 | Client* client = gCameraService->getClientByIdUnsafe((int) user); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 789 | |
| 790 | // This could happen if the Client is in the process of shutting down (the |
| 791 | // last strong reference is gone, but the destructor hasn't finished |
| 792 | // stopping the hardware). |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 793 | if (client == NULL) return NULL; |
| 794 | |
| 795 | // destruction already started, so should not be accessed |
| 796 | if (client->mDestructionStarted) return NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 797 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 798 | return client; |
| 799 | } |
| 800 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 801 | void CameraService::Client::notifyError() { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 802 | mRemoteCallback->notifyCallback(CAMERA_MSG_ERROR, CAMERA_ERROR_RELEASED, 0); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 803 | } |
| 804 | |
Igor Murashkin | 036bc3e | 2012-10-08 15:09:46 -0700 | [diff] [blame] | 805 | // NOTE: function is idempotent |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 806 | void CameraService::Client::disconnect() { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 807 | BasicClient::disconnect(); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 808 | mCameraService->setCameraFree(mCameraId); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 809 | mCameraService->updateStatus(ICameraServiceListener::STATUS_AVAILABLE, |
| 810 | mCameraId); |
Wu-cheng Li | e09591e | 2010-10-14 20:17:44 +0800 | [diff] [blame] | 811 | } |
| 812 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 813 | CameraService::Client::OpsCallback::OpsCallback(wp<BasicClient> client): |
| 814 | mClient(client) { |
| 815 | } |
| 816 | |
| 817 | void CameraService::Client::OpsCallback::opChanged(int32_t op, |
| 818 | const String16& packageName) { |
| 819 | sp<BasicClient> client = mClient.promote(); |
| 820 | if (client != NULL) { |
| 821 | client->opChanged(op, packageName); |
| 822 | } |
| 823 | } |
| 824 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 825 | // ---------------------------------------------------------------------------- |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 826 | // IProCamera |
| 827 | // ---------------------------------------------------------------------------- |
| 828 | |
| 829 | CameraService::ProClient::ProClient(const sp<CameraService>& cameraService, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 830 | const sp<IProCameraCallbacks>& remoteCallback, |
| 831 | const String16& clientPackageName, |
| 832 | int cameraId, |
| 833 | int cameraFacing, |
| 834 | int clientPid, |
| 835 | uid_t clientUid, |
| 836 | int servicePid) |
| 837 | : CameraService::BasicClient(cameraService, remoteCallback->asBinder(), |
| 838 | clientPackageName, cameraId, cameraFacing, |
| 839 | clientPid, clientUid, servicePid) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 840 | { |
| 841 | mRemoteCallback = remoteCallback; |
| 842 | } |
| 843 | |
| 844 | CameraService::ProClient::~ProClient() { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 847 | void CameraService::ProClient::notifyError() { |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 848 | mRemoteCallback->notifyCallback(CAMERA_MSG_ERROR, CAMERA_ERROR_RELEASED, 0); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 849 | } |
| 850 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 851 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 852 | |
| 853 | static const int kDumpLockRetries = 50; |
| 854 | static const int kDumpLockSleep = 60000; |
| 855 | |
| 856 | static bool tryLock(Mutex& mutex) |
| 857 | { |
| 858 | bool locked = false; |
| 859 | for (int i = 0; i < kDumpLockRetries; ++i) { |
| 860 | if (mutex.tryLock() == NO_ERROR) { |
| 861 | locked = true; |
| 862 | break; |
| 863 | } |
| 864 | usleep(kDumpLockSleep); |
| 865 | } |
| 866 | return locked; |
| 867 | } |
| 868 | |
| 869 | status_t CameraService::dump(int fd, const Vector<String16>& args) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 870 | String8 result; |
| 871 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 872 | result.appendFormat("Permission Denial: " |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 873 | "can't dump CameraService from pid=%d, uid=%d\n", |
| 874 | getCallingPid(), |
| 875 | getCallingUid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 876 | write(fd, result.string(), result.size()); |
| 877 | } else { |
| 878 | bool locked = tryLock(mServiceLock); |
| 879 | // failed to lock - CameraService is probably deadlocked |
| 880 | if (!locked) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 881 | result.append("CameraService may be deadlocked\n"); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 882 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | bool hasClient = false; |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 886 | if (!mModule) { |
| 887 | result = String8::format("No camera module available!\n"); |
| 888 | write(fd, result.string(), result.size()); |
| 889 | return NO_ERROR; |
| 890 | } |
| 891 | |
| 892 | result = String8::format("Camera module HAL API version: 0x%x\n", |
| 893 | mModule->common.hal_api_version); |
| 894 | result.appendFormat("Camera module API version: 0x%x\n", |
| 895 | mModule->common.module_api_version); |
| 896 | result.appendFormat("Camera module name: %s\n", |
| 897 | mModule->common.name); |
| 898 | result.appendFormat("Camera module author: %s\n", |
| 899 | mModule->common.author); |
| 900 | result.appendFormat("Number of camera devices: %d\n\n", mNumberOfCameras); |
| 901 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 902 | for (int i = 0; i < mNumberOfCameras; i++) { |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 903 | result = String8::format("Camera %d static information:\n", i); |
| 904 | camera_info info; |
| 905 | |
| 906 | status_t rc = mModule->get_camera_info(i, &info); |
| 907 | if (rc != OK) { |
| 908 | result.appendFormat(" Error reading static information!\n"); |
| 909 | write(fd, result.string(), result.size()); |
| 910 | } else { |
| 911 | result.appendFormat(" Facing: %s\n", |
| 912 | info.facing == CAMERA_FACING_BACK ? "BACK" : "FRONT"); |
| 913 | result.appendFormat(" Orientation: %d\n", info.orientation); |
| 914 | int deviceVersion; |
| 915 | if (mModule->common.module_api_version < |
| 916 | CAMERA_MODULE_API_VERSION_2_0) { |
| 917 | deviceVersion = CAMERA_DEVICE_API_VERSION_1_0; |
| 918 | } else { |
| 919 | deviceVersion = info.device_version; |
| 920 | } |
| 921 | result.appendFormat(" Device version: 0x%x\n", deviceVersion); |
| 922 | if (deviceVersion >= CAMERA_DEVICE_API_VERSION_2_0) { |
| 923 | result.appendFormat(" Device static metadata:\n"); |
| 924 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 925 | dump_indented_camera_metadata(info.static_camera_characteristics, |
| 926 | fd, 2, 4); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 927 | } else { |
| 928 | write(fd, result.string(), result.size()); |
| 929 | } |
| 930 | } |
| 931 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 932 | sp<Client> client = mClient[i].promote(); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 933 | if (client == 0) { |
| 934 | result = String8::format(" Device is closed, no client instance\n"); |
| 935 | write(fd, result.string(), result.size()); |
| 936 | continue; |
| 937 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 938 | hasClient = true; |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 939 | result = String8::format(" Device is open. Client instance dump:\n"); |
| 940 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 941 | client->dump(fd, args); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 942 | } |
| 943 | if (!hasClient) { |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 944 | result = String8::format("\nNo active camera clients yet.\n"); |
| 945 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | if (locked) mServiceLock.unlock(); |
| 949 | |
| 950 | // change logging level |
| 951 | int n = args.size(); |
| 952 | for (int i = 0; i + 1 < n; i++) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 953 | String16 verboseOption("-v"); |
| 954 | if (args[i] == verboseOption) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 955 | String8 levelStr(args[i+1]); |
| 956 | int level = atoi(levelStr.string()); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 957 | result = String8::format("\nSetting log level to %d.\n", level); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 958 | setLogLevel(level); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 959 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 960 | } |
| 961 | } |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 962 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 963 | } |
| 964 | return NO_ERROR; |
| 965 | } |
| 966 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 967 | /*virtual*/void CameraService::binderDied( |
| 968 | const wp<IBinder> &who) { |
| 969 | |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 970 | /** |
| 971 | * While tempting to promote the wp<IBinder> into a sp, |
| 972 | * it's actually not supported by the binder driver |
| 973 | */ |
| 974 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 975 | ALOGV("java clients' binder died"); |
| 976 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 977 | sp<BasicClient> cameraClient = getClientByRemote(who); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 978 | |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 979 | if (cameraClient == 0) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 980 | ALOGV("java clients' binder death already cleaned up (normal case)"); |
| 981 | return; |
| 982 | } |
| 983 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 984 | ALOGW("Disconnecting camera client %p since the binder for it " |
| 985 | "died (this pid %d)", cameraClient.get(), getCallingPid()); |
| 986 | |
| 987 | cameraClient->disconnect(); |
| 988 | |
| 989 | } |
| 990 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 991 | void CameraService::updateStatus(ICameraServiceListener::Status status, |
| 992 | int32_t cameraId) { |
| 993 | // do not lock mServiceLock here or can get into a deadlock from |
| 994 | // connect() -> ProClient::disconnect -> updateStatus |
| 995 | Mutex::Autolock lock(mStatusMutex); |
| 996 | updateStatusUnsafe(status, cameraId); |
| 997 | } |
| 998 | |
| 999 | void CameraService::updateStatusUnsafe(ICameraServiceListener::Status status, |
| 1000 | int32_t cameraId) { |
| 1001 | |
| 1002 | ICameraServiceListener::Status oldStatus = mStatusList[cameraId]; |
| 1003 | |
| 1004 | mStatusList[cameraId] = status; |
| 1005 | |
| 1006 | if (oldStatus != status) { |
| 1007 | ALOGV("%s: Status has changed for camera ID %d from 0x%x to 0x%x", |
| 1008 | __FUNCTION__, cameraId, (uint32_t)oldStatus, (uint32_t)status); |
| 1009 | |
| 1010 | /** |
| 1011 | * ProClients lose their exclusive lock. |
| 1012 | * - Done before the CameraClient can initialize the HAL device, |
| 1013 | * since we want to be able to close it before they get to initialize |
| 1014 | */ |
| 1015 | if (status == ICameraServiceListener::STATUS_NOT_AVAILABLE) { |
| 1016 | Vector<wp<ProClient> > proClients(mProClientList[cameraId]); |
| 1017 | Vector<wp<ProClient> >::const_iterator it; |
| 1018 | |
| 1019 | for (it = proClients.begin(); it != proClients.end(); ++it) { |
| 1020 | sp<ProClient> proCl = it->promote(); |
| 1021 | if (proCl.get() != NULL) { |
| 1022 | proCl->onExclusiveLockStolen(); |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | Vector<sp<ICameraServiceListener> >::const_iterator it; |
| 1028 | for (it = mListenerList.begin(); it != mListenerList.end(); ++it) { |
| 1029 | (*it)->onStatusChanged(status, cameraId); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1034 | }; // namespace android |