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