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> |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 35 | #include <media/IMediaHTTPService.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 36 | #include <media/mediaplayer.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 37 | #include <utils/Errors.h> |
| 38 | #include <utils/Log.h> |
| 39 | #include <utils/String16.h> |
| 40 | |
| 41 | #include "CameraService.h" |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 42 | #include "api1/CameraClient.h" |
| 43 | #include "api1/Camera2Client.h" |
| 44 | #include "api_pro/ProCamera2Client.h" |
| 45 | #include "api2/CameraDeviceClient.h" |
Igor Murashkin | ff3e31d | 2013-10-23 16:40:06 -0700 | [diff] [blame] | 46 | #include "utils/CameraTraces.h" |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 47 | #include "CameraDeviceFactory.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 48 | |
| 49 | namespace android { |
| 50 | |
| 51 | // ---------------------------------------------------------------------------- |
| 52 | // Logging support -- this is for debugging only |
| 53 | // Use "adb shell dumpsys media.camera -v 1" to change it. |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 54 | volatile int32_t gLogLevel = 0; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 55 | |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 56 | #define LOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__); |
| 57 | #define LOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 58 | |
| 59 | static void setLogLevel(int level) { |
| 60 | android_atomic_write(level, &gLogLevel); |
| 61 | } |
| 62 | |
| 63 | // ---------------------------------------------------------------------------- |
| 64 | |
| 65 | static int getCallingPid() { |
| 66 | return IPCThreadState::self()->getCallingPid(); |
| 67 | } |
| 68 | |
| 69 | static int getCallingUid() { |
| 70 | return IPCThreadState::self()->getCallingUid(); |
| 71 | } |
| 72 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 73 | extern "C" { |
| 74 | static void camera_device_status_change( |
| 75 | const struct camera_module_callbacks* callbacks, |
| 76 | int camera_id, |
| 77 | int new_status) { |
| 78 | sp<CameraService> cs = const_cast<CameraService*>( |
| 79 | static_cast<const CameraService*>(callbacks)); |
| 80 | |
| 81 | cs->onDeviceStatusChanged( |
| 82 | camera_id, |
| 83 | new_status); |
| 84 | } |
| 85 | } // extern "C" |
| 86 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 87 | // ---------------------------------------------------------------------------- |
| 88 | |
| 89 | // This is ugly and only safe if we never re-create the CameraService, but |
| 90 | // should be ok for now. |
| 91 | static CameraService *gCameraService; |
| 92 | |
| 93 | CameraService::CameraService() |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 94 | :mSoundRef(0), mModule(0) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 95 | { |
Steve Block | df64d15 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 96 | ALOGI("CameraService started (pid=%d)", getpid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 97 | gCameraService = this; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 98 | |
| 99 | for (size_t i = 0; i < MAX_CAMERAS; ++i) { |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 100 | mStatusList[i] = ICameraServiceListener::STATUS_PRESENT; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 101 | } |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 102 | |
| 103 | this->camera_device_status_change = android::camera_device_status_change; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 106 | void CameraService::onFirstRef() |
| 107 | { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 108 | LOG1("CameraService::onFirstRef"); |
| 109 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 110 | BnCameraService::onFirstRef(); |
| 111 | |
| 112 | if (hw_get_module(CAMERA_HARDWARE_MODULE_ID, |
| 113 | (const hw_module_t **)&mModule) < 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 114 | ALOGE("Could not load camera HAL module"); |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 115 | mNumberOfCameras = 0; |
| 116 | } |
| 117 | else { |
Alex Ray | c0dd54f | 2013-02-20 13:39:37 -0800 | [diff] [blame] | 118 | ALOGI("Loaded \"%s\" camera module", mModule->common.name); |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 119 | mNumberOfCameras = mModule->get_number_of_cameras(); |
| 120 | if (mNumberOfCameras > MAX_CAMERAS) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 121 | ALOGE("Number of cameras(%d) > MAX_CAMERAS(%d).", |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 122 | mNumberOfCameras, MAX_CAMERAS); |
| 123 | mNumberOfCameras = MAX_CAMERAS; |
| 124 | } |
| 125 | for (int i = 0; i < mNumberOfCameras; i++) { |
| 126 | setCameraFree(i); |
| 127 | } |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 128 | |
| 129 | if (mModule->common.module_api_version >= |
| 130 | CAMERA_MODULE_API_VERSION_2_1) { |
| 131 | mModule->set_callbacks(this); |
| 132 | } |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 133 | |
| 134 | CameraDeviceFactory::registerService(this); |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 138 | CameraService::~CameraService() { |
| 139 | for (int i = 0; i < mNumberOfCameras; i++) { |
| 140 | if (mBusy[i]) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 141 | ALOGE("camera %d is still in use in destructor!", i); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | gCameraService = NULL; |
| 146 | } |
| 147 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 148 | void CameraService::onDeviceStatusChanged(int cameraId, |
| 149 | int newStatus) |
| 150 | { |
| 151 | ALOGI("%s: Status changed for cameraId=%d, newStatus=%d", __FUNCTION__, |
| 152 | cameraId, newStatus); |
| 153 | |
| 154 | if (cameraId < 0 || cameraId >= MAX_CAMERAS) { |
| 155 | ALOGE("%s: Bad camera ID %d", __FUNCTION__, cameraId); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | if ((int)getStatus(cameraId) == newStatus) { |
| 160 | ALOGE("%s: State transition to the same status 0x%x not allowed", |
| 161 | __FUNCTION__, (uint32_t)newStatus); |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | /* don't do this in updateStatus |
| 166 | since it is also called from connect and we could get into a deadlock */ |
| 167 | if (newStatus == CAMERA_DEVICE_STATUS_NOT_PRESENT) { |
| 168 | Vector<sp<BasicClient> > clientsToDisconnect; |
| 169 | { |
| 170 | Mutex::Autolock al(mServiceLock); |
| 171 | |
| 172 | /* Find all clients that we need to disconnect */ |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 173 | sp<BasicClient> client = mClient[cameraId].promote(); |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 174 | if (client.get() != NULL) { |
| 175 | clientsToDisconnect.push_back(client); |
| 176 | } |
| 177 | |
| 178 | int i = cameraId; |
| 179 | for (size_t j = 0; j < mProClientList[i].size(); ++j) { |
| 180 | sp<ProClient> cl = mProClientList[i][j].promote(); |
| 181 | if (cl != NULL) { |
| 182 | clientsToDisconnect.push_back(cl); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /* now disconnect them. don't hold the lock |
| 188 | or we can get into a deadlock */ |
| 189 | |
| 190 | for (size_t i = 0; i < clientsToDisconnect.size(); ++i) { |
| 191 | sp<BasicClient> client = clientsToDisconnect[i]; |
| 192 | |
| 193 | client->disconnect(); |
| 194 | /** |
| 195 | * The remote app will no longer be able to call methods on the |
| 196 | * client since the client PID will be reset to 0 |
| 197 | */ |
| 198 | } |
| 199 | |
| 200 | ALOGV("%s: After unplug, disconnected %d clients", |
| 201 | __FUNCTION__, clientsToDisconnect.size()); |
| 202 | } |
| 203 | |
| 204 | updateStatus( |
| 205 | static_cast<ICameraServiceListener::Status>(newStatus), cameraId); |
| 206 | |
| 207 | } |
| 208 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 209 | int32_t CameraService::getNumberOfCameras() { |
| 210 | return mNumberOfCameras; |
| 211 | } |
| 212 | |
| 213 | status_t CameraService::getCameraInfo(int cameraId, |
| 214 | struct CameraInfo* cameraInfo) { |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 215 | if (!mModule) { |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 216 | return -ENODEV; |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 219 | if (cameraId < 0 || cameraId >= mNumberOfCameras) { |
| 220 | return BAD_VALUE; |
| 221 | } |
| 222 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 223 | struct camera_info info; |
| 224 | status_t rc = mModule->get_camera_info(cameraId, &info); |
| 225 | cameraInfo->facing = info.facing; |
| 226 | cameraInfo->orientation = info.orientation; |
| 227 | return rc; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Zhijun He | 2b59be8 | 2013-09-25 10:14:30 -0700 | [diff] [blame] | 230 | status_t CameraService::getCameraCharacteristics(int cameraId, |
| 231 | CameraMetadata* cameraInfo) { |
| 232 | if (!cameraInfo) { |
| 233 | ALOGE("%s: cameraInfo is NULL", __FUNCTION__); |
| 234 | return BAD_VALUE; |
| 235 | } |
| 236 | |
| 237 | if (!mModule) { |
| 238 | ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__); |
| 239 | return -ENODEV; |
| 240 | } |
| 241 | |
| 242 | if (mModule->common.module_api_version < CAMERA_MODULE_API_VERSION_2_0) { |
| 243 | // TODO: Remove this check once HAL1 shim is in place. |
| 244 | ALOGE("%s: Only HAL module version V2 or higher supports static metadata", __FUNCTION__); |
| 245 | return BAD_VALUE; |
| 246 | } |
| 247 | |
| 248 | if (cameraId < 0 || cameraId >= mNumberOfCameras) { |
| 249 | ALOGE("%s: Invalid camera id: %d", __FUNCTION__, cameraId); |
| 250 | return BAD_VALUE; |
| 251 | } |
| 252 | |
| 253 | int facing; |
| 254 | if (getDeviceVersion(cameraId, &facing) == CAMERA_DEVICE_API_VERSION_1_0) { |
| 255 | // TODO: Remove this check once HAL1 shim is in place. |
| 256 | ALOGE("%s: HAL1 doesn't support static metadata yet", __FUNCTION__); |
| 257 | return BAD_VALUE; |
| 258 | } |
| 259 | |
Zhijun He | f05e50e | 2013-10-01 11:05:33 -0700 | [diff] [blame] | 260 | if (getDeviceVersion(cameraId, &facing) <= CAMERA_DEVICE_API_VERSION_2_1) { |
| 261 | // Disable HAL2.x support for camera2 API for now. |
| 262 | ALOGW("%s: HAL2.x doesn't support getCameraCharacteristics for now", __FUNCTION__); |
| 263 | return BAD_VALUE; |
| 264 | } |
| 265 | |
Zhijun He | 2b59be8 | 2013-09-25 10:14:30 -0700 | [diff] [blame] | 266 | struct camera_info info; |
| 267 | status_t ret = mModule->get_camera_info(cameraId, &info); |
| 268 | *cameraInfo = info.static_camera_characteristics; |
| 269 | |
| 270 | return ret; |
| 271 | } |
| 272 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 273 | int CameraService::getDeviceVersion(int cameraId, int* facing) { |
| 274 | struct camera_info info; |
| 275 | if (mModule->get_camera_info(cameraId, &info) != OK) { |
| 276 | return -1; |
| 277 | } |
| 278 | |
| 279 | int deviceVersion; |
| 280 | if (mModule->common.module_api_version >= CAMERA_MODULE_API_VERSION_2_0) { |
| 281 | deviceVersion = info.device_version; |
| 282 | } else { |
| 283 | deviceVersion = CAMERA_DEVICE_API_VERSION_1_0; |
| 284 | } |
| 285 | |
| 286 | if (facing) { |
| 287 | *facing = info.facing; |
| 288 | } |
| 289 | |
| 290 | return deviceVersion; |
| 291 | } |
| 292 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 293 | bool CameraService::isValidCameraId(int cameraId) { |
| 294 | int facing; |
| 295 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
| 296 | |
| 297 | switch(deviceVersion) { |
| 298 | case CAMERA_DEVICE_API_VERSION_1_0: |
| 299 | case CAMERA_DEVICE_API_VERSION_2_0: |
| 300 | case CAMERA_DEVICE_API_VERSION_2_1: |
| 301 | case CAMERA_DEVICE_API_VERSION_3_0: |
| 302 | return true; |
| 303 | default: |
| 304 | return false; |
| 305 | } |
| 306 | |
| 307 | return false; |
| 308 | } |
| 309 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 310 | status_t CameraService::validateConnect(int cameraId, |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 311 | /*inout*/ |
| 312 | int& clientUid) const { |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 313 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 314 | int callingPid = getCallingPid(); |
Tyler Luu | 5861a9a | 2011-10-06 00:00:03 -0500 | [diff] [blame] | 315 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 316 | if (clientUid == USE_CALLING_UID) { |
| 317 | clientUid = getCallingUid(); |
| 318 | } else { |
| 319 | // We only trust our own process to forward client UIDs |
| 320 | if (callingPid != getpid()) { |
| 321 | ALOGE("CameraService::connect X (pid %d) rejected (don't trust clientUid)", |
| 322 | callingPid); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 323 | return PERMISSION_DENIED; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 326 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 327 | if (!mModule) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 328 | ALOGE("Camera HAL module not loaded"); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 329 | return -ENODEV; |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 332 | if (cameraId < 0 || cameraId >= mNumberOfCameras) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 333 | ALOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).", |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 334 | callingPid, cameraId); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 335 | return -ENODEV; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Wu-cheng Li | a335543 | 2011-05-20 14:54:25 +0800 | [diff] [blame] | 338 | char value[PROPERTY_VALUE_MAX]; |
| 339 | property_get("sys.secpolicy.camera.disabled", value, "0"); |
| 340 | if (strcmp(value, "1") == 0) { |
| 341 | // Camera is disabled by DevicePolicyManager. |
Steve Block | df64d15 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 342 | ALOGI("Camera is disabled. connect X (pid %d) rejected", callingPid); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 343 | return -EACCES; |
Wu-cheng Li | a335543 | 2011-05-20 14:54:25 +0800 | [diff] [blame] | 344 | } |
| 345 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 346 | ICameraServiceListener::Status currentStatus = getStatus(cameraId); |
| 347 | if (currentStatus == ICameraServiceListener::STATUS_NOT_PRESENT) { |
| 348 | ALOGI("Camera is not plugged in," |
| 349 | " connect X (pid %d) rejected", callingPid); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 350 | return -ENODEV; |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 351 | } else if (currentStatus == ICameraServiceListener::STATUS_ENUMERATING) { |
| 352 | ALOGI("Camera is enumerating," |
| 353 | " connect X (pid %d) rejected", callingPid); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 354 | return -EBUSY; |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 355 | } |
| 356 | // Else don't check for STATUS_NOT_AVAILABLE. |
| 357 | // -- It's done implicitly in canConnectUnsafe /w the mBusy array |
| 358 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 359 | return OK; |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | bool CameraService::canConnectUnsafe(int cameraId, |
| 363 | const String16& clientPackageName, |
| 364 | const sp<IBinder>& remoteCallback, |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 365 | sp<BasicClient> &client) { |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 366 | String8 clientName8(clientPackageName); |
| 367 | int callingPid = getCallingPid(); |
| 368 | |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 369 | if (mClient[cameraId] != 0) { |
| 370 | client = mClient[cameraId].promote(); |
| 371 | if (client != 0) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 372 | if (remoteCallback == client->getRemote()) { |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 373 | LOG1("CameraService::connect X (pid %d) (the same client)", |
| 374 | callingPid); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 375 | return true; |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 376 | } else { |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 377 | // TODOSC: need to support 1 regular client, |
| 378 | // multiple shared clients here |
| 379 | ALOGW("CameraService::connect X (pid %d) rejected" |
| 380 | " (existing client).", callingPid); |
| 381 | return false; |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 382 | } |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 383 | } |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 384 | mClient[cameraId].clear(); |
| 385 | } |
| 386 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 387 | /* |
| 388 | mBusy is set to false as the last step of the Client destructor, |
| 389 | after which it is guaranteed that the Client destructor has finished ( |
| 390 | including any inherited destructors) |
| 391 | |
| 392 | We only need this for a Client subclasses since we don't allow |
| 393 | multiple Clents to be opened concurrently, but multiple BasicClient |
| 394 | would be fine |
| 395 | */ |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 396 | if (mBusy[cameraId]) { |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 397 | ALOGW("CameraService::connect X (pid %d, \"%s\") rejected" |
| 398 | " (camera %d is still busy).", callingPid, |
| 399 | clientName8.string(), cameraId); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 400 | return false; |
| 401 | } |
| 402 | |
| 403 | return true; |
| 404 | } |
| 405 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 406 | status_t CameraService::connect( |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 407 | const sp<ICameraClient>& cameraClient, |
| 408 | int cameraId, |
| 409 | const String16& clientPackageName, |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 410 | int clientUid, |
| 411 | /*out*/ |
| 412 | sp<ICamera>& device) { |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 413 | |
| 414 | String8 clientName8(clientPackageName); |
| 415 | int callingPid = getCallingPid(); |
| 416 | |
| 417 | LOG1("CameraService::connect E (pid %d \"%s\", id %d)", callingPid, |
| 418 | clientName8.string(), cameraId); |
| 419 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 420 | status_t status = validateConnect(cameraId, /*inout*/clientUid); |
| 421 | if (status != OK) { |
| 422 | return status; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 425 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 426 | sp<Client> client; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 427 | { |
| 428 | Mutex::Autolock lock(mServiceLock); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 429 | sp<BasicClient> clientTmp; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 430 | if (!canConnectUnsafe(cameraId, clientPackageName, |
| 431 | cameraClient->asBinder(), |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 432 | /*out*/clientTmp)) { |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 433 | return -EBUSY; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 434 | } else if (client.get() != NULL) { |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 435 | device = static_cast<Client*>(clientTmp.get()); |
| 436 | return OK; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | int facing = -1; |
| 440 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
| 441 | |
| 442 | // If there are other non-exclusive users of the camera, |
| 443 | // this will tear them down before we can reuse the camera |
| 444 | if (isValidCameraId(cameraId)) { |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 445 | // transition from PRESENT -> NOT_AVAILABLE |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 446 | updateStatus(ICameraServiceListener::STATUS_NOT_AVAILABLE, |
| 447 | cameraId); |
| 448 | } |
| 449 | |
| 450 | switch(deviceVersion) { |
| 451 | case CAMERA_DEVICE_API_VERSION_1_0: |
| 452 | client = new CameraClient(this, cameraClient, |
| 453 | clientPackageName, cameraId, |
| 454 | facing, callingPid, clientUid, getpid()); |
| 455 | break; |
| 456 | case CAMERA_DEVICE_API_VERSION_2_0: |
| 457 | case CAMERA_DEVICE_API_VERSION_2_1: |
| 458 | case CAMERA_DEVICE_API_VERSION_3_0: |
| 459 | client = new Camera2Client(this, cameraClient, |
| 460 | clientPackageName, cameraId, |
| 461 | facing, callingPid, clientUid, getpid(), |
| 462 | deviceVersion); |
| 463 | break; |
| 464 | case -1: |
| 465 | ALOGE("Invalid camera id %d", cameraId); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 466 | return BAD_VALUE; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 467 | default: |
| 468 | ALOGE("Unknown camera device HAL version: %d", deviceVersion); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 469 | return INVALID_OPERATION; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 472 | status_t status = connectFinishUnsafe(client, client->getRemote()); |
| 473 | if (status != OK) { |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 474 | // this is probably not recoverable.. maybe the client can try again |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 475 | // OK: we can only get here if we were originally in PRESENT state |
| 476 | updateStatus(ICameraServiceListener::STATUS_PRESENT, cameraId); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 477 | return status; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | mClient[cameraId] = client; |
| 481 | LOG1("CameraService::connect X (id %d, this pid is %d)", cameraId, |
| 482 | getpid()); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 483 | } |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 484 | // important: release the mutex here so the client can call back |
| 485 | // into the service from its destructor (can be at the end of the call) |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 486 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 487 | device = client; |
| 488 | return OK; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 491 | status_t CameraService::connectFinishUnsafe(const sp<BasicClient>& client, |
| 492 | const sp<IBinder>& remoteCallback) { |
| 493 | status_t status = client->initialize(mModule); |
| 494 | if (status != OK) { |
| 495 | return status; |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 498 | remoteCallback->linkToDeath(this); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 499 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 500 | return OK; |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 503 | status_t CameraService::connectPro( |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 504 | const sp<IProCameraCallbacks>& cameraCb, |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 505 | int cameraId, |
| 506 | const String16& clientPackageName, |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 507 | int clientUid, |
| 508 | /*out*/ |
| 509 | sp<IProCameraUser>& device) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 510 | { |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 511 | String8 clientName8(clientPackageName); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 512 | int callingPid = getCallingPid(); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 513 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 514 | LOG1("CameraService::connectPro E (pid %d \"%s\", id %d)", callingPid, |
| 515 | clientName8.string(), cameraId); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 516 | status_t status = validateConnect(cameraId, /*inout*/clientUid); |
| 517 | if (status != OK) { |
| 518 | return status; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 521 | sp<ProClient> client; |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 522 | { |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 523 | Mutex::Autolock lock(mServiceLock); |
| 524 | { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 525 | sp<BasicClient> client; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 526 | if (!canConnectUnsafe(cameraId, clientPackageName, |
| 527 | cameraCb->asBinder(), |
| 528 | /*out*/client)) { |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 529 | return -EBUSY; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | int facing = -1; |
| 534 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
| 535 | |
| 536 | switch(deviceVersion) { |
| 537 | case CAMERA_DEVICE_API_VERSION_1_0: |
| 538 | ALOGE("Camera id %d uses HALv1, doesn't support ProCamera", |
| 539 | cameraId); |
Ruben Brunk | 17963d1 | 2013-08-19 15:21:19 -0700 | [diff] [blame] | 540 | return -EOPNOTSUPP; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 541 | break; |
| 542 | case CAMERA_DEVICE_API_VERSION_2_0: |
| 543 | case CAMERA_DEVICE_API_VERSION_2_1: |
Zhijun He | 4711005 | 2013-07-22 17:34:34 -0700 | [diff] [blame] | 544 | case CAMERA_DEVICE_API_VERSION_3_0: |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 545 | client = new ProCamera2Client(this, cameraCb, String16(), |
| 546 | cameraId, facing, callingPid, USE_CALLING_UID, getpid()); |
| 547 | break; |
| 548 | case -1: |
| 549 | ALOGE("Invalid camera id %d", cameraId); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 550 | return BAD_VALUE; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 551 | default: |
| 552 | ALOGE("Unknown camera device HAL version: %d", deviceVersion); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 553 | return INVALID_OPERATION; |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 554 | } |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 555 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 556 | status_t status = connectFinishUnsafe(client, client->getRemote()); |
| 557 | if (status != OK) { |
| 558 | return status; |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | mProClientList[cameraId].push(client); |
| 562 | |
| 563 | LOG1("CameraService::connectPro X (id %d, this pid is %d)", cameraId, |
| 564 | getpid()); |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 565 | } |
Igor Murashkin | acd695c | 2013-03-13 17:23:00 -0700 | [diff] [blame] | 566 | // important: release the mutex here so the client can call back |
| 567 | // into the service from its destructor (can be at the end of the call) |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 568 | device = client; |
| 569 | return OK; |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 570 | } |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 571 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 572 | status_t CameraService::connectDevice( |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 573 | const sp<ICameraDeviceCallbacks>& cameraCb, |
| 574 | int cameraId, |
| 575 | const String16& clientPackageName, |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 576 | int clientUid, |
| 577 | /*out*/ |
| 578 | sp<ICameraDeviceUser>& device) |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 579 | { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 580 | |
| 581 | String8 clientName8(clientPackageName); |
| 582 | int callingPid = getCallingPid(); |
| 583 | |
| 584 | LOG1("CameraService::connectDevice E (pid %d \"%s\", id %d)", callingPid, |
| 585 | clientName8.string(), cameraId); |
| 586 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 587 | status_t status = validateConnect(cameraId, /*inout*/clientUid); |
| 588 | if (status != OK) { |
| 589 | return status; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | sp<CameraDeviceClient> client; |
| 593 | { |
| 594 | Mutex::Autolock lock(mServiceLock); |
| 595 | { |
| 596 | sp<BasicClient> client; |
| 597 | if (!canConnectUnsafe(cameraId, clientPackageName, |
| 598 | cameraCb->asBinder(), |
| 599 | /*out*/client)) { |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 600 | return -EBUSY; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
| 604 | int facing = -1; |
| 605 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
| 606 | |
| 607 | // If there are other non-exclusive users of the camera, |
| 608 | // this will tear them down before we can reuse the camera |
| 609 | if (isValidCameraId(cameraId)) { |
| 610 | // transition from PRESENT -> NOT_AVAILABLE |
| 611 | updateStatus(ICameraServiceListener::STATUS_NOT_AVAILABLE, |
| 612 | cameraId); |
| 613 | } |
| 614 | |
| 615 | switch(deviceVersion) { |
| 616 | case CAMERA_DEVICE_API_VERSION_1_0: |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 617 | ALOGW("Camera using old HAL version: %d", deviceVersion); |
Ruben Brunk | 17963d1 | 2013-08-19 15:21:19 -0700 | [diff] [blame] | 618 | return -EOPNOTSUPP; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 619 | // TODO: don't allow 2.0 Only allow 2.1 and higher |
| 620 | case CAMERA_DEVICE_API_VERSION_2_0: |
| 621 | case CAMERA_DEVICE_API_VERSION_2_1: |
| 622 | case CAMERA_DEVICE_API_VERSION_3_0: |
| 623 | client = new CameraDeviceClient(this, cameraCb, String16(), |
| 624 | cameraId, facing, callingPid, USE_CALLING_UID, getpid()); |
| 625 | break; |
| 626 | case -1: |
| 627 | ALOGE("Invalid camera id %d", cameraId); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 628 | return BAD_VALUE; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 629 | default: |
| 630 | ALOGE("Unknown camera device HAL version: %d", deviceVersion); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 631 | return INVALID_OPERATION; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 634 | status_t status = connectFinishUnsafe(client, client->getRemote()); |
| 635 | if (status != OK) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 636 | // this is probably not recoverable.. maybe the client can try again |
| 637 | // OK: we can only get here if we were originally in PRESENT state |
| 638 | updateStatus(ICameraServiceListener::STATUS_PRESENT, cameraId); |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 639 | return status; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | LOG1("CameraService::connectDevice X (id %d, this pid is %d)", cameraId, |
| 643 | getpid()); |
| 644 | |
| 645 | mClient[cameraId] = client; |
| 646 | } |
| 647 | // important: release the mutex here so the client can call back |
| 648 | // into the service from its destructor (can be at the end of the call) |
| 649 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 650 | device = client; |
| 651 | return OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 655 | status_t CameraService::addListener( |
| 656 | const sp<ICameraServiceListener>& listener) { |
| 657 | ALOGV("%s: Add listener %p", __FUNCTION__, listener.get()); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 658 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 659 | Mutex::Autolock lock(mServiceLock); |
| 660 | |
| 661 | Vector<sp<ICameraServiceListener> >::iterator it, end; |
| 662 | for (it = mListenerList.begin(); it != mListenerList.end(); ++it) { |
| 663 | if ((*it)->asBinder() == listener->asBinder()) { |
| 664 | ALOGW("%s: Tried to add listener %p which was already subscribed", |
| 665 | __FUNCTION__, listener.get()); |
| 666 | return ALREADY_EXISTS; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | mListenerList.push_back(listener); |
| 671 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 672 | /* Immediately signal current status to this listener only */ |
| 673 | { |
| 674 | Mutex::Autolock m(mStatusMutex) ; |
| 675 | int numCams = getNumberOfCameras(); |
| 676 | for (int i = 0; i < numCams; ++i) { |
| 677 | listener->onStatusChanged(mStatusList[i], i); |
| 678 | } |
| 679 | } |
| 680 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 681 | return OK; |
| 682 | } |
| 683 | status_t CameraService::removeListener( |
| 684 | const sp<ICameraServiceListener>& listener) { |
| 685 | ALOGV("%s: Remove listener %p", __FUNCTION__, listener.get()); |
| 686 | |
| 687 | Mutex::Autolock lock(mServiceLock); |
| 688 | |
| 689 | Vector<sp<ICameraServiceListener> >::iterator it; |
| 690 | for (it = mListenerList.begin(); it != mListenerList.end(); ++it) { |
| 691 | if ((*it)->asBinder() == listener->asBinder()) { |
| 692 | mListenerList.erase(it); |
| 693 | return OK; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | ALOGW("%s: Tried to remove a listener %p which was not subscribed", |
| 698 | __FUNCTION__, listener.get()); |
| 699 | |
| 700 | return BAD_VALUE; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | void CameraService::removeClientByRemote(const wp<IBinder>& remoteBinder) { |
| 704 | int callingPid = getCallingPid(); |
| 705 | LOG1("CameraService::removeClientByRemote E (pid %d)", callingPid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 706 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 707 | // Declare this before the lock to make absolutely sure the |
| 708 | // destructor won't be called with the lock held. |
| 709 | Mutex::Autolock lock(mServiceLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 710 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 711 | int outIndex; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 712 | sp<BasicClient> client = findClientUnsafe(remoteBinder, outIndex); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 713 | |
| 714 | if (client != 0) { |
| 715 | // Found our camera, clear and leave. |
| 716 | LOG1("removeClient: clear camera %d", outIndex); |
| 717 | mClient[outIndex].clear(); |
| 718 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 719 | client->getRemote()->unlinkToDeath(this); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 720 | } else { |
| 721 | |
| 722 | sp<ProClient> clientPro = findProClientUnsafe(remoteBinder); |
| 723 | |
| 724 | if (clientPro != NULL) { |
| 725 | // Found our camera, clear and leave. |
| 726 | LOG1("removeClient: clear pro %p", clientPro.get()); |
| 727 | |
| 728 | clientPro->getRemoteCallback()->asBinder()->unlinkToDeath(this); |
| 729 | } |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 732 | LOG1("CameraService::removeClientByRemote X (pid %d)", callingPid); |
| 733 | } |
| 734 | |
| 735 | sp<CameraService::ProClient> CameraService::findProClientUnsafe( |
| 736 | const wp<IBinder>& cameraCallbacksRemote) |
| 737 | { |
| 738 | sp<ProClient> clientPro; |
| 739 | |
| 740 | for (int i = 0; i < mNumberOfCameras; ++i) { |
| 741 | Vector<size_t> removeIdx; |
| 742 | |
| 743 | for (size_t j = 0; j < mProClientList[i].size(); ++j) { |
| 744 | wp<ProClient> cl = mProClientList[i][j]; |
| 745 | |
| 746 | sp<ProClient> clStrong = cl.promote(); |
| 747 | if (clStrong != NULL && clStrong->getRemote() == cameraCallbacksRemote) { |
| 748 | clientPro = clStrong; |
| 749 | break; |
| 750 | } else if (clStrong == NULL) { |
| 751 | // mark to clean up dead ptr |
| 752 | removeIdx.push(j); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | // remove stale ptrs (in reverse so the indices dont change) |
| 757 | for (ssize_t j = (ssize_t)removeIdx.size() - 1; j >= 0; --j) { |
| 758 | mProClientList[i].removeAt(removeIdx[j]); |
| 759 | } |
| 760 | |
| 761 | } |
| 762 | |
| 763 | return clientPro; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 766 | sp<CameraService::BasicClient> CameraService::findClientUnsafe( |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 767 | const wp<IBinder>& cameraClient, int& outIndex) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 768 | sp<BasicClient> client; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 769 | |
| 770 | for (int i = 0; i < mNumberOfCameras; i++) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 771 | |
| 772 | // This happens when we have already disconnected (or this is |
| 773 | // just another unused camera). |
| 774 | if (mClient[i] == 0) continue; |
| 775 | |
| 776 | // Promote mClient. It can fail if we are called from this path: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 777 | // Client::~Client() -> disconnect() -> removeClientByRemote(). |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 778 | client = mClient[i].promote(); |
| 779 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 780 | // Clean up stale client entry |
| 781 | if (client == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 782 | mClient[i].clear(); |
| 783 | continue; |
| 784 | } |
| 785 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 786 | if (cameraClient == client->getRemote()) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 787 | // Found our camera |
| 788 | outIndex = i; |
| 789 | return client; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 793 | outIndex = -1; |
| 794 | return NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 797 | CameraService::BasicClient* CameraService::getClientByIdUnsafe(int cameraId) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 798 | if (cameraId < 0 || cameraId >= mNumberOfCameras) return NULL; |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 799 | return mClient[cameraId].unsafe_get(); |
| 800 | } |
| 801 | |
| 802 | Mutex* CameraService::getClientLockById(int cameraId) { |
| 803 | if (cameraId < 0 || cameraId >= mNumberOfCameras) return NULL; |
| 804 | return &mClientLock[cameraId]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 807 | sp<CameraService::BasicClient> CameraService::getClientByRemote( |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 808 | const wp<IBinder>& cameraClient) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 809 | |
| 810 | // Declare this before the lock to make absolutely sure the |
| 811 | // destructor won't be called with the lock held. |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 812 | sp<BasicClient> client; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 813 | |
| 814 | Mutex::Autolock lock(mServiceLock); |
| 815 | |
| 816 | int outIndex; |
| 817 | client = findClientUnsafe(cameraClient, outIndex); |
| 818 | |
| 819 | return client; |
| 820 | } |
| 821 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 822 | status_t CameraService::onTransact( |
| 823 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 824 | // Permission checks |
| 825 | switch (code) { |
| 826 | case BnCameraService::CONNECT: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 827 | case BnCameraService::CONNECT_PRO: |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 828 | const int pid = getCallingPid(); |
| 829 | const int self_pid = getpid(); |
| 830 | if (pid != self_pid) { |
| 831 | // we're called from a different process, do the real check |
| 832 | if (!checkCallingPermission( |
| 833 | String16("android.permission.CAMERA"))) { |
| 834 | const int uid = getCallingUid(); |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 835 | ALOGE("Permission Denial: " |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 836 | "can't use the camera pid=%d, uid=%d", pid, uid); |
| 837 | return PERMISSION_DENIED; |
| 838 | } |
| 839 | } |
| 840 | break; |
| 841 | } |
| 842 | |
| 843 | return BnCameraService::onTransact(code, data, reply, flags); |
| 844 | } |
| 845 | |
| 846 | // The reason we need this busy bit is a new CameraService::connect() request |
| 847 | // may come in while the previous Client's destructor has not been run or is |
| 848 | // still running. If the last strong reference of the previous Client is gone |
| 849 | // but the destructor has not been finished, we should not allow the new Client |
| 850 | // to be created because we need to wait for the previous Client to tear down |
| 851 | // the hardware first. |
| 852 | void CameraService::setCameraBusy(int cameraId) { |
| 853 | android_atomic_write(1, &mBusy[cameraId]); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 854 | |
| 855 | ALOGV("setCameraBusy cameraId=%d", cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | void CameraService::setCameraFree(int cameraId) { |
| 859 | android_atomic_write(0, &mBusy[cameraId]); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 860 | |
| 861 | ALOGV("setCameraFree cameraId=%d", cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | // We share the media players for shutter and recording sound for all clients. |
| 865 | // A reference count is kept to determine when we will actually release the |
| 866 | // media players. |
| 867 | |
Chih-Chung Chang | ff4f55c | 2011-10-17 19:03:12 +0800 | [diff] [blame] | 868 | MediaPlayer* CameraService::newMediaPlayer(const char *file) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 869 | MediaPlayer* mp = new MediaPlayer(); |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 870 | if (mp->setDataSource(NULL /* httpService */, file, NULL) == NO_ERROR) { |
Eino-Ville Talvala | 60a78ac | 2012-01-05 15:34:53 -0800 | [diff] [blame] | 871 | mp->setAudioStreamType(AUDIO_STREAM_ENFORCED_AUDIBLE); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 872 | mp->prepare(); |
| 873 | } else { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 874 | ALOGE("Failed to load CameraService sounds: %s", file); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 875 | return NULL; |
| 876 | } |
| 877 | return mp; |
| 878 | } |
| 879 | |
| 880 | void CameraService::loadSound() { |
| 881 | Mutex::Autolock lock(mSoundLock); |
| 882 | LOG1("CameraService::loadSound ref=%d", mSoundRef); |
| 883 | if (mSoundRef++) return; |
| 884 | |
| 885 | mSoundPlayer[SOUND_SHUTTER] = newMediaPlayer("/system/media/audio/ui/camera_click.ogg"); |
| 886 | mSoundPlayer[SOUND_RECORDING] = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg"); |
| 887 | } |
| 888 | |
| 889 | void CameraService::releaseSound() { |
| 890 | Mutex::Autolock lock(mSoundLock); |
| 891 | LOG1("CameraService::releaseSound ref=%d", mSoundRef); |
| 892 | if (--mSoundRef) return; |
| 893 | |
| 894 | for (int i = 0; i < NUM_SOUNDS; i++) { |
| 895 | if (mSoundPlayer[i] != 0) { |
| 896 | mSoundPlayer[i]->disconnect(); |
| 897 | mSoundPlayer[i].clear(); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | void CameraService::playSound(sound_kind kind) { |
| 903 | LOG1("playSound(%d)", kind); |
| 904 | Mutex::Autolock lock(mSoundLock); |
| 905 | sp<MediaPlayer> player = mSoundPlayer[kind]; |
| 906 | if (player != 0) { |
Chih-Chung Chang | 8888a75 | 2011-10-20 10:47:26 +0800 | [diff] [blame] | 907 | player->seekTo(0); |
| 908 | player->start(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
| 912 | // ---------------------------------------------------------------------------- |
| 913 | |
| 914 | CameraService::Client::Client(const sp<CameraService>& cameraService, |
Wu-cheng Li | b7a6794 | 2010-08-17 15:45:37 -0700 | [diff] [blame] | 915 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 916 | const String16& clientPackageName, |
| 917 | int cameraId, int cameraFacing, |
| 918 | int clientPid, uid_t clientUid, |
| 919 | int servicePid) : |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 920 | CameraService::BasicClient(cameraService, cameraClient->asBinder(), |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 921 | clientPackageName, |
| 922 | cameraId, cameraFacing, |
| 923 | clientPid, clientUid, |
| 924 | servicePid) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 925 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 926 | int callingPid = getCallingPid(); |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 927 | LOG1("Client::Client E (pid %d, id %d)", callingPid, cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 928 | |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 929 | mRemoteCallback = cameraClient; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 930 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 931 | cameraService->setCameraBusy(cameraId); |
| 932 | cameraService->loadSound(); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 933 | |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 934 | LOG1("Client::Client X (pid %d, id %d)", callingPid, cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 937 | // tear down the client |
| 938 | CameraService::Client::~Client() { |
Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 939 | ALOGV("~Client"); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 940 | mDestructionStarted = true; |
| 941 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 942 | mCameraService->releaseSound(); |
Igor Murashkin | 036bc3e | 2012-10-08 15:09:46 -0700 | [diff] [blame] | 943 | // unconditionally disconnect. function is idempotent |
| 944 | Client::disconnect(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 947 | CameraService::BasicClient::BasicClient(const sp<CameraService>& cameraService, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 948 | const sp<IBinder>& remoteCallback, |
| 949 | const String16& clientPackageName, |
| 950 | int cameraId, int cameraFacing, |
| 951 | int clientPid, uid_t clientUid, |
| 952 | int servicePid): |
| 953 | mClientPackageName(clientPackageName) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 954 | { |
| 955 | mCameraService = cameraService; |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 956 | mRemoteBinder = remoteCallback; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 957 | mCameraId = cameraId; |
| 958 | mCameraFacing = cameraFacing; |
| 959 | mClientPid = clientPid; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 960 | mClientUid = clientUid; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 961 | mServicePid = servicePid; |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 962 | mOpsActive = false; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 963 | mDestructionStarted = false; |
| 964 | } |
| 965 | |
| 966 | CameraService::BasicClient::~BasicClient() { |
Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 967 | ALOGV("~BasicClient"); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 968 | mDestructionStarted = true; |
| 969 | } |
| 970 | |
| 971 | void CameraService::BasicClient::disconnect() { |
Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 972 | ALOGV("BasicClient::disconnect"); |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 973 | mCameraService->removeClientByRemote(mRemoteBinder); |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 974 | // client shouldn't be able to call into us anymore |
| 975 | mClientPid = 0; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 976 | } |
| 977 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 978 | status_t CameraService::BasicClient::startCameraOps() { |
| 979 | int32_t res; |
| 980 | |
| 981 | mOpsCallback = new OpsCallback(this); |
| 982 | |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 983 | { |
| 984 | ALOGV("%s: Start camera ops, package name = %s, client UID = %d", |
| 985 | __FUNCTION__, String8(mClientPackageName).string(), mClientUid); |
| 986 | } |
| 987 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 988 | mAppOpsManager.startWatchingMode(AppOpsManager::OP_CAMERA, |
| 989 | mClientPackageName, mOpsCallback); |
| 990 | res = mAppOpsManager.startOp(AppOpsManager::OP_CAMERA, |
| 991 | mClientUid, mClientPackageName); |
| 992 | |
| 993 | if (res != AppOpsManager::MODE_ALLOWED) { |
| 994 | ALOGI("Camera %d: Access for \"%s\" has been revoked", |
| 995 | mCameraId, String8(mClientPackageName).string()); |
| 996 | return PERMISSION_DENIED; |
| 997 | } |
| 998 | mOpsActive = true; |
| 999 | return OK; |
| 1000 | } |
| 1001 | |
| 1002 | status_t CameraService::BasicClient::finishCameraOps() { |
| 1003 | if (mOpsActive) { |
| 1004 | mAppOpsManager.finishOp(AppOpsManager::OP_CAMERA, mClientUid, |
| 1005 | mClientPackageName); |
| 1006 | mOpsActive = false; |
| 1007 | } |
| 1008 | mAppOpsManager.stopWatchingMode(mOpsCallback); |
| 1009 | mOpsCallback.clear(); |
| 1010 | |
| 1011 | return OK; |
| 1012 | } |
| 1013 | |
| 1014 | void CameraService::BasicClient::opChanged(int32_t op, const String16& packageName) { |
| 1015 | String8 name(packageName); |
| 1016 | String8 myName(mClientPackageName); |
| 1017 | |
| 1018 | if (op != AppOpsManager::OP_CAMERA) { |
| 1019 | ALOGW("Unexpected app ops notification received: %d", op); |
| 1020 | return; |
| 1021 | } |
| 1022 | |
| 1023 | int32_t res; |
| 1024 | res = mAppOpsManager.checkOp(AppOpsManager::OP_CAMERA, |
| 1025 | mClientUid, mClientPackageName); |
| 1026 | ALOGV("checkOp returns: %d, %s ", res, |
| 1027 | res == AppOpsManager::MODE_ALLOWED ? "ALLOWED" : |
| 1028 | res == AppOpsManager::MODE_IGNORED ? "IGNORED" : |
| 1029 | res == AppOpsManager::MODE_ERRORED ? "ERRORED" : |
| 1030 | "UNKNOWN"); |
| 1031 | |
| 1032 | if (res != AppOpsManager::MODE_ALLOWED) { |
| 1033 | ALOGI("Camera %d: Access for \"%s\" revoked", mCameraId, |
| 1034 | myName.string()); |
| 1035 | // Reset the client PID to allow server-initiated disconnect, |
| 1036 | // and to prevent further calls by client. |
| 1037 | mClientPid = getCallingPid(); |
| 1038 | notifyError(); |
| 1039 | disconnect(); |
| 1040 | } |
| 1041 | } |
| 1042 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1043 | // ---------------------------------------------------------------------------- |
| 1044 | |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 1045 | Mutex* CameraService::Client::getClientLockFromCookie(void* user) { |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 1046 | return gCameraService->getClientLockById((int)(intptr_t) user); |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | // Provide client pointer for callbacks. Client lock returned from getClientLockFromCookie should |
| 1050 | // be acquired for this to be safe |
| 1051 | CameraService::Client* CameraService::Client::getClientFromCookie(void* user) { |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 1052 | BasicClient *basicClient = gCameraService->getClientByIdUnsafe((int)(intptr_t) user); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 1053 | // OK: only CameraClient calls this, and they already cast anyway. |
| 1054 | Client* client = static_cast<Client*>(basicClient); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1055 | |
| 1056 | // This could happen if the Client is in the process of shutting down (the |
| 1057 | // last strong reference is gone, but the destructor hasn't finished |
| 1058 | // stopping the hardware). |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 1059 | if (client == NULL) return NULL; |
| 1060 | |
| 1061 | // destruction already started, so should not be accessed |
| 1062 | if (client->mDestructionStarted) return NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1063 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1064 | return client; |
| 1065 | } |
| 1066 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 1067 | void CameraService::Client::notifyError() { |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 1068 | mRemoteCallback->notifyCallback(CAMERA_MSG_ERROR, CAMERA_ERROR_RELEASED, 0); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 1069 | } |
| 1070 | |
Igor Murashkin | 036bc3e | 2012-10-08 15:09:46 -0700 | [diff] [blame] | 1071 | // NOTE: function is idempotent |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 1072 | void CameraService::Client::disconnect() { |
Eino-Ville Talvala | d09801b | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 1073 | ALOGV("Client::disconnect"); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 1074 | BasicClient::disconnect(); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 1075 | mCameraService->setCameraFree(mCameraId); |
Igor Murashkin | 93747b9 | 2013-05-01 15:42:20 -0700 | [diff] [blame] | 1076 | |
| 1077 | StatusVector rejectSourceStates; |
| 1078 | rejectSourceStates.push_back(ICameraServiceListener::STATUS_NOT_PRESENT); |
| 1079 | rejectSourceStates.push_back(ICameraServiceListener::STATUS_ENUMERATING); |
| 1080 | |
| 1081 | // Transition to PRESENT if the camera is not in either of above 2 states |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 1082 | mCameraService->updateStatus(ICameraServiceListener::STATUS_PRESENT, |
Igor Murashkin | 93747b9 | 2013-05-01 15:42:20 -0700 | [diff] [blame] | 1083 | mCameraId, |
| 1084 | &rejectSourceStates); |
Wu-cheng Li | e09591e | 2010-10-14 20:17:44 +0800 | [diff] [blame] | 1085 | } |
| 1086 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 1087 | CameraService::Client::OpsCallback::OpsCallback(wp<BasicClient> client): |
| 1088 | mClient(client) { |
| 1089 | } |
| 1090 | |
| 1091 | void CameraService::Client::OpsCallback::opChanged(int32_t op, |
| 1092 | const String16& packageName) { |
| 1093 | sp<BasicClient> client = mClient.promote(); |
| 1094 | if (client != NULL) { |
| 1095 | client->opChanged(op, packageName); |
| 1096 | } |
| 1097 | } |
| 1098 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1099 | // ---------------------------------------------------------------------------- |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 1100 | // IProCamera |
| 1101 | // ---------------------------------------------------------------------------- |
| 1102 | |
| 1103 | CameraService::ProClient::ProClient(const sp<CameraService>& cameraService, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 1104 | const sp<IProCameraCallbacks>& remoteCallback, |
| 1105 | const String16& clientPackageName, |
| 1106 | int cameraId, |
| 1107 | int cameraFacing, |
| 1108 | int clientPid, |
| 1109 | uid_t clientUid, |
| 1110 | int servicePid) |
| 1111 | : CameraService::BasicClient(cameraService, remoteCallback->asBinder(), |
| 1112 | clientPackageName, cameraId, cameraFacing, |
| 1113 | clientPid, clientUid, servicePid) |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 1114 | { |
| 1115 | mRemoteCallback = remoteCallback; |
| 1116 | } |
| 1117 | |
| 1118 | CameraService::ProClient::~ProClient() { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 1119 | } |
| 1120 | |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 1121 | void CameraService::ProClient::notifyError() { |
Igor Murashkin | e6800ce | 2013-03-04 17:25:57 -0800 | [diff] [blame] | 1122 | mRemoteCallback->notifyCallback(CAMERA_MSG_ERROR, CAMERA_ERROR_RELEASED, 0); |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 1123 | } |
| 1124 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 1125 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1126 | |
| 1127 | static const int kDumpLockRetries = 50; |
| 1128 | static const int kDumpLockSleep = 60000; |
| 1129 | |
| 1130 | static bool tryLock(Mutex& mutex) |
| 1131 | { |
| 1132 | bool locked = false; |
| 1133 | for (int i = 0; i < kDumpLockRetries; ++i) { |
| 1134 | if (mutex.tryLock() == NO_ERROR) { |
| 1135 | locked = true; |
| 1136 | break; |
| 1137 | } |
| 1138 | usleep(kDumpLockSleep); |
| 1139 | } |
| 1140 | return locked; |
| 1141 | } |
| 1142 | |
| 1143 | status_t CameraService::dump(int fd, const Vector<String16>& args) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1144 | String8 result; |
| 1145 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 1146 | result.appendFormat("Permission Denial: " |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1147 | "can't dump CameraService from pid=%d, uid=%d\n", |
| 1148 | getCallingPid(), |
| 1149 | getCallingUid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1150 | write(fd, result.string(), result.size()); |
| 1151 | } else { |
| 1152 | bool locked = tryLock(mServiceLock); |
| 1153 | // failed to lock - CameraService is probably deadlocked |
| 1154 | if (!locked) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 1155 | result.append("CameraService may be deadlocked\n"); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1156 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | bool hasClient = false; |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1160 | if (!mModule) { |
| 1161 | result = String8::format("No camera module available!\n"); |
| 1162 | write(fd, result.string(), result.size()); |
| 1163 | return NO_ERROR; |
| 1164 | } |
| 1165 | |
| 1166 | result = String8::format("Camera module HAL API version: 0x%x\n", |
| 1167 | mModule->common.hal_api_version); |
| 1168 | result.appendFormat("Camera module API version: 0x%x\n", |
| 1169 | mModule->common.module_api_version); |
| 1170 | result.appendFormat("Camera module name: %s\n", |
| 1171 | mModule->common.name); |
| 1172 | result.appendFormat("Camera module author: %s\n", |
| 1173 | mModule->common.author); |
| 1174 | result.appendFormat("Number of camera devices: %d\n\n", mNumberOfCameras); |
| 1175 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1176 | for (int i = 0; i < mNumberOfCameras; i++) { |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1177 | result = String8::format("Camera %d static information:\n", i); |
| 1178 | camera_info info; |
| 1179 | |
| 1180 | status_t rc = mModule->get_camera_info(i, &info); |
| 1181 | if (rc != OK) { |
| 1182 | result.appendFormat(" Error reading static information!\n"); |
| 1183 | write(fd, result.string(), result.size()); |
| 1184 | } else { |
| 1185 | result.appendFormat(" Facing: %s\n", |
| 1186 | info.facing == CAMERA_FACING_BACK ? "BACK" : "FRONT"); |
| 1187 | result.appendFormat(" Orientation: %d\n", info.orientation); |
| 1188 | int deviceVersion; |
| 1189 | if (mModule->common.module_api_version < |
| 1190 | CAMERA_MODULE_API_VERSION_2_0) { |
| 1191 | deviceVersion = CAMERA_DEVICE_API_VERSION_1_0; |
| 1192 | } else { |
| 1193 | deviceVersion = info.device_version; |
| 1194 | } |
| 1195 | result.appendFormat(" Device version: 0x%x\n", deviceVersion); |
| 1196 | if (deviceVersion >= CAMERA_DEVICE_API_VERSION_2_0) { |
| 1197 | result.appendFormat(" Device static metadata:\n"); |
| 1198 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 1199 | dump_indented_camera_metadata(info.static_camera_characteristics, |
| 1200 | fd, 2, 4); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1201 | } else { |
| 1202 | write(fd, result.string(), result.size()); |
| 1203 | } |
| 1204 | } |
| 1205 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 1206 | sp<BasicClient> client = mClient[i].promote(); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1207 | if (client == 0) { |
| 1208 | result = String8::format(" Device is closed, no client instance\n"); |
| 1209 | write(fd, result.string(), result.size()); |
| 1210 | continue; |
| 1211 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1212 | hasClient = true; |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1213 | result = String8::format(" Device is open. Client instance dump:\n"); |
| 1214 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 1215 | client->dump(fd, args); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1216 | } |
| 1217 | if (!hasClient) { |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1218 | result = String8::format("\nNo active camera clients yet.\n"); |
| 1219 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | if (locked) mServiceLock.unlock(); |
| 1223 | |
Igor Murashkin | ff3e31d | 2013-10-23 16:40:06 -0700 | [diff] [blame] | 1224 | // Dump camera traces if there were any |
| 1225 | write(fd, "\n", 1); |
| 1226 | camera3::CameraTraces::dump(fd, args); |
| 1227 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1228 | // change logging level |
| 1229 | int n = args.size(); |
| 1230 | for (int i = 0; i + 1 < n; i++) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 1231 | String16 verboseOption("-v"); |
| 1232 | if (args[i] == verboseOption) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1233 | String8 levelStr(args[i+1]); |
| 1234 | int level = atoi(levelStr.string()); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1235 | result = String8::format("\nSetting log level to %d.\n", level); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1236 | setLogLevel(level); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1237 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1238 | } |
| 1239 | } |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 1240 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1241 | } |
| 1242 | return NO_ERROR; |
| 1243 | } |
| 1244 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 1245 | /*virtual*/void CameraService::binderDied( |
| 1246 | const wp<IBinder> &who) { |
| 1247 | |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 1248 | /** |
| 1249 | * While tempting to promote the wp<IBinder> into a sp, |
| 1250 | * it's actually not supported by the binder driver |
| 1251 | */ |
| 1252 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 1253 | ALOGV("java clients' binder died"); |
| 1254 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 1255 | sp<BasicClient> cameraClient = getClientByRemote(who); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 1256 | |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 1257 | if (cameraClient == 0) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 1258 | ALOGV("java clients' binder death already cleaned up (normal case)"); |
| 1259 | return; |
| 1260 | } |
| 1261 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 1262 | ALOGW("Disconnecting camera client %p since the binder for it " |
| 1263 | "died (this pid %d)", cameraClient.get(), getCallingPid()); |
| 1264 | |
| 1265 | cameraClient->disconnect(); |
| 1266 | |
| 1267 | } |
| 1268 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 1269 | void CameraService::updateStatus(ICameraServiceListener::Status status, |
Igor Murashkin | 93747b9 | 2013-05-01 15:42:20 -0700 | [diff] [blame] | 1270 | int32_t cameraId, |
| 1271 | const StatusVector *rejectSourceStates) { |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 1272 | // do not lock mServiceLock here or can get into a deadlock from |
| 1273 | // connect() -> ProClient::disconnect -> updateStatus |
| 1274 | Mutex::Autolock lock(mStatusMutex); |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 1275 | |
| 1276 | ICameraServiceListener::Status oldStatus = mStatusList[cameraId]; |
| 1277 | |
| 1278 | mStatusList[cameraId] = status; |
| 1279 | |
| 1280 | if (oldStatus != status) { |
| 1281 | ALOGV("%s: Status has changed for camera ID %d from 0x%x to 0x%x", |
| 1282 | __FUNCTION__, cameraId, (uint32_t)oldStatus, (uint32_t)status); |
| 1283 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 1284 | if (oldStatus == ICameraServiceListener::STATUS_NOT_PRESENT && |
| 1285 | (status != ICameraServiceListener::STATUS_PRESENT && |
| 1286 | status != ICameraServiceListener::STATUS_ENUMERATING)) { |
| 1287 | |
| 1288 | ALOGW("%s: From NOT_PRESENT can only transition into PRESENT" |
| 1289 | " or ENUMERATING", __FUNCTION__); |
| 1290 | mStatusList[cameraId] = oldStatus; |
| 1291 | return; |
| 1292 | } |
| 1293 | |
Igor Murashkin | 93747b9 | 2013-05-01 15:42:20 -0700 | [diff] [blame] | 1294 | if (rejectSourceStates != NULL) { |
| 1295 | const StatusVector &rejectList = *rejectSourceStates; |
| 1296 | StatusVector::const_iterator it = rejectList.begin(); |
| 1297 | |
| 1298 | /** |
| 1299 | * Sometimes we want to conditionally do a transition. |
| 1300 | * For example if a client disconnects, we want to go to PRESENT |
| 1301 | * only if we weren't already in NOT_PRESENT or ENUMERATING. |
| 1302 | */ |
| 1303 | for (; it != rejectList.end(); ++it) { |
| 1304 | if (oldStatus == *it) { |
| 1305 | ALOGV("%s: Rejecting status transition for Camera ID %d, " |
| 1306 | " since the source state was was in one of the bad " |
| 1307 | " states.", __FUNCTION__, cameraId); |
| 1308 | mStatusList[cameraId] = oldStatus; |
| 1309 | return; |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
Igor Murashkin | bfc9915 | 2013-02-27 12:55:20 -0800 | [diff] [blame] | 1314 | /** |
| 1315 | * ProClients lose their exclusive lock. |
| 1316 | * - Done before the CameraClient can initialize the HAL device, |
| 1317 | * since we want to be able to close it before they get to initialize |
| 1318 | */ |
| 1319 | if (status == ICameraServiceListener::STATUS_NOT_AVAILABLE) { |
| 1320 | Vector<wp<ProClient> > proClients(mProClientList[cameraId]); |
| 1321 | Vector<wp<ProClient> >::const_iterator it; |
| 1322 | |
| 1323 | for (it = proClients.begin(); it != proClients.end(); ++it) { |
| 1324 | sp<ProClient> proCl = it->promote(); |
| 1325 | if (proCl.get() != NULL) { |
| 1326 | proCl->onExclusiveLockStolen(); |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | Vector<sp<ICameraServiceListener> >::const_iterator it; |
| 1332 | for (it = mListenerList.begin(); it != mListenerList.end(); ++it) { |
| 1333 | (*it)->onStatusChanged(status, cameraId); |
| 1334 | } |
| 1335 | } |
| 1336 | } |
| 1337 | |
Igor Murashkin | cba2c16 | 2013-03-20 15:56:31 -0700 | [diff] [blame] | 1338 | ICameraServiceListener::Status CameraService::getStatus(int cameraId) const { |
| 1339 | if (cameraId < 0 || cameraId >= MAX_CAMERAS) { |
| 1340 | ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId); |
| 1341 | return ICameraServiceListener::STATUS_UNKNOWN; |
| 1342 | } |
| 1343 | |
| 1344 | Mutex::Autolock al(mStatusMutex); |
| 1345 | return mStatusList[cameraId]; |
| 1346 | } |
| 1347 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1348 | }; // namespace android |