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