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