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" |
| 20 | #include "parse_xml.h" |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 21 | #include "utils.h" |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 22 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 23 | #include <functional> |
| 24 | #include <memory> |
| 25 | #include <mutex> |
| 26 | |
Bowgo Tsai | 39adc14 | 2017-11-03 12:46:26 +0800 | [diff] [blame] | 27 | #ifdef LIBVINTF_TARGET |
| 28 | #include <android-base/properties.h> |
| 29 | #endif |
| 30 | |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 31 | #include <android-base/logging.h> |
| 32 | |
| 33 | using std::placeholders::_1; |
| 34 | using std::placeholders::_2; |
| 35 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 36 | namespace android { |
| 37 | namespace vintf { |
| 38 | |
| 39 | template <typename T> |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 40 | struct LockedSharedPtr { |
| 41 | std::shared_ptr<T> object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 42 | std::mutex mutex; |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 43 | bool fetchedOnce = false; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 46 | struct LockedRuntimeInfoCache { |
| 47 | std::shared_ptr<RuntimeInfo> object; |
| 48 | std::mutex mutex; |
| 49 | RuntimeInfo::FetchFlags fetchedFlags = RuntimeInfo::FetchFlag::NONE; |
| 50 | }; |
| 51 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 52 | template <typename T, typename F> |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 53 | static std::shared_ptr<const T> Get( |
| 54 | LockedSharedPtr<T> *ptr, |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 55 | bool skipCache, |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 56 | const F &fetchAllInformation) { |
| 57 | std::unique_lock<std::mutex> _lock(ptr->mutex); |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 58 | if (skipCache || !ptr->fetchedOnce) { |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 59 | ptr->object = std::make_unique<T>(); |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 60 | std::string error; |
| 61 | if (fetchAllInformation(ptr->object.get(), &error) != OK) { |
| 62 | LOG(WARNING) << error; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 63 | ptr->object = nullptr; // frees the old object |
| 64 | } |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 65 | ptr->fetchedOnce = true; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 66 | } |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 67 | return ptr->object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | // static |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 71 | std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) { |
Steven Moreland | 648a001 | 2017-10-19 21:23:41 -0700 | [diff] [blame] | 72 | static LockedSharedPtr<HalManifest> gVendorManifest; |
| 73 | static LockedSharedPtr<HalManifest> gOdmManifest; |
Bowgo Tsai | 39adc14 | 2017-11-03 12:46:26 +0800 | [diff] [blame] | 74 | #ifdef LIBVINTF_TARGET |
| 75 | static LockedSharedPtr<HalManifest> gProductManifest; |
| 76 | #endif |
Steven Moreland | 648a001 | 2017-10-19 21:23:41 -0700 | [diff] [blame] | 77 | static std::mutex gDeviceManifestMutex; |
| 78 | |
| 79 | std::unique_lock<std::mutex> _lock(gDeviceManifestMutex); |
| 80 | |
Bowgo Tsai | 39adc14 | 2017-11-03 12:46:26 +0800 | [diff] [blame] | 81 | #ifdef LIBVINTF_TARGET |
Steven Moreland | c9bd73b | 2017-12-28 12:15:10 -0800 | [diff] [blame] | 82 | std::string productModel = android::base::GetProperty("ro.boot.product.hardware.sku", ""); |
Bowgo Tsai | 39adc14 | 2017-11-03 12:46:26 +0800 | [diff] [blame] | 83 | if (!productModel.empty()) { |
| 84 | auto product = Get(&gProductManifest, skipCache, |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 85 | std::bind(&HalManifest::fetchAllInformation, _1, |
Steven Moreland | c9bd73b | 2017-12-28 12:15:10 -0800 | [diff] [blame] | 86 | "/odm/etc/manifest_" + productModel + ".xml", _2)); |
Bowgo Tsai | 39adc14 | 2017-11-03 12:46:26 +0800 | [diff] [blame] | 87 | if (product != nullptr) { |
| 88 | return product; |
| 89 | } |
| 90 | } |
| 91 | #endif |
| 92 | |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 93 | auto odm = Get(&gOdmManifest, skipCache, |
Steven Moreland | c9bd73b | 2017-12-28 12:15:10 -0800 | [diff] [blame] | 94 | std::bind(&HalManifest::fetchAllInformation, _1, "/odm/etc/manifest.xml", _2)); |
Steven Moreland | 648a001 | 2017-10-19 21:23:41 -0700 | [diff] [blame] | 95 | if (odm != nullptr) { |
| 96 | return odm; |
| 97 | } |
| 98 | |
| 99 | return Get(&gVendorManifest, skipCache, |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 100 | std::bind(&HalManifest::fetchAllInformation, _1, "/vendor/manifest.xml", _2)); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // static |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 104 | std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) { |
| 105 | static LockedSharedPtr<HalManifest> gFrameworkManifest; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 106 | return Get(&gFrameworkManifest, skipCache, |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 107 | std::bind(&HalManifest::fetchAllInformation, _1, "/system/manifest.xml", _2)); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 110 | |
| 111 | // static |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 112 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) { |
| 113 | static LockedSharedPtr<CompatibilityMatrix> gDeviceMatrix; |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 114 | return Get(&gDeviceMatrix, skipCache, |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 115 | std::bind(&CompatibilityMatrix::fetchAllInformation, _1, |
| 116 | "/vendor/compatibility_matrix.xml", _2)); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | // static |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 120 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) { |
| 121 | static LockedSharedPtr<CompatibilityMatrix> gFrameworkMatrix; |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 122 | return Get(&gFrameworkMatrix, skipCache, |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 123 | std::bind(&CompatibilityMatrix::fetchAllInformation, _1, |
| 124 | "/system/compatibility_matrix.xml", _2)); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 127 | // static |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 128 | std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache, |
| 129 | RuntimeInfo::FetchFlags flags) { |
| 130 | static LockedRuntimeInfoCache gDeviceRuntimeInfo; |
| 131 | std::unique_lock<std::mutex> _lock(gDeviceRuntimeInfo.mutex); |
| 132 | |
| 133 | if (!skipCache) { |
| 134 | flags &= (~gDeviceRuntimeInfo.fetchedFlags); |
| 135 | } |
| 136 | |
| 137 | if (gDeviceRuntimeInfo.object == nullptr) { |
Yifan Hong | 29bb2d4 | 2017-09-27 13:28:00 -0700 | [diff] [blame] | 138 | gDeviceRuntimeInfo.object = details::gRuntimeInfoFactory->make_shared(); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | status_t status = gDeviceRuntimeInfo.object->fetchAllInformation(flags); |
| 142 | if (status != OK) { |
| 143 | gDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched" |
| 144 | return nullptr; |
| 145 | } |
| 146 | |
| 147 | gDeviceRuntimeInfo.fetchedFlags |= flags; |
| 148 | return gDeviceRuntimeInfo.object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 151 | namespace details { |
| 152 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 153 | enum class ParseStatus { |
| 154 | OK, |
| 155 | PARSE_ERROR, |
| 156 | DUPLICATED_FWK_ENTRY, |
| 157 | DUPLICATED_DEV_ENTRY, |
| 158 | }; |
| 159 | |
Yifan Hong | 9532bd2 | 2017-04-14 15:30:52 -0700 | [diff] [blame] | 160 | static std::string toString(ParseStatus status) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 161 | switch(status) { |
| 162 | case ParseStatus::OK: return "OK"; |
| 163 | case ParseStatus::PARSE_ERROR: return "parse error"; |
| 164 | case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework"; |
| 165 | case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device"; |
| 166 | } |
| 167 | return ""; |
| 168 | } |
| 169 | |
| 170 | template<typename T> |
Yifan Hong | 9532bd2 | 2017-04-14 15:30:52 -0700 | [diff] [blame] | 171 | static ParseStatus tryParse(const std::string &xml, const XmlConverter<T> &parse, |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 172 | std::shared_ptr<T> *fwk, std::shared_ptr<T> *dev) { |
| 173 | std::shared_ptr<T> ret = std::make_shared<T>(); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 174 | if (!parse(ret.get(), xml)) { |
| 175 | return ParseStatus::PARSE_ERROR; |
| 176 | } |
| 177 | if (ret->type() == SchemaType::FRAMEWORK) { |
| 178 | if (fwk->get() != nullptr) { |
| 179 | return ParseStatus::DUPLICATED_FWK_ENTRY; |
| 180 | } |
| 181 | *fwk = std::move(ret); |
| 182 | } else if (ret->type() == SchemaType::DEVICE) { |
| 183 | if (dev->get() != nullptr) { |
| 184 | return ParseStatus::DUPLICATED_DEV_ENTRY; |
| 185 | } |
| 186 | *dev = std::move(ret); |
| 187 | } |
| 188 | return ParseStatus::OK; |
| 189 | } |
| 190 | |
| 191 | template<typename T, typename GetFunction> |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 192 | static status_t getMissing(const std::shared_ptr<T>& pkg, bool mount, |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 193 | std::function<status_t(void)> mountFunction, |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 194 | std::shared_ptr<const T>* updated, |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 195 | GetFunction getFunction) { |
| 196 | if (pkg != nullptr) { |
| 197 | *updated = pkg; |
| 198 | } else { |
| 199 | if (mount) { |
| 200 | (void)mountFunction(); // ignore mount errors |
| 201 | } |
| 202 | *updated = getFunction(); |
| 203 | } |
| 204 | return OK; |
| 205 | } |
| 206 | |
| 207 | #define ADD_MESSAGE(__error__) \ |
| 208 | if (error != nullptr) { \ |
| 209 | *error += (__error__); \ |
| 210 | } \ |
| 211 | |
| 212 | struct PackageInfo { |
| 213 | struct Pair { |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 214 | std::shared_ptr<HalManifest> manifest; |
| 215 | std::shared_ptr<CompatibilityMatrix> matrix; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 216 | }; |
| 217 | Pair dev; |
| 218 | Pair fwk; |
| 219 | }; |
| 220 | |
| 221 | struct UpdatedInfo { |
| 222 | struct Pair { |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 223 | std::shared_ptr<const HalManifest> manifest; |
| 224 | std::shared_ptr<const CompatibilityMatrix> matrix; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 225 | }; |
| 226 | Pair dev; |
| 227 | Pair fwk; |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 228 | std::shared_ptr<const RuntimeInfo> runtimeInfo; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 229 | }; |
| 230 | |
Michael Schwartz | 97dc0f9 | 2017-05-08 14:07:14 -0700 | [diff] [blame] | 231 | // Checks given compatibility info against info on the device. If no |
| 232 | // compatability info is given then the device info will be checked against |
| 233 | // itself. |
Yifan Hong | db6423e | 2017-09-11 14:38:46 -0700 | [diff] [blame] | 234 | int32_t checkCompatibility(const std::vector<std::string>& xmls, bool mount, |
| 235 | const PartitionMounter& mounter, std::string* error, |
| 236 | DisabledChecks disabledChecks) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 237 | status_t status; |
| 238 | ParseStatus parseStatus; |
| 239 | PackageInfo pkg; // All information from package. |
| 240 | UpdatedInfo updated; // All files and runtime info after the update. |
| 241 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 242 | // parse all information from package |
| 243 | for (const auto &xml : xmls) { |
| 244 | parseStatus = tryParse(xml, gHalManifestConverter, &pkg.fwk.manifest, &pkg.dev.manifest); |
| 245 | if (parseStatus == ParseStatus::OK) { |
| 246 | continue; // work on next one |
| 247 | } |
| 248 | if (parseStatus != ParseStatus::PARSE_ERROR) { |
| 249 | ADD_MESSAGE(toString(parseStatus) + " manifest"); |
| 250 | return ALREADY_EXISTS; |
| 251 | } |
| 252 | parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &pkg.fwk.matrix, &pkg.dev.matrix); |
| 253 | if (parseStatus == ParseStatus::OK) { |
| 254 | continue; // work on next one |
| 255 | } |
| 256 | if (parseStatus != ParseStatus::PARSE_ERROR) { |
| 257 | ADD_MESSAGE(toString(parseStatus) + " matrix"); |
| 258 | return ALREADY_EXISTS; |
| 259 | } |
| 260 | ADD_MESSAGE(toString(parseStatus)); // parse error |
| 261 | return BAD_VALUE; |
| 262 | } |
| 263 | |
| 264 | // get missing info from device |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 265 | // use functions instead of std::bind because std::bind doesn't work well with mock objects |
| 266 | auto mountSystem = [&mounter] { return mounter.mountSystem(); }; |
| 267 | auto mountVendor = [&mounter] { return mounter.mountVendor(); }; |
| 268 | if ((status = getMissing( |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 269 | pkg.fwk.manifest, mount, mountSystem, &updated.fwk.manifest, |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 270 | std::bind(VintfObject::GetFrameworkHalManifest, true /* skipCache */))) != OK) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 271 | return status; |
| 272 | } |
Michael Schwartz | 97dc0f9 | 2017-05-08 14:07:14 -0700 | [diff] [blame] | 273 | if ((status = getMissing( |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 274 | pkg.dev.manifest, mount, mountVendor, &updated.dev.manifest, |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 275 | std::bind(VintfObject::GetDeviceHalManifest, true /* skipCache */))) != OK) { |
| 276 | return status; |
| 277 | } |
| 278 | if ((status = getMissing( |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 279 | pkg.fwk.matrix, mount, mountSystem, &updated.fwk.matrix, |
Michael Schwartz | 97dc0f9 | 2017-05-08 14:07:14 -0700 | [diff] [blame] | 280 | std::bind(VintfObject::GetFrameworkCompatibilityMatrix, true /* skipCache */))) != |
| 281 | OK) { |
| 282 | return status; |
| 283 | } |
| 284 | if ((status = getMissing( |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 285 | pkg.dev.matrix, mount, mountVendor, &updated.dev.matrix, |
Michael Schwartz | 97dc0f9 | 2017-05-08 14:07:14 -0700 | [diff] [blame] | 286 | std::bind(VintfObject::GetDeviceCompatibilityMatrix, true /* skipCache */))) != OK) { |
| 287 | return status; |
| 288 | } |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 289 | |
| 290 | if (mount) { |
| 291 | (void)mounter.umountSystem(); // ignore errors |
| 292 | (void)mounter.umountVendor(); // ignore errors |
| 293 | } |
| 294 | |
| 295 | updated.runtimeInfo = VintfObject::GetRuntimeInfo(true /* skipCache */); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 296 | |
| 297 | // null checks for files and runtime info after the update |
| 298 | // TODO(b/37321309) if a compat mat is missing, it is not matched and considered compatible. |
| 299 | if (updated.fwk.manifest == nullptr) { |
| 300 | ADD_MESSAGE("No framework manifest file from device or from update package"); |
| 301 | return NO_INIT; |
| 302 | } |
| 303 | if (updated.dev.manifest == nullptr) { |
| 304 | ADD_MESSAGE("No device manifest file from device or from update package"); |
| 305 | return NO_INIT; |
| 306 | } |
| 307 | if (updated.fwk.matrix == nullptr) { |
| 308 | ADD_MESSAGE("No framework matrix, skipping;"); |
| 309 | // TODO(b/37321309) consider missing matricies as errors. |
| 310 | } |
| 311 | if (updated.dev.matrix == nullptr) { |
| 312 | ADD_MESSAGE("No device matrix, skipping;"); |
| 313 | // TODO(b/37321309) consider missing matricies as errors. |
| 314 | } |
| 315 | if (updated.runtimeInfo == nullptr) { |
| 316 | ADD_MESSAGE("No runtime info from device"); |
| 317 | return NO_INIT; |
| 318 | } |
| 319 | |
| 320 | // compatiblity check. |
| 321 | // TODO(b/37321309) outer if checks can be removed if we consider missing matrices as errors. |
| 322 | if (updated.dev.manifest && updated.fwk.matrix) { |
| 323 | if (!updated.dev.manifest->checkCompatibility(*updated.fwk.matrix, error)) { |
Yifan Hong | 0d4be12 | 2017-05-15 17:04:22 -0700 | [diff] [blame] | 324 | if (error) |
| 325 | error->insert(0, "Device manifest and framework compatibility matrix " |
| 326 | "are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 327 | return INCOMPATIBLE; |
| 328 | } |
| 329 | } |
| 330 | if (updated.fwk.manifest && updated.dev.matrix) { |
| 331 | if (!updated.fwk.manifest->checkCompatibility(*updated.dev.matrix, error)) { |
Yifan Hong | 0d4be12 | 2017-05-15 17:04:22 -0700 | [diff] [blame] | 332 | if (error) |
| 333 | error->insert(0, "Framework manifest and device compatibility matrix " |
| 334 | "are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 335 | return INCOMPATIBLE; |
| 336 | } |
| 337 | } |
| 338 | if (updated.runtimeInfo && updated.fwk.matrix) { |
Yifan Hong | db6423e | 2017-09-11 14:38:46 -0700 | [diff] [blame] | 339 | if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error, disabledChecks)) { |
Yifan Hong | 0d4be12 | 2017-05-15 17:04:22 -0700 | [diff] [blame] | 340 | if (error) |
| 341 | error->insert(0, "Runtime info and framework compatibility matrix " |
| 342 | "are incompatible: "); |
Yifan Hong | e8b8684 | 2017-05-25 17:59:22 +0000 | [diff] [blame] | 343 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
| 347 | return COMPATIBLE; |
| 348 | } |
| 349 | |
| 350 | } // namespace details |
| 351 | |
Yifan Hong | fbbf047 | 2017-04-07 18:14:18 -0700 | [diff] [blame] | 352 | // static |
Yifan Hong | db6423e | 2017-09-11 14:38:46 -0700 | [diff] [blame] | 353 | int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error, |
| 354 | DisabledChecks disabledChecks) { |
| 355 | return details::checkCompatibility(xmls, false /* mount */, *details::gPartitionMounter, error, |
| 356 | disabledChecks); |
Yifan Hong | fbbf047 | 2017-04-07 18:14:18 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 359 | |
| 360 | } // namespace vintf |
| 361 | } // namespace android |