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 | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 19 | #include <dirent.h> |
| 20 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 21 | #include <functional> |
| 22 | #include <memory> |
| 23 | #include <mutex> |
| 24 | |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 25 | #include <android-base/logging.h> |
Yifan Hong | 6e32a5f | 2020-03-12 16:06:27 -0700 | [diff] [blame] | 26 | #include <android-base/result.h> |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 27 | #include <android-base/strings.h> |
Yifan Hong | ff1a25c | 2020-03-17 14:09:10 -0700 | [diff] [blame^] | 28 | #include <hidl/metadata.h> |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 29 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 30 | #include "CompatibilityMatrix.h" |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 31 | #include "parse_string.h" |
| 32 | #include "parse_xml.h" |
| 33 | #include "utils.h" |
| 34 | |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 35 | using std::placeholders::_1; |
| 36 | using std::placeholders::_2; |
| 37 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 38 | namespace android { |
| 39 | namespace vintf { |
| 40 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 41 | using namespace details; |
| 42 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 43 | #ifdef LIBVINTF_TARGET |
| 44 | static constexpr bool kIsTarget = true; |
| 45 | #else |
| 46 | static constexpr bool kIsTarget = false; |
| 47 | #endif |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 48 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 49 | template <typename T, typename F> |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 50 | static std::shared_ptr<const T> Get( |
| 51 | LockedSharedPtr<T> *ptr, |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 52 | bool skipCache, |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 53 | const F &fetchAllInformation) { |
| 54 | std::unique_lock<std::mutex> _lock(ptr->mutex); |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 55 | if (skipCache || !ptr->fetchedOnce) { |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 56 | ptr->object = std::make_unique<T>(); |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 57 | std::string error; |
| 58 | if (fetchAllInformation(ptr->object.get(), &error) != OK) { |
| 59 | LOG(WARNING) << error; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 60 | ptr->object = nullptr; // frees the old object |
| 61 | } |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 62 | ptr->fetchedOnce = true; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 63 | } |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 64 | return ptr->object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 67 | static std::unique_ptr<FileSystem> createDefaultFileSystem() { |
| 68 | std::unique_ptr<FileSystem> fileSystem; |
| 69 | if (kIsTarget) { |
| 70 | fileSystem = std::make_unique<details::FileSystemImpl>(); |
| 71 | } else { |
| 72 | fileSystem = std::make_unique<details::FileSystemNoOp>(); |
| 73 | } |
| 74 | return fileSystem; |
| 75 | } |
| 76 | |
| 77 | static std::unique_ptr<PropertyFetcher> createDefaultPropertyFetcher() { |
| 78 | std::unique_ptr<PropertyFetcher> propertyFetcher; |
| 79 | if (kIsTarget) { |
| 80 | propertyFetcher = std::make_unique<details::PropertyFetcherImpl>(); |
| 81 | } else { |
| 82 | propertyFetcher = std::make_unique<details::PropertyFetcherNoOp>(); |
| 83 | } |
| 84 | return propertyFetcher; |
| 85 | } |
| 86 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 87 | std::shared_ptr<VintfObject> VintfObject::GetInstance() { |
Steven Moreland | 954c464 | 2020-02-26 17:03:37 -0800 | [diff] [blame] | 88 | static details::LockedSharedPtr<VintfObject> sInstance{}; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 89 | std::unique_lock<std::mutex> lock(sInstance.mutex); |
| 90 | if (sInstance.object == nullptr) { |
Yifan Hong | 78f5b57 | 2018-11-27 14:05:03 -0800 | [diff] [blame] | 91 | sInstance.object = std::shared_ptr<VintfObject>(VintfObject::Builder().build().release()); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 92 | } |
| 93 | return sInstance.object; |
| 94 | } |
| 95 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 96 | std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 97 | return GetInstance()->getDeviceHalManifest(skipCache); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 100 | std::shared_ptr<const HalManifest> VintfObject::getDeviceHalManifest(bool skipCache) { |
| 101 | return Get(&mDeviceManifest, skipCache, |
| 102 | std::bind(&VintfObject::fetchDeviceHalManifest, this, _1, _2)); |
| 103 | } |
| 104 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 105 | std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 106 | return GetInstance()->getFrameworkHalManifest(skipCache); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 109 | std::shared_ptr<const HalManifest> VintfObject::getFrameworkHalManifest(bool skipCache) { |
| 110 | return Get(&mFrameworkManifest, skipCache, |
| 111 | std::bind(&VintfObject::fetchFrameworkHalManifest, this, _1, _2)); |
| 112 | } |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 113 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 114 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 115 | return GetInstance()->getDeviceCompatibilityMatrix(skipCache); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 118 | std::shared_ptr<const CompatibilityMatrix> VintfObject::getDeviceCompatibilityMatrix( |
| 119 | bool skipCache) { |
| 120 | return Get(&mDeviceMatrix, skipCache, std::bind(&VintfObject::fetchDeviceMatrix, this, _1, _2)); |
| 121 | } |
| 122 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 123 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 124 | return GetInstance()->getFrameworkCompatibilityMatrix(skipCache); |
| 125 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 126 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 127 | std::shared_ptr<const CompatibilityMatrix> VintfObject::getFrameworkCompatibilityMatrix( |
| 128 | bool skipCache) { |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 129 | // To avoid deadlock, get device manifest before any locks. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 130 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 131 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 132 | std::unique_lock<std::mutex> _lock(mFrameworkCompatibilityMatrixMutex); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 133 | |
| 134 | auto combined = |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 135 | Get(&mCombinedFrameworkMatrix, skipCache, |
| 136 | std::bind(&VintfObject::getCombinedFrameworkMatrix, this, deviceManifest, _1, _2)); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 137 | if (combined != nullptr) { |
| 138 | return combined; |
| 139 | } |
| 140 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 141 | return Get(&mFrameworkMatrix, skipCache, |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 142 | std::bind(&CompatibilityMatrix::fetchAllInformation, _1, getFileSystem().get(), |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 143 | kSystemLegacyMatrix, _2)); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 146 | status_t VintfObject::getCombinedFrameworkMatrix( |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 147 | const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out, |
| 148 | std::string* error) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 149 | std::vector<Named<CompatibilityMatrix>> matrixFragments; |
| 150 | auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error); |
| 151 | if (matrixFragmentsStatus != OK) { |
| 152 | return matrixFragmentsStatus; |
| 153 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 154 | if (matrixFragments.empty()) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 155 | if (error && error->empty()) { |
| 156 | *error = "Cannot get framework matrix for each FCM version for unknown error."; |
| 157 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 158 | return NAME_NOT_FOUND; |
| 159 | } |
| 160 | |
| 161 | Level deviceLevel = Level::UNSPECIFIED; |
| 162 | |
| 163 | if (deviceManifest != nullptr) { |
| 164 | deviceLevel = deviceManifest->level(); |
| 165 | } |
| 166 | |
| 167 | // TODO(b/70628538): Do not infer from Shipping API level. |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 168 | if (deviceLevel == Level::UNSPECIFIED) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 169 | auto shippingApi = getPropertyFetcher()->getUintProperty("ro.product.first_api_level", 0u); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 170 | if (shippingApi != 0u) { |
| 171 | deviceLevel = details::convertFromApiLevel(shippingApi); |
| 172 | } |
| 173 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 174 | |
| 175 | if (deviceLevel == Level::UNSPECIFIED) { |
| 176 | // Cannot infer FCM version. Combine all matrices by assuming |
| 177 | // Shipping FCM Version == min(all supported FCM Versions in the framework) |
| 178 | for (auto&& pair : matrixFragments) { |
| 179 | Level fragmentLevel = pair.object.level(); |
| 180 | if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) { |
| 181 | deviceLevel = fragmentLevel; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if (deviceLevel == Level::UNSPECIFIED) { |
| 187 | // None of the fragments specify any FCM version. Should never happen except |
| 188 | // for inconsistent builds. |
| 189 | if (error) { |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 190 | *error = "No framework compatibility matrix files under " + kSystemVintfDir + |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 191 | " declare FCM version."; |
| 192 | } |
| 193 | return NAME_NOT_FOUND; |
| 194 | } |
| 195 | |
Yifan Hong | e7837b1 | 2018-10-11 10:38:57 -0700 | [diff] [blame] | 196 | auto combined = CompatibilityMatrix::combine(deviceLevel, &matrixFragments, error); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 197 | if (combined == nullptr) { |
| 198 | return BAD_VALUE; |
| 199 | } |
| 200 | *out = std::move(*combined); |
| 201 | return OK; |
| 202 | } |
| 203 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 204 | // Load and combine all of the manifests in a directory |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 205 | status_t VintfObject::addDirectoryManifests(const std::string& directory, HalManifest* manifest, |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 206 | std::string* error) { |
| 207 | std::vector<std::string> fileNames; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 208 | status_t err = getFileSystem()->listFiles(directory, &fileNames, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 209 | // if the directory isn't there, that's okay |
| 210 | if (err == NAME_NOT_FOUND) return OK; |
| 211 | if (err != OK) return err; |
| 212 | |
| 213 | for (const std::string& file : fileNames) { |
| 214 | // Only adds HALs because all other things are added by libvintf |
| 215 | // itself for now. |
| 216 | HalManifest fragmentManifest; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 217 | err = fetchOneHalManifest(directory + file, &fragmentManifest, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 218 | if (err != OK) return err; |
| 219 | |
Yifan Hong | 4c6962d | 2019-01-30 15:50:46 -0800 | [diff] [blame] | 220 | if (!manifest->addAll(&fragmentManifest, error)) { |
| 221 | if (error) { |
| 222 | error->insert(0, "Cannot add manifest fragment " + directory + file + ":"); |
| 223 | } |
| 224 | return UNKNOWN_ERROR; |
| 225 | } |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | return OK; |
| 229 | } |
| 230 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 231 | // Priority for loading vendor manifest: |
Roopesh Nataraja | fe7068d | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 232 | // 1. Vendor manifest + device fragments + ODM manifest (optional) + odm fragments |
| 233 | // 2. Vendor manifest + device fragments |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 234 | // 3. ODM manifest (optional) + odm fragments |
| 235 | // 4. /vendor/manifest.xml (legacy, no fragments) |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 236 | // where: |
Steven Moreland | 30a532c | 2018-11-01 08:46:32 -0700 | [diff] [blame] | 237 | // A + B means unioning <hal> tags from A and B. If B declares an override, then this takes priority |
| 238 | // over A. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 239 | status_t VintfObject::fetchDeviceHalManifest(HalManifest* out, std::string* error) { |
Roopesh Nataraja | fe7068d | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 240 | HalManifest vendorManifest; |
| 241 | status_t vendorStatus = fetchVendorHalManifest(&vendorManifest, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 242 | if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) { |
| 243 | return vendorStatus; |
| 244 | } |
| 245 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 246 | if (vendorStatus == OK) { |
Roopesh Nataraja | fe7068d | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 247 | *out = std::move(vendorManifest); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 248 | status_t fragmentStatus = addDirectoryManifests(kVendorManifestFragmentDir, out, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 249 | if (fragmentStatus != OK) { |
| 250 | return fragmentStatus; |
| 251 | } |
| 252 | } |
| 253 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 254 | HalManifest odmManifest; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 255 | status_t odmStatus = fetchOdmHalManifest(&odmManifest, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 256 | if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) { |
| 257 | return odmStatus; |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 260 | if (vendorStatus == OK) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 261 | if (odmStatus == OK) { |
Yifan Hong | 4c6962d | 2019-01-30 15:50:46 -0800 | [diff] [blame] | 262 | if (!out->addAll(&odmManifest, error)) { |
| 263 | if (error) { |
| 264 | error->insert(0, "Cannot add ODM manifest :"); |
| 265 | } |
| 266 | return UNKNOWN_ERROR; |
| 267 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 268 | } |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 269 | return addDirectoryManifests(kOdmManifestFragmentDir, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 272 | // vendorStatus != OK, "out" is not changed. |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 273 | if (odmStatus == OK) { |
| 274 | *out = std::move(odmManifest); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 275 | return addDirectoryManifests(kOdmManifestFragmentDir, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | // Use legacy /vendor/manifest.xml |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 279 | return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyManifest, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Roopesh Nataraja | fe7068d | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 282 | // Priority: |
| 283 | // 1. if {vendorSku} is defined, /vendor/etc/vintf/manifest_{vendorSku}.xml |
| 284 | // 2. /vendor/etc/vintf/manifest.xml |
| 285 | // where: |
| 286 | // {vendorSku} is the value of ro.boot.product.vendor.sku |
| 287 | status_t VintfObject::fetchVendorHalManifest(HalManifest* out, std::string* error) { |
| 288 | status_t status; |
| 289 | |
| 290 | std::string vendorSku; |
| 291 | vendorSku = getPropertyFetcher()->getProperty("ro.boot.product.vendor.sku", ""); |
| 292 | |
| 293 | if (!vendorSku.empty()) { |
| 294 | status = |
| 295 | fetchOneHalManifest(kVendorVintfDir + "manifest_" + vendorSku + ".xml", out, error); |
| 296 | if (status == OK || status != NAME_NOT_FOUND) { |
| 297 | return status; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | status = fetchOneHalManifest(kVendorManifest, out, error); |
| 302 | if (status == OK || status != NAME_NOT_FOUND) { |
| 303 | return status; |
| 304 | } |
| 305 | |
| 306 | return NAME_NOT_FOUND; |
| 307 | } |
| 308 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 309 | // "out" is written to iff return status is OK. |
| 310 | // Priority: |
| 311 | // 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml |
| 312 | // 2. /odm/etc/vintf/manifest.xml |
| 313 | // 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml |
| 314 | // 4. /odm/etc/manifest.xml |
| 315 | // where: |
| 316 | // {sku} is the value of ro.boot.product.hardware.sku |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 317 | status_t VintfObject::fetchOdmHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 318 | status_t status; |
| 319 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 320 | std::string productModel; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 321 | productModel = getPropertyFetcher()->getProperty("ro.boot.product.hardware.sku", ""); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 322 | |
| 323 | if (!productModel.empty()) { |
| 324 | status = |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 325 | fetchOneHalManifest(kOdmVintfDir + "manifest_" + productModel + ".xml", out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 326 | if (status == OK || status != NAME_NOT_FOUND) { |
| 327 | return status; |
| 328 | } |
| 329 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 330 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 331 | status = fetchOneHalManifest(kOdmManifest, out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 332 | if (status == OK || status != NAME_NOT_FOUND) { |
| 333 | return status; |
| 334 | } |
| 335 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 336 | if (!productModel.empty()) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 337 | status = fetchOneHalManifest(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", out, |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 338 | error); |
| 339 | if (status == OK || status != NAME_NOT_FOUND) { |
| 340 | return status; |
| 341 | } |
| 342 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 343 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 344 | status = fetchOneHalManifest(kOdmLegacyManifest, out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 345 | if (status == OK || status != NAME_NOT_FOUND) { |
| 346 | return status; |
| 347 | } |
| 348 | |
| 349 | return NAME_NOT_FOUND; |
| 350 | } |
| 351 | |
| 352 | // Fetch one manifest.xml file. "out" is written to iff return status is OK. |
| 353 | // Returns NAME_NOT_FOUND if file is missing. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 354 | status_t VintfObject::fetchOneHalManifest(const std::string& path, HalManifest* out, |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 355 | std::string* error) { |
| 356 | HalManifest ret; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 357 | status_t status = ret.fetchAllInformation(getFileSystem().get(), path, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 358 | if (status == OK) { |
| 359 | *out = std::move(ret); |
| 360 | } |
| 361 | return status; |
| 362 | } |
| 363 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 364 | status_t VintfObject::fetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) { |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 365 | CompatibilityMatrix etcMatrix; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 366 | if (etcMatrix.fetchAllInformation(getFileSystem().get(), kVendorMatrix, error) == OK) { |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 367 | *out = std::move(etcMatrix); |
| 368 | return OK; |
| 369 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 370 | return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyMatrix, error); |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 373 | // Priority: |
| 374 | // 1. /system/etc/vintf/manifest.xml |
| 375 | // + /system/etc/vintf/manifest/*.xml if they exist |
| 376 | // + /product/etc/vintf/manifest.xml if it exists |
| 377 | // + /product/etc/vintf/manifest/*.xml if they exist |
| 378 | // 2. (deprecated) /system/manifest.xml |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 379 | status_t VintfObject::fetchFrameworkHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 380 | auto systemEtcStatus = fetchOneHalManifest(kSystemManifest, out, error); |
| 381 | if (systemEtcStatus == OK) { |
| 382 | auto dirStatus = addDirectoryManifests(kSystemManifestFragmentDir, out, error); |
| 383 | if (dirStatus != OK) { |
| 384 | return dirStatus; |
| 385 | } |
| 386 | |
| 387 | HalManifest productManifest; |
| 388 | auto productStatus = fetchOneHalManifest(kProductManifest, &productManifest, error); |
| 389 | if (productStatus != OK && productStatus != NAME_NOT_FOUND) { |
| 390 | return productStatus; |
| 391 | } |
| 392 | if (productStatus == OK) { |
| 393 | if (!out->addAll(&productManifest, error)) { |
| 394 | if (error) { |
| 395 | error->insert(0, "Cannot add " + kProductManifest + ":"); |
| 396 | } |
| 397 | return UNKNOWN_ERROR; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return addDirectoryManifests(kProductManifestFragmentDir, out, error); |
| 402 | } else { |
| 403 | LOG(WARNING) << "Cannot fetch " << kSystemManifest << ": " |
| 404 | << (error ? *error : strerror(-systemEtcStatus)); |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 405 | } |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 406 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 407 | return out->fetchAllInformation(getFileSystem().get(), kSystemLegacyManifest, error); |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Yifan Hong | 9f8f656 | 2018-11-06 16:26:20 -0800 | [diff] [blame] | 410 | static void appendLine(std::string* error, const std::string& message) { |
| 411 | if (error != nullptr) { |
| 412 | if (!error->empty()) *error += "\n"; |
| 413 | *error += message; |
| 414 | } |
| 415 | } |
| 416 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 417 | status_t VintfObject::getOneMatrix(const std::string& path, Named<CompatibilityMatrix>* out, |
| 418 | std::string* error) { |
| 419 | std::string content; |
| 420 | status_t status = getFileSystem()->fetch(path, &content, error); |
| 421 | if (status != OK) { |
| 422 | return status; |
| 423 | } |
| 424 | if (!gCompatibilityMatrixConverter(&out->object, content, error)) { |
| 425 | if (error) { |
| 426 | error->insert(0, "Cannot parse " + path + ": "); |
| 427 | } |
| 428 | return BAD_VALUE; |
| 429 | } |
| 430 | out->name = path; |
| 431 | return OK; |
| 432 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 433 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 434 | status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<Named<CompatibilityMatrix>>* results, |
| 435 | std::string* error) { |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 436 | std::vector<std::string> dirs = { |
| 437 | kSystemVintfDir, |
Yifan Hong | a0968e8 | 2019-12-19 14:08:13 -0800 | [diff] [blame] | 438 | kSystemExtVintfDir, |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 439 | kProductVintfDir, |
| 440 | }; |
| 441 | for (const auto& dir : dirs) { |
| 442 | std::vector<std::string> fileNames; |
| 443 | status_t listStatus = getFileSystem()->listFiles(dir, &fileNames, error); |
| 444 | if (listStatus == NAME_NOT_FOUND) { |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 445 | continue; |
| 446 | } |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 447 | if (listStatus != OK) { |
| 448 | return listStatus; |
| 449 | } |
| 450 | for (const std::string& fileName : fileNames) { |
| 451 | std::string path = dir + fileName; |
| 452 | Named<CompatibilityMatrix> namedMatrix; |
| 453 | std::string matrixError; |
| 454 | status_t matrixStatus = getOneMatrix(path, &namedMatrix, &matrixError); |
| 455 | if (matrixStatus != OK) { |
| 456 | // Manifests and matrices share the same dir. Client may not have enough |
| 457 | // permissions to read system manifests, or may not be able to parse it. |
| 458 | auto logLevel = matrixStatus == BAD_VALUE ? base::DEBUG : base::ERROR; |
| 459 | LOG(logLevel) << "Framework Matrix: Ignore file " << path << ": " << matrixError; |
| 460 | continue; |
| 461 | } |
| 462 | results->emplace_back(std::move(namedMatrix)); |
| 463 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 464 | |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 465 | if (dir == kSystemVintfDir && results->empty()) { |
| 466 | if (error) { |
| 467 | *error = "No framework matrices under " + dir + " can be fetched or parsed.\n"; |
| 468 | } |
| 469 | return NAME_NOT_FOUND; |
| 470 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 473 | if (results->empty()) { |
| 474 | if (error) { |
| 475 | *error = |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 476 | "No framework matrices can be fetched or parsed. " |
| 477 | "The following directories are searched:\n " + |
| 478 | android::base::Join(dirs, "\n "); |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 479 | } |
| 480 | return NAME_NOT_FOUND; |
| 481 | } |
| 482 | return OK; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 483 | } |
| 484 | |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 485 | std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache, |
| 486 | RuntimeInfo::FetchFlags flags) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 487 | return GetInstance()->getRuntimeInfo(skipCache, flags); |
| 488 | } |
| 489 | std::shared_ptr<const RuntimeInfo> VintfObject::getRuntimeInfo(bool skipCache, |
| 490 | RuntimeInfo::FetchFlags flags) { |
| 491 | std::unique_lock<std::mutex> _lock(mDeviceRuntimeInfo.mutex); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 492 | |
| 493 | if (!skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 494 | flags &= (~mDeviceRuntimeInfo.fetchedFlags); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 497 | if (mDeviceRuntimeInfo.object == nullptr) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 498 | mDeviceRuntimeInfo.object = getRuntimeInfoFactory()->make_shared(); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Yifan Hong | f324798 | 2019-12-12 12:11:36 -0800 | [diff] [blame] | 501 | // Fetch kernel FCM version from device HAL manifest and store it in RuntimeInfo too. |
| 502 | if ((flags & RuntimeInfo::FetchFlag::KERNEL_FCM) != 0) { |
| 503 | auto manifest = getDeviceHalManifest(); |
| 504 | if (!manifest) { |
| 505 | mDeviceRuntimeInfo.fetchedFlags &= ~RuntimeInfo::FetchFlag::KERNEL_FCM; |
| 506 | return nullptr; |
| 507 | } |
| 508 | Level level = Level::UNSPECIFIED; |
| 509 | if (manifest->kernel().has_value()) { |
| 510 | level = manifest->kernel()->level(); |
| 511 | } |
| 512 | mDeviceRuntimeInfo.object->setKernelLevel(level); |
| 513 | flags &= ~RuntimeInfo::FetchFlag::KERNEL_FCM; |
| 514 | } |
| 515 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 516 | status_t status = mDeviceRuntimeInfo.object->fetchAllInformation(flags); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 517 | if (status != OK) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 518 | mDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched" |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 519 | return nullptr; |
| 520 | } |
| 521 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 522 | mDeviceRuntimeInfo.fetchedFlags |= flags; |
| 523 | return mDeviceRuntimeInfo.object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 526 | int32_t VintfObject::checkCompatibility(std::string* error, CheckFlags::Type flags) { |
| 527 | status_t status = OK; |
| 528 | // null checks for files and runtime info |
| 529 | if (getFrameworkHalManifest() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 530 | appendLine(error, "No framework manifest file from device or from update package"); |
| 531 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 532 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 533 | if (getDeviceHalManifest() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 534 | appendLine(error, "No device manifest file from device or from update package"); |
| 535 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 536 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 537 | if (getFrameworkCompatibilityMatrix() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 538 | appendLine(error, "No framework matrix file from device or from update package"); |
| 539 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 540 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 541 | if (getDeviceCompatibilityMatrix() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 542 | appendLine(error, "No device matrix file from device or from update package"); |
| 543 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 544 | } |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 545 | |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 546 | if (flags.isRuntimeInfoEnabled()) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 547 | if (getRuntimeInfo() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 548 | appendLine(error, "No runtime info from device"); |
| 549 | status = NO_INIT; |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 550 | } |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 551 | } |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 552 | if (status != OK) return status; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 553 | |
| 554 | // compatiblity check. |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 555 | if (!getDeviceHalManifest()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error)) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 556 | if (error) { |
| 557 | error->insert(0, |
| 558 | "Device manifest and framework compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 559 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 560 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 561 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 562 | if (!getFrameworkHalManifest()->checkCompatibility(*getDeviceCompatibilityMatrix(), error)) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 563 | if (error) { |
| 564 | error->insert(0, |
| 565 | "Framework manifest and device compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 566 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 567 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 568 | } |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 569 | |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 570 | if (flags.isRuntimeInfoEnabled()) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 571 | if (!getRuntimeInfo()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error, |
Yifan Hong | 85e589e | 2019-12-18 13:12:29 -0800 | [diff] [blame] | 572 | flags)) { |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 573 | if (error) { |
| 574 | error->insert(0, |
| 575 | "Runtime info and framework compatibility matrix are incompatible: "); |
| 576 | } |
| 577 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
| 581 | return COMPATIBLE; |
| 582 | } |
| 583 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 584 | namespace details { |
| 585 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 586 | const std::string kSystemVintfDir = "/system/etc/vintf/"; |
Yifan Hong | ccbea05 | 2018-01-18 18:48:46 -0800 | [diff] [blame] | 587 | const std::string kVendorVintfDir = "/vendor/etc/vintf/"; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 588 | const std::string kOdmVintfDir = "/odm/etc/vintf/"; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 589 | const std::string kProductVintfDir = "/product/etc/vintf/"; |
Yifan Hong | 5bbc4ae | 2020-01-09 14:30:27 -0800 | [diff] [blame] | 590 | const std::string kSystemExtVintfDir = "/system_ext/etc/vintf/"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 591 | |
| 592 | const std::string kVendorManifest = kVendorVintfDir + "manifest.xml"; |
Yifan Hong | a5ddddf | 2018-01-18 18:50:13 -0800 | [diff] [blame] | 593 | const std::string kSystemManifest = kSystemVintfDir + "manifest.xml"; |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 594 | const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml"; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 595 | const std::string kOdmManifest = kOdmVintfDir + "manifest.xml"; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 596 | const std::string kProductMatrix = kProductVintfDir + "compatibility_matrix.xml"; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 597 | const std::string kProductManifest = kProductVintfDir + "manifest.xml"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 598 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 599 | const std::string kVendorManifestFragmentDir = kVendorVintfDir + "manifest/"; |
| 600 | const std::string kSystemManifestFragmentDir = kSystemVintfDir + "manifest/"; |
| 601 | const std::string kOdmManifestFragmentDir = kOdmVintfDir + "manifest/"; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 602 | const std::string kProductManifestFragmentDir = kProductVintfDir + "manifest/"; |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 603 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 604 | const std::string kVendorLegacyManifest = "/vendor/manifest.xml"; |
| 605 | const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml"; |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 606 | const std::string kSystemLegacyManifest = "/system/manifest.xml"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 607 | const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml"; |
| 608 | const std::string kOdmLegacyVintfDir = "/odm/etc/"; |
| 609 | const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml"; |
| 610 | |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 611 | std::vector<std::string> dumpFileList() { |
| 612 | return { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 613 | // clang-format off |
| 614 | kSystemVintfDir, |
| 615 | kVendorVintfDir, |
| 616 | kOdmVintfDir, |
| 617 | kProductVintfDir, |
Yifan Hong | a0968e8 | 2019-12-19 14:08:13 -0800 | [diff] [blame] | 618 | kSystemExtVintfDir, |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 619 | kOdmLegacyVintfDir, |
| 620 | kVendorLegacyManifest, |
| 621 | kVendorLegacyMatrix, |
| 622 | kSystemLegacyManifest, |
| 623 | kSystemLegacyMatrix, |
| 624 | // clang-format on |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 625 | }; |
| 626 | } |
| 627 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 628 | } // namespace details |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 629 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 630 | bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal, |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 631 | const CompatibilityMatrix& targetMatrix, |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 632 | const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 633 | bool isDeprecated = false; |
| 634 | oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 635 | if (IsInstanceDeprecated(oldMatrixInstance, targetMatrix, listInstances, error)) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 636 | isDeprecated = true; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 637 | } |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 638 | return !isDeprecated; // continue if no deprecated instance is found. |
| 639 | }); |
| 640 | return isDeprecated; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 641 | } |
| 642 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 643 | // Let oldMatrixInstance = package@x.y-w::interface with instancePattern. |
| 644 | // If any "servedInstance" in listInstances(package@x.y::interface) matches instancePattern, return |
| 645 | // true iff: |
| 646 | // 1. package@x.?::interface/servedInstance is not in targetMatrix; OR |
| 647 | // 2. package@x.z::interface/servedInstance is in targetMatrix but |
| 648 | // servedInstance is not in listInstances(package@x.z::interface) |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 649 | bool VintfObject::IsInstanceDeprecated(const MatrixInstance& oldMatrixInstance, |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 650 | const CompatibilityMatrix& targetMatrix, |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 651 | const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 652 | const std::string& package = oldMatrixInstance.package(); |
| 653 | const Version& version = oldMatrixInstance.versionRange().minVer(); |
| 654 | const std::string& interface = oldMatrixInstance.interface(); |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 655 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 656 | std::vector<std::string> instanceHint; |
| 657 | if (!oldMatrixInstance.isRegex()) { |
| 658 | instanceHint.push_back(oldMatrixInstance.exactInstance()); |
| 659 | } |
| 660 | |
| 661 | auto list = listInstances(package, version, interface, instanceHint); |
| 662 | for (const auto& pair : list) { |
| 663 | const std::string& servedInstance = pair.first; |
| 664 | Version servedVersion = pair.second; |
| 665 | if (!oldMatrixInstance.matchInstance(servedInstance)) { |
| 666 | continue; |
| 667 | } |
| 668 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 669 | // Find any package@x.? in target matrix, and check if instance is in target matrix. |
Yifan Hong | 217f47e | 2018-03-15 12:34:05 -0700 | [diff] [blame] | 670 | bool foundInstance = false; |
| 671 | Version targetMatrixMinVer; |
Yifan Hong | 0b1916f | 2019-09-10 19:04:52 -0700 | [diff] [blame] | 672 | targetMatrix.forEachHidlInstanceOfPackage(package, [&](const auto& targetMatrixInstance) { |
Yifan Hong | 217f47e | 2018-03-15 12:34:05 -0700 | [diff] [blame] | 673 | if (targetMatrixInstance.versionRange().majorVer == version.majorVer && |
| 674 | targetMatrixInstance.interface() == interface && |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 675 | targetMatrixInstance.matchInstance(servedInstance)) { |
Yifan Hong | 217f47e | 2018-03-15 12:34:05 -0700 | [diff] [blame] | 676 | targetMatrixMinVer = targetMatrixInstance.versionRange().minVer(); |
| 677 | foundInstance = true; |
| 678 | } |
| 679 | return !foundInstance; // continue if not found |
| 680 | }); |
| 681 | if (!foundInstance) { |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 682 | if (error) { |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 683 | *error = toFQNameString(package, servedVersion, interface, servedInstance) + |
Steven Moreland | a1b984c | 2018-03-09 13:09:15 -0800 | [diff] [blame] | 684 | " is deprecated in compatibility matrix at FCM Version " + |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 685 | to_string(targetMatrix.level()) + "; it should not be served."; |
| 686 | } |
| 687 | return true; |
| 688 | } |
| 689 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 690 | // Assuming that targetMatrix requires @x.u-v, require that at least @x.u is served. |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 691 | bool targetVersionServed = false; |
| 692 | for (const auto& newPair : |
| 693 | listInstances(package, targetMatrixMinVer, interface, instanceHint)) { |
| 694 | if (newPair.first == servedInstance) { |
| 695 | targetVersionServed = true; |
| 696 | break; |
| 697 | } |
| 698 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 699 | |
| 700 | if (!targetVersionServed) { |
Yifan Hong | 9f8f656 | 2018-11-06 16:26:20 -0800 | [diff] [blame] | 701 | appendLine(error, toFQNameString(package, servedVersion, interface, servedInstance) + |
| 702 | " is deprecated; requires at least " + |
| 703 | to_string(targetMatrixMinVer)); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 704 | return true; |
| 705 | } |
| 706 | } |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 707 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 708 | return false; |
| 709 | } |
| 710 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 711 | int32_t VintfObject::CheckDeprecation(const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 712 | return GetInstance()->checkDeprecation(listInstances, error); |
| 713 | } |
| 714 | int32_t VintfObject::checkDeprecation(const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 715 | std::vector<Named<CompatibilityMatrix>> matrixFragments; |
| 716 | auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error); |
| 717 | if (matrixFragmentsStatus != OK) { |
| 718 | return matrixFragmentsStatus; |
| 719 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 720 | if (matrixFragments.empty()) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 721 | if (error && error->empty()) { |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 722 | *error = "Cannot get framework matrix for each FCM version for unknown error."; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 723 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 724 | return NAME_NOT_FOUND; |
| 725 | } |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 726 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 727 | if (deviceManifest == nullptr) { |
| 728 | if (error) *error = "No device manifest."; |
| 729 | return NAME_NOT_FOUND; |
| 730 | } |
| 731 | Level deviceLevel = deviceManifest->level(); |
| 732 | if (deviceLevel == Level::UNSPECIFIED) { |
| 733 | if (error) *error = "Device manifest does not specify Shipping FCM Version."; |
| 734 | return BAD_VALUE; |
| 735 | } |
| 736 | |
| 737 | const CompatibilityMatrix* targetMatrix = nullptr; |
| 738 | for (const auto& namedMatrix : matrixFragments) { |
| 739 | if (namedMatrix.object.level() == deviceLevel) { |
| 740 | targetMatrix = &namedMatrix.object; |
| 741 | } |
| 742 | } |
| 743 | if (targetMatrix == nullptr) { |
| 744 | if (error) |
| 745 | *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + "."; |
| 746 | return NAME_NOT_FOUND; |
| 747 | } |
| 748 | |
| 749 | bool hasDeprecatedHals = false; |
| 750 | for (const auto& namedMatrix : matrixFragments) { |
| 751 | if (namedMatrix.object.level() == Level::UNSPECIFIED) continue; |
| 752 | if (namedMatrix.object.level() >= deviceLevel) continue; |
| 753 | |
| 754 | const auto& oldMatrix = namedMatrix.object; |
| 755 | for (const MatrixHal& hal : oldMatrix.getHals()) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 756 | hasDeprecatedHals |= IsHalDeprecated(hal, *targetMatrix, listInstances, error); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | return hasDeprecatedHals ? DEPRECATED : NO_DEPRECATED_HALS; |
| 761 | } |
| 762 | |
| 763 | int32_t VintfObject::CheckDeprecation(std::string* error) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 764 | return GetInstance()->checkDeprecation(error); |
| 765 | } |
| 766 | int32_t VintfObject::checkDeprecation(std::string* error) { |
Yifan Hong | 2a90ffe | 2018-03-05 17:45:34 -0800 | [diff] [blame] | 767 | using namespace std::placeholders; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 768 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 769 | ListInstances inManifest = |
| 770 | [&deviceManifest](const std::string& package, Version version, const std::string& interface, |
| 771 | const std::vector<std::string>& /* hintInstances */) { |
| 772 | std::vector<std::pair<std::string, Version>> ret; |
| 773 | deviceManifest->forEachInstanceOfInterface( |
Yifan Hong | ac62148 | 2019-09-10 19:27:20 -0700 | [diff] [blame] | 774 | HalFormat::HIDL, package, version, interface, |
| 775 | [&ret](const ManifestInstance& manifestInstance) { |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 776 | ret.push_back( |
| 777 | std::make_pair(manifestInstance.instance(), manifestInstance.version())); |
| 778 | return true; |
| 779 | }); |
| 780 | return ret; |
| 781 | }; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 782 | return checkDeprecation(inManifest, error); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 783 | } |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 784 | |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 785 | Level VintfObject::getKernelLevel(std::string* error) { |
| 786 | auto manifest = getDeviceHalManifest(); |
| 787 | if (!manifest) { |
| 788 | if (error) *error = "Cannot retrieve device manifest."; |
| 789 | return Level::UNSPECIFIED; |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 790 | } |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 791 | if (manifest->kernel().has_value() && manifest->kernel()->level() != Level::UNSPECIFIED) { |
| 792 | return manifest->kernel()->level(); |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 793 | } |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 794 | if (error) *error = "Device manifest does not specify kernel FCM version."; |
| 795 | return Level::UNSPECIFIED; |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 798 | const std::unique_ptr<FileSystem>& VintfObject::getFileSystem() { |
| 799 | return mFileSystem; |
| 800 | } |
| 801 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 802 | const std::unique_ptr<PropertyFetcher>& VintfObject::getPropertyFetcher() { |
| 803 | return mPropertyFetcher; |
| 804 | } |
| 805 | |
Yifan Hong | d038b2b | 2018-11-27 13:57:56 -0800 | [diff] [blame] | 806 | const std::unique_ptr<ObjectFactory<RuntimeInfo>>& VintfObject::getRuntimeInfoFactory() { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 807 | return mRuntimeInfoFactory; |
Yifan Hong | 10d8622 | 2018-04-06 15:41:05 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Yifan Hong | 6e32a5f | 2020-03-12 16:06:27 -0700 | [diff] [blame] | 810 | android::base::Result<bool> VintfObject::hasFrameworkCompatibilityMatrixExtensions() { |
| 811 | std::vector<Named<CompatibilityMatrix>> matrixFragments; |
| 812 | std::string error; |
| 813 | status_t status = getAllFrameworkMatrixLevels(&matrixFragments, &error); |
| 814 | if (status != OK) { |
| 815 | return android::base::Error(-status) |
| 816 | << "Cannot get all framework matrix fragments: " << error; |
| 817 | } |
| 818 | for (const auto& namedMatrix : matrixFragments) { |
| 819 | // Returns true if product matrix exists. |
| 820 | if (android::base::StartsWith(namedMatrix.name, kProductVintfDir)) { |
| 821 | return true; |
| 822 | } |
Yifan Hong | 238c6dc | 2020-03-12 22:56:16 -0700 | [diff] [blame] | 823 | // Returns true if system_ext matrix exists. |
| 824 | if (android::base::StartsWith(namedMatrix.name, kSystemExtVintfDir)) { |
| 825 | return true; |
| 826 | } |
Yifan Hong | 6e32a5f | 2020-03-12 16:06:27 -0700 | [diff] [blame] | 827 | // Returns true if device system matrix exists. |
| 828 | if (android::base::StartsWith(namedMatrix.name, kSystemVintfDir) && |
| 829 | namedMatrix.object.level() == Level::UNSPECIFIED && |
| 830 | !namedMatrix.object.getHals().empty()) { |
| 831 | return true; |
| 832 | } |
| 833 | } |
| 834 | return false; |
| 835 | } |
| 836 | |
Yifan Hong | ff1a25c | 2020-03-17 14:09:10 -0700 | [diff] [blame^] | 837 | android::base::Result<void> VintfObject::checkUnusedHals( |
| 838 | const std::vector<HidlInterfaceMetadata>& hidlMetadata) { |
Yifan Hong | 6e32a5f | 2020-03-12 16:06:27 -0700 | [diff] [blame] | 839 | auto matrix = getFrameworkCompatibilityMatrix(); |
| 840 | if (matrix == nullptr) { |
| 841 | return android::base::Error(-NAME_NOT_FOUND) << "Missing framework matrix."; |
| 842 | } |
| 843 | auto manifest = getDeviceHalManifest(); |
| 844 | if (manifest == nullptr) { |
| 845 | return android::base::Error(-NAME_NOT_FOUND) << "Missing device manifest."; |
| 846 | } |
Yifan Hong | ff1a25c | 2020-03-17 14:09:10 -0700 | [diff] [blame^] | 847 | auto unused = manifest->checkUnusedHals(*matrix, hidlMetadata); |
Yifan Hong | 6e32a5f | 2020-03-12 16:06:27 -0700 | [diff] [blame] | 848 | if (!unused.empty()) { |
| 849 | return android::base::Error() |
| 850 | << "The following instances are in the device manifest but " |
| 851 | << "not specified in framework compatibility matrix: \n" |
| 852 | << " " << android::base::Join(unused, "\n ") << "\n" |
| 853 | << "Suggested fix:\n" |
| 854 | << "1. Check for any typos in device manifest or framework compatibility " |
| 855 | << "matrices with FCM version >= " << matrix->level() << ".\n" |
| 856 | << "2. Add them to any framework compatibility matrix with FCM " |
| 857 | << "version >= " << matrix->level() << " where applicable.\n" |
| 858 | << "3. Add them to DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE " |
| 859 | << "or DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE."; |
| 860 | } |
| 861 | return {}; |
| 862 | } |
| 863 | |
Yifan Hong | 78f5b57 | 2018-11-27 14:05:03 -0800 | [diff] [blame] | 864 | // make_unique does not work because VintfObject constructor is private. |
| 865 | VintfObject::Builder::Builder() : mObject(std::unique_ptr<VintfObject>(new VintfObject())) {} |
| 866 | |
| 867 | VintfObject::Builder& VintfObject::Builder::setFileSystem(std::unique_ptr<FileSystem>&& e) { |
| 868 | mObject->mFileSystem = std::move(e); |
| 869 | return *this; |
| 870 | } |
| 871 | |
| 872 | VintfObject::Builder& VintfObject::Builder::setRuntimeInfoFactory( |
| 873 | std::unique_ptr<ObjectFactory<RuntimeInfo>>&& e) { |
| 874 | mObject->mRuntimeInfoFactory = std::move(e); |
| 875 | return *this; |
| 876 | } |
| 877 | |
| 878 | VintfObject::Builder& VintfObject::Builder::setPropertyFetcher( |
| 879 | std::unique_ptr<PropertyFetcher>&& e) { |
| 880 | mObject->mPropertyFetcher = std::move(e); |
| 881 | return *this; |
| 882 | } |
| 883 | |
| 884 | std::unique_ptr<VintfObject> VintfObject::Builder::build() { |
| 885 | if (!mObject->mFileSystem) mObject->mFileSystem = createDefaultFileSystem(); |
| 886 | if (!mObject->mRuntimeInfoFactory) |
| 887 | mObject->mRuntimeInfoFactory = std::make_unique<ObjectFactory<RuntimeInfo>>(); |
| 888 | if (!mObject->mPropertyFetcher) mObject->mPropertyFetcher = createDefaultPropertyFetcher(); |
| 889 | return std::move(mObject); |
| 890 | } |
| 891 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 892 | } // namespace vintf |
| 893 | } // namespace android |