Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_TAG "CameraProviderManager" |
| 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | #include "CameraProviderManager.h" |
| 22 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 23 | #include <algorithm> |
Yin-Chia Yeh | 6540509 | 2017-01-13 15:42:28 -0800 | [diff] [blame] | 24 | #include <chrono> |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 25 | #include <inttypes.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 26 | #include <hidl/ServiceManagement.h> |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 27 | #include <functional> |
| 28 | #include <camera_metadata_hidden.h> |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 29 | #include <android-base/parseint.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | using namespace ::android::hardware::camera; |
| 34 | using namespace ::android::hardware::camera::common::V1_0; |
| 35 | |
| 36 | namespace { |
| 37 | // Hardcoded name for the passthrough HAL implementation, since it can't be discovered via the |
| 38 | // service manager |
| 39 | const std::string kLegacyProviderName("legacy/0"); |
Yin-Chia Yeh | d78041a | 2018-01-20 13:45:38 -0800 | [diff] [blame] | 40 | const std::string kExternalProviderName("external/0"); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 41 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 42 | } // anonymous namespace |
| 43 | |
| 44 | CameraProviderManager::HardwareServiceInteractionProxy |
| 45 | CameraProviderManager::sHardwareServiceInteractionProxy{}; |
| 46 | |
| 47 | CameraProviderManager::~CameraProviderManager() { |
| 48 | } |
| 49 | |
| 50 | status_t CameraProviderManager::initialize(wp<CameraProviderManager::StatusListener> listener, |
| 51 | ServiceInteractionProxy* proxy) { |
Yin-Chia Yeh | 4c5b1c7 | 2017-01-31 13:20:56 -0800 | [diff] [blame] | 52 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 53 | if (proxy == nullptr) { |
| 54 | ALOGE("%s: No valid service interaction proxy provided", __FUNCTION__); |
| 55 | return BAD_VALUE; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 56 | } |
Yin-Chia Yeh | 4c5b1c7 | 2017-01-31 13:20:56 -0800 | [diff] [blame] | 57 | mListener = listener; |
| 58 | mServiceProxy = proxy; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 59 | |
Yin-Chia Yeh | 4c5b1c7 | 2017-01-31 13:20:56 -0800 | [diff] [blame] | 60 | // Registering will trigger notifications for all already-known providers |
| 61 | bool success = mServiceProxy->registerForNotifications( |
| 62 | /* instance name, empty means no filter */ "", |
| 63 | this); |
| 64 | if (!success) { |
| 65 | ALOGE("%s: Unable to register with hardware service manager for notifications " |
| 66 | "about camera providers", __FUNCTION__); |
| 67 | return INVALID_OPERATION; |
Yin-Chia Yeh | 6540509 | 2017-01-13 15:42:28 -0800 | [diff] [blame] | 68 | } |
Emilian Peev | 5d7e515 | 2017-02-22 15:37:48 +0000 | [diff] [blame] | 69 | |
Eino-Ville Talvala | 6566536 | 2017-02-24 13:07:56 -0800 | [diff] [blame] | 70 | // See if there's a passthrough HAL, but let's not complain if there's not |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 71 | addProviderLocked(kLegacyProviderName, /*expected*/ false); |
Yin-Chia Yeh | d78041a | 2018-01-20 13:45:38 -0800 | [diff] [blame] | 72 | addProviderLocked(kExternalProviderName, /*expected*/ false); |
Eino-Ville Talvala | 6566536 | 2017-02-24 13:07:56 -0800 | [diff] [blame] | 73 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 74 | return OK; |
| 75 | } |
| 76 | |
| 77 | int CameraProviderManager::getCameraCount() const { |
| 78 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 79 | int count = 0; |
| 80 | for (auto& provider : mProviders) { |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 81 | count += provider->mUniqueCameraIds.size(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 82 | } |
| 83 | return count; |
| 84 | } |
| 85 | |
| 86 | std::vector<std::string> CameraProviderManager::getCameraDeviceIds() const { |
| 87 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 88 | std::vector<std::string> deviceIds; |
| 89 | for (auto& provider : mProviders) { |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 90 | for (auto& id : provider->mUniqueCameraIds) { |
| 91 | deviceIds.push_back(id); |
| 92 | } |
| 93 | } |
| 94 | return deviceIds; |
| 95 | } |
| 96 | |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 97 | std::vector<std::string> CameraProviderManager::getAPI1CompatibleCameraDeviceIds() const { |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 98 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 99 | std::vector<std::string> deviceIds; |
| 100 | for (auto& provider : mProviders) { |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 101 | std::vector<std::string> providerDeviceIds = provider->mUniqueAPI1CompatibleCameraIds; |
| 102 | |
| 103 | // API1 app doesn't handle logical and physical camera devices well. So |
| 104 | // for each [logical, physical1, physical2, ...] id combo, only take the |
| 105 | // first id advertised by HAL, and filter out the rest. |
| 106 | filterLogicalCameraIdsLocked(providerDeviceIds); |
| 107 | |
| 108 | deviceIds.insert(deviceIds.end(), providerDeviceIds.begin(), providerDeviceIds.end()); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 109 | } |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 110 | |
| 111 | std::sort(deviceIds.begin(), deviceIds.end(), |
| 112 | [](const std::string& a, const std::string& b) -> bool { |
| 113 | uint32_t aUint = 0, bUint = 0; |
| 114 | bool aIsUint = base::ParseUint(a, &aUint); |
| 115 | bool bIsUint = base::ParseUint(b, &bUint); |
| 116 | |
| 117 | // Uint device IDs first |
| 118 | if (aIsUint && bIsUint) { |
| 119 | return aUint < bUint; |
| 120 | } else if (aIsUint) { |
| 121 | return true; |
| 122 | } else if (bIsUint) { |
| 123 | return false; |
| 124 | } |
| 125 | // Simple string compare if both id are not uint |
| 126 | return a < b; |
| 127 | }); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 128 | return deviceIds; |
| 129 | } |
| 130 | |
| 131 | bool CameraProviderManager::isValidDevice(const std::string &id, uint16_t majorVersion) const { |
| 132 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 133 | return isValidDeviceLocked(id, majorVersion); |
| 134 | } |
| 135 | |
| 136 | bool CameraProviderManager::isValidDeviceLocked(const std::string &id, uint16_t majorVersion) const { |
| 137 | for (auto& provider : mProviders) { |
| 138 | for (auto& deviceInfo : provider->mDevices) { |
| 139 | if (deviceInfo->mId == id && deviceInfo->mVersion.get_major() == majorVersion) { |
| 140 | return true; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | bool CameraProviderManager::hasFlashUnit(const std::string &id) const { |
| 148 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 149 | |
| 150 | auto deviceInfo = findDeviceInfoLocked(id); |
| 151 | if (deviceInfo == nullptr) return false; |
| 152 | |
| 153 | return deviceInfo->hasFlashUnit(); |
| 154 | } |
| 155 | |
| 156 | status_t CameraProviderManager::getResourceCost(const std::string &id, |
| 157 | CameraResourceCost* cost) const { |
| 158 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 159 | |
| 160 | auto deviceInfo = findDeviceInfoLocked(id); |
| 161 | if (deviceInfo == nullptr) return NAME_NOT_FOUND; |
| 162 | |
| 163 | *cost = deviceInfo->mResourceCost; |
| 164 | return OK; |
| 165 | } |
| 166 | |
| 167 | status_t CameraProviderManager::getCameraInfo(const std::string &id, |
| 168 | hardware::CameraInfo* info) const { |
| 169 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 170 | |
| 171 | auto deviceInfo = findDeviceInfoLocked(id); |
| 172 | if (deviceInfo == nullptr) return NAME_NOT_FOUND; |
| 173 | |
| 174 | return deviceInfo->getCameraInfo(info); |
| 175 | } |
| 176 | |
| 177 | status_t CameraProviderManager::getCameraCharacteristics(const std::string &id, |
| 178 | CameraMetadata* characteristics) const { |
| 179 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 180 | return getCameraCharacteristicsLocked(id, characteristics); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | status_t CameraProviderManager::getHighestSupportedVersion(const std::string &id, |
| 184 | hardware::hidl_version *v) { |
| 185 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 186 | |
| 187 | hardware::hidl_version maxVersion{0,0}; |
| 188 | bool found = false; |
| 189 | for (auto& provider : mProviders) { |
| 190 | for (auto& deviceInfo : provider->mDevices) { |
| 191 | if (deviceInfo->mId == id) { |
| 192 | if (deviceInfo->mVersion > maxVersion) { |
| 193 | maxVersion = deviceInfo->mVersion; |
| 194 | found = true; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | if (!found) { |
| 200 | return NAME_NOT_FOUND; |
| 201 | } |
| 202 | *v = maxVersion; |
| 203 | return OK; |
| 204 | } |
| 205 | |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 206 | bool CameraProviderManager::supportSetTorchMode(const std::string &id) { |
| 207 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 208 | bool support = false; |
| 209 | for (auto& provider : mProviders) { |
| 210 | auto deviceInfo = findDeviceInfoLocked(id); |
| 211 | if (deviceInfo != nullptr) { |
Yin-Chia Yeh | 73d0374 | 2017-09-29 12:01:02 -0700 | [diff] [blame] | 212 | auto ret = provider->mInterface->isSetTorchModeSupported( |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 213 | [&support](auto status, bool supported) { |
| 214 | if (status == Status::OK) { |
| 215 | support = supported; |
| 216 | } |
| 217 | }); |
Yin-Chia Yeh | 73d0374 | 2017-09-29 12:01:02 -0700 | [diff] [blame] | 218 | if (!ret.isOk()) { |
| 219 | ALOGE("%s: Transaction error checking torch mode support '%s': %s", |
| 220 | __FUNCTION__, provider->mProviderName.c_str(), ret.description().c_str()); |
| 221 | } |
| 222 | break; |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | return support; |
| 226 | } |
| 227 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 228 | status_t CameraProviderManager::setTorchMode(const std::string &id, bool enabled) { |
| 229 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 230 | |
| 231 | auto deviceInfo = findDeviceInfoLocked(id); |
| 232 | if (deviceInfo == nullptr) return NAME_NOT_FOUND; |
| 233 | |
| 234 | return deviceInfo->setTorchMode(enabled); |
| 235 | } |
| 236 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 237 | status_t CameraProviderManager::setUpVendorTags() { |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 238 | sp<VendorTagDescriptorCache> tagCache = new VendorTagDescriptorCache(); |
| 239 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 240 | for (auto& provider : mProviders) { |
| 241 | hardware::hidl_vec<VendorTagSection> vts; |
| 242 | Status status; |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 243 | hardware::Return<void> ret; |
| 244 | ret = provider->mInterface->getVendorTags( |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 245 | [&](auto s, const auto& vendorTagSecs) { |
| 246 | status = s; |
| 247 | if (s == Status::OK) { |
| 248 | vts = vendorTagSecs; |
| 249 | } |
| 250 | }); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 251 | if (!ret.isOk()) { |
| 252 | ALOGE("%s: Transaction error getting vendor tags from provider '%s': %s", |
| 253 | __FUNCTION__, provider->mProviderName.c_str(), ret.description().c_str()); |
| 254 | return DEAD_OBJECT; |
| 255 | } |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 256 | if (status != Status::OK) { |
| 257 | return mapToStatusT(status); |
| 258 | } |
| 259 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 260 | // Read all vendor tag definitions into a descriptor |
| 261 | sp<VendorTagDescriptor> desc; |
| 262 | status_t res; |
| 263 | if ((res = HidlVendorTagDescriptor::createDescriptorFromHidl(vts, /*out*/desc)) |
| 264 | != OK) { |
| 265 | ALOGE("%s: Could not generate descriptor from vendor tag operations," |
| 266 | "received error %s (%d). Camera clients will not be able to use" |
| 267 | "vendor tags", __FUNCTION__, strerror(res), res); |
| 268 | return res; |
| 269 | } |
| 270 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 271 | tagCache->addVendorDescriptor(provider->mProviderTagid, desc); |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 272 | } |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 273 | |
| 274 | VendorTagDescriptorCache::setAsGlobalVendorTagCache(tagCache); |
| 275 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 276 | return OK; |
| 277 | } |
| 278 | |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 279 | status_t CameraProviderManager::openSession(const std::string &id, |
| 280 | const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback, |
| 281 | /*out*/ |
| 282 | sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session) { |
| 283 | |
| 284 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 285 | |
| 286 | auto deviceInfo = findDeviceInfoLocked(id, |
| 287 | /*minVersion*/ {3,0}, /*maxVersion*/ {4,0}); |
| 288 | if (deviceInfo == nullptr) return NAME_NOT_FOUND; |
| 289 | |
| 290 | auto *deviceInfo3 = static_cast<ProviderInfo::DeviceInfo3*>(deviceInfo); |
| 291 | |
| 292 | Status status; |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 293 | hardware::Return<void> ret; |
| 294 | ret = deviceInfo3->mInterface->open(callback, [&status, &session] |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 295 | (Status s, const sp<device::V3_2::ICameraDeviceSession>& cameraSession) { |
| 296 | status = s; |
| 297 | if (status == Status::OK) { |
| 298 | *session = cameraSession; |
| 299 | } |
| 300 | }); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 301 | if (!ret.isOk()) { |
| 302 | ALOGE("%s: Transaction error opening a session for camera device %s: %s", |
| 303 | __FUNCTION__, id.c_str(), ret.description().c_str()); |
| 304 | return DEAD_OBJECT; |
| 305 | } |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 306 | return mapToStatusT(status); |
| 307 | } |
| 308 | |
| 309 | status_t CameraProviderManager::openSession(const std::string &id, |
| 310 | const sp<hardware::camera::device::V1_0::ICameraDeviceCallback>& callback, |
| 311 | /*out*/ |
| 312 | sp<hardware::camera::device::V1_0::ICameraDevice> *session) { |
| 313 | |
| 314 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 315 | |
| 316 | auto deviceInfo = findDeviceInfoLocked(id, |
| 317 | /*minVersion*/ {1,0}, /*maxVersion*/ {2,0}); |
| 318 | if (deviceInfo == nullptr) return NAME_NOT_FOUND; |
| 319 | |
| 320 | auto *deviceInfo1 = static_cast<ProviderInfo::DeviceInfo1*>(deviceInfo); |
| 321 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 322 | hardware::Return<Status> status = deviceInfo1->mInterface->open(callback); |
| 323 | if (!status.isOk()) { |
| 324 | ALOGE("%s: Transaction error opening a session for camera device %s: %s", |
| 325 | __FUNCTION__, id.c_str(), status.description().c_str()); |
| 326 | return DEAD_OBJECT; |
| 327 | } |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 328 | if (status == Status::OK) { |
| 329 | *session = deviceInfo1->mInterface; |
| 330 | } |
| 331 | return mapToStatusT(status); |
| 332 | } |
| 333 | |
| 334 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 335 | hardware::Return<void> CameraProviderManager::onRegistration( |
| 336 | const hardware::hidl_string& /*fqName*/, |
| 337 | const hardware::hidl_string& name, |
| 338 | bool /*preexisting*/) { |
Shuzhen Wang | 6ba8eb2 | 2018-07-08 13:10:44 -0700 | [diff] [blame] | 339 | std::lock_guard<std::mutex> providerLock(mProviderLifecycleLock); |
Emilian Peev | aee727d | 2017-05-04 16:35:48 +0100 | [diff] [blame] | 340 | { |
| 341 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 342 | |
Emilian Peev | aee727d | 2017-05-04 16:35:48 +0100 | [diff] [blame] | 343 | addProviderLocked(name); |
| 344 | } |
| 345 | |
| 346 | sp<StatusListener> listener = getStatusListener(); |
| 347 | if (nullptr != listener.get()) { |
| 348 | listener->onNewProviderRegistered(); |
| 349 | } |
| 350 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 351 | return hardware::Return<void>(); |
| 352 | } |
| 353 | |
| 354 | status_t CameraProviderManager::dump(int fd, const Vector<String16>& args) { |
| 355 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 356 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 357 | for (auto& provider : mProviders) { |
| 358 | provider->dump(fd, args); |
| 359 | } |
| 360 | return OK; |
| 361 | } |
| 362 | |
| 363 | CameraProviderManager::ProviderInfo::DeviceInfo* CameraProviderManager::findDeviceInfoLocked( |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 364 | const std::string& id, |
| 365 | hardware::hidl_version minVersion, hardware::hidl_version maxVersion) const { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 366 | for (auto& provider : mProviders) { |
| 367 | for (auto& deviceInfo : provider->mDevices) { |
Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 368 | if (deviceInfo->mId == id && |
| 369 | minVersion <= deviceInfo->mVersion && maxVersion >= deviceInfo->mVersion) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 370 | return deviceInfo.get(); |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | return nullptr; |
| 375 | } |
| 376 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 377 | metadata_vendor_id_t CameraProviderManager::getProviderTagIdLocked( |
| 378 | const std::string& id, hardware::hidl_version minVersion, |
| 379 | hardware::hidl_version maxVersion) const { |
| 380 | metadata_vendor_id_t ret = CAMERA_METADATA_INVALID_VENDOR_ID; |
| 381 | |
| 382 | std::lock_guard<std::mutex> lock(mInterfaceMutex); |
| 383 | for (auto& provider : mProviders) { |
| 384 | for (auto& deviceInfo : provider->mDevices) { |
| 385 | if (deviceInfo->mId == id && |
| 386 | minVersion <= deviceInfo->mVersion && |
| 387 | maxVersion >= deviceInfo->mVersion) { |
| 388 | return provider->mProviderTagid; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | return ret; |
| 394 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 395 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 396 | bool CameraProviderManager::isLogicalCamera(const CameraMetadata& staticInfo, |
| 397 | std::vector<std::string>* physicalCameraIds) { |
| 398 | bool isLogicalCam = false; |
| 399 | camera_metadata_ro_entry_t entryCap; |
| 400 | |
| 401 | entryCap = staticInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES); |
| 402 | for (size_t i = 0; i < entryCap.count; ++i) { |
| 403 | uint8_t capability = entryCap.data.u8[i]; |
| 404 | if (capability == ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA) { |
| 405 | isLogicalCam = true; |
| 406 | break; |
| 407 | } |
| 408 | } |
| 409 | if (!isLogicalCam) { |
| 410 | return false; |
| 411 | } |
| 412 | |
| 413 | camera_metadata_ro_entry_t entryIds = staticInfo.find(ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS); |
| 414 | const uint8_t* ids = entryIds.data.u8; |
| 415 | size_t start = 0; |
| 416 | for (size_t i = 0; i < entryIds.count; ++i) { |
| 417 | if (ids[i] == '\0') { |
| 418 | if (start != i) { |
| 419 | physicalCameraIds->push_back((const char*)ids+start); |
| 420 | } |
| 421 | start = i+1; |
| 422 | } |
| 423 | } |
| 424 | return true; |
| 425 | } |
| 426 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 427 | status_t CameraProviderManager::addProviderLocked(const std::string& newProvider, bool expected) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 428 | for (const auto& providerInfo : mProviders) { |
| 429 | if (providerInfo->mProviderName == newProvider) { |
| 430 | ALOGW("%s: Camera provider HAL with name '%s' already registered", __FUNCTION__, |
| 431 | newProvider.c_str()); |
| 432 | return ALREADY_EXISTS; |
| 433 | } |
| 434 | } |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 435 | |
| 436 | sp<provider::V2_4::ICameraProvider> interface; |
| 437 | interface = mServiceProxy->getService(newProvider); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 438 | |
| 439 | if (interface == nullptr) { |
| 440 | if (expected) { |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 441 | ALOGE("%s: Camera provider HAL '%s' is not actually available", __FUNCTION__, |
| 442 | newProvider.c_str()); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 443 | return BAD_VALUE; |
| 444 | } else { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 445 | return OK; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | sp<ProviderInfo> providerInfo = |
| 450 | new ProviderInfo(newProvider, interface, this); |
| 451 | status_t res = providerInfo->initialize(); |
| 452 | if (res != OK) { |
| 453 | return res; |
| 454 | } |
| 455 | |
| 456 | mProviders.push_back(providerInfo); |
| 457 | |
| 458 | return OK; |
| 459 | } |
| 460 | |
| 461 | status_t CameraProviderManager::removeProvider(const std::string& provider) { |
Shuzhen Wang | 6ba8eb2 | 2018-07-08 13:10:44 -0700 | [diff] [blame] | 462 | std::lock_guard<std::mutex> providerLock(mProviderLifecycleLock); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 463 | std::unique_lock<std::mutex> lock(mInterfaceMutex); |
| 464 | std::vector<String8> removedDeviceIds; |
| 465 | status_t res = NAME_NOT_FOUND; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 466 | for (auto it = mProviders.begin(); it != mProviders.end(); it++) { |
| 467 | if ((*it)->mProviderName == provider) { |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 468 | removedDeviceIds.reserve((*it)->mDevices.size()); |
| 469 | for (auto& deviceInfo : (*it)->mDevices) { |
| 470 | removedDeviceIds.push_back(String8(deviceInfo->mId.c_str())); |
| 471 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 472 | mProviders.erase(it); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 473 | res = OK; |
| 474 | break; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 475 | } |
| 476 | } |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 477 | if (res != OK) { |
| 478 | ALOGW("%s: Camera provider HAL with name '%s' is not registered", __FUNCTION__, |
| 479 | provider.c_str()); |
| 480 | } else { |
| 481 | // Inform camera service of loss of presence for all the devices from this provider, |
| 482 | // without lock held for reentrancy |
| 483 | sp<StatusListener> listener = getStatusListener(); |
| 484 | if (listener != nullptr) { |
| 485 | lock.unlock(); |
| 486 | for (auto& id : removedDeviceIds) { |
| 487 | listener->onDeviceStatusChanged(id, CameraDeviceStatus::NOT_PRESENT); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | return res; |
| 492 | } |
| 493 | |
| 494 | sp<CameraProviderManager::StatusListener> CameraProviderManager::getStatusListener() const { |
| 495 | return mListener.promote(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /**** Methods for ProviderInfo ****/ |
| 499 | |
| 500 | |
| 501 | CameraProviderManager::ProviderInfo::ProviderInfo( |
| 502 | const std::string &providerName, |
| 503 | sp<provider::V2_4::ICameraProvider>& interface, |
| 504 | CameraProviderManager *manager) : |
| 505 | mProviderName(providerName), |
| 506 | mInterface(interface), |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 507 | mProviderTagid(generateVendorTagId(providerName)), |
Emilian Peev | cdb74a6 | 2017-05-11 20:29:52 +0100 | [diff] [blame] | 508 | mUniqueDeviceCount(0), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 509 | mManager(manager) { |
| 510 | (void) mManager; |
| 511 | } |
| 512 | |
| 513 | status_t CameraProviderManager::ProviderInfo::initialize() { |
| 514 | status_t res = parseProviderName(mProviderName, &mType, &mId); |
| 515 | if (res != OK) { |
| 516 | ALOGE("%s: Invalid provider name, ignoring", __FUNCTION__); |
| 517 | return BAD_VALUE; |
| 518 | } |
Yin-Chia Yeh | 6540509 | 2017-01-13 15:42:28 -0800 | [diff] [blame] | 519 | ALOGI("Connecting to new camera provider: %s, isRemote? %d", |
| 520 | mProviderName.c_str(), mInterface->isRemote()); |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 521 | // cameraDeviceStatusChange callbacks may be called (and causing new devices added) |
| 522 | // before setCallback returns |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 523 | hardware::Return<Status> status = mInterface->setCallback(this); |
| 524 | if (!status.isOk()) { |
| 525 | ALOGE("%s: Transaction error setting up callbacks with camera provider '%s': %s", |
| 526 | __FUNCTION__, mProviderName.c_str(), status.description().c_str()); |
| 527 | return DEAD_OBJECT; |
| 528 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 529 | if (status != Status::OK) { |
| 530 | ALOGE("%s: Unable to register callbacks with camera provider '%s'", |
| 531 | __FUNCTION__, mProviderName.c_str()); |
| 532 | return mapToStatusT(status); |
| 533 | } |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 534 | |
| 535 | hardware::Return<bool> linked = mInterface->linkToDeath(this, /*cookie*/ mId); |
| 536 | if (!linked.isOk()) { |
| 537 | ALOGE("%s: Transaction error in linking to camera provider '%s' death: %s", |
| 538 | __FUNCTION__, mProviderName.c_str(), linked.description().c_str()); |
| 539 | return DEAD_OBJECT; |
| 540 | } else if (!linked) { |
| 541 | ALOGW("%s: Unable to link to provider '%s' death notifications", |
| 542 | __FUNCTION__, mProviderName.c_str()); |
| 543 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 544 | |
| 545 | // Get initial list of camera devices, if any |
| 546 | std::vector<std::string> devices; |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 547 | hardware::Return<void> ret = mInterface->getCameraIdList([&status, &devices]( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 548 | Status idStatus, |
| 549 | const hardware::hidl_vec<hardware::hidl_string>& cameraDeviceNames) { |
| 550 | status = idStatus; |
| 551 | if (status == Status::OK) { |
| 552 | for (size_t i = 0; i < cameraDeviceNames.size(); i++) { |
| 553 | devices.push_back(cameraDeviceNames[i]); |
| 554 | } |
| 555 | } }); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 556 | if (!ret.isOk()) { |
| 557 | ALOGE("%s: Transaction error in getting camera ID list from provider '%s': %s", |
| 558 | __FUNCTION__, mProviderName.c_str(), linked.description().c_str()); |
| 559 | return DEAD_OBJECT; |
| 560 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 561 | if (status != Status::OK) { |
| 562 | ALOGE("%s: Unable to query for camera devices from provider '%s'", |
| 563 | __FUNCTION__, mProviderName.c_str()); |
| 564 | return mapToStatusT(status); |
| 565 | } |
| 566 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 567 | sp<StatusListener> listener = mManager->getStatusListener(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 568 | for (auto& device : devices) { |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 569 | std::string id; |
| 570 | status_t res = addDevice(device, |
| 571 | hardware::camera::common::V1_0::CameraDeviceStatus::PRESENT, &id); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 572 | if (res != OK) { |
| 573 | ALOGE("%s: Unable to enumerate camera device '%s': %s (%d)", |
| 574 | __FUNCTION__, device.c_str(), strerror(-res), res); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 575 | continue; |
| 576 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | ALOGI("Camera provider %s ready with %zu camera devices", |
| 580 | mProviderName.c_str(), mDevices.size()); |
| 581 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 582 | mInitialized = true; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 583 | return OK; |
| 584 | } |
| 585 | |
| 586 | const std::string& CameraProviderManager::ProviderInfo::getType() const { |
| 587 | return mType; |
| 588 | } |
| 589 | |
| 590 | status_t CameraProviderManager::ProviderInfo::addDevice(const std::string& name, |
| 591 | CameraDeviceStatus initialStatus, /*out*/ std::string* parsedId) { |
| 592 | |
| 593 | ALOGI("Enumerating new camera device: %s", name.c_str()); |
| 594 | |
| 595 | uint16_t major, minor; |
| 596 | std::string type, id; |
| 597 | |
| 598 | status_t res = parseDeviceName(name, &major, &minor, &type, &id); |
| 599 | if (res != OK) { |
| 600 | return res; |
| 601 | } |
| 602 | if (type != mType) { |
| 603 | ALOGE("%s: Device type %s does not match provider type %s", __FUNCTION__, |
| 604 | type.c_str(), mType.c_str()); |
| 605 | return BAD_VALUE; |
| 606 | } |
| 607 | if (mManager->isValidDeviceLocked(id, major)) { |
| 608 | ALOGE("%s: Device %s: ID %s is already in use for device major version %d", __FUNCTION__, |
| 609 | name.c_str(), id.c_str(), major); |
| 610 | return BAD_VALUE; |
| 611 | } |
| 612 | |
| 613 | std::unique_ptr<DeviceInfo> deviceInfo; |
| 614 | switch (major) { |
| 615 | case 1: |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 616 | deviceInfo = initializeDeviceInfo<DeviceInfo1>(name, mProviderTagid, |
| 617 | id, minor); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 618 | break; |
| 619 | case 3: |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 620 | deviceInfo = initializeDeviceInfo<DeviceInfo3>(name, mProviderTagid, |
| 621 | id, minor); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 622 | break; |
| 623 | default: |
| 624 | ALOGE("%s: Device %s: Unknown HIDL device HAL major version %d:", __FUNCTION__, |
| 625 | name.c_str(), major); |
| 626 | return BAD_VALUE; |
| 627 | } |
| 628 | if (deviceInfo == nullptr) return BAD_VALUE; |
| 629 | deviceInfo->mStatus = initialStatus; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 630 | bool isAPI1Compatible = deviceInfo->isAPI1Compatible(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 631 | |
| 632 | mDevices.push_back(std::move(deviceInfo)); |
| 633 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 634 | mUniqueCameraIds.insert(id); |
| 635 | if (isAPI1Compatible) { |
Shuzhen Wang | 975a39e | 2018-06-27 14:35:46 -0700 | [diff] [blame] | 636 | // addDevice can be called more than once for the same camera id if HAL |
| 637 | // supports openLegacy. |
| 638 | if (std::find(mUniqueAPI1CompatibleCameraIds.begin(), mUniqueAPI1CompatibleCameraIds.end(), |
| 639 | id) == mUniqueAPI1CompatibleCameraIds.end()) { |
| 640 | mUniqueAPI1CompatibleCameraIds.push_back(id); |
| 641 | } |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 642 | } |
| 643 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 644 | if (parsedId != nullptr) { |
| 645 | *parsedId = id; |
| 646 | } |
| 647 | return OK; |
| 648 | } |
| 649 | |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 650 | void CameraProviderManager::ProviderInfo::removeDevice(std::string id) { |
| 651 | for (auto it = mDevices.begin(); it != mDevices.end(); it++) { |
| 652 | if ((*it)->mId == id) { |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 653 | mUniqueCameraIds.erase(id); |
| 654 | if ((*it)->isAPI1Compatible()) { |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 655 | mUniqueAPI1CompatibleCameraIds.erase(std::remove( |
| 656 | mUniqueAPI1CompatibleCameraIds.begin(), |
| 657 | mUniqueAPI1CompatibleCameraIds.end(), id)); |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 658 | } |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 659 | mDevices.erase(it); |
| 660 | break; |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 665 | status_t CameraProviderManager::ProviderInfo::dump(int fd, const Vector<String16>&) const { |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 666 | dprintf(fd, "== Camera Provider HAL %s (v2.4, %s) static info: %zu devices: ==\n", |
| 667 | mProviderName.c_str(), mInterface->isRemote() ? "remote" : "passthrough", |
| 668 | mDevices.size()); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 669 | |
| 670 | for (auto& device : mDevices) { |
Eino-Ville Talvala | d00111e | 2017-01-31 11:59:12 -0800 | [diff] [blame] | 671 | dprintf(fd, "== Camera HAL device %s (v%d.%d) static information: ==\n", device->mName.c_str(), |
| 672 | device->mVersion.get_major(), device->mVersion.get_minor()); |
| 673 | dprintf(fd, " Resource cost: %d\n", device->mResourceCost.resourceCost); |
| 674 | if (device->mResourceCost.conflictingDevices.size() == 0) { |
| 675 | dprintf(fd, " Conflicting devices: None\n"); |
| 676 | } else { |
| 677 | dprintf(fd, " Conflicting devices:\n"); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 678 | for (size_t i = 0; i < device->mResourceCost.conflictingDevices.size(); i++) { |
Eino-Ville Talvala | d00111e | 2017-01-31 11:59:12 -0800 | [diff] [blame] | 679 | dprintf(fd, " %s\n", |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 680 | device->mResourceCost.conflictingDevices[i].c_str()); |
| 681 | } |
| 682 | } |
Eino-Ville Talvala | d00111e | 2017-01-31 11:59:12 -0800 | [diff] [blame] | 683 | dprintf(fd, " API1 info:\n"); |
| 684 | dprintf(fd, " Has a flash unit: %s\n", |
| 685 | device->hasFlashUnit() ? "true" : "false"); |
| 686 | hardware::CameraInfo info; |
| 687 | status_t res = device->getCameraInfo(&info); |
| 688 | if (res != OK) { |
| 689 | dprintf(fd, " <Error reading camera info: %s (%d)>\n", |
| 690 | strerror(-res), res); |
| 691 | } else { |
| 692 | dprintf(fd, " Facing: %s\n", |
| 693 | info.facing == hardware::CAMERA_FACING_BACK ? "Back" : "Front"); |
| 694 | dprintf(fd, " Orientation: %d\n", info.orientation); |
| 695 | } |
| 696 | CameraMetadata info2; |
| 697 | res = device->getCameraCharacteristics(&info2); |
| 698 | if (res == INVALID_OPERATION) { |
| 699 | dprintf(fd, " API2 not directly supported\n"); |
| 700 | } else if (res != OK) { |
| 701 | dprintf(fd, " <Error reading camera characteristics: %s (%d)>\n", |
| 702 | strerror(-res), res); |
| 703 | } else { |
| 704 | dprintf(fd, " API2 camera characteristics:\n"); |
| 705 | info2.dump(fd, /*verbosity*/ 2, /*indentation*/ 4); |
| 706 | } |
Yin-Chia Yeh | 487785a | 2018-01-02 12:06:57 -0800 | [diff] [blame] | 707 | |
| 708 | dprintf(fd, "== Camera HAL device %s (v%d.%d) dumpState: ==\n", device->mName.c_str(), |
| 709 | device->mVersion.get_major(), device->mVersion.get_minor()); |
| 710 | res = device->dumpState(fd); |
| 711 | if (res != OK) { |
| 712 | dprintf(fd, " <Error dumping device %s state: %s (%d)>\n", |
| 713 | device->mName.c_str(), strerror(-res), res); |
| 714 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 715 | } |
| 716 | return OK; |
| 717 | } |
| 718 | |
| 719 | hardware::Return<void> CameraProviderManager::ProviderInfo::cameraDeviceStatusChange( |
| 720 | const hardware::hidl_string& cameraDeviceName, |
| 721 | CameraDeviceStatus newStatus) { |
| 722 | sp<StatusListener> listener; |
| 723 | std::string id; |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 724 | bool initialized = false; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 725 | { |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 726 | std::lock_guard<std::mutex> lock(mLock); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 727 | bool known = false; |
| 728 | for (auto& deviceInfo : mDevices) { |
| 729 | if (deviceInfo->mName == cameraDeviceName) { |
| 730 | ALOGI("Camera device %s status is now %s, was %s", cameraDeviceName.c_str(), |
| 731 | deviceStatusToString(newStatus), deviceStatusToString(deviceInfo->mStatus)); |
| 732 | deviceInfo->mStatus = newStatus; |
| 733 | // TODO: Handle device removal (NOT_PRESENT) |
| 734 | id = deviceInfo->mId; |
| 735 | known = true; |
| 736 | break; |
| 737 | } |
| 738 | } |
| 739 | // Previously unseen device; status must not be NOT_PRESENT |
| 740 | if (!known) { |
| 741 | if (newStatus == CameraDeviceStatus::NOT_PRESENT) { |
| 742 | ALOGW("Camera provider %s says an unknown camera device %s is not present. Curious.", |
| 743 | mProviderName.c_str(), cameraDeviceName.c_str()); |
| 744 | return hardware::Void(); |
| 745 | } |
| 746 | addDevice(cameraDeviceName, newStatus, &id); |
Guennadi Liakhovetski | 6034bf5 | 2017-12-07 10:28:29 +0100 | [diff] [blame] | 747 | } else if (newStatus == CameraDeviceStatus::NOT_PRESENT) { |
| 748 | removeDevice(id); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 749 | } |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 750 | listener = mManager->getStatusListener(); |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 751 | initialized = mInitialized; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 752 | } |
| 753 | // Call without lock held to allow reentrancy into provider manager |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 754 | // Don't send the callback if providerInfo hasn't been initialized. |
| 755 | // CameraService will initialize device status after provider is |
| 756 | // initialized |
| 757 | if (listener != nullptr && initialized) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 758 | listener->onDeviceStatusChanged(String8(id.c_str()), newStatus); |
| 759 | } |
| 760 | return hardware::Void(); |
| 761 | } |
| 762 | |
| 763 | hardware::Return<void> CameraProviderManager::ProviderInfo::torchModeStatusChange( |
| 764 | const hardware::hidl_string& cameraDeviceName, |
| 765 | TorchModeStatus newStatus) { |
| 766 | sp<StatusListener> listener; |
| 767 | std::string id; |
| 768 | { |
Yin-Chia Yeh | 52778d4 | 2016-12-22 18:20:43 -0800 | [diff] [blame] | 769 | std::lock_guard<std::mutex> lock(mManager->mStatusListenerMutex); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 770 | bool known = false; |
| 771 | for (auto& deviceInfo : mDevices) { |
| 772 | if (deviceInfo->mName == cameraDeviceName) { |
| 773 | ALOGI("Camera device %s torch status is now %s", cameraDeviceName.c_str(), |
| 774 | torchStatusToString(newStatus)); |
| 775 | id = deviceInfo->mId; |
| 776 | known = true; |
| 777 | break; |
| 778 | } |
| 779 | } |
| 780 | if (!known) { |
| 781 | ALOGW("Camera provider %s says an unknown camera %s now has torch status %d. Curious.", |
| 782 | mProviderName.c_str(), cameraDeviceName.c_str(), newStatus); |
| 783 | return hardware::Void(); |
| 784 | } |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 785 | listener = mManager->getStatusListener(); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 786 | } |
| 787 | // Call without lock held to allow reentrancy into provider manager |
| 788 | if (listener != nullptr) { |
| 789 | listener->onTorchStatusChanged(String8(id.c_str()), newStatus); |
| 790 | } |
| 791 | return hardware::Void(); |
| 792 | } |
| 793 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 794 | void CameraProviderManager::ProviderInfo::serviceDied(uint64_t cookie, |
| 795 | const wp<hidl::base::V1_0::IBase>& who) { |
| 796 | (void) who; |
| 797 | ALOGI("Camera provider '%s' has died; removing it", mProviderName.c_str()); |
| 798 | if (cookie != mId) { |
| 799 | ALOGW("%s: Unexpected serviceDied cookie %" PRIu64 ", expected %" PRIu32, |
| 800 | __FUNCTION__, cookie, mId); |
| 801 | } |
| 802 | mManager->removeProvider(mProviderName); |
| 803 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 804 | |
| 805 | template<class DeviceInfoT> |
| 806 | std::unique_ptr<CameraProviderManager::ProviderInfo::DeviceInfo> |
| 807 | CameraProviderManager::ProviderInfo::initializeDeviceInfo( |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 808 | const std::string &name, const metadata_vendor_id_t tagId, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 809 | const std::string &id, uint16_t minorVersion) const { |
| 810 | Status status; |
| 811 | |
| 812 | auto cameraInterface = |
| 813 | getDeviceInterface<typename DeviceInfoT::InterfaceT>(name); |
| 814 | if (cameraInterface == nullptr) return nullptr; |
| 815 | |
| 816 | CameraResourceCost resourceCost; |
| 817 | cameraInterface->getResourceCost([&status, &resourceCost]( |
| 818 | Status s, CameraResourceCost cost) { |
| 819 | status = s; |
| 820 | resourceCost = cost; |
| 821 | }); |
| 822 | if (status != Status::OK) { |
| 823 | ALOGE("%s: Unable to obtain resource costs for camera device %s: %s", __FUNCTION__, |
| 824 | name.c_str(), statusToString(status)); |
| 825 | return nullptr; |
| 826 | } |
Shuzhen Wang | 4728369 | 2018-04-24 18:05:02 -0700 | [diff] [blame] | 827 | |
| 828 | for (auto& conflictName : resourceCost.conflictingDevices) { |
| 829 | uint16_t major, minor; |
| 830 | std::string type, id; |
| 831 | status_t res = parseDeviceName(conflictName, &major, &minor, &type, &id); |
| 832 | if (res != OK) { |
| 833 | ALOGE("%s: Failed to parse conflicting device %s", __FUNCTION__, conflictName.c_str()); |
| 834 | return nullptr; |
| 835 | } |
| 836 | conflictName = id; |
| 837 | } |
| 838 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 839 | return std::unique_ptr<DeviceInfo>( |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 840 | new DeviceInfoT(name, tagId, id, minorVersion, resourceCost, |
| 841 | cameraInterface)); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | template<class InterfaceT> |
| 845 | sp<InterfaceT> |
| 846 | CameraProviderManager::ProviderInfo::getDeviceInterface(const std::string &name) const { |
| 847 | ALOGE("%s: Device %s: Unknown HIDL device HAL major version %d:", __FUNCTION__, |
| 848 | name.c_str(), InterfaceT::version.get_major()); |
| 849 | return nullptr; |
| 850 | } |
| 851 | |
| 852 | template<> |
| 853 | sp<device::V1_0::ICameraDevice> |
| 854 | CameraProviderManager::ProviderInfo::getDeviceInterface |
| 855 | <device::V1_0::ICameraDevice>(const std::string &name) const { |
| 856 | Status status; |
| 857 | sp<device::V1_0::ICameraDevice> cameraInterface; |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 858 | hardware::Return<void> ret; |
| 859 | ret = mInterface->getCameraDeviceInterface_V1_x(name, [&status, &cameraInterface]( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 860 | Status s, sp<device::V1_0::ICameraDevice> interface) { |
| 861 | status = s; |
| 862 | cameraInterface = interface; |
| 863 | }); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 864 | if (!ret.isOk()) { |
| 865 | ALOGE("%s: Transaction error trying to obtain interface for camera device %s: %s", |
| 866 | __FUNCTION__, name.c_str(), ret.description().c_str()); |
| 867 | return nullptr; |
| 868 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 869 | if (status != Status::OK) { |
| 870 | ALOGE("%s: Unable to obtain interface for camera device %s: %s", __FUNCTION__, |
| 871 | name.c_str(), statusToString(status)); |
| 872 | return nullptr; |
| 873 | } |
| 874 | return cameraInterface; |
| 875 | } |
| 876 | |
| 877 | template<> |
| 878 | sp<device::V3_2::ICameraDevice> |
| 879 | CameraProviderManager::ProviderInfo::getDeviceInterface |
| 880 | <device::V3_2::ICameraDevice>(const std::string &name) const { |
| 881 | Status status; |
| 882 | sp<device::V3_2::ICameraDevice> cameraInterface; |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 883 | hardware::Return<void> ret; |
| 884 | ret = mInterface->getCameraDeviceInterface_V3_x(name, [&status, &cameraInterface]( |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 885 | Status s, sp<device::V3_2::ICameraDevice> interface) { |
| 886 | status = s; |
| 887 | cameraInterface = interface; |
| 888 | }); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 889 | if (!ret.isOk()) { |
| 890 | ALOGE("%s: Transaction error trying to obtain interface for camera device %s: %s", |
| 891 | __FUNCTION__, name.c_str(), ret.description().c_str()); |
| 892 | return nullptr; |
| 893 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 894 | if (status != Status::OK) { |
| 895 | ALOGE("%s: Unable to obtain interface for camera device %s: %s", __FUNCTION__, |
| 896 | name.c_str(), statusToString(status)); |
| 897 | return nullptr; |
| 898 | } |
| 899 | return cameraInterface; |
| 900 | } |
| 901 | |
| 902 | CameraProviderManager::ProviderInfo::DeviceInfo::~DeviceInfo() {} |
| 903 | |
| 904 | template<class InterfaceT> |
| 905 | status_t CameraProviderManager::ProviderInfo::DeviceInfo::setTorchMode(InterfaceT& interface, |
| 906 | bool enabled) { |
| 907 | Status s = interface->setTorchMode(enabled ? TorchMode::ON : TorchMode::OFF); |
| 908 | return mapToStatusT(s); |
| 909 | } |
| 910 | |
| 911 | CameraProviderManager::ProviderInfo::DeviceInfo1::DeviceInfo1(const std::string& name, |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 912 | const metadata_vendor_id_t tagId, const std::string &id, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 913 | uint16_t minorVersion, |
| 914 | const CameraResourceCost& resourceCost, |
| 915 | sp<InterfaceT> interface) : |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 916 | DeviceInfo(name, tagId, id, hardware::hidl_version{1, minorVersion}, |
| 917 | resourceCost), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 918 | mInterface(interface) { |
| 919 | // Get default parameters and initialize flash unit availability |
| 920 | // Requires powering on the camera device |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 921 | hardware::Return<Status> status = mInterface->open(nullptr); |
| 922 | if (!status.isOk()) { |
| 923 | ALOGE("%s: Transaction error opening camera device %s to check for a flash unit: %s", |
| 924 | __FUNCTION__, mId.c_str(), status.description().c_str()); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 925 | return; |
| 926 | } |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 927 | if (status != Status::OK) { |
| 928 | ALOGE("%s: Unable to open camera device %s to check for a flash unit: %s", __FUNCTION__, |
| 929 | mId.c_str(), CameraProviderManager::statusToString(status)); |
| 930 | return; |
| 931 | } |
| 932 | hardware::Return<void> ret; |
| 933 | ret = mInterface->getParameters([this](const hardware::hidl_string& parms) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 934 | mDefaultParameters.unflatten(String8(parms.c_str())); |
| 935 | }); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 936 | if (!ret.isOk()) { |
| 937 | ALOGE("%s: Transaction error reading camera device %s params to check for a flash unit: %s", |
| 938 | __FUNCTION__, mId.c_str(), status.description().c_str()); |
| 939 | return; |
| 940 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 941 | const char *flashMode = |
| 942 | mDefaultParameters.get(CameraParameters::KEY_SUPPORTED_FLASH_MODES); |
| 943 | if (flashMode && strstr(flashMode, CameraParameters::FLASH_MODE_TORCH)) { |
| 944 | mHasFlashUnit = true; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 947 | ret = mInterface->close(); |
| 948 | if (!ret.isOk()) { |
| 949 | ALOGE("%s: Transaction error closing camera device %s after check for a flash unit: %s", |
| 950 | __FUNCTION__, mId.c_str(), status.description().c_str()); |
| 951 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | CameraProviderManager::ProviderInfo::DeviceInfo1::~DeviceInfo1() {} |
| 955 | |
| 956 | status_t CameraProviderManager::ProviderInfo::DeviceInfo1::setTorchMode(bool enabled) { |
| 957 | return DeviceInfo::setTorchMode(mInterface, enabled); |
| 958 | } |
| 959 | |
| 960 | status_t CameraProviderManager::ProviderInfo::DeviceInfo1::getCameraInfo( |
| 961 | hardware::CameraInfo *info) const { |
| 962 | if (info == nullptr) return BAD_VALUE; |
| 963 | |
| 964 | Status status; |
| 965 | device::V1_0::CameraInfo cInfo; |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 966 | hardware::Return<void> ret; |
| 967 | ret = mInterface->getCameraInfo([&status, &cInfo](Status s, device::V1_0::CameraInfo camInfo) { |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 968 | status = s; |
| 969 | cInfo = camInfo; |
| 970 | }); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 971 | if (!ret.isOk()) { |
| 972 | ALOGE("%s: Transaction error reading camera info from device %s: %s", |
| 973 | __FUNCTION__, mId.c_str(), ret.description().c_str()); |
| 974 | return DEAD_OBJECT; |
| 975 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 976 | if (status != Status::OK) { |
| 977 | return mapToStatusT(status); |
| 978 | } |
| 979 | |
| 980 | switch(cInfo.facing) { |
| 981 | case device::V1_0::CameraFacing::BACK: |
| 982 | info->facing = hardware::CAMERA_FACING_BACK; |
| 983 | break; |
| 984 | case device::V1_0::CameraFacing::EXTERNAL: |
| 985 | // Map external to front for legacy API |
| 986 | case device::V1_0::CameraFacing::FRONT: |
| 987 | info->facing = hardware::CAMERA_FACING_FRONT; |
| 988 | break; |
| 989 | default: |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 990 | ALOGW("%s: Device %s: Unknown camera facing: %d", |
| 991 | __FUNCTION__, mId.c_str(), cInfo.facing); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 992 | info->facing = hardware::CAMERA_FACING_BACK; |
| 993 | } |
| 994 | info->orientation = cInfo.orientation; |
| 995 | |
| 996 | return OK; |
| 997 | } |
| 998 | |
Yin-Chia Yeh | 487785a | 2018-01-02 12:06:57 -0800 | [diff] [blame] | 999 | status_t CameraProviderManager::ProviderInfo::DeviceInfo1::dumpState(int fd) const { |
| 1000 | native_handle_t* handle = native_handle_create(1,0); |
| 1001 | handle->data[0] = fd; |
| 1002 | hardware::Return<Status> s = mInterface->dumpState(handle); |
| 1003 | native_handle_delete(handle); |
| 1004 | if (!s.isOk()) { |
| 1005 | return INVALID_OPERATION; |
| 1006 | } |
| 1007 | return mapToStatusT(s); |
| 1008 | } |
| 1009 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1010 | CameraProviderManager::ProviderInfo::DeviceInfo3::DeviceInfo3(const std::string& name, |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 1011 | const metadata_vendor_id_t tagId, const std::string &id, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1012 | uint16_t minorVersion, |
| 1013 | const CameraResourceCost& resourceCost, |
| 1014 | sp<InterfaceT> interface) : |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 1015 | DeviceInfo(name, tagId, id, hardware::hidl_version{3, minorVersion}, |
| 1016 | resourceCost), |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1017 | mInterface(interface) { |
| 1018 | // Get camera characteristics and initialize flash unit availability |
| 1019 | Status status; |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 1020 | hardware::Return<void> ret; |
| 1021 | ret = mInterface->getCameraCharacteristics([&status, this](Status s, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1022 | device::V3_2::CameraMetadata metadata) { |
| 1023 | status = s; |
| 1024 | if (s == Status::OK) { |
| 1025 | camera_metadata_t *buffer = |
| 1026 | reinterpret_cast<camera_metadata_t*>(metadata.data()); |
Yin-Chia Yeh | 238ef5f | 2017-04-18 15:01:15 -0700 | [diff] [blame] | 1027 | size_t expectedSize = metadata.size(); |
| 1028 | int res = validate_camera_metadata_structure(buffer, &expectedSize); |
| 1029 | if (res == OK || res == CAMERA_METADATA_VALIDATION_SHIFTED) { |
| 1030 | set_camera_metadata_vendor_id(buffer, mProviderTagid); |
| 1031 | mCameraCharacteristics = buffer; |
| 1032 | } else { |
| 1033 | ALOGE("%s: Malformed camera metadata received from HAL", __FUNCTION__); |
| 1034 | status = Status::INTERNAL_ERROR; |
| 1035 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1036 | } |
| 1037 | }); |
Eino-Ville Talvala | 8d942f9 | 2017-03-13 10:09:51 -0700 | [diff] [blame] | 1038 | if (!ret.isOk()) { |
| 1039 | ALOGE("%s: Transaction error getting camera characteristics for device %s" |
| 1040 | " to check for a flash unit: %s", __FUNCTION__, mId.c_str(), |
| 1041 | ret.description().c_str()); |
| 1042 | return; |
| 1043 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1044 | if (status != Status::OK) { |
| 1045 | ALOGE("%s: Unable to get camera characteristics for device %s: %s (%d)", |
| 1046 | __FUNCTION__, mId.c_str(), CameraProviderManager::statusToString(status), status); |
| 1047 | return; |
| 1048 | } |
| 1049 | camera_metadata_entry flashAvailable = |
| 1050 | mCameraCharacteristics.find(ANDROID_FLASH_INFO_AVAILABLE); |
| 1051 | if (flashAvailable.count == 1 && |
| 1052 | flashAvailable.data.u8[0] == ANDROID_FLASH_INFO_AVAILABLE_TRUE) { |
| 1053 | mHasFlashUnit = true; |
| 1054 | } else { |
| 1055 | mHasFlashUnit = false; |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | CameraProviderManager::ProviderInfo::DeviceInfo3::~DeviceInfo3() {} |
| 1060 | |
| 1061 | status_t CameraProviderManager::ProviderInfo::DeviceInfo3::setTorchMode(bool enabled) { |
| 1062 | return DeviceInfo::setTorchMode(mInterface, enabled); |
| 1063 | } |
| 1064 | |
| 1065 | status_t CameraProviderManager::ProviderInfo::DeviceInfo3::getCameraInfo( |
| 1066 | hardware::CameraInfo *info) const { |
| 1067 | if (info == nullptr) return BAD_VALUE; |
| 1068 | |
| 1069 | camera_metadata_ro_entry facing = |
| 1070 | mCameraCharacteristics.find(ANDROID_LENS_FACING); |
| 1071 | if (facing.count == 1) { |
| 1072 | switch (facing.data.u8[0]) { |
| 1073 | case ANDROID_LENS_FACING_BACK: |
| 1074 | info->facing = hardware::CAMERA_FACING_BACK; |
| 1075 | break; |
| 1076 | case ANDROID_LENS_FACING_EXTERNAL: |
| 1077 | // Map external to front for legacy API |
| 1078 | case ANDROID_LENS_FACING_FRONT: |
| 1079 | info->facing = hardware::CAMERA_FACING_FRONT; |
| 1080 | break; |
| 1081 | } |
| 1082 | } else { |
| 1083 | ALOGE("%s: Unable to find android.lens.facing static metadata", __FUNCTION__); |
| 1084 | return NAME_NOT_FOUND; |
| 1085 | } |
| 1086 | |
| 1087 | camera_metadata_ro_entry orientation = |
| 1088 | mCameraCharacteristics.find(ANDROID_SENSOR_ORIENTATION); |
| 1089 | if (orientation.count == 1) { |
| 1090 | info->orientation = orientation.data.i32[0]; |
| 1091 | } else { |
| 1092 | ALOGE("%s: Unable to find android.sensor.orientation static metadata", __FUNCTION__); |
| 1093 | return NAME_NOT_FOUND; |
| 1094 | } |
| 1095 | |
| 1096 | return OK; |
| 1097 | } |
Emilian Peev | f53f66e | 2017-04-11 14:29:43 +0100 | [diff] [blame] | 1098 | bool CameraProviderManager::ProviderInfo::DeviceInfo3::isAPI1Compatible() const { |
| 1099 | bool isBackwardCompatible = false; |
| 1100 | camera_metadata_ro_entry_t caps = mCameraCharacteristics.find( |
| 1101 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES); |
| 1102 | for (size_t i = 0; i < caps.count; i++) { |
| 1103 | if (caps.data.u8[i] == |
| 1104 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE) { |
| 1105 | isBackwardCompatible = true; |
| 1106 | break; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | return isBackwardCompatible; |
| 1111 | } |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1112 | |
Yin-Chia Yeh | 487785a | 2018-01-02 12:06:57 -0800 | [diff] [blame] | 1113 | status_t CameraProviderManager::ProviderInfo::DeviceInfo3::dumpState(int fd) const { |
| 1114 | native_handle_t* handle = native_handle_create(1,0); |
| 1115 | handle->data[0] = fd; |
| 1116 | auto ret = mInterface->dumpState(handle); |
| 1117 | native_handle_delete(handle); |
| 1118 | if (!ret.isOk()) { |
| 1119 | return INVALID_OPERATION; |
| 1120 | } |
| 1121 | return OK; |
| 1122 | } |
| 1123 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1124 | status_t CameraProviderManager::ProviderInfo::DeviceInfo3::getCameraCharacteristics( |
| 1125 | CameraMetadata *characteristics) const { |
| 1126 | if (characteristics == nullptr) return BAD_VALUE; |
| 1127 | |
| 1128 | *characteristics = mCameraCharacteristics; |
| 1129 | return OK; |
| 1130 | } |
| 1131 | |
| 1132 | status_t CameraProviderManager::ProviderInfo::parseProviderName(const std::string& name, |
| 1133 | std::string *type, uint32_t *id) { |
| 1134 | // Format must be "<type>/<id>" |
| 1135 | #define ERROR_MSG_PREFIX "%s: Invalid provider name '%s'. " \ |
| 1136 | "Should match '<type>/<id>' - " |
| 1137 | |
| 1138 | if (!type || !id) return INVALID_OPERATION; |
| 1139 | |
| 1140 | std::string::size_type slashIdx = name.find('/'); |
| 1141 | if (slashIdx == std::string::npos || slashIdx == name.size() - 1) { |
| 1142 | ALOGE(ERROR_MSG_PREFIX |
| 1143 | "does not have / separator between type and id", |
| 1144 | __FUNCTION__, name.c_str()); |
| 1145 | return BAD_VALUE; |
| 1146 | } |
| 1147 | |
| 1148 | std::string typeVal = name.substr(0, slashIdx); |
| 1149 | |
| 1150 | char *endPtr; |
| 1151 | errno = 0; |
| 1152 | long idVal = strtol(name.c_str() + slashIdx + 1, &endPtr, 10); |
| 1153 | if (errno != 0) { |
| 1154 | ALOGE(ERROR_MSG_PREFIX |
| 1155 | "cannot parse provider id as an integer: %s (%d)", |
| 1156 | __FUNCTION__, name.c_str(), strerror(errno), errno); |
| 1157 | return BAD_VALUE; |
| 1158 | } |
| 1159 | if (endPtr != name.c_str() + name.size()) { |
| 1160 | ALOGE(ERROR_MSG_PREFIX |
| 1161 | "provider id has unexpected length", |
| 1162 | __FUNCTION__, name.c_str()); |
| 1163 | return BAD_VALUE; |
| 1164 | } |
| 1165 | if (idVal < 0) { |
| 1166 | ALOGE(ERROR_MSG_PREFIX |
| 1167 | "id is negative: %ld", |
| 1168 | __FUNCTION__, name.c_str(), idVal); |
| 1169 | return BAD_VALUE; |
| 1170 | } |
| 1171 | |
| 1172 | #undef ERROR_MSG_PREFIX |
| 1173 | |
| 1174 | *type = typeVal; |
| 1175 | *id = static_cast<uint32_t>(idVal); |
| 1176 | |
| 1177 | return OK; |
| 1178 | } |
| 1179 | |
Emilian Peev | 71c73a2 | 2017-03-21 16:35:51 +0000 | [diff] [blame] | 1180 | metadata_vendor_id_t CameraProviderManager::ProviderInfo::generateVendorTagId( |
| 1181 | const std::string &name) { |
| 1182 | metadata_vendor_id_t ret = std::hash<std::string> {} (name); |
| 1183 | // CAMERA_METADATA_INVALID_VENDOR_ID is not a valid hash value |
| 1184 | if (CAMERA_METADATA_INVALID_VENDOR_ID == ret) { |
| 1185 | ret = 0; |
| 1186 | } |
| 1187 | |
| 1188 | return ret; |
| 1189 | } |
| 1190 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1191 | status_t CameraProviderManager::ProviderInfo::parseDeviceName(const std::string& name, |
| 1192 | uint16_t *major, uint16_t *minor, std::string *type, std::string *id) { |
| 1193 | |
| 1194 | // Format must be "device@<major>.<minor>/<type>/<id>" |
| 1195 | |
| 1196 | #define ERROR_MSG_PREFIX "%s: Invalid device name '%s'. " \ |
| 1197 | "Should match 'device@<major>.<minor>/<type>/<id>' - " |
| 1198 | |
| 1199 | if (!major || !minor || !type || !id) return INVALID_OPERATION; |
| 1200 | |
| 1201 | // Verify starting prefix |
| 1202 | const char expectedPrefix[] = "device@"; |
| 1203 | |
| 1204 | if (name.find(expectedPrefix) != 0) { |
| 1205 | ALOGE(ERROR_MSG_PREFIX |
| 1206 | "does not start with '%s'", |
| 1207 | __FUNCTION__, name.c_str(), expectedPrefix); |
| 1208 | return BAD_VALUE; |
| 1209 | } |
| 1210 | |
| 1211 | // Extract major/minor versions |
| 1212 | constexpr std::string::size_type atIdx = sizeof(expectedPrefix) - 2; |
| 1213 | std::string::size_type dotIdx = name.find('.', atIdx); |
| 1214 | if (dotIdx == std::string::npos) { |
| 1215 | ALOGE(ERROR_MSG_PREFIX |
| 1216 | "does not have @<major>. version section", |
| 1217 | __FUNCTION__, name.c_str()); |
| 1218 | return BAD_VALUE; |
| 1219 | } |
| 1220 | std::string::size_type typeSlashIdx = name.find('/', dotIdx); |
| 1221 | if (typeSlashIdx == std::string::npos) { |
| 1222 | ALOGE(ERROR_MSG_PREFIX |
| 1223 | "does not have .<minor>/ version section", |
| 1224 | __FUNCTION__, name.c_str()); |
| 1225 | return BAD_VALUE; |
| 1226 | } |
| 1227 | |
| 1228 | char *endPtr; |
| 1229 | errno = 0; |
| 1230 | long majorVal = strtol(name.c_str() + atIdx + 1, &endPtr, 10); |
| 1231 | if (errno != 0) { |
| 1232 | ALOGE(ERROR_MSG_PREFIX |
| 1233 | "cannot parse major version: %s (%d)", |
| 1234 | __FUNCTION__, name.c_str(), strerror(errno), errno); |
| 1235 | return BAD_VALUE; |
| 1236 | } |
| 1237 | if (endPtr != name.c_str() + dotIdx) { |
| 1238 | ALOGE(ERROR_MSG_PREFIX |
| 1239 | "major version has unexpected length", |
| 1240 | __FUNCTION__, name.c_str()); |
| 1241 | return BAD_VALUE; |
| 1242 | } |
| 1243 | long minorVal = strtol(name.c_str() + dotIdx + 1, &endPtr, 10); |
| 1244 | if (errno != 0) { |
| 1245 | ALOGE(ERROR_MSG_PREFIX |
| 1246 | "cannot parse minor version: %s (%d)", |
| 1247 | __FUNCTION__, name.c_str(), strerror(errno), errno); |
| 1248 | return BAD_VALUE; |
| 1249 | } |
| 1250 | if (endPtr != name.c_str() + typeSlashIdx) { |
| 1251 | ALOGE(ERROR_MSG_PREFIX |
| 1252 | "minor version has unexpected length", |
| 1253 | __FUNCTION__, name.c_str()); |
| 1254 | return BAD_VALUE; |
| 1255 | } |
| 1256 | if (majorVal < 0 || majorVal > UINT16_MAX || minorVal < 0 || minorVal > UINT16_MAX) { |
| 1257 | ALOGE(ERROR_MSG_PREFIX |
| 1258 | "major/minor version is out of range of uint16_t: %ld.%ld", |
| 1259 | __FUNCTION__, name.c_str(), majorVal, minorVal); |
| 1260 | return BAD_VALUE; |
| 1261 | } |
| 1262 | |
| 1263 | // Extract type and id |
| 1264 | |
| 1265 | std::string::size_type instanceSlashIdx = name.find('/', typeSlashIdx + 1); |
| 1266 | if (instanceSlashIdx == std::string::npos) { |
| 1267 | ALOGE(ERROR_MSG_PREFIX |
| 1268 | "does not have /<type>/ component", |
| 1269 | __FUNCTION__, name.c_str()); |
| 1270 | return BAD_VALUE; |
| 1271 | } |
| 1272 | std::string typeVal = name.substr(typeSlashIdx + 1, instanceSlashIdx - typeSlashIdx - 1); |
| 1273 | |
| 1274 | if (instanceSlashIdx == name.size() - 1) { |
| 1275 | ALOGE(ERROR_MSG_PREFIX |
| 1276 | "does not have an /<id> component", |
| 1277 | __FUNCTION__, name.c_str()); |
| 1278 | return BAD_VALUE; |
| 1279 | } |
| 1280 | std::string idVal = name.substr(instanceSlashIdx + 1); |
| 1281 | |
| 1282 | #undef ERROR_MSG_PREFIX |
| 1283 | |
| 1284 | *major = static_cast<uint16_t>(majorVal); |
| 1285 | *minor = static_cast<uint16_t>(minorVal); |
| 1286 | *type = typeVal; |
| 1287 | *id = idVal; |
| 1288 | |
| 1289 | return OK; |
| 1290 | } |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | CameraProviderManager::ProviderInfo::~ProviderInfo() { |
| 1295 | // Destruction of ProviderInfo is only supposed to happen when the respective |
| 1296 | // CameraProvider interface dies, so do not unregister callbacks. |
| 1297 | |
| 1298 | } |
| 1299 | |
| 1300 | status_t CameraProviderManager::mapToStatusT(const Status& s) { |
| 1301 | switch(s) { |
| 1302 | case Status::OK: |
| 1303 | return OK; |
| 1304 | case Status::ILLEGAL_ARGUMENT: |
| 1305 | return BAD_VALUE; |
| 1306 | case Status::CAMERA_IN_USE: |
| 1307 | return -EBUSY; |
| 1308 | case Status::MAX_CAMERAS_IN_USE: |
| 1309 | return -EUSERS; |
| 1310 | case Status::METHOD_NOT_SUPPORTED: |
| 1311 | return UNKNOWN_TRANSACTION; |
| 1312 | case Status::OPERATION_NOT_SUPPORTED: |
| 1313 | return INVALID_OPERATION; |
| 1314 | case Status::CAMERA_DISCONNECTED: |
| 1315 | return DEAD_OBJECT; |
| 1316 | case Status::INTERNAL_ERROR: |
| 1317 | return INVALID_OPERATION; |
| 1318 | } |
| 1319 | ALOGW("Unexpected HAL status code %d", s); |
| 1320 | return INVALID_OPERATION; |
| 1321 | } |
| 1322 | |
| 1323 | const char* CameraProviderManager::statusToString(const Status& s) { |
| 1324 | switch(s) { |
| 1325 | case Status::OK: |
| 1326 | return "OK"; |
| 1327 | case Status::ILLEGAL_ARGUMENT: |
| 1328 | return "ILLEGAL_ARGUMENT"; |
| 1329 | case Status::CAMERA_IN_USE: |
| 1330 | return "CAMERA_IN_USE"; |
| 1331 | case Status::MAX_CAMERAS_IN_USE: |
| 1332 | return "MAX_CAMERAS_IN_USE"; |
| 1333 | case Status::METHOD_NOT_SUPPORTED: |
| 1334 | return "METHOD_NOT_SUPPORTED"; |
| 1335 | case Status::OPERATION_NOT_SUPPORTED: |
| 1336 | return "OPERATION_NOT_SUPPORTED"; |
| 1337 | case Status::CAMERA_DISCONNECTED: |
| 1338 | return "CAMERA_DISCONNECTED"; |
| 1339 | case Status::INTERNAL_ERROR: |
| 1340 | return "INTERNAL_ERROR"; |
| 1341 | } |
| 1342 | ALOGW("Unexpected HAL status code %d", s); |
| 1343 | return "UNKNOWN_ERROR"; |
| 1344 | } |
| 1345 | |
| 1346 | const char* CameraProviderManager::deviceStatusToString(const CameraDeviceStatus& s) { |
| 1347 | switch(s) { |
| 1348 | case CameraDeviceStatus::NOT_PRESENT: |
| 1349 | return "NOT_PRESENT"; |
| 1350 | case CameraDeviceStatus::PRESENT: |
| 1351 | return "PRESENT"; |
| 1352 | case CameraDeviceStatus::ENUMERATING: |
| 1353 | return "ENUMERATING"; |
| 1354 | } |
| 1355 | ALOGW("Unexpected HAL device status code %d", s); |
| 1356 | return "UNKNOWN_STATUS"; |
| 1357 | } |
| 1358 | |
| 1359 | const char* CameraProviderManager::torchStatusToString(const TorchModeStatus& s) { |
| 1360 | switch(s) { |
| 1361 | case TorchModeStatus::NOT_AVAILABLE: |
| 1362 | return "NOT_AVAILABLE"; |
| 1363 | case TorchModeStatus::AVAILABLE_OFF: |
| 1364 | return "AVAILABLE_OFF"; |
| 1365 | case TorchModeStatus::AVAILABLE_ON: |
| 1366 | return "AVAILABLE_ON"; |
| 1367 | } |
| 1368 | ALOGW("Unexpected HAL torch mode status code %d", s); |
| 1369 | return "UNKNOWN_STATUS"; |
| 1370 | } |
| 1371 | |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 1372 | |
| 1373 | status_t HidlVendorTagDescriptor::createDescriptorFromHidl( |
| 1374 | const hardware::hidl_vec<hardware::camera::common::V1_0::VendorTagSection>& vts, |
| 1375 | /*out*/ |
| 1376 | sp<VendorTagDescriptor>& descriptor) { |
| 1377 | |
| 1378 | int tagCount = 0; |
| 1379 | |
| 1380 | for (size_t s = 0; s < vts.size(); s++) { |
| 1381 | tagCount += vts[s].tags.size(); |
| 1382 | } |
| 1383 | |
| 1384 | if (tagCount < 0 || tagCount > INT32_MAX) { |
| 1385 | ALOGE("%s: tag count %d from vendor tag sections is invalid.", __FUNCTION__, tagCount); |
| 1386 | return BAD_VALUE; |
| 1387 | } |
| 1388 | |
| 1389 | Vector<uint32_t> tagArray; |
| 1390 | LOG_ALWAYS_FATAL_IF(tagArray.resize(tagCount) != tagCount, |
| 1391 | "%s: too many (%u) vendor tags defined.", __FUNCTION__, tagCount); |
| 1392 | |
| 1393 | |
| 1394 | sp<HidlVendorTagDescriptor> desc = new HidlVendorTagDescriptor(); |
| 1395 | desc->mTagCount = tagCount; |
| 1396 | |
| 1397 | SortedVector<String8> sections; |
| 1398 | KeyedVector<uint32_t, String8> tagToSectionMap; |
| 1399 | |
| 1400 | int idx = 0; |
| 1401 | for (size_t s = 0; s < vts.size(); s++) { |
| 1402 | const hardware::camera::common::V1_0::VendorTagSection& section = vts[s]; |
| 1403 | const char *sectionName = section.sectionName.c_str(); |
| 1404 | if (sectionName == NULL) { |
| 1405 | ALOGE("%s: no section name defined for vendor tag section %zu.", __FUNCTION__, s); |
| 1406 | return BAD_VALUE; |
| 1407 | } |
| 1408 | String8 sectionString(sectionName); |
| 1409 | sections.add(sectionString); |
| 1410 | |
| 1411 | for (size_t j = 0; j < section.tags.size(); j++) { |
| 1412 | uint32_t tag = section.tags[j].tagId; |
| 1413 | if (tag < CAMERA_METADATA_VENDOR_TAG_BOUNDARY) { |
| 1414 | ALOGE("%s: vendor tag %d not in vendor tag section.", __FUNCTION__, tag); |
| 1415 | return BAD_VALUE; |
| 1416 | } |
| 1417 | |
| 1418 | tagArray.editItemAt(idx++) = section.tags[j].tagId; |
| 1419 | |
| 1420 | const char *tagName = section.tags[j].tagName.c_str(); |
| 1421 | if (tagName == NULL) { |
| 1422 | ALOGE("%s: no tag name defined for vendor tag %d.", __FUNCTION__, tag); |
| 1423 | return BAD_VALUE; |
| 1424 | } |
| 1425 | desc->mTagToNameMap.add(tag, String8(tagName)); |
| 1426 | tagToSectionMap.add(tag, sectionString); |
| 1427 | |
| 1428 | int tagType = (int) section.tags[j].tagType; |
| 1429 | if (tagType < 0 || tagType >= NUM_TYPES) { |
| 1430 | ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType); |
| 1431 | return BAD_VALUE; |
| 1432 | } |
| 1433 | desc->mTagToTypeMap.add(tag, tagType); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | desc->mSections = sections; |
| 1438 | |
| 1439 | for (size_t i = 0; i < tagArray.size(); ++i) { |
| 1440 | uint32_t tag = tagArray[i]; |
| 1441 | String8 sectionString = tagToSectionMap.valueFor(tag); |
| 1442 | |
| 1443 | // Set up tag to section index map |
| 1444 | ssize_t index = sections.indexOf(sectionString); |
| 1445 | LOG_ALWAYS_FATAL_IF(index < 0, "index %zd must be non-negative", index); |
| 1446 | desc->mTagToSectionMap.add(tag, static_cast<uint32_t>(index)); |
| 1447 | |
| 1448 | // Set up reverse mapping |
| 1449 | ssize_t reverseIndex = -1; |
| 1450 | if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) { |
| 1451 | KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>(); |
| 1452 | reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper); |
| 1453 | } |
| 1454 | desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag); |
| 1455 | } |
| 1456 | |
George Burgess IV | a0b8496 | 2017-08-29 17:46:19 -0700 | [diff] [blame] | 1457 | descriptor = std::move(desc); |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 1458 | return OK; |
| 1459 | } |
| 1460 | |
Shuzhen Wang | e8aceb5 | 2018-05-21 12:00:56 -0700 | [diff] [blame] | 1461 | status_t CameraProviderManager::getCameraCharacteristicsLocked(const std::string &id, |
| 1462 | CameraMetadata* characteristics) const { |
| 1463 | auto deviceInfo = findDeviceInfoLocked(id, /*minVersion*/ {3,0}, /*maxVersion*/ {4,0}); |
| 1464 | if (deviceInfo == nullptr) return NAME_NOT_FOUND; |
| 1465 | |
| 1466 | return deviceInfo->getCameraCharacteristics(characteristics); |
| 1467 | } |
| 1468 | |
| 1469 | void CameraProviderManager::filterLogicalCameraIdsLocked( |
| 1470 | std::vector<std::string>& deviceIds) const |
| 1471 | { |
| 1472 | std::unordered_set<std::string> removedIds; |
| 1473 | |
| 1474 | for (auto& deviceId : deviceIds) { |
| 1475 | CameraMetadata info; |
| 1476 | status_t res = getCameraCharacteristicsLocked(deviceId, &info); |
| 1477 | if (res != OK) { |
| 1478 | ALOGE("%s: Failed to getCameraCharacteristics for id %s", __FUNCTION__, |
| 1479 | deviceId.c_str()); |
| 1480 | return; |
| 1481 | } |
| 1482 | |
| 1483 | // idCombo contains the ids of a logical camera and its physical cameras |
| 1484 | std::vector<std::string> idCombo; |
| 1485 | bool logicalCamera = CameraProviderManager::isLogicalCamera(info, &idCombo); |
| 1486 | if (!logicalCamera) { |
| 1487 | continue; |
| 1488 | } |
| 1489 | idCombo.push_back(deviceId); |
| 1490 | |
| 1491 | for (auto& id : deviceIds) { |
| 1492 | auto foundId = std::find(idCombo.begin(), idCombo.end(), id); |
| 1493 | if (foundId == idCombo.end()) { |
| 1494 | continue; |
| 1495 | } |
| 1496 | |
| 1497 | idCombo.erase(foundId); |
| 1498 | removedIds.insert(idCombo.begin(), idCombo.end()); |
| 1499 | break; |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | deviceIds.erase(std::remove_if(deviceIds.begin(), deviceIds.end(), |
| 1504 | [&removedIds](const std::string& s) {return removedIds.find(s) != removedIds.end();}), |
| 1505 | deviceIds.end()); |
| 1506 | } |
Yin-Chia Yeh | 067428c | 2017-01-13 15:19:24 -0800 | [diff] [blame] | 1507 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 1508 | } // namespace android |