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