Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #include "VintfObject.h" |
| 18 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 19 | #include "CompatibilityMatrix.h" |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 20 | #include "parse_string.h" |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 21 | #include "parse_xml.h" |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 22 | #include "utils.h" |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 23 | |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 24 | #include <dirent.h> |
| 25 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 26 | #include <functional> |
| 27 | #include <memory> |
| 28 | #include <mutex> |
| 29 | |
Bowgo Tsai | 39adc14 | 2017-11-03 12:46:26 +0800 | [diff] [blame] | 30 | #ifdef LIBVINTF_TARGET |
| 31 | #include <android-base/properties.h> |
| 32 | #endif |
| 33 | |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 34 | #include <android-base/logging.h> |
| 35 | |
| 36 | using std::placeholders::_1; |
| 37 | using std::placeholders::_2; |
| 38 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 39 | namespace android { |
| 40 | namespace vintf { |
| 41 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 42 | using namespace details; |
| 43 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 44 | template <typename T> |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 45 | struct LockedSharedPtr { |
| 46 | std::shared_ptr<T> object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 47 | std::mutex mutex; |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 48 | bool fetchedOnce = false; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 51 | struct LockedRuntimeInfoCache { |
| 52 | std::shared_ptr<RuntimeInfo> object; |
| 53 | std::mutex mutex; |
| 54 | RuntimeInfo::FetchFlags fetchedFlags = RuntimeInfo::FetchFlag::NONE; |
| 55 | }; |
| 56 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 57 | template <typename T, typename F> |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 58 | static std::shared_ptr<const T> Get( |
| 59 | LockedSharedPtr<T> *ptr, |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 60 | bool skipCache, |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 61 | const F &fetchAllInformation) { |
| 62 | std::unique_lock<std::mutex> _lock(ptr->mutex); |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 63 | if (skipCache || !ptr->fetchedOnce) { |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 64 | ptr->object = std::make_unique<T>(); |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 65 | std::string error; |
| 66 | if (fetchAllInformation(ptr->object.get(), &error) != OK) { |
| 67 | LOG(WARNING) << error; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 68 | ptr->object = nullptr; // frees the old object |
| 69 | } |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 70 | ptr->fetchedOnce = true; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 71 | } |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 72 | return ptr->object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | // static |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 76 | std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) { |
Steven Moreland | 648a001 | 2017-10-19 21:23:41 -0700 | [diff] [blame] | 77 | static LockedSharedPtr<HalManifest> gVendorManifest; |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 78 | return Get(&gVendorManifest, skipCache, &VintfObject::FetchDeviceHalManifest); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // static |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 82 | std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) { |
| 83 | static LockedSharedPtr<HalManifest> gFrameworkManifest; |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame^] | 84 | return Get(&gFrameworkManifest, skipCache, &VintfObject::FetchFrameworkHalManifest); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 87 | |
| 88 | // static |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 89 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) { |
| 90 | static LockedSharedPtr<CompatibilityMatrix> gDeviceMatrix; |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 91 | return Get(&gDeviceMatrix, skipCache, &VintfObject::FetchDeviceMatrix); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // static |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 95 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) { |
| 96 | static LockedSharedPtr<CompatibilityMatrix> gFrameworkMatrix; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 97 | static LockedSharedPtr<CompatibilityMatrix> gCombinedFrameworkMatrix; |
| 98 | static std::mutex gFrameworkCompatibilityMatrixMutex; |
| 99 | |
| 100 | // To avoid deadlock, get device manifest before any locks. |
| 101 | auto deviceManifest = GetDeviceHalManifest(); |
| 102 | |
| 103 | std::unique_lock<std::mutex> _lock(gFrameworkCompatibilityMatrixMutex); |
| 104 | |
| 105 | auto combined = |
| 106 | Get(&gCombinedFrameworkMatrix, skipCache, |
| 107 | std::bind(&VintfObject::GetCombinedFrameworkMatrix, deviceManifest, _1, _2)); |
| 108 | if (combined != nullptr) { |
| 109 | return combined; |
| 110 | } |
| 111 | |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 112 | return Get(&gFrameworkMatrix, skipCache, |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 113 | std::bind(&CompatibilityMatrix::fetchAllInformation, _1, kSystemLegacyMatrix, _2)); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 116 | status_t VintfObject::GetCombinedFrameworkMatrix( |
| 117 | const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out, |
| 118 | std::string* error) { |
| 119 | auto matrixFragments = GetAllFrameworkMatrixLevels(error); |
| 120 | if (matrixFragments.empty()) { |
| 121 | return NAME_NOT_FOUND; |
| 122 | } |
| 123 | |
| 124 | Level deviceLevel = Level::UNSPECIFIED; |
| 125 | |
| 126 | if (deviceManifest != nullptr) { |
| 127 | deviceLevel = deviceManifest->level(); |
| 128 | } |
| 129 | |
| 130 | // TODO(b/70628538): Do not infer from Shipping API level. |
| 131 | #ifdef LIBVINTF_TARGET |
| 132 | if (deviceLevel == Level::UNSPECIFIED) { |
| 133 | auto shippingApi = |
| 134 | android::base::GetUintProperty<uint64_t>("ro.product.first_api_level", 0u); |
| 135 | if (shippingApi != 0u) { |
| 136 | deviceLevel = details::convertFromApiLevel(shippingApi); |
| 137 | } |
| 138 | } |
| 139 | #endif |
| 140 | |
| 141 | if (deviceLevel == Level::UNSPECIFIED) { |
| 142 | // Cannot infer FCM version. Combine all matrices by assuming |
| 143 | // Shipping FCM Version == min(all supported FCM Versions in the framework) |
| 144 | for (auto&& pair : matrixFragments) { |
| 145 | Level fragmentLevel = pair.object.level(); |
| 146 | if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) { |
| 147 | deviceLevel = fragmentLevel; |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if (deviceLevel == Level::UNSPECIFIED) { |
| 153 | // None of the fragments specify any FCM version. Should never happen except |
| 154 | // for inconsistent builds. |
| 155 | if (error) { |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 156 | *error = "No framework compatibility matrix files under " + kSystemVintfDir + |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 157 | " declare FCM version."; |
| 158 | } |
| 159 | return NAME_NOT_FOUND; |
| 160 | } |
| 161 | |
| 162 | CompatibilityMatrix* combined = |
| 163 | CompatibilityMatrix::combine(deviceLevel, &matrixFragments, error); |
| 164 | if (combined == nullptr) { |
| 165 | return BAD_VALUE; |
| 166 | } |
| 167 | *out = std::move(*combined); |
| 168 | return OK; |
| 169 | } |
| 170 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 171 | // Priority for loading vendor manifest: |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 172 | // 1. /vendor/etc/vintf/manifest.xml + ODM manifest |
| 173 | // 2. /vendor/etc/vintf/manifest.xml |
| 174 | // 3. ODM manifest |
| 175 | // 4. /vendor/manifest.xml |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 176 | // where: |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 177 | // A + B means adding <hal> tags from B to A (so that <hal>s from B can override A) |
| 178 | status_t VintfObject::FetchDeviceHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 179 | status_t vendorStatus = FetchOneHalManifest(kVendorManifest, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 180 | if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) { |
| 181 | return vendorStatus; |
| 182 | } |
| 183 | |
| 184 | HalManifest odmManifest; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 185 | status_t odmStatus = FetchOdmHalManifest(&odmManifest, error); |
| 186 | if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) { |
| 187 | return odmStatus; |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 190 | if (vendorStatus == OK) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 191 | if (odmStatus == OK) { |
| 192 | out->addAllHals(&odmManifest); |
| 193 | } |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 194 | return OK; |
| 195 | } |
| 196 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 197 | // vendorStatus != OK, "out" is not changed. |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 198 | if (odmStatus == OK) { |
| 199 | *out = std::move(odmManifest); |
| 200 | return OK; |
| 201 | } |
| 202 | |
| 203 | // Use legacy /vendor/manifest.xml |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 204 | return out->fetchAllInformation(kVendorLegacyManifest, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 207 | // "out" is written to iff return status is OK. |
| 208 | // Priority: |
| 209 | // 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml |
| 210 | // 2. /odm/etc/vintf/manifest.xml |
| 211 | // 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml |
| 212 | // 4. /odm/etc/manifest.xml |
| 213 | // where: |
| 214 | // {sku} is the value of ro.boot.product.hardware.sku |
| 215 | status_t VintfObject::FetchOdmHalManifest(HalManifest* out, std::string* error) { |
| 216 | status_t status; |
| 217 | |
| 218 | #ifdef LIBVINTF_TARGET |
| 219 | std::string productModel; |
| 220 | productModel = android::base::GetProperty("ro.boot.product.hardware.sku", ""); |
| 221 | |
| 222 | if (!productModel.empty()) { |
| 223 | status = |
| 224 | FetchOneHalManifest(kOdmVintfDir + "manifest_" + productModel + ".xml", out, error); |
| 225 | if (status == OK || status != NAME_NOT_FOUND) { |
| 226 | return status; |
| 227 | } |
| 228 | } |
| 229 | #endif |
| 230 | |
| 231 | status = FetchOneHalManifest(kOdmManifest, out, error); |
| 232 | if (status == OK || status != NAME_NOT_FOUND) { |
| 233 | return status; |
| 234 | } |
| 235 | |
| 236 | #ifdef LIBVINTF_TARGET |
| 237 | if (!productModel.empty()) { |
| 238 | status = FetchOneHalManifest(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", out, |
| 239 | error); |
| 240 | if (status == OK || status != NAME_NOT_FOUND) { |
| 241 | return status; |
| 242 | } |
| 243 | } |
| 244 | #endif |
| 245 | |
| 246 | status = FetchOneHalManifest(kOdmLegacyManifest, out, error); |
| 247 | if (status == OK || status != NAME_NOT_FOUND) { |
| 248 | return status; |
| 249 | } |
| 250 | |
| 251 | return NAME_NOT_FOUND; |
| 252 | } |
| 253 | |
| 254 | // Fetch one manifest.xml file. "out" is written to iff return status is OK. |
| 255 | // Returns NAME_NOT_FOUND if file is missing. |
| 256 | status_t VintfObject::FetchOneHalManifest(const std::string& path, HalManifest* out, |
| 257 | std::string* error) { |
| 258 | HalManifest ret; |
| 259 | status_t status = ret.fetchAllInformation(path, error); |
| 260 | if (status == OK) { |
| 261 | *out = std::move(ret); |
| 262 | } |
| 263 | return status; |
| 264 | } |
| 265 | |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 266 | status_t VintfObject::FetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) { |
| 267 | CompatibilityMatrix etcMatrix; |
| 268 | if (etcMatrix.fetchAllInformation(kVendorMatrix, error) == OK) { |
| 269 | *out = std::move(etcMatrix); |
| 270 | return OK; |
| 271 | } |
| 272 | return out->fetchAllInformation(kVendorLegacyMatrix, error); |
| 273 | } |
| 274 | |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame^] | 275 | status_t VintfObject::FetchFrameworkHalManifest(HalManifest* out, std::string* error) { |
| 276 | HalManifest etcManifest; |
| 277 | if (etcManifest.fetchAllInformation(kSystemManifest, error) == OK) { |
| 278 | *out = std::move(etcManifest); |
| 279 | return OK; |
| 280 | } |
| 281 | return out->fetchAllInformation(kSystemLegacyManifest, error); |
| 282 | } |
| 283 | |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 284 | std::vector<Named<CompatibilityMatrix>> VintfObject::GetAllFrameworkMatrixLevels( |
| 285 | std::string* error) { |
| 286 | std::vector<std::string> fileNames; |
| 287 | std::vector<Named<CompatibilityMatrix>> results; |
| 288 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 289 | if (details::gFetcher->listFiles(kSystemVintfDir, &fileNames, error) != OK) { |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 290 | return {}; |
| 291 | } |
| 292 | for (const std::string& fileName : fileNames) { |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 293 | std::string path = kSystemVintfDir + fileName; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 294 | |
| 295 | std::string content; |
| 296 | std::string fetchError; |
| 297 | status_t status = details::gFetcher->fetch(path, content, &fetchError); |
| 298 | if (status != OK) { |
| 299 | if (error) { |
| 300 | *error += "Ignore file " + path + ": " + fetchError + "\n"; |
| 301 | } |
| 302 | continue; |
| 303 | } |
| 304 | |
| 305 | auto it = results.emplace(results.end()); |
Yifan Hong | 9475706 | 2018-02-09 16:36:31 -0800 | [diff] [blame] | 306 | if (!gCompatibilityMatrixConverter(&it->object, content, error)) { |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 307 | if (error) { |
Yifan Hong | 9475706 | 2018-02-09 16:36:31 -0800 | [diff] [blame] | 308 | *error += "Ignore file " + path + ": " + *error + "\n"; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 309 | } |
| 310 | results.erase(it); |
| 311 | continue; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | if (results.empty()) { |
| 316 | if (error) { |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 317 | *error = "No framework matrices under " + kSystemVintfDir + |
| 318 | " can be fetched or parsed.\n" + *error; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 319 | } |
| 320 | } else { |
| 321 | if (error && !error->empty()) { |
| 322 | LOG(WARNING) << *error; |
| 323 | *error = ""; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | return results; |
| 328 | } |
| 329 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 330 | // static |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 331 | std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache, |
| 332 | RuntimeInfo::FetchFlags flags) { |
| 333 | static LockedRuntimeInfoCache gDeviceRuntimeInfo; |
| 334 | std::unique_lock<std::mutex> _lock(gDeviceRuntimeInfo.mutex); |
| 335 | |
| 336 | if (!skipCache) { |
| 337 | flags &= (~gDeviceRuntimeInfo.fetchedFlags); |
| 338 | } |
| 339 | |
| 340 | if (gDeviceRuntimeInfo.object == nullptr) { |
Yifan Hong | 29bb2d4 | 2017-09-27 13:28:00 -0700 | [diff] [blame] | 341 | gDeviceRuntimeInfo.object = details::gRuntimeInfoFactory->make_shared(); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | status_t status = gDeviceRuntimeInfo.object->fetchAllInformation(flags); |
| 345 | if (status != OK) { |
| 346 | gDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched" |
| 347 | return nullptr; |
| 348 | } |
| 349 | |
| 350 | gDeviceRuntimeInfo.fetchedFlags |= flags; |
| 351 | return gDeviceRuntimeInfo.object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 354 | namespace details { |
| 355 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 356 | enum class ParseStatus { |
| 357 | OK, |
| 358 | PARSE_ERROR, |
| 359 | DUPLICATED_FWK_ENTRY, |
| 360 | DUPLICATED_DEV_ENTRY, |
| 361 | }; |
| 362 | |
Yifan Hong | 9532bd2 | 2017-04-14 15:30:52 -0700 | [diff] [blame] | 363 | static std::string toString(ParseStatus status) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 364 | switch(status) { |
| 365 | case ParseStatus::OK: return "OK"; |
| 366 | case ParseStatus::PARSE_ERROR: return "parse error"; |
| 367 | case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework"; |
| 368 | case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device"; |
| 369 | } |
| 370 | return ""; |
| 371 | } |
| 372 | |
| 373 | template<typename T> |
Yifan Hong | 9532bd2 | 2017-04-14 15:30:52 -0700 | [diff] [blame] | 374 | static ParseStatus tryParse(const std::string &xml, const XmlConverter<T> &parse, |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 375 | std::shared_ptr<T> *fwk, std::shared_ptr<T> *dev) { |
| 376 | std::shared_ptr<T> ret = std::make_shared<T>(); |
Yifan Hong | 9475706 | 2018-02-09 16:36:31 -0800 | [diff] [blame] | 377 | if (!parse(ret.get(), xml, nullptr /* error */)) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 378 | return ParseStatus::PARSE_ERROR; |
| 379 | } |
| 380 | if (ret->type() == SchemaType::FRAMEWORK) { |
| 381 | if (fwk->get() != nullptr) { |
| 382 | return ParseStatus::DUPLICATED_FWK_ENTRY; |
| 383 | } |
| 384 | *fwk = std::move(ret); |
| 385 | } else if (ret->type() == SchemaType::DEVICE) { |
| 386 | if (dev->get() != nullptr) { |
| 387 | return ParseStatus::DUPLICATED_DEV_ENTRY; |
| 388 | } |
| 389 | *dev = std::move(ret); |
| 390 | } |
| 391 | return ParseStatus::OK; |
| 392 | } |
| 393 | |
| 394 | template<typename T, typename GetFunction> |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 395 | static status_t getMissing(const std::shared_ptr<T>& pkg, bool mount, |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 396 | std::function<status_t(void)> mountFunction, |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 397 | std::shared_ptr<const T>* updated, |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 398 | GetFunction getFunction) { |
| 399 | if (pkg != nullptr) { |
| 400 | *updated = pkg; |
| 401 | } else { |
| 402 | if (mount) { |
| 403 | (void)mountFunction(); // ignore mount errors |
| 404 | } |
| 405 | *updated = getFunction(); |
| 406 | } |
| 407 | return OK; |
| 408 | } |
| 409 | |
| 410 | #define ADD_MESSAGE(__error__) \ |
| 411 | if (error != nullptr) { \ |
| 412 | *error += (__error__); \ |
| 413 | } \ |
| 414 | |
| 415 | struct PackageInfo { |
| 416 | struct Pair { |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 417 | std::shared_ptr<HalManifest> manifest; |
| 418 | std::shared_ptr<CompatibilityMatrix> matrix; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 419 | }; |
| 420 | Pair dev; |
| 421 | Pair fwk; |
| 422 | }; |
| 423 | |
| 424 | struct UpdatedInfo { |
| 425 | struct Pair { |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 426 | std::shared_ptr<const HalManifest> manifest; |
| 427 | std::shared_ptr<const CompatibilityMatrix> matrix; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 428 | }; |
| 429 | Pair dev; |
| 430 | Pair fwk; |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 431 | std::shared_ptr<const RuntimeInfo> runtimeInfo; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 432 | }; |
| 433 | |
Michael Schwartz | 97dc0f9 | 2017-05-08 14:07:14 -0700 | [diff] [blame] | 434 | // Checks given compatibility info against info on the device. If no |
| 435 | // compatability info is given then the device info will be checked against |
| 436 | // itself. |
Yifan Hong | db6423e | 2017-09-11 14:38:46 -0700 | [diff] [blame] | 437 | int32_t checkCompatibility(const std::vector<std::string>& xmls, bool mount, |
| 438 | const PartitionMounter& mounter, std::string* error, |
| 439 | DisabledChecks disabledChecks) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 440 | status_t status; |
| 441 | ParseStatus parseStatus; |
| 442 | PackageInfo pkg; // All information from package. |
| 443 | UpdatedInfo updated; // All files and runtime info after the update. |
| 444 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 445 | // parse all information from package |
| 446 | for (const auto &xml : xmls) { |
| 447 | parseStatus = tryParse(xml, gHalManifestConverter, &pkg.fwk.manifest, &pkg.dev.manifest); |
| 448 | if (parseStatus == ParseStatus::OK) { |
| 449 | continue; // work on next one |
| 450 | } |
| 451 | if (parseStatus != ParseStatus::PARSE_ERROR) { |
| 452 | ADD_MESSAGE(toString(parseStatus) + " manifest"); |
| 453 | return ALREADY_EXISTS; |
| 454 | } |
| 455 | parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &pkg.fwk.matrix, &pkg.dev.matrix); |
| 456 | if (parseStatus == ParseStatus::OK) { |
| 457 | continue; // work on next one |
| 458 | } |
| 459 | if (parseStatus != ParseStatus::PARSE_ERROR) { |
| 460 | ADD_MESSAGE(toString(parseStatus) + " matrix"); |
| 461 | return ALREADY_EXISTS; |
| 462 | } |
| 463 | ADD_MESSAGE(toString(parseStatus)); // parse error |
| 464 | return BAD_VALUE; |
| 465 | } |
| 466 | |
| 467 | // get missing info from device |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 468 | // use functions instead of std::bind because std::bind doesn't work well with mock objects |
| 469 | auto mountSystem = [&mounter] { return mounter.mountSystem(); }; |
| 470 | auto mountVendor = [&mounter] { return mounter.mountVendor(); }; |
| 471 | if ((status = getMissing( |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 472 | pkg.fwk.manifest, mount, mountSystem, &updated.fwk.manifest, |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 473 | std::bind(VintfObject::GetFrameworkHalManifest, true /* skipCache */))) != OK) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 474 | return status; |
| 475 | } |
Michael Schwartz | 97dc0f9 | 2017-05-08 14:07:14 -0700 | [diff] [blame] | 476 | if ((status = getMissing( |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 477 | pkg.dev.manifest, mount, mountVendor, &updated.dev.manifest, |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 478 | std::bind(VintfObject::GetDeviceHalManifest, true /* skipCache */))) != OK) { |
| 479 | return status; |
| 480 | } |
| 481 | if ((status = getMissing( |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 482 | pkg.fwk.matrix, mount, mountSystem, &updated.fwk.matrix, |
Michael Schwartz | 97dc0f9 | 2017-05-08 14:07:14 -0700 | [diff] [blame] | 483 | std::bind(VintfObject::GetFrameworkCompatibilityMatrix, true /* skipCache */))) != |
| 484 | OK) { |
| 485 | return status; |
| 486 | } |
| 487 | if ((status = getMissing( |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 488 | pkg.dev.matrix, mount, mountVendor, &updated.dev.matrix, |
Michael Schwartz | 97dc0f9 | 2017-05-08 14:07:14 -0700 | [diff] [blame] | 489 | std::bind(VintfObject::GetDeviceCompatibilityMatrix, true /* skipCache */))) != OK) { |
| 490 | return status; |
| 491 | } |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 492 | |
| 493 | if (mount) { |
| 494 | (void)mounter.umountSystem(); // ignore errors |
| 495 | (void)mounter.umountVendor(); // ignore errors |
| 496 | } |
| 497 | |
| 498 | updated.runtimeInfo = VintfObject::GetRuntimeInfo(true /* skipCache */); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 499 | |
| 500 | // null checks for files and runtime info after the update |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 501 | if (updated.fwk.manifest == nullptr) { |
| 502 | ADD_MESSAGE("No framework manifest file from device or from update package"); |
| 503 | return NO_INIT; |
| 504 | } |
| 505 | if (updated.dev.manifest == nullptr) { |
| 506 | ADD_MESSAGE("No device manifest file from device or from update package"); |
| 507 | return NO_INIT; |
| 508 | } |
| 509 | if (updated.fwk.matrix == nullptr) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 510 | ADD_MESSAGE("No framework matrix file from device or from update package"); |
| 511 | return NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 512 | } |
| 513 | if (updated.dev.matrix == nullptr) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 514 | ADD_MESSAGE("No device matrix file from device or from update package"); |
| 515 | return NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 516 | } |
| 517 | if (updated.runtimeInfo == nullptr) { |
| 518 | ADD_MESSAGE("No runtime info from device"); |
| 519 | return NO_INIT; |
| 520 | } |
| 521 | |
| 522 | // compatiblity check. |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 523 | if (!updated.dev.manifest->checkCompatibility(*updated.fwk.matrix, error)) { |
| 524 | if (error) { |
| 525 | error->insert(0, |
| 526 | "Device manifest and framework compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 527 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 528 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 529 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 530 | if (!updated.fwk.manifest->checkCompatibility(*updated.dev.matrix, error)) { |
| 531 | if (error) { |
| 532 | error->insert(0, |
| 533 | "Framework manifest and device compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 534 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 535 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 536 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 537 | if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error, disabledChecks)) { |
| 538 | if (error) { |
| 539 | error->insert(0, "Runtime info and framework compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 540 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 541 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | return COMPATIBLE; |
| 545 | } |
| 546 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 547 | const std::string kSystemVintfDir = "/system/etc/vintf/"; |
Yifan Hong | ccbea05 | 2018-01-18 18:48:46 -0800 | [diff] [blame] | 548 | const std::string kVendorVintfDir = "/vendor/etc/vintf/"; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 549 | const std::string kOdmVintfDir = "/odm/etc/vintf/"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 550 | |
| 551 | const std::string kVendorManifest = kVendorVintfDir + "manifest.xml"; |
Yifan Hong | a5ddddf | 2018-01-18 18:50:13 -0800 | [diff] [blame] | 552 | const std::string kSystemManifest = kSystemVintfDir + "manifest.xml"; |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 553 | const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml"; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 554 | const std::string kOdmManifest = kOdmVintfDir + "manifest.xml"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 555 | |
| 556 | const std::string kVendorLegacyManifest = "/vendor/manifest.xml"; |
| 557 | const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml"; |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame^] | 558 | const std::string kSystemLegacyManifest = "/system/manifest.xml"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 559 | const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml"; |
| 560 | const std::string kOdmLegacyVintfDir = "/odm/etc/"; |
| 561 | const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml"; |
| 562 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 563 | } // namespace details |
| 564 | |
Yifan Hong | fbbf047 | 2017-04-07 18:14:18 -0700 | [diff] [blame] | 565 | // static |
Yifan Hong | db6423e | 2017-09-11 14:38:46 -0700 | [diff] [blame] | 566 | int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error, |
| 567 | DisabledChecks disabledChecks) { |
| 568 | return details::checkCompatibility(xmls, false /* mount */, *details::gPartitionMounter, error, |
| 569 | disabledChecks); |
Yifan Hong | fbbf047 | 2017-04-07 18:14:18 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 572 | bool VintfObject::isHalDeprecated(const MatrixHal& oldMatrixHal, |
| 573 | const CompatibilityMatrix& targetMatrix, |
| 574 | const IsInstanceInUse& isInstanceInUse, std::string* error) { |
| 575 | for (const VersionRange& range : oldMatrixHal.versionRanges) { |
| 576 | for (const HalInterface& interface : iterateValues(oldMatrixHal.interfaces)) { |
| 577 | for (const std::string& instance : interface.instances) { |
| 578 | if (isInstanceDeprecated(oldMatrixHal.name, range.minVer(), interface.name, |
| 579 | instance, targetMatrix, isInstanceInUse, error)) { |
| 580 | return true; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | return false; |
| 586 | } |
| 587 | |
| 588 | // If isInstanceInUse(package@x.y::interface/instance), return true iff: |
| 589 | // 1. package@x.?::interface/instance is not in targetMatrix; OR |
| 590 | // 2. package@x.z::interface/instance is in targetMatrix but |
| 591 | // !isInstanceInUse(package@x.z::interface/instance) |
| 592 | bool VintfObject::isInstanceDeprecated(const std::string& package, Version version, |
| 593 | const std::string& interface, const std::string& instance, |
| 594 | const CompatibilityMatrix& targetMatrix, |
| 595 | const IsInstanceInUse& isInstanceInUse, |
| 596 | std::string* error) { |
| 597 | bool oldVersionIsServed; |
| 598 | Version servedVersion; |
| 599 | std::tie(oldVersionIsServed, servedVersion) = |
| 600 | isInstanceInUse(package, version, interface, instance); |
| 601 | if (oldVersionIsServed) { |
| 602 | // Find any package@x.? in target matrix, and check if instance is in target matrix. |
| 603 | const MatrixHal* targetMatrixHal; |
| 604 | const VersionRange* targetMatrixRange; |
| 605 | std::tie(targetMatrixHal, targetMatrixRange) = |
| 606 | targetMatrix.getHalWithMajorVersion(package, version.majorVer); |
| 607 | if (targetMatrixHal == nullptr || targetMatrixRange == nullptr) { |
| 608 | if (error) { |
Yifan Hong | b6c7f49 | 2018-02-27 14:07:57 -0800 | [diff] [blame] | 609 | *error = toFQNameString(package, servedVersion) + |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 610 | "is deprecated in compatibility matrix at FCM Version " + |
| 611 | to_string(targetMatrix.level()) + "; it should not be served."; |
| 612 | } |
| 613 | return true; |
| 614 | } |
| 615 | |
| 616 | const auto& targetMatrixInstances = targetMatrixHal->getInstances(interface); |
| 617 | if (targetMatrixInstances.find(instance) == targetMatrixInstances.end()) { |
| 618 | if (error) { |
Yifan Hong | b6c7f49 | 2018-02-27 14:07:57 -0800 | [diff] [blame] | 619 | *error += toFQNameString(package, servedVersion, interface, instance) + |
| 620 | " is deprecated at FCM version " + to_string(targetMatrix.level()) + |
| 621 | "; it should be not be served.\n"; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 622 | } |
| 623 | return true; |
| 624 | } |
| 625 | |
| 626 | // Assuming that targetMatrix requires @x.u-v, require that at least @x.u is served. |
| 627 | bool targetVersionServed; |
| 628 | std::tie(targetVersionServed, std::ignore) = |
| 629 | isInstanceInUse(package, targetMatrixRange->minVer(), interface, instance); |
| 630 | |
| 631 | if (!targetVersionServed) { |
| 632 | if (error) { |
Yifan Hong | b6c7f49 | 2018-02-27 14:07:57 -0800 | [diff] [blame] | 633 | *error += toFQNameString(package, servedVersion) + " is deprecated; " + |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 634 | "require at least " + to_string(targetMatrixRange->minVer()) + "\n"; |
| 635 | } |
| 636 | return true; |
| 637 | } |
| 638 | } |
| 639 | return false; |
| 640 | } |
| 641 | |
| 642 | int32_t VintfObject::CheckDeprecation(const IsInstanceInUse& isInstanceInUse, |
| 643 | std::string* error) { |
| 644 | auto matrixFragments = GetAllFrameworkMatrixLevels(error); |
| 645 | if (matrixFragments.empty()) { |
| 646 | if (error && error->empty()) |
| 647 | *error = "Cannot get framework matrix for each FCM version for unknown error."; |
| 648 | return NAME_NOT_FOUND; |
| 649 | } |
| 650 | auto deviceManifest = GetDeviceHalManifest(); |
| 651 | if (deviceManifest == nullptr) { |
| 652 | if (error) *error = "No device manifest."; |
| 653 | return NAME_NOT_FOUND; |
| 654 | } |
| 655 | Level deviceLevel = deviceManifest->level(); |
| 656 | if (deviceLevel == Level::UNSPECIFIED) { |
| 657 | if (error) *error = "Device manifest does not specify Shipping FCM Version."; |
| 658 | return BAD_VALUE; |
| 659 | } |
| 660 | |
| 661 | const CompatibilityMatrix* targetMatrix = nullptr; |
| 662 | for (const auto& namedMatrix : matrixFragments) { |
| 663 | if (namedMatrix.object.level() == deviceLevel) { |
| 664 | targetMatrix = &namedMatrix.object; |
| 665 | } |
| 666 | } |
| 667 | if (targetMatrix == nullptr) { |
| 668 | if (error) |
| 669 | *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + "."; |
| 670 | return NAME_NOT_FOUND; |
| 671 | } |
| 672 | |
| 673 | bool hasDeprecatedHals = false; |
| 674 | for (const auto& namedMatrix : matrixFragments) { |
| 675 | if (namedMatrix.object.level() == Level::UNSPECIFIED) continue; |
| 676 | if (namedMatrix.object.level() >= deviceLevel) continue; |
| 677 | |
| 678 | const auto& oldMatrix = namedMatrix.object; |
| 679 | for (const MatrixHal& hal : oldMatrix.getHals()) { |
| 680 | hasDeprecatedHals |= isHalDeprecated(hal, *targetMatrix, isInstanceInUse, error); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | return hasDeprecatedHals ? DEPRECATED : NO_DEPRECATED_HALS; |
| 685 | } |
| 686 | |
| 687 | int32_t VintfObject::CheckDeprecation(std::string* error) { |
| 688 | auto deviceManifest = GetDeviceHalManifest(); |
| 689 | IsInstanceInUse inManifest = [&deviceManifest](const std::string& package, Version version, |
| 690 | const std::string& interface, |
| 691 | const std::string& instance) { |
| 692 | const ManifestHal* hal = deviceManifest->getHal(package, version); |
| 693 | if (hal == nullptr) { |
| 694 | return std::make_pair(false, Version{}); |
| 695 | } |
| 696 | const auto& instances = hal->getInstances(interface); |
| 697 | if (instances.find(instance) == instances.end()) { |
| 698 | return std::make_pair(false, Version{}); |
| 699 | } |
| 700 | |
| 701 | for (Version v : hal->versions) { |
| 702 | if (v.minorAtLeast(version)) { |
| 703 | return std::make_pair(true, v); |
| 704 | } |
| 705 | } |
| 706 | return std::make_pair(false, Version{}); |
| 707 | }; |
| 708 | return CheckDeprecation(inManifest, error); |
| 709 | } |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 710 | |
| 711 | } // namespace vintf |
| 712 | } // namespace android |