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 | |
| 25 | #include <binder/IPCThreadState.h> |
| 26 | #include <binder/IServiceManager.h> |
| 27 | #include <binder/MemoryBase.h> |
| 28 | #include <binder/MemoryHeapBase.h> |
| 29 | #include <cutils/atomic.h> |
Nipun Kwatra | b5ca461 | 2010-09-11 19:31:10 -0700 | [diff] [blame] | 30 | #include <cutils/properties.h> |
Mathias Agopian | df712ea | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 31 | #include <gui/Surface.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 32 | #include <hardware/hardware.h> |
| 33 | #include <media/AudioSystem.h> |
| 34 | #include <media/mediaplayer.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 35 | #include <utils/Errors.h> |
| 36 | #include <utils/Log.h> |
| 37 | #include <utils/String16.h> |
| 38 | |
| 39 | #include "CameraService.h" |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 40 | #include "CameraClient.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 41 | #include "Camera2Client.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 42 | |
| 43 | namespace android { |
| 44 | |
| 45 | // ---------------------------------------------------------------------------- |
| 46 | // Logging support -- this is for debugging only |
| 47 | // Use "adb shell dumpsys media.camera -v 1" to change it. |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 48 | volatile int32_t gLogLevel = 0; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 49 | |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 50 | #define LOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__); |
| 51 | #define LOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 52 | |
| 53 | static void setLogLevel(int level) { |
| 54 | android_atomic_write(level, &gLogLevel); |
| 55 | } |
| 56 | |
| 57 | // ---------------------------------------------------------------------------- |
| 58 | |
| 59 | static int getCallingPid() { |
| 60 | return IPCThreadState::self()->getCallingPid(); |
| 61 | } |
| 62 | |
| 63 | static int getCallingUid() { |
| 64 | return IPCThreadState::self()->getCallingUid(); |
| 65 | } |
| 66 | |
| 67 | // ---------------------------------------------------------------------------- |
| 68 | |
| 69 | // This is ugly and only safe if we never re-create the CameraService, but |
| 70 | // should be ok for now. |
| 71 | static CameraService *gCameraService; |
| 72 | |
| 73 | CameraService::CameraService() |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 74 | :mSoundRef(0), mModule(0) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 75 | { |
Steve Block | df64d15 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 76 | ALOGI("CameraService started (pid=%d)", getpid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 77 | gCameraService = this; |
| 78 | } |
| 79 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 80 | void CameraService::onFirstRef() |
| 81 | { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 82 | LOG1("CameraService::onFirstRef"); |
| 83 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 84 | BnCameraService::onFirstRef(); |
| 85 | |
| 86 | if (hw_get_module(CAMERA_HARDWARE_MODULE_ID, |
| 87 | (const hw_module_t **)&mModule) < 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 88 | ALOGE("Could not load camera HAL module"); |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 89 | mNumberOfCameras = 0; |
| 90 | } |
| 91 | else { |
Alex Ray | c0dd54f | 2013-02-20 13:39:37 -0800 | [diff] [blame] | 92 | ALOGI("Loaded \"%s\" camera module", mModule->common.name); |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 93 | mNumberOfCameras = mModule->get_number_of_cameras(); |
| 94 | if (mNumberOfCameras > MAX_CAMERAS) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 95 | ALOGE("Number of cameras(%d) > MAX_CAMERAS(%d).", |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 96 | mNumberOfCameras, MAX_CAMERAS); |
| 97 | mNumberOfCameras = MAX_CAMERAS; |
| 98 | } |
| 99 | for (int i = 0; i < mNumberOfCameras; i++) { |
| 100 | setCameraFree(i); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 105 | CameraService::~CameraService() { |
| 106 | for (int i = 0; i < mNumberOfCameras; i++) { |
| 107 | if (mBusy[i]) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 108 | ALOGE("camera %d is still in use in destructor!", i); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | gCameraService = NULL; |
| 113 | } |
| 114 | |
| 115 | int32_t CameraService::getNumberOfCameras() { |
| 116 | return mNumberOfCameras; |
| 117 | } |
| 118 | |
| 119 | status_t CameraService::getCameraInfo(int cameraId, |
| 120 | struct CameraInfo* cameraInfo) { |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 121 | if (!mModule) { |
| 122 | return NO_INIT; |
| 123 | } |
| 124 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 125 | if (cameraId < 0 || cameraId >= mNumberOfCameras) { |
| 126 | return BAD_VALUE; |
| 127 | } |
| 128 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 129 | struct camera_info info; |
| 130 | status_t rc = mModule->get_camera_info(cameraId, &info); |
| 131 | cameraInfo->facing = info.facing; |
| 132 | cameraInfo->orientation = info.orientation; |
| 133 | return rc; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 136 | int CameraService::getDeviceVersion(int cameraId, int* facing) { |
| 137 | struct camera_info info; |
| 138 | if (mModule->get_camera_info(cameraId, &info) != OK) { |
| 139 | return -1; |
| 140 | } |
| 141 | |
| 142 | int deviceVersion; |
| 143 | if (mModule->common.module_api_version >= CAMERA_MODULE_API_VERSION_2_0) { |
| 144 | deviceVersion = info.device_version; |
| 145 | } else { |
| 146 | deviceVersion = CAMERA_DEVICE_API_VERSION_1_0; |
| 147 | } |
| 148 | |
| 149 | if (facing) { |
| 150 | *facing = info.facing; |
| 151 | } |
| 152 | |
| 153 | return deviceVersion; |
| 154 | } |
| 155 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 156 | sp<ICamera> CameraService::connect( |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 157 | const sp<ICameraClient>& cameraClient, int cameraId) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 158 | int callingPid = getCallingPid(); |
Tyler Luu | 5861a9a | 2011-10-06 00:00:03 -0500 | [diff] [blame] | 159 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 160 | LOG1("CameraService::connect E (pid %d, id %d)", callingPid, cameraId); |
| 161 | |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 162 | if (!mModule) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 163 | ALOGE("Camera HAL module not loaded"); |
Iliyan Malchev | 8951a97 | 2011-04-14 16:55:59 -0700 | [diff] [blame] | 164 | return NULL; |
| 165 | } |
| 166 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 167 | sp<Client> client; |
| 168 | if (cameraId < 0 || cameraId >= mNumberOfCameras) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 169 | ALOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).", |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 170 | callingPid, cameraId); |
| 171 | return NULL; |
| 172 | } |
| 173 | |
Wu-cheng Li | a335543 | 2011-05-20 14:54:25 +0800 | [diff] [blame] | 174 | char value[PROPERTY_VALUE_MAX]; |
| 175 | property_get("sys.secpolicy.camera.disabled", value, "0"); |
| 176 | if (strcmp(value, "1") == 0) { |
| 177 | // Camera is disabled by DevicePolicyManager. |
Steve Block | df64d15 | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 178 | ALOGI("Camera is disabled. connect X (pid %d) rejected", callingPid); |
Wu-cheng Li | a335543 | 2011-05-20 14:54:25 +0800 | [diff] [blame] | 179 | return NULL; |
| 180 | } |
| 181 | |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 182 | Mutex::Autolock lock(mServiceLock); |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 183 | if (mClient[cameraId] != 0) { |
| 184 | client = mClient[cameraId].promote(); |
| 185 | if (client != 0) { |
| 186 | if (cameraClient->asBinder() == client->getCameraClient()->asBinder()) { |
| 187 | LOG1("CameraService::connect X (pid %d) (the same client)", |
| 188 | callingPid); |
| 189 | return client; |
| 190 | } else { |
Igor Murashkin | 1d88023 | 2013-02-20 16:50:13 -0800 | [diff] [blame] | 191 | // TODOSC: need to support 1 regular client, multiple shared clients here |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 192 | ALOGW("CameraService::connect X (pid %d) rejected (existing client).", |
| 193 | callingPid); |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 194 | return NULL; |
| 195 | } |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 196 | } |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 197 | mClient[cameraId].clear(); |
| 198 | } |
| 199 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 200 | /* |
| 201 | mBusy is set to false as the last step of the Client destructor, |
| 202 | after which it is guaranteed that the Client destructor has finished ( |
| 203 | including any inherited destructors) |
| 204 | |
| 205 | We only need this for a Client subclasses since we don't allow |
| 206 | multiple Clents to be opened concurrently, but multiple BasicClient |
| 207 | would be fine |
| 208 | */ |
Wu-cheng Li | 08ad5ef | 2012-04-19 12:35:00 +0800 | [diff] [blame] | 209 | if (mBusy[cameraId]) { |
| 210 | ALOGW("CameraService::connect X (pid %d) rejected" |
| 211 | " (camera %d is still busy).", callingPid, cameraId); |
| 212 | return NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 215 | int facing = -1; |
| 216 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 217 | |
| 218 | switch(deviceVersion) { |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 219 | case CAMERA_DEVICE_API_VERSION_1_0: |
| 220 | client = new CameraClient(this, cameraClient, cameraId, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 221 | facing, callingPid, getpid()); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 222 | break; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 223 | case CAMERA_DEVICE_API_VERSION_2_0: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 224 | case CAMERA_DEVICE_API_VERSION_2_1: |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 225 | client = new Camera2Client(this, cameraClient, cameraId, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 226 | facing, callingPid, getpid()); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 227 | break; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 228 | case -1: |
| 229 | ALOGE("Invalid camera id %d", cameraId); |
| 230 | return NULL; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 231 | default: |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 232 | ALOGE("Unknown camera device HAL version: %d", deviceVersion); |
Tyler Luu | 5861a9a | 2011-10-06 00:00:03 -0500 | [diff] [blame] | 233 | return NULL; |
| 234 | } |
| 235 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 236 | if (client->initialize(mModule) != OK) { |
| 237 | return NULL; |
| 238 | } |
| 239 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 240 | cameraClient->asBinder()->linkToDeath(this); |
| 241 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 242 | mClient[cameraId] = client; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 243 | LOG1("CameraService::connect X (id %d, this pid is %d)", cameraId, getpid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 244 | return client; |
| 245 | } |
| 246 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 247 | sp<IProCameraUser> CameraService::connect( |
| 248 | const sp<IProCameraCallbacks>& cameraCb, |
| 249 | int cameraId) |
| 250 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 251 | int callingPid = getCallingPid(); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 252 | |
| 253 | LOG1("CameraService::connectPro E (pid %d, id %d)", callingPid, cameraId); |
| 254 | |
| 255 | if (!mModule) { |
| 256 | ALOGE("Camera HAL module not loaded"); |
| 257 | return NULL; |
| 258 | } |
| 259 | |
| 260 | sp<ProClient> client; |
| 261 | if (cameraId < 0 || cameraId >= mNumberOfCameras) { |
| 262 | ALOGE("CameraService::connectPro X (pid %d) rejected (invalid cameraId %d).", |
| 263 | callingPid, cameraId); |
| 264 | return NULL; |
| 265 | } |
| 266 | |
| 267 | char value[PROPERTY_VALUE_MAX]; |
| 268 | property_get("sys.secpolicy.camera.disabled", value, "0"); |
| 269 | if (strcmp(value, "1") == 0) { |
| 270 | // Camera is disabled by DevicePolicyManager. |
| 271 | ALOGI("Camera is disabled. connect X (pid %d) rejected", callingPid); |
| 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | int facing = -1; |
| 276 | int deviceVersion = getDeviceVersion(cameraId, &facing); |
| 277 | |
| 278 | switch(deviceVersion) { |
| 279 | case CAMERA_DEVICE_API_VERSION_1_0: |
| 280 | ALOGE("Camera id %d uses HALv1, doesn't support ProCamera", cameraId); |
| 281 | return NULL; |
| 282 | break; |
| 283 | case CAMERA_DEVICE_API_VERSION_2_0: |
| 284 | client = new ProClient(this, cameraCb, cameraId, |
| 285 | facing, callingPid, getpid()); |
| 286 | break; |
| 287 | case -1: |
| 288 | ALOGE("Invalid camera id %d", cameraId); |
| 289 | return NULL; |
| 290 | default: |
| 291 | ALOGE("Unknown camera device HAL version: %d", deviceVersion); |
| 292 | return NULL; |
| 293 | } |
| 294 | |
| 295 | if (client->initialize(mModule) != OK) { |
| 296 | return NULL; |
| 297 | } |
| 298 | |
| 299 | mProClientList[cameraId].push(client); |
| 300 | |
| 301 | cameraCb->asBinder()->linkToDeath(this); |
| 302 | |
| 303 | LOG1("CameraService::connect X (id %d, this pid is %d)", cameraId, getpid()); |
| 304 | return client; |
| 305 | |
| 306 | |
| 307 | return NULL; |
| 308 | } |
| 309 | |
| 310 | void CameraService::removeClientByRemote(const wp<IBinder>& remoteBinder) { |
| 311 | int callingPid = getCallingPid(); |
| 312 | LOG1("CameraService::removeClientByRemote E (pid %d)", callingPid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 313 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 314 | // Declare this before the lock to make absolutely sure the |
| 315 | // destructor won't be called with the lock held. |
| 316 | Mutex::Autolock lock(mServiceLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 317 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 318 | int outIndex; |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 319 | sp<Client> client = findClientUnsafe(remoteBinder, outIndex); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 320 | |
| 321 | if (client != 0) { |
| 322 | // Found our camera, clear and leave. |
| 323 | LOG1("removeClient: clear camera %d", outIndex); |
| 324 | mClient[outIndex].clear(); |
| 325 | |
| 326 | client->unlinkToDeath(this); |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 327 | } else { |
| 328 | |
| 329 | sp<ProClient> clientPro = findProClientUnsafe(remoteBinder); |
| 330 | |
| 331 | if (clientPro != NULL) { |
| 332 | // Found our camera, clear and leave. |
| 333 | LOG1("removeClient: clear pro %p", clientPro.get()); |
| 334 | |
| 335 | clientPro->getRemoteCallback()->asBinder()->unlinkToDeath(this); |
| 336 | } |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 339 | LOG1("CameraService::removeClientByRemote X (pid %d)", callingPid); |
| 340 | } |
| 341 | |
| 342 | sp<CameraService::ProClient> CameraService::findProClientUnsafe( |
| 343 | const wp<IBinder>& cameraCallbacksRemote) |
| 344 | { |
| 345 | sp<ProClient> clientPro; |
| 346 | |
| 347 | for (int i = 0; i < mNumberOfCameras; ++i) { |
| 348 | Vector<size_t> removeIdx; |
| 349 | |
| 350 | for (size_t j = 0; j < mProClientList[i].size(); ++j) { |
| 351 | wp<ProClient> cl = mProClientList[i][j]; |
| 352 | |
| 353 | sp<ProClient> clStrong = cl.promote(); |
| 354 | if (clStrong != NULL && clStrong->getRemote() == cameraCallbacksRemote) { |
| 355 | clientPro = clStrong; |
| 356 | break; |
| 357 | } else if (clStrong == NULL) { |
| 358 | // mark to clean up dead ptr |
| 359 | removeIdx.push(j); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // remove stale ptrs (in reverse so the indices dont change) |
| 364 | for (ssize_t j = (ssize_t)removeIdx.size() - 1; j >= 0; --j) { |
| 365 | mProClientList[i].removeAt(removeIdx[j]); |
| 366 | } |
| 367 | |
| 368 | } |
| 369 | |
| 370 | return clientPro; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | sp<CameraService::Client> CameraService::findClientUnsafe( |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 374 | const wp<IBinder>& cameraClient, int& outIndex) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 375 | sp<Client> client; |
| 376 | |
| 377 | for (int i = 0; i < mNumberOfCameras; i++) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 378 | |
| 379 | // This happens when we have already disconnected (or this is |
| 380 | // just another unused camera). |
| 381 | if (mClient[i] == 0) continue; |
| 382 | |
| 383 | // Promote mClient. It can fail if we are called from this path: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 384 | // Client::~Client() -> disconnect() -> removeClientByRemote(). |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 385 | client = mClient[i].promote(); |
| 386 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 387 | // Clean up stale client entry |
| 388 | if (client == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 389 | mClient[i].clear(); |
| 390 | continue; |
| 391 | } |
| 392 | |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 393 | if (cameraClient == client->getCameraClient()->asBinder()) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 394 | // Found our camera |
| 395 | outIndex = i; |
| 396 | return client; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 400 | outIndex = -1; |
| 401 | return NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 404 | CameraService::Client* CameraService::getClientByIdUnsafe(int cameraId) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 405 | if (cameraId < 0 || cameraId >= mNumberOfCameras) return NULL; |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 406 | return mClient[cameraId].unsafe_get(); |
| 407 | } |
| 408 | |
| 409 | Mutex* CameraService::getClientLockById(int cameraId) { |
| 410 | if (cameraId < 0 || cameraId >= mNumberOfCameras) return NULL; |
| 411 | return &mClientLock[cameraId]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 414 | sp<CameraService::BasicClient> CameraService::getClientByRemote( |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 415 | const wp<IBinder>& cameraClient) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 416 | |
| 417 | // Declare this before the lock to make absolutely sure the |
| 418 | // destructor won't be called with the lock held. |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 419 | sp<BasicClient> client; |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 420 | |
| 421 | Mutex::Autolock lock(mServiceLock); |
| 422 | |
| 423 | int outIndex; |
| 424 | client = findClientUnsafe(cameraClient, outIndex); |
| 425 | |
| 426 | return client; |
| 427 | } |
| 428 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 429 | status_t CameraService::onTransact( |
| 430 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 431 | // Permission checks |
| 432 | switch (code) { |
| 433 | case BnCameraService::CONNECT: |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 434 | case BnCameraService::CONNECT_PRO: |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 435 | const int pid = getCallingPid(); |
| 436 | const int self_pid = getpid(); |
| 437 | if (pid != self_pid) { |
| 438 | // we're called from a different process, do the real check |
| 439 | if (!checkCallingPermission( |
| 440 | String16("android.permission.CAMERA"))) { |
| 441 | const int uid = getCallingUid(); |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 442 | ALOGE("Permission Denial: " |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 443 | "can't use the camera pid=%d, uid=%d", pid, uid); |
| 444 | return PERMISSION_DENIED; |
| 445 | } |
| 446 | } |
| 447 | break; |
| 448 | } |
| 449 | |
| 450 | return BnCameraService::onTransact(code, data, reply, flags); |
| 451 | } |
| 452 | |
| 453 | // The reason we need this busy bit is a new CameraService::connect() request |
| 454 | // may come in while the previous Client's destructor has not been run or is |
| 455 | // still running. If the last strong reference of the previous Client is gone |
| 456 | // but the destructor has not been finished, we should not allow the new Client |
| 457 | // to be created because we need to wait for the previous Client to tear down |
| 458 | // the hardware first. |
| 459 | void CameraService::setCameraBusy(int cameraId) { |
| 460 | android_atomic_write(1, &mBusy[cameraId]); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 461 | |
| 462 | ALOGV("setCameraBusy cameraId=%d", cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void CameraService::setCameraFree(int cameraId) { |
| 466 | android_atomic_write(0, &mBusy[cameraId]); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 467 | |
| 468 | ALOGV("setCameraFree cameraId=%d", cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | // We share the media players for shutter and recording sound for all clients. |
| 472 | // A reference count is kept to determine when we will actually release the |
| 473 | // media players. |
| 474 | |
Chih-Chung Chang | ff4f55c | 2011-10-17 19:03:12 +0800 | [diff] [blame] | 475 | MediaPlayer* CameraService::newMediaPlayer(const char *file) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 476 | MediaPlayer* mp = new MediaPlayer(); |
| 477 | if (mp->setDataSource(file, NULL) == NO_ERROR) { |
Eino-Ville Talvala | 60a78ac | 2012-01-05 15:34:53 -0800 | [diff] [blame] | 478 | mp->setAudioStreamType(AUDIO_STREAM_ENFORCED_AUDIBLE); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 479 | mp->prepare(); |
| 480 | } else { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 481 | ALOGE("Failed to load CameraService sounds: %s", file); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 482 | return NULL; |
| 483 | } |
| 484 | return mp; |
| 485 | } |
| 486 | |
| 487 | void CameraService::loadSound() { |
| 488 | Mutex::Autolock lock(mSoundLock); |
| 489 | LOG1("CameraService::loadSound ref=%d", mSoundRef); |
| 490 | if (mSoundRef++) return; |
| 491 | |
| 492 | mSoundPlayer[SOUND_SHUTTER] = newMediaPlayer("/system/media/audio/ui/camera_click.ogg"); |
| 493 | mSoundPlayer[SOUND_RECORDING] = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg"); |
| 494 | } |
| 495 | |
| 496 | void CameraService::releaseSound() { |
| 497 | Mutex::Autolock lock(mSoundLock); |
| 498 | LOG1("CameraService::releaseSound ref=%d", mSoundRef); |
| 499 | if (--mSoundRef) return; |
| 500 | |
| 501 | for (int i = 0; i < NUM_SOUNDS; i++) { |
| 502 | if (mSoundPlayer[i] != 0) { |
| 503 | mSoundPlayer[i]->disconnect(); |
| 504 | mSoundPlayer[i].clear(); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | void CameraService::playSound(sound_kind kind) { |
| 510 | LOG1("playSound(%d)", kind); |
| 511 | Mutex::Autolock lock(mSoundLock); |
| 512 | sp<MediaPlayer> player = mSoundPlayer[kind]; |
| 513 | if (player != 0) { |
Chih-Chung Chang | 8888a75 | 2011-10-20 10:47:26 +0800 | [diff] [blame] | 514 | player->seekTo(0); |
| 515 | player->start(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
| 519 | // ---------------------------------------------------------------------------- |
| 520 | |
| 521 | CameraService::Client::Client(const sp<CameraService>& cameraService, |
Wu-cheng Li | b7a6794 | 2010-08-17 15:45:37 -0700 | [diff] [blame] | 522 | const sp<ICameraClient>& cameraClient, |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 523 | int cameraId, int cameraFacing, int clientPid, int servicePid) : |
| 524 | CameraService::BasicClient(cameraService, cameraClient->asBinder(), |
| 525 | cameraId, cameraFacing, |
| 526 | clientPid, servicePid) |
| 527 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 528 | int callingPid = getCallingPid(); |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 529 | LOG1("Client::Client E (pid %d, id %d)", callingPid, cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 530 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 531 | mCameraClient = cameraClient; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 532 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 533 | cameraService->setCameraBusy(cameraId); |
| 534 | cameraService->loadSound(); |
Wu-cheng Li | 2fd2440 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 535 | LOG1("Client::Client X (pid %d, id %d)", callingPid, cameraId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 538 | // tear down the client |
| 539 | CameraService::Client::~Client() { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 540 | mDestructionStarted = true; |
| 541 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 542 | mCameraService->releaseSound(); |
Igor Murashkin | 036bc3e | 2012-10-08 15:09:46 -0700 | [diff] [blame] | 543 | |
| 544 | // unconditionally disconnect. function is idempotent |
| 545 | Client::disconnect(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 548 | CameraService::BasicClient::BasicClient(const sp<CameraService>& cameraService, |
| 549 | const sp<IBinder>& remoteCallback, |
| 550 | int cameraId, int cameraFacing, |
| 551 | int clientPid, int servicePid) |
| 552 | { |
| 553 | mCameraService = cameraService; |
| 554 | mRemoteCallback = remoteCallback; |
| 555 | mCameraId = cameraId; |
| 556 | mCameraFacing = cameraFacing; |
| 557 | mClientPid = clientPid; |
| 558 | mServicePid = servicePid; |
| 559 | |
| 560 | mDestructionStarted = false; |
| 561 | } |
| 562 | |
| 563 | CameraService::BasicClient::~BasicClient() { |
| 564 | mDestructionStarted = true; |
| 565 | } |
| 566 | |
| 567 | void CameraService::BasicClient::disconnect() { |
| 568 | mCameraService->removeClientByRemote(mRemoteCallback); |
| 569 | } |
| 570 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 571 | // ---------------------------------------------------------------------------- |
| 572 | |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 573 | Mutex* CameraService::Client::getClientLockFromCookie(void* user) { |
| 574 | return gCameraService->getClientLockById((int) user); |
| 575 | } |
| 576 | |
| 577 | // Provide client pointer for callbacks. Client lock returned from getClientLockFromCookie should |
| 578 | // be acquired for this to be safe |
| 579 | CameraService::Client* CameraService::Client::getClientFromCookie(void* user) { |
| 580 | Client* client = gCameraService->getClientByIdUnsafe((int) user); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 581 | |
| 582 | // This could happen if the Client is in the process of shutting down (the |
| 583 | // last strong reference is gone, but the destructor hasn't finished |
| 584 | // stopping the hardware). |
Keun young Park | d8973a7 | 2012-03-28 14:13:09 -0700 | [diff] [blame] | 585 | if (client == NULL) return NULL; |
| 586 | |
| 587 | // destruction already started, so should not be accessed |
| 588 | if (client->mDestructionStarted) return NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 589 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 590 | return client; |
| 591 | } |
| 592 | |
Igor Murashkin | 036bc3e | 2012-10-08 15:09:46 -0700 | [diff] [blame] | 593 | // NOTE: function is idempotent |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 594 | void CameraService::Client::disconnect() { |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 595 | BasicClient::disconnect(); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 596 | mCameraService->setCameraFree(mCameraId); |
Wu-cheng Li | e09591e | 2010-10-14 20:17:44 +0800 | [diff] [blame] | 597 | } |
| 598 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 599 | // ---------------------------------------------------------------------------- |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 600 | // IProCamera |
| 601 | // ---------------------------------------------------------------------------- |
| 602 | |
| 603 | CameraService::ProClient::ProClient(const sp<CameraService>& cameraService, |
| 604 | const sp<IProCameraCallbacks>& remoteCallback, |
| 605 | int cameraId, |
| 606 | int cameraFacing, |
| 607 | int clientPid, |
| 608 | int servicePid) |
| 609 | : CameraService::BasicClient(cameraService, remoteCallback->asBinder(), |
| 610 | cameraId, cameraFacing, |
| 611 | clientPid, servicePid) |
| 612 | { |
| 613 | mRemoteCallback = remoteCallback; |
| 614 | } |
| 615 | |
| 616 | CameraService::ProClient::~ProClient() { |
| 617 | mDestructionStarted = true; |
| 618 | |
| 619 | ProClient::disconnect(); |
| 620 | } |
| 621 | |
| 622 | status_t CameraService::ProClient::connect(const sp<IProCameraCallbacks>& callbacks) { |
| 623 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 624 | |
| 625 | return INVALID_OPERATION; |
| 626 | } |
| 627 | |
| 628 | void CameraService::ProClient::disconnect() { |
| 629 | BasicClient::disconnect(); |
| 630 | } |
| 631 | |
| 632 | status_t CameraService::ProClient::initialize(camera_module_t* module) |
| 633 | { |
| 634 | ALOGW("%s: not implemented yet", __FUNCTION__); |
| 635 | return OK; |
| 636 | } |
| 637 | |
| 638 | status_t CameraService::ProClient::exclusiveTryLock() { |
| 639 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 640 | return INVALID_OPERATION; |
| 641 | } |
| 642 | |
| 643 | status_t CameraService::ProClient::exclusiveLock() { |
| 644 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 645 | return INVALID_OPERATION; |
| 646 | } |
| 647 | |
| 648 | status_t CameraService::ProClient::exclusiveUnlock() { |
| 649 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 650 | return INVALID_OPERATION; |
| 651 | } |
| 652 | |
| 653 | bool CameraService::ProClient::hasExclusiveLock() { |
| 654 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 655 | return false; |
| 656 | } |
| 657 | |
| 658 | status_t CameraService::ProClient::submitRequest(camera_metadata_t* request, bool streaming) { |
| 659 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 660 | |
| 661 | free_camera_metadata(request); |
| 662 | |
| 663 | return INVALID_OPERATION; |
| 664 | } |
| 665 | |
| 666 | status_t CameraService::ProClient::cancelRequest(int requestId) { |
| 667 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 668 | |
| 669 | return INVALID_OPERATION; |
| 670 | } |
| 671 | |
| 672 | status_t CameraService::ProClient::requestStream(int streamId) { |
| 673 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 674 | |
| 675 | return INVALID_OPERATION; |
| 676 | } |
| 677 | |
| 678 | status_t CameraService::ProClient::cancelStream(int streamId) { |
| 679 | ALOGE("%s: not implemented yet", __FUNCTION__); |
| 680 | |
| 681 | return INVALID_OPERATION; |
| 682 | } |
| 683 | |
| 684 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 685 | |
| 686 | static const int kDumpLockRetries = 50; |
| 687 | static const int kDumpLockSleep = 60000; |
| 688 | |
| 689 | static bool tryLock(Mutex& mutex) |
| 690 | { |
| 691 | bool locked = false; |
| 692 | for (int i = 0; i < kDumpLockRetries; ++i) { |
| 693 | if (mutex.tryLock() == NO_ERROR) { |
| 694 | locked = true; |
| 695 | break; |
| 696 | } |
| 697 | usleep(kDumpLockSleep); |
| 698 | } |
| 699 | return locked; |
| 700 | } |
| 701 | |
| 702 | status_t CameraService::dump(int fd, const Vector<String16>& args) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 703 | String8 result; |
| 704 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 705 | result.appendFormat("Permission Denial: " |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 706 | "can't dump CameraService from pid=%d, uid=%d\n", |
| 707 | getCallingPid(), |
| 708 | getCallingUid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 709 | write(fd, result.string(), result.size()); |
| 710 | } else { |
| 711 | bool locked = tryLock(mServiceLock); |
| 712 | // failed to lock - CameraService is probably deadlocked |
| 713 | if (!locked) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 714 | result.append("CameraService may be deadlocked\n"); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 715 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | bool hasClient = false; |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 719 | if (!mModule) { |
| 720 | result = String8::format("No camera module available!\n"); |
| 721 | write(fd, result.string(), result.size()); |
| 722 | return NO_ERROR; |
| 723 | } |
| 724 | |
| 725 | result = String8::format("Camera module HAL API version: 0x%x\n", |
| 726 | mModule->common.hal_api_version); |
| 727 | result.appendFormat("Camera module API version: 0x%x\n", |
| 728 | mModule->common.module_api_version); |
| 729 | result.appendFormat("Camera module name: %s\n", |
| 730 | mModule->common.name); |
| 731 | result.appendFormat("Camera module author: %s\n", |
| 732 | mModule->common.author); |
| 733 | result.appendFormat("Number of camera devices: %d\n\n", mNumberOfCameras); |
| 734 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 735 | for (int i = 0; i < mNumberOfCameras; i++) { |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 736 | result = String8::format("Camera %d static information:\n", i); |
| 737 | camera_info info; |
| 738 | |
| 739 | status_t rc = mModule->get_camera_info(i, &info); |
| 740 | if (rc != OK) { |
| 741 | result.appendFormat(" Error reading static information!\n"); |
| 742 | write(fd, result.string(), result.size()); |
| 743 | } else { |
| 744 | result.appendFormat(" Facing: %s\n", |
| 745 | info.facing == CAMERA_FACING_BACK ? "BACK" : "FRONT"); |
| 746 | result.appendFormat(" Orientation: %d\n", info.orientation); |
| 747 | int deviceVersion; |
| 748 | if (mModule->common.module_api_version < |
| 749 | CAMERA_MODULE_API_VERSION_2_0) { |
| 750 | deviceVersion = CAMERA_DEVICE_API_VERSION_1_0; |
| 751 | } else { |
| 752 | deviceVersion = info.device_version; |
| 753 | } |
| 754 | result.appendFormat(" Device version: 0x%x\n", deviceVersion); |
| 755 | if (deviceVersion >= CAMERA_DEVICE_API_VERSION_2_0) { |
| 756 | result.appendFormat(" Device static metadata:\n"); |
| 757 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 758 | dump_indented_camera_metadata(info.static_camera_characteristics, |
| 759 | fd, 2, 4); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 760 | } else { |
| 761 | write(fd, result.string(), result.size()); |
| 762 | } |
| 763 | } |
| 764 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 765 | sp<Client> client = mClient[i].promote(); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 766 | if (client == 0) { |
| 767 | result = String8::format(" Device is closed, no client instance\n"); |
| 768 | write(fd, result.string(), result.size()); |
| 769 | continue; |
| 770 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 771 | hasClient = true; |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 772 | result = String8::format(" Device is open. Client instance dump:\n"); |
| 773 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 5e08d60 | 2012-05-16 14:59:25 -0700 | [diff] [blame] | 774 | client->dump(fd, args); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 775 | } |
| 776 | if (!hasClient) { |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 777 | result = String8::format("\nNo active camera clients yet.\n"); |
| 778 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | if (locked) mServiceLock.unlock(); |
| 782 | |
| 783 | // change logging level |
| 784 | int n = args.size(); |
| 785 | for (int i = 0; i + 1 < n; i++) { |
Eino-Ville Talvala | 611f619 | 2012-05-31 12:28:23 -0700 | [diff] [blame] | 786 | String16 verboseOption("-v"); |
| 787 | if (args[i] == verboseOption) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 788 | String8 levelStr(args[i+1]); |
| 789 | int level = atoi(levelStr.string()); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 790 | result = String8::format("\nSetting log level to %d.\n", level); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 791 | setLogLevel(level); |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 792 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 793 | } |
| 794 | } |
Eino-Ville Talvala | f592613 | 2012-07-17 13:54:20 -0700 | [diff] [blame] | 795 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 796 | } |
| 797 | return NO_ERROR; |
| 798 | } |
| 799 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 800 | /*virtual*/void CameraService::binderDied( |
| 801 | const wp<IBinder> &who) { |
| 802 | |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 803 | /** |
| 804 | * While tempting to promote the wp<IBinder> into a sp, |
| 805 | * it's actually not supported by the binder driver |
| 806 | */ |
| 807 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 808 | ALOGV("java clients' binder died"); |
| 809 | |
Igor Murashkin | 634a515 | 2013-02-20 17:15:11 -0800 | [diff] [blame] | 810 | sp<BasicClient> cameraClient = getClientByRemote(who); |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 811 | |
Igor Murashkin | 294d0ec | 2012-10-05 10:44:57 -0700 | [diff] [blame] | 812 | if (cameraClient == 0) { |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 813 | ALOGV("java clients' binder death already cleaned up (normal case)"); |
| 814 | return; |
| 815 | } |
| 816 | |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 817 | ALOGW("Disconnecting camera client %p since the binder for it " |
| 818 | "died (this pid %d)", cameraClient.get(), getCallingPid()); |
| 819 | |
| 820 | cameraClient->disconnect(); |
| 821 | |
| 822 | } |
| 823 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 824 | }; // namespace android |