Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "ACameraManager" |
| 19 | |
| 20 | #include <memory> |
| 21 | #include "ACameraManager.h" |
| 22 | #include "ACameraMetadata.h" |
| 23 | #include "ACameraDevice.h" |
| 24 | #include <utils/Vector.h> |
Ivan Podogov | ee844a8 | 2016-09-15 11:32:41 +0100 | [diff] [blame] | 25 | #include <cutils/properties.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 26 | #include <stdlib.h> |
| 27 | #include <camera/VendorTagDescriptor.h> |
| 28 | |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 29 | using namespace android::acam; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 30 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 31 | namespace android { |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 32 | namespace acam { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 33 | // Static member definitions |
| 34 | const char* CameraManagerGlobal::kCameraIdKey = "CameraId"; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame^] | 35 | const char* CameraManagerGlobal::kPhysicalCameraIdKey = "PhysicalCameraId"; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 36 | const char* CameraManagerGlobal::kCallbackFpKey = "CallbackFp"; |
| 37 | const char* CameraManagerGlobal::kContextKey = "CallbackContext"; |
| 38 | Mutex CameraManagerGlobal::sLock; |
| 39 | CameraManagerGlobal* CameraManagerGlobal::sInstance = nullptr; |
| 40 | |
| 41 | CameraManagerGlobal& |
| 42 | CameraManagerGlobal::getInstance() { |
| 43 | Mutex::Autolock _l(sLock); |
| 44 | CameraManagerGlobal* instance = sInstance; |
| 45 | if (instance == nullptr) { |
| 46 | instance = new CameraManagerGlobal(); |
| 47 | sInstance = instance; |
| 48 | } |
| 49 | return *instance; |
| 50 | } |
| 51 | |
| 52 | CameraManagerGlobal::~CameraManagerGlobal() { |
| 53 | // clear sInstance so next getInstance call knows to create a new one |
| 54 | Mutex::Autolock _sl(sLock); |
| 55 | sInstance = nullptr; |
| 56 | Mutex::Autolock _l(mLock); |
| 57 | if (mCameraService != nullptr) { |
| 58 | IInterface::asBinder(mCameraService)->unlinkToDeath(mDeathNotifier); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 59 | mCameraService->removeListener(mCameraServiceListener); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 60 | } |
| 61 | mDeathNotifier.clear(); |
| 62 | if (mCbLooper != nullptr) { |
| 63 | mCbLooper->unregisterHandler(mHandler->id()); |
| 64 | mCbLooper->stop(); |
| 65 | } |
| 66 | mCbLooper.clear(); |
| 67 | mHandler.clear(); |
| 68 | mCameraServiceListener.clear(); |
| 69 | mCameraService.clear(); |
| 70 | } |
| 71 | |
Ivan Podogov | ee844a8 | 2016-09-15 11:32:41 +0100 | [diff] [blame] | 72 | static bool isCameraServiceDisabled() { |
| 73 | char value[PROPERTY_VALUE_MAX]; |
| 74 | property_get("config.disable_cameraservice", value, "0"); |
| 75 | return (strncmp(value, "0", 2) != 0 && strncasecmp(value, "false", 6) != 0); |
| 76 | } |
| 77 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 78 | sp<hardware::ICameraService> CameraManagerGlobal::getCameraService() { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 79 | Mutex::Autolock _l(mLock); |
Jayant Chowdhary | 80f128b | 2019-10-30 16:13:31 -0700 | [diff] [blame] | 80 | return getCameraServiceLocked(); |
| 81 | } |
| 82 | |
| 83 | sp<hardware::ICameraService> CameraManagerGlobal::getCameraServiceLocked() { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 84 | if (mCameraService.get() == nullptr) { |
Ivan Podogov | ee844a8 | 2016-09-15 11:32:41 +0100 | [diff] [blame] | 85 | if (isCameraServiceDisabled()) { |
| 86 | return mCameraService; |
| 87 | } |
| 88 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 89 | sp<IServiceManager> sm = defaultServiceManager(); |
| 90 | sp<IBinder> binder; |
| 91 | do { |
| 92 | binder = sm->getService(String16(kCameraServiceName)); |
| 93 | if (binder != nullptr) { |
| 94 | break; |
| 95 | } |
| 96 | ALOGW("CameraService not published, waiting..."); |
| 97 | usleep(kCameraServicePollDelay); |
| 98 | } while(true); |
| 99 | if (mDeathNotifier == nullptr) { |
| 100 | mDeathNotifier = new DeathNotifier(this); |
| 101 | } |
| 102 | binder->linkToDeath(mDeathNotifier); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 103 | mCameraService = interface_cast<hardware::ICameraService>(binder); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 104 | |
| 105 | // Setup looper thread to perfrom availiability callbacks |
| 106 | if (mCbLooper == nullptr) { |
| 107 | mCbLooper = new ALooper; |
| 108 | mCbLooper->setName("C2N-mgr-looper"); |
Eino-Ville Talvala | 02bf032 | 2016-02-18 12:41:10 -0800 | [diff] [blame] | 109 | status_t err = mCbLooper->start( |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 110 | /*runOnCallingThread*/false, |
| 111 | /*canCallJava*/ true, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 112 | PRIORITY_DEFAULT); |
Eino-Ville Talvala | 02bf032 | 2016-02-18 12:41:10 -0800 | [diff] [blame] | 113 | if (err != OK) { |
| 114 | ALOGE("%s: Unable to start camera service listener looper: %s (%d)", |
| 115 | __FUNCTION__, strerror(-err), err); |
| 116 | mCbLooper.clear(); |
| 117 | return nullptr; |
| 118 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 119 | if (mHandler == nullptr) { |
| 120 | mHandler = new CallbackHandler(); |
| 121 | } |
| 122 | mCbLooper->registerHandler(mHandler); |
| 123 | } |
| 124 | |
| 125 | // register ICameraServiceListener |
| 126 | if (mCameraServiceListener == nullptr) { |
| 127 | mCameraServiceListener = new CameraServiceListener(this); |
| 128 | } |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 129 | std::vector<hardware::CameraStatus> cameraStatuses{}; |
| 130 | mCameraService->addListener(mCameraServiceListener, &cameraStatuses); |
| 131 | for (auto& c : cameraStatuses) { |
| 132 | onStatusChangedLocked(c.status, c.cameraId); |
| 133 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 134 | |
| 135 | // setup vendor tags |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 136 | sp<VendorTagDescriptor> desc = new VendorTagDescriptor(); |
| 137 | binder::Status ret = mCameraService->getCameraVendorTagDescriptor(/*out*/desc.get()); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 138 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 139 | if (ret.isOk()) { |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 140 | if (0 < desc->getTagCount()) { |
| 141 | status_t err = VendorTagDescriptor::setAsGlobalVendorTagDescriptor(desc); |
| 142 | if (err != OK) { |
| 143 | ALOGE("%s: Failed to set vendor tag descriptors, received error %s (%d)", |
| 144 | __FUNCTION__, strerror(-err), err); |
| 145 | } |
| 146 | } else { |
| 147 | sp<VendorTagDescriptorCache> cache = |
| 148 | new VendorTagDescriptorCache(); |
| 149 | binder::Status res = |
| 150 | mCameraService->getCameraVendorTagCache( |
| 151 | /*out*/cache.get()); |
| 152 | if (res.serviceSpecificErrorCode() == |
| 153 | hardware::ICameraService::ERROR_DISCONNECTED) { |
| 154 | // No camera module available, not an error on devices with no cameras |
| 155 | VendorTagDescriptorCache::clearGlobalVendorTagCache(); |
| 156 | } else if (res.isOk()) { |
| 157 | status_t err = |
| 158 | VendorTagDescriptorCache::setAsGlobalVendorTagCache( |
| 159 | cache); |
| 160 | if (err != OK) { |
| 161 | ALOGE("%s: Failed to set vendor tag cache," |
| 162 | "received error %s (%d)", __FUNCTION__, |
| 163 | strerror(-err), err); |
| 164 | } |
| 165 | } else { |
| 166 | VendorTagDescriptorCache::clearGlobalVendorTagCache(); |
| 167 | ALOGE("%s: Failed to setup vendor tag cache: %s", |
| 168 | __FUNCTION__, res.toString8().string()); |
| 169 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 170 | } |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 171 | } else if (ret.serviceSpecificErrorCode() == |
| 172 | hardware::ICameraService::ERROR_DEPRECATED_HAL) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 173 | ALOGW("%s: Camera HAL too old; does not support vendor tags", |
| 174 | __FUNCTION__); |
| 175 | VendorTagDescriptor::clearGlobalVendorTagDescriptor(); |
| 176 | } else { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 177 | ALOGE("%s: Failed to get vendor tag descriptors: %s", |
| 178 | __FUNCTION__, ret.toString8().string()); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | ALOGE_IF(mCameraService == nullptr, "no CameraService!?"); |
| 182 | return mCameraService; |
| 183 | } |
| 184 | |
| 185 | void CameraManagerGlobal::DeathNotifier::binderDied(const wp<IBinder>&) |
| 186 | { |
| 187 | ALOGE("Camera service binderDied!"); |
| 188 | sp<CameraManagerGlobal> cm = mCameraManager.promote(); |
| 189 | if (cm != nullptr) { |
| 190 | AutoMutex lock(cm->mLock); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 191 | for (auto& pair : cm->mDeviceStatusMap) { |
| 192 | const String8 &cameraId = pair.first; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 193 | cm->onStatusChangedLocked( |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 194 | CameraServiceListener::STATUS_NOT_PRESENT, cameraId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 195 | } |
| 196 | cm->mCameraService.clear(); |
| 197 | // TODO: consider adding re-connect call here? |
| 198 | } |
| 199 | } |
| 200 | |
Emilian Peev | c6f2ab3 | 2019-03-04 11:18:59 -0800 | [diff] [blame] | 201 | void CameraManagerGlobal::registerExtendedAvailabilityCallback( |
| 202 | const ACameraManager_ExtendedAvailabilityCallbacks *callback) { |
| 203 | Mutex::Autolock _l(mLock); |
| 204 | Callback cb(callback); |
| 205 | mCallbacks.insert(cb); |
| 206 | } |
| 207 | |
| 208 | void CameraManagerGlobal::unregisterExtendedAvailabilityCallback( |
| 209 | const ACameraManager_ExtendedAvailabilityCallbacks *callback) { |
| 210 | Mutex::Autolock _l(mLock); |
| 211 | Callback cb(callback); |
| 212 | mCallbacks.erase(cb); |
| 213 | } |
| 214 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 215 | void CameraManagerGlobal::registerAvailabilityCallback( |
| 216 | const ACameraManager_AvailabilityCallbacks *callback) { |
| 217 | Mutex::Autolock _l(mLock); |
| 218 | Callback cb(callback); |
| 219 | auto pair = mCallbacks.insert(cb); |
| 220 | // Send initial callbacks if callback is newly registered |
| 221 | if (pair.second) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 222 | for (auto& pair : mDeviceStatusMap) { |
| 223 | const String8& cameraId = pair.first; |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame^] | 224 | int32_t status = pair.second.getStatus(); |
Jayant Chowdhary | 80f128b | 2019-10-30 16:13:31 -0700 | [diff] [blame] | 225 | // Don't send initial callbacks for camera ids which don't support |
| 226 | // camera2 |
| 227 | if (!pair.second.supportsHAL3) { |
| 228 | continue; |
| 229 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 230 | sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler); |
| 231 | ACameraManager_AvailabilityCallback cb = isStatusAvailable(status) ? |
| 232 | callback->onCameraAvailable : callback->onCameraUnavailable; |
| 233 | msg->setPointer(kCallbackFpKey, (void *) cb); |
| 234 | msg->setPointer(kContextKey, callback->context); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 235 | msg->setString(kCameraIdKey, AString(cameraId)); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 236 | msg->post(); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | void CameraManagerGlobal::unregisterAvailabilityCallback( |
| 242 | const ACameraManager_AvailabilityCallbacks *callback) { |
| 243 | Mutex::Autolock _l(mLock); |
| 244 | Callback cb(callback); |
| 245 | mCallbacks.erase(cb); |
| 246 | } |
| 247 | |
Jayant Chowdhary | 80f128b | 2019-10-30 16:13:31 -0700 | [diff] [blame] | 248 | bool CameraManagerGlobal::supportsCamera2ApiLocked(const String8 &cameraId) { |
| 249 | bool camera2Support = false; |
| 250 | auto cs = getCameraServiceLocked(); |
| 251 | binder::Status serviceRet = |
| 252 | cs->supportsCameraApi(String16(cameraId), |
| 253 | hardware::ICameraService::API_VERSION_2, &camera2Support); |
| 254 | if (!serviceRet.isOk()) { |
| 255 | ALOGE("%s: supportsCameraApi2Locked() call failed for cameraId %s", |
| 256 | __FUNCTION__, cameraId.c_str()); |
| 257 | return false; |
| 258 | } |
| 259 | return camera2Support; |
| 260 | } |
| 261 | |
Yin-Chia Yeh | 03f5575 | 2018-03-14 15:28:02 -0700 | [diff] [blame] | 262 | void CameraManagerGlobal::getCameraIdList(std::vector<String8>* cameraIds) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 263 | // Ensure that we have initialized/refreshed the list of available devices |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 264 | Mutex::Autolock _l(mLock); |
Jayant Chowdhary | 80f128b | 2019-10-30 16:13:31 -0700 | [diff] [blame] | 265 | // Needed to make sure we're connected to cameraservice |
| 266 | getCameraServiceLocked(); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 267 | for(auto& deviceStatus : mDeviceStatusMap) { |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame^] | 268 | int32_t status = deviceStatus.second.getStatus(); |
| 269 | if (status == hardware::ICameraServiceListener::STATUS_NOT_PRESENT || |
| 270 | status == hardware::ICameraServiceListener::STATUS_ENUMERATING) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 271 | continue; |
| 272 | } |
Jayant Chowdhary | 80f128b | 2019-10-30 16:13:31 -0700 | [diff] [blame] | 273 | if (!deviceStatus.second.supportsHAL3) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 274 | continue; |
| 275 | } |
| 276 | cameraIds->push_back(deviceStatus.first); |
| 277 | } |
| 278 | } |
| 279 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 280 | bool CameraManagerGlobal::validStatus(int32_t status) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 281 | switch (status) { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 282 | case hardware::ICameraServiceListener::STATUS_NOT_PRESENT: |
| 283 | case hardware::ICameraServiceListener::STATUS_PRESENT: |
| 284 | case hardware::ICameraServiceListener::STATUS_ENUMERATING: |
| 285 | case hardware::ICameraServiceListener::STATUS_NOT_AVAILABLE: |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 286 | return true; |
| 287 | default: |
| 288 | return false; |
| 289 | } |
| 290 | } |
| 291 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 292 | bool CameraManagerGlobal::isStatusAvailable(int32_t status) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 293 | switch (status) { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 294 | case hardware::ICameraServiceListener::STATUS_PRESENT: |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 295 | return true; |
| 296 | default: |
| 297 | return false; |
| 298 | } |
| 299 | } |
| 300 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 301 | void CameraManagerGlobal::CallbackHandler::onMessageReceived( |
| 302 | const sp<AMessage> &msg) { |
| 303 | switch (msg->what()) { |
| 304 | case kWhatSendSingleCallback: |
| 305 | { |
| 306 | ACameraManager_AvailabilityCallback cb; |
| 307 | void* context; |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 308 | AString cameraId; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 309 | bool found = msg->findPointer(kCallbackFpKey, (void**) &cb); |
| 310 | if (!found) { |
| 311 | ALOGE("%s: Cannot find camera callback fp!", __FUNCTION__); |
| 312 | return; |
| 313 | } |
| 314 | found = msg->findPointer(kContextKey, &context); |
| 315 | if (!found) { |
| 316 | ALOGE("%s: Cannot find callback context!", __FUNCTION__); |
| 317 | return; |
| 318 | } |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 319 | found = msg->findString(kCameraIdKey, &cameraId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 320 | if (!found) { |
| 321 | ALOGE("%s: Cannot find camera ID!", __FUNCTION__); |
| 322 | return; |
| 323 | } |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 324 | (*cb)(context, cameraId.c_str()); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 325 | break; |
| 326 | } |
Emilian Peev | c6f2ab3 | 2019-03-04 11:18:59 -0800 | [diff] [blame] | 327 | case kWhatSendSingleAccessCallback: |
| 328 | { |
| 329 | ACameraManager_AccessPrioritiesChangedCallback cb; |
| 330 | void* context; |
| 331 | AString cameraId; |
| 332 | bool found = msg->findPointer(kCallbackFpKey, (void**) &cb); |
| 333 | if (!found) { |
| 334 | ALOGE("%s: Cannot find camera callback fp!", __FUNCTION__); |
| 335 | return; |
| 336 | } |
| 337 | found = msg->findPointer(kContextKey, &context); |
| 338 | if (!found) { |
| 339 | ALOGE("%s: Cannot find callback context!", __FUNCTION__); |
| 340 | return; |
| 341 | } |
| 342 | (*cb)(context); |
| 343 | break; |
| 344 | } |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame^] | 345 | case kWhatSendSinglePhysicalCameraCallback: |
| 346 | { |
| 347 | ACameraManager_PhysicalCameraAvailabilityCallback cb; |
| 348 | void* context; |
| 349 | AString cameraId; |
| 350 | AString physicalCameraId; |
| 351 | bool found = msg->findPointer(kCallbackFpKey, (void**) &cb); |
| 352 | if (!found) { |
| 353 | ALOGE("%s: Cannot find camera callback fp!", __FUNCTION__); |
| 354 | return; |
| 355 | } |
| 356 | if (cb == nullptr) { |
| 357 | // Physical camera callback is null |
| 358 | return; |
| 359 | } |
| 360 | found = msg->findPointer(kContextKey, &context); |
| 361 | if (!found) { |
| 362 | ALOGE("%s: Cannot find callback context!", __FUNCTION__); |
| 363 | return; |
| 364 | } |
| 365 | found = msg->findString(kCameraIdKey, &cameraId); |
| 366 | if (!found) { |
| 367 | ALOGE("%s: Cannot find camera ID!", __FUNCTION__); |
| 368 | return; |
| 369 | } |
| 370 | found = msg->findString(kPhysicalCameraIdKey, &physicalCameraId); |
| 371 | if (!found) { |
| 372 | ALOGE("%s: Cannot find physical camera ID!", __FUNCTION__); |
| 373 | return; |
| 374 | } |
| 375 | (*cb)(context, cameraId.c_str(), physicalCameraId.c_str()); |
| 376 | break; |
| 377 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 378 | default: |
| 379 | ALOGE("%s: unknown message type %d", __FUNCTION__, msg->what()); |
| 380 | break; |
| 381 | } |
| 382 | } |
| 383 | |
Emilian Peev | c6f2ab3 | 2019-03-04 11:18:59 -0800 | [diff] [blame] | 384 | binder::Status CameraManagerGlobal::CameraServiceListener::onCameraAccessPrioritiesChanged() { |
| 385 | sp<CameraManagerGlobal> cm = mCameraManager.promote(); |
| 386 | if (cm != nullptr) { |
| 387 | cm->onCameraAccessPrioritiesChanged(); |
| 388 | } else { |
| 389 | ALOGE("Cannot deliver camera access priority callback. Global camera manager died"); |
| 390 | } |
| 391 | return binder::Status::ok(); |
| 392 | } |
| 393 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 394 | binder::Status CameraManagerGlobal::CameraServiceListener::onStatusChanged( |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 395 | int32_t status, const String16& cameraId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 396 | sp<CameraManagerGlobal> cm = mCameraManager.promote(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 397 | if (cm != nullptr) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 398 | cm->onStatusChanged(status, String8(cameraId)); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 399 | } else { |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 400 | ALOGE("Cannot deliver status change. Global camera manager died"); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 401 | } |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 402 | return binder::Status::ok(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 403 | } |
| 404 | |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame^] | 405 | binder::Status CameraManagerGlobal::CameraServiceListener::onPhysicalCameraStatusChanged( |
| 406 | int32_t status, const String16& cameraId, const String16& physicalCameraId) { |
| 407 | sp<CameraManagerGlobal> cm = mCameraManager.promote(); |
| 408 | if (cm != nullptr) { |
| 409 | cm->onStatusChanged(status, String8(cameraId), String8(physicalCameraId)); |
| 410 | } else { |
| 411 | ALOGE("Cannot deliver physical camera status change. Global camera manager died"); |
| 412 | } |
| 413 | return binder::Status::ok(); |
| 414 | } |
| 415 | |
Emilian Peev | c6f2ab3 | 2019-03-04 11:18:59 -0800 | [diff] [blame] | 416 | void CameraManagerGlobal::onCameraAccessPrioritiesChanged() { |
| 417 | Mutex::Autolock _l(mLock); |
| 418 | for (auto cb : mCallbacks) { |
| 419 | sp<AMessage> msg = new AMessage(kWhatSendSingleAccessCallback, mHandler); |
| 420 | ACameraManager_AccessPrioritiesChangedCallback cbFp = cb.mAccessPriorityChanged; |
| 421 | if (cbFp != nullptr) { |
| 422 | msg->setPointer(kCallbackFpKey, (void *) cbFp); |
| 423 | msg->setPointer(kContextKey, cb.mContext); |
| 424 | msg->post(); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 429 | void CameraManagerGlobal::onStatusChanged( |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 430 | int32_t status, const String8& cameraId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 431 | Mutex::Autolock _l(mLock); |
| 432 | onStatusChangedLocked(status, cameraId); |
| 433 | } |
| 434 | |
| 435 | void CameraManagerGlobal::onStatusChangedLocked( |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 436 | int32_t status, const String8& cameraId) { |
| 437 | if (!validStatus(status)) { |
| 438 | ALOGE("%s: Invalid status %d", __FUNCTION__, status); |
| 439 | return; |
| 440 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 441 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 442 | bool firstStatus = (mDeviceStatusMap.count(cameraId) == 0); |
| 443 | int32_t oldStatus = firstStatus ? |
| 444 | status : // first status |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame^] | 445 | mDeviceStatusMap[cameraId].getStatus(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 446 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 447 | if (!firstStatus && |
| 448 | isStatusAvailable(status) == isStatusAvailable(oldStatus)) { |
| 449 | // No status update. No need to send callback |
| 450 | return; |
| 451 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 452 | |
Jayant Chowdhary | 80f128b | 2019-10-30 16:13:31 -0700 | [diff] [blame] | 453 | bool supportsHAL3 = supportsCamera2ApiLocked(cameraId); |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame^] | 454 | if (firstStatus) { |
| 455 | mDeviceStatusMap.emplace(std::piecewise_construct, |
| 456 | std::forward_as_tuple(cameraId), |
| 457 | std::forward_as_tuple(status, supportsHAL3)); |
| 458 | } else { |
| 459 | mDeviceStatusMap[cameraId].updateStatus(status); |
| 460 | } |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 461 | // Iterate through all registered callbacks |
Jayant Chowdhary | 80f128b | 2019-10-30 16:13:31 -0700 | [diff] [blame] | 462 | if (supportsHAL3) { |
| 463 | for (auto cb : mCallbacks) { |
| 464 | sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler); |
| 465 | ACameraManager_AvailabilityCallback cbFp = isStatusAvailable(status) ? |
| 466 | cb.mAvailable : cb.mUnavailable; |
| 467 | msg->setPointer(kCallbackFpKey, (void *) cbFp); |
| 468 | msg->setPointer(kContextKey, cb.mContext); |
| 469 | msg->setString(kCameraIdKey, AString(cameraId)); |
| 470 | msg->post(); |
| 471 | } |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 472 | } |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 473 | if (status == hardware::ICameraServiceListener::STATUS_NOT_PRESENT) { |
| 474 | mDeviceStatusMap.erase(cameraId); |
| 475 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Shuzhen Wang | 4385816 | 2020-01-10 13:42:15 -0800 | [diff] [blame^] | 478 | void CameraManagerGlobal::onStatusChanged( |
| 479 | int32_t status, const String8& cameraId, const String8& physicalCameraId) { |
| 480 | Mutex::Autolock _l(mLock); |
| 481 | onStatusChangedLocked(status, cameraId, physicalCameraId); |
| 482 | } |
| 483 | |
| 484 | void CameraManagerGlobal::onStatusChangedLocked( |
| 485 | int32_t status, const String8& cameraId, const String8& physicalCameraId) { |
| 486 | if (!validStatus(status)) { |
| 487 | ALOGE("%s: Invalid status %d", __FUNCTION__, status); |
| 488 | return; |
| 489 | } |
| 490 | |
| 491 | auto logicalStatus = mDeviceStatusMap.find(cameraId); |
| 492 | if (logicalStatus == mDeviceStatusMap.end()) { |
| 493 | ALOGE("%s: Physical camera id %s status change on a non-present id %s", |
| 494 | __FUNCTION__, physicalCameraId.c_str(), cameraId.c_str()); |
| 495 | return; |
| 496 | } |
| 497 | int32_t logicalCamStatus = mDeviceStatusMap[cameraId].getStatus(); |
| 498 | if (logicalCamStatus != hardware::ICameraServiceListener::STATUS_PRESENT && |
| 499 | logicalCamStatus != hardware::ICameraServiceListener::STATUS_NOT_AVAILABLE) { |
| 500 | ALOGE("%s: Physical camera id %s status %d change for an invalid logical camera state %d", |
| 501 | __FUNCTION__, physicalCameraId.string(), status, logicalCamStatus); |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | bool supportsHAL3 = supportsCamera2ApiLocked(cameraId); |
| 506 | |
| 507 | bool updated = false; |
| 508 | if (status == hardware::ICameraServiceListener::STATUS_PRESENT) { |
| 509 | updated = mDeviceStatusMap[cameraId].removeUnavailablePhysicalId(physicalCameraId); |
| 510 | } else { |
| 511 | updated = mDeviceStatusMap[cameraId].addUnavailablePhysicalId(physicalCameraId); |
| 512 | } |
| 513 | |
| 514 | // Iterate through all registered callbacks |
| 515 | if (supportsHAL3 && updated) { |
| 516 | for (auto cb : mCallbacks) { |
| 517 | sp<AMessage> msg = new AMessage(kWhatSendSinglePhysicalCameraCallback, mHandler); |
| 518 | ACameraManager_PhysicalCameraAvailabilityCallback cbFp = isStatusAvailable(status) ? |
| 519 | cb.mPhysicalCamAvailable : cb.mPhysicalCamUnavailable; |
| 520 | msg->setPointer(kCallbackFpKey, (void *) cbFp); |
| 521 | msg->setPointer(kContextKey, cb.mContext); |
| 522 | msg->setString(kCameraIdKey, AString(cameraId)); |
| 523 | msg->setString(kPhysicalCameraIdKey, AString(physicalCameraId)); |
| 524 | msg->post(); |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | int32_t CameraManagerGlobal::StatusAndHAL3Support::getStatus() { |
| 530 | std::lock_guard<std::mutex> lock(mLock); |
| 531 | return status; |
| 532 | } |
| 533 | |
| 534 | void CameraManagerGlobal::StatusAndHAL3Support::updateStatus(int32_t newStatus) { |
| 535 | std::lock_guard<std::mutex> lock(mLock); |
| 536 | status = newStatus; |
| 537 | } |
| 538 | |
| 539 | bool CameraManagerGlobal::StatusAndHAL3Support::addUnavailablePhysicalId( |
| 540 | const String8& physicalCameraId) { |
| 541 | std::lock_guard<std::mutex> lock(mLock); |
| 542 | auto result = unavailablePhysicalIds.insert(physicalCameraId); |
| 543 | return result.second; |
| 544 | } |
| 545 | |
| 546 | bool CameraManagerGlobal::StatusAndHAL3Support::removeUnavailablePhysicalId( |
| 547 | const String8& physicalCameraId) { |
| 548 | std::lock_guard<std::mutex> lock(mLock); |
| 549 | auto count = unavailablePhysicalIds.erase(physicalCameraId); |
| 550 | return count > 0; |
| 551 | } |
| 552 | |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 553 | } // namespace acam |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 554 | } // namespace android |
| 555 | |
| 556 | /** |
| 557 | * ACameraManger Implementation |
| 558 | */ |
| 559 | camera_status_t |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 560 | ACameraManager::getCameraIdList(ACameraIdList** cameraIdList) { |
| 561 | Mutex::Autolock _l(mLock); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 562 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 563 | std::vector<String8> idList; |
| 564 | CameraManagerGlobal::getInstance().getCameraIdList(&idList); |
| 565 | |
| 566 | int numCameras = idList.size(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 567 | ACameraIdList *out = new ACameraIdList; |
| 568 | if (!out) { |
| 569 | ALOGE("Allocate memory for ACameraIdList failed!"); |
| 570 | return ACAMERA_ERROR_NOT_ENOUGH_MEMORY; |
| 571 | } |
| 572 | out->numCameras = numCameras; |
Bjoern Johansson | 1a5954c | 2017-01-10 10:30:18 -0800 | [diff] [blame] | 573 | out->cameraIds = new const char*[numCameras]; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 574 | if (!out->cameraIds) { |
| 575 | ALOGE("Allocate memory for ACameraIdList failed!"); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 576 | deleteCameraIdList(out); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 577 | return ACAMERA_ERROR_NOT_ENOUGH_MEMORY; |
| 578 | } |
| 579 | for (int i = 0; i < numCameras; i++) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 580 | const char* src = idList[i].string(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 581 | size_t dstSize = strlen(src) + 1; |
| 582 | char* dst = new char[dstSize]; |
| 583 | if (!dst) { |
| 584 | ALOGE("Allocate memory for ACameraIdList failed!"); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 585 | deleteCameraIdList(out); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 586 | return ACAMERA_ERROR_NOT_ENOUGH_MEMORY; |
| 587 | } |
| 588 | strlcpy(dst, src, dstSize); |
| 589 | out->cameraIds[i] = dst; |
| 590 | } |
| 591 | *cameraIdList = out; |
| 592 | return ACAMERA_OK; |
| 593 | } |
| 594 | |
| 595 | void |
| 596 | ACameraManager::deleteCameraIdList(ACameraIdList* cameraIdList) { |
| 597 | if (cameraIdList != nullptr) { |
| 598 | if (cameraIdList->cameraIds != nullptr) { |
| 599 | for (int i = 0; i < cameraIdList->numCameras; i ++) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 600 | if (cameraIdList->cameraIds[i] != nullptr) { |
| 601 | delete[] cameraIdList->cameraIds[i]; |
| 602 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 603 | } |
| 604 | delete[] cameraIdList->cameraIds; |
| 605 | } |
| 606 | delete cameraIdList; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | camera_status_t ACameraManager::getCameraCharacteristics( |
Yin-Chia Yeh | dd045bf | 2018-08-20 12:39:19 -0700 | [diff] [blame] | 611 | const char* cameraIdStr, sp<ACameraMetadata>* characteristics) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 612 | Mutex::Autolock _l(mLock); |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 613 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 614 | sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 615 | if (cs == nullptr) { |
| 616 | ALOGE("%s: Cannot reach camera service!", __FUNCTION__); |
| 617 | return ACAMERA_ERROR_CAMERA_DISCONNECTED; |
| 618 | } |
| 619 | CameraMetadata rawMetadata; |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 620 | binder::Status serviceRet = cs->getCameraCharacteristics(String16(cameraIdStr), &rawMetadata); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 621 | if (!serviceRet.isOk()) { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 622 | switch(serviceRet.serviceSpecificErrorCode()) { |
| 623 | case hardware::ICameraService::ERROR_DISCONNECTED: |
| 624 | ALOGE("%s: Camera %s has been disconnected", __FUNCTION__, cameraIdStr); |
| 625 | return ACAMERA_ERROR_CAMERA_DISCONNECTED; |
| 626 | case hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT: |
| 627 | ALOGE("%s: Camera ID %s does not exist!", __FUNCTION__, cameraIdStr); |
| 628 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 629 | default: |
| 630 | ALOGE("Get camera characteristics from camera service failed: %s", |
| 631 | serviceRet.toString8().string()); |
| 632 | return ACAMERA_ERROR_UNKNOWN; // should not reach here |
| 633 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | *characteristics = new ACameraMetadata( |
| 637 | rawMetadata.release(), ACameraMetadata::ACM_CHARACTERISTICS); |
| 638 | return ACAMERA_OK; |
| 639 | } |
| 640 | |
| 641 | camera_status_t |
| 642 | ACameraManager::openCamera( |
| 643 | const char* cameraId, |
| 644 | ACameraDevice_StateCallbacks* callback, |
| 645 | /*out*/ACameraDevice** outDevice) { |
Yin-Chia Yeh | dd045bf | 2018-08-20 12:39:19 -0700 | [diff] [blame] | 646 | sp<ACameraMetadata> chars; |
| 647 | camera_status_t ret = getCameraCharacteristics(cameraId, &chars); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 648 | Mutex::Autolock _l(mLock); |
| 649 | if (ret != ACAMERA_OK) { |
| 650 | ALOGE("%s: cannot get camera characteristics for camera %s. err %d", |
| 651 | __FUNCTION__, cameraId, ret); |
| 652 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 653 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 654 | |
Yin-Chia Yeh | dd045bf | 2018-08-20 12:39:19 -0700 | [diff] [blame] | 655 | ACameraDevice* device = new ACameraDevice(cameraId, callback, chars); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 656 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 657 | sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 658 | if (cs == nullptr) { |
| 659 | ALOGE("%s: Cannot reach camera service!", __FUNCTION__); |
Yunlian Jiang | b01d8f7 | 2016-10-04 16:34:18 -0700 | [diff] [blame] | 660 | delete device; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 661 | return ACAMERA_ERROR_CAMERA_DISCONNECTED; |
| 662 | } |
| 663 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 664 | sp<hardware::camera2::ICameraDeviceCallbacks> callbacks = device->getServiceCallback(); |
| 665 | sp<hardware::camera2::ICameraDeviceUser> deviceRemote; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 666 | // No way to get package name from native. |
| 667 | // Send a zero length package name and let camera service figure it out from UID |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 668 | binder::Status serviceRet = cs->connectDevice( |
Philip P. Moltmann | 9e648f6 | 2019-11-04 12:52:45 -0800 | [diff] [blame] | 669 | callbacks, String16(cameraId), String16(""), std::unique_ptr<String16>(), |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 670 | hardware::ICameraService::USE_CALLING_UID, /*out*/&deviceRemote); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 671 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 672 | if (!serviceRet.isOk()) { |
| 673 | ALOGE("%s: connect camera device failed: %s", __FUNCTION__, serviceRet.toString8().string()); |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame] | 674 | // Convert serviceRet to camera_status_t |
| 675 | switch(serviceRet.serviceSpecificErrorCode()) { |
| 676 | case hardware::ICameraService::ERROR_DISCONNECTED: |
| 677 | ret = ACAMERA_ERROR_CAMERA_DISCONNECTED; |
| 678 | break; |
| 679 | case hardware::ICameraService::ERROR_CAMERA_IN_USE: |
| 680 | ret = ACAMERA_ERROR_CAMERA_IN_USE; |
| 681 | break; |
| 682 | case hardware::ICameraService::ERROR_MAX_CAMERAS_IN_USE: |
| 683 | ret = ACAMERA_ERROR_MAX_CAMERA_IN_USE; |
| 684 | break; |
| 685 | case hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT: |
| 686 | ret = ACAMERA_ERROR_INVALID_PARAMETER; |
| 687 | break; |
| 688 | case hardware::ICameraService::ERROR_DEPRECATED_HAL: |
| 689 | // Should not reach here since we filtered legacy HALs earlier |
| 690 | ret = ACAMERA_ERROR_INVALID_PARAMETER; |
| 691 | break; |
| 692 | case hardware::ICameraService::ERROR_DISABLED: |
| 693 | ret = ACAMERA_ERROR_CAMERA_DISABLED; |
| 694 | break; |
| 695 | case hardware::ICameraService::ERROR_PERMISSION_DENIED: |
| 696 | ret = ACAMERA_ERROR_PERMISSION_DENIED; |
| 697 | break; |
| 698 | case hardware::ICameraService::ERROR_INVALID_OPERATION: |
| 699 | default: |
| 700 | ret = ACAMERA_ERROR_UNKNOWN; |
| 701 | break; |
| 702 | } |
| 703 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 704 | delete device; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame] | 705 | return ret; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 706 | } |
| 707 | if (deviceRemote == nullptr) { |
| 708 | ALOGE("%s: connect camera device failed! remote device is null", __FUNCTION__); |
| 709 | delete device; |
| 710 | return ACAMERA_ERROR_CAMERA_DISCONNECTED; |
| 711 | } |
| 712 | device->setRemoteDevice(deviceRemote); |
| 713 | *outDevice = device; |
| 714 | return ACAMERA_OK; |
| 715 | } |
| 716 | |
| 717 | ACameraManager::~ACameraManager() { |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 718 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 719 | } |