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 | 03ea428 | 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 | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 26 | #include <aidl/metadata.h> |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 27 | #include <android-base/logging.h> |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 28 | #include <android-base/result.h> |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 29 | #include <android-base/strings.h> |
Yifan Hong | d7924ff | 2020-03-17 14:09:10 -0700 | [diff] [blame] | 30 | #include <hidl/metadata.h> |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 31 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 32 | #include "CompatibilityMatrix.h" |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 33 | #include "constants-private.h" |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 34 | #include "parse_string.h" |
| 35 | #include "parse_xml.h" |
| 36 | #include "utils.h" |
| 37 | |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 38 | using std::placeholders::_1; |
| 39 | using std::placeholders::_2; |
Yifan Hong | c7a9a29 | 2021-02-03 17:27:58 -0800 | [diff] [blame] | 40 | using std::string_literals::operator""s; |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 41 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 42 | namespace android { |
| 43 | namespace vintf { |
| 44 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 45 | using namespace details; |
| 46 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 47 | #ifdef LIBVINTF_TARGET |
| 48 | static constexpr bool kIsTarget = true; |
| 49 | #else |
| 50 | static constexpr bool kIsTarget = false; |
| 51 | #endif |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 52 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 53 | template <typename T, typename F> |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 54 | static std::shared_ptr<const T> Get(const char* id, LockedSharedPtr<T>* ptr, |
Steven Moreland | ec0721d | 2020-04-30 15:48:35 -0700 | [diff] [blame] | 55 | const F& fetchAllInformation) { |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 56 | std::unique_lock<std::mutex> _lock(ptr->mutex); |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 57 | if (!ptr->fetchedOnce) { |
Steven Moreland | ec0721d | 2020-04-30 15:48:35 -0700 | [diff] [blame] | 58 | LOG(INFO) << id << ": Reading VINTF information."; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 59 | ptr->object = std::make_unique<T>(); |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 60 | std::string error; |
Steven Moreland | 609d7ff | 2020-03-27 15:48:40 -0700 | [diff] [blame] | 61 | status_t status = fetchAllInformation(ptr->object.get(), &error); |
Steven Moreland | ec0721d | 2020-04-30 15:48:35 -0700 | [diff] [blame] | 62 | if (status == OK) { |
Steven Moreland | 2cc413f | 2020-04-30 16:42:56 -0700 | [diff] [blame] | 63 | ptr->fetchedOnce = true; |
Steven Moreland | ec0721d | 2020-04-30 15:48:35 -0700 | [diff] [blame] | 64 | LOG(INFO) << id << ": Successfully processed VINTF information"; |
| 65 | } else { |
| 66 | // Doubled because a malformed error std::string might cause us to |
| 67 | // lose the status. |
| 68 | LOG(ERROR) << id << ": status from fetching VINTF information: " << status; |
| 69 | LOG(ERROR) << id << ": " << status << " VINTF parse error: " << error; |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 70 | ptr->object = nullptr; // frees the old object |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 71 | } |
| 72 | } |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 73 | return ptr->object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 76 | static std::unique_ptr<FileSystem> createDefaultFileSystem() { |
| 77 | std::unique_ptr<FileSystem> fileSystem; |
| 78 | if (kIsTarget) { |
| 79 | fileSystem = std::make_unique<details::FileSystemImpl>(); |
| 80 | } else { |
| 81 | fileSystem = std::make_unique<details::FileSystemNoOp>(); |
| 82 | } |
| 83 | return fileSystem; |
| 84 | } |
| 85 | |
| 86 | static std::unique_ptr<PropertyFetcher> createDefaultPropertyFetcher() { |
| 87 | std::unique_ptr<PropertyFetcher> propertyFetcher; |
| 88 | if (kIsTarget) { |
| 89 | propertyFetcher = std::make_unique<details::PropertyFetcherImpl>(); |
| 90 | } else { |
| 91 | propertyFetcher = std::make_unique<details::PropertyFetcherNoOp>(); |
| 92 | } |
| 93 | return propertyFetcher; |
| 94 | } |
| 95 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 96 | std::shared_ptr<VintfObject> VintfObject::GetInstance() { |
Steven Moreland | c16ff2b | 2020-02-26 17:03:37 -0800 | [diff] [blame] | 97 | static details::LockedSharedPtr<VintfObject> sInstance{}; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 98 | std::unique_lock<std::mutex> lock(sInstance.mutex); |
| 99 | if (sInstance.object == nullptr) { |
Yifan Hong | 78f5b57 | 2018-11-27 14:05:03 -0800 | [diff] [blame] | 100 | sInstance.object = std::shared_ptr<VintfObject>(VintfObject::Builder().build().release()); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 101 | } |
| 102 | return sInstance.object; |
| 103 | } |
| 104 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 105 | std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest() { |
| 106 | return GetInstance()->getDeviceHalManifest(); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 109 | std::shared_ptr<const HalManifest> VintfObject::getDeviceHalManifest() { |
| 110 | return Get(__func__, &mDeviceManifest, |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 111 | std::bind(&VintfObject::fetchDeviceHalManifest, this, _1, _2)); |
| 112 | } |
| 113 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 114 | std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest() { |
| 115 | return GetInstance()->getFrameworkHalManifest(); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 118 | std::shared_ptr<const HalManifest> VintfObject::getFrameworkHalManifest() { |
| 119 | return Get(__func__, &mFrameworkManifest, |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 120 | std::bind(&VintfObject::fetchFrameworkHalManifest, this, _1, _2)); |
| 121 | } |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 122 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 123 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix() { |
| 124 | return GetInstance()->getDeviceCompatibilityMatrix(); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 127 | std::shared_ptr<const CompatibilityMatrix> VintfObject::getDeviceCompatibilityMatrix() { |
| 128 | return Get(__func__, &mDeviceMatrix, std::bind(&VintfObject::fetchDeviceMatrix, this, _1, _2)); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 131 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix() { |
| 132 | return GetInstance()->getFrameworkCompatibilityMatrix(); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 133 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 134 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 135 | std::shared_ptr<const CompatibilityMatrix> VintfObject::getFrameworkCompatibilityMatrix() { |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 136 | // To avoid deadlock, get device manifest before any locks. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 137 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 138 | |
Yifan Hong | 507815b | 2021-05-21 16:48:37 -0700 | [diff] [blame] | 139 | std::string error; |
| 140 | auto kernelLevel = getKernelLevel(&error); |
| 141 | if (kernelLevel == Level::UNSPECIFIED) { |
| 142 | LOG(WARNING) << "getKernelLevel: " << error; |
| 143 | } |
| 144 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 145 | std::unique_lock<std::mutex> _lock(mFrameworkCompatibilityMatrixMutex); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 146 | |
Yifan Hong | 507815b | 2021-05-21 16:48:37 -0700 | [diff] [blame] | 147 | auto combined = Get(__func__, &mCombinedFrameworkMatrix, |
| 148 | std::bind(&VintfObject::getCombinedFrameworkMatrix, this, deviceManifest, |
| 149 | kernelLevel, _1, _2)); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 150 | if (combined != nullptr) { |
| 151 | return combined; |
| 152 | } |
| 153 | |
Yifan Hong | 44f611c | 2020-07-21 11:57:57 -0700 | [diff] [blame] | 154 | return Get(__func__, &mFrameworkMatrix, |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 155 | std::bind(&CompatibilityMatrix::fetchAllInformation, _1, getFileSystem().get(), |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 156 | kSystemLegacyMatrix, _2)); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 159 | status_t VintfObject::getCombinedFrameworkMatrix( |
Yifan Hong | 507815b | 2021-05-21 16:48:37 -0700 | [diff] [blame] | 160 | const std::shared_ptr<const HalManifest>& deviceManifest, Level kernelLevel, |
| 161 | CompatibilityMatrix* out, std::string* error) { |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 162 | std::vector<CompatibilityMatrix> matrixFragments; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 163 | auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error); |
| 164 | if (matrixFragmentsStatus != OK) { |
| 165 | return matrixFragmentsStatus; |
| 166 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 167 | if (matrixFragments.empty()) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 168 | if (error && error->empty()) { |
| 169 | *error = "Cannot get framework matrix for each FCM version for unknown error."; |
| 170 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 171 | return NAME_NOT_FOUND; |
| 172 | } |
| 173 | |
| 174 | Level deviceLevel = Level::UNSPECIFIED; |
| 175 | |
| 176 | if (deviceManifest != nullptr) { |
| 177 | deviceLevel = deviceManifest->level(); |
| 178 | } |
| 179 | |
| 180 | // TODO(b/70628538): Do not infer from Shipping API level. |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 181 | if (deviceLevel == Level::UNSPECIFIED) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 182 | auto shippingApi = getPropertyFetcher()->getUintProperty("ro.product.first_api_level", 0u); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 183 | if (shippingApi != 0u) { |
| 184 | deviceLevel = details::convertFromApiLevel(shippingApi); |
| 185 | } |
| 186 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 187 | |
| 188 | if (deviceLevel == Level::UNSPECIFIED) { |
| 189 | // Cannot infer FCM version. Combine all matrices by assuming |
| 190 | // Shipping FCM Version == min(all supported FCM Versions in the framework) |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 191 | for (auto&& fragment : matrixFragments) { |
| 192 | Level fragmentLevel = fragment.level(); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 193 | if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) { |
| 194 | deviceLevel = fragmentLevel; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if (deviceLevel == Level::UNSPECIFIED) { |
| 200 | // None of the fragments specify any FCM version. Should never happen except |
| 201 | // for inconsistent builds. |
| 202 | if (error) { |
Yifan Hong | c7a9a29 | 2021-02-03 17:27:58 -0800 | [diff] [blame] | 203 | *error = "No framework compatibility matrix files under "s + kSystemVintfDir + |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 204 | " declare FCM version."; |
| 205 | } |
| 206 | return NAME_NOT_FOUND; |
| 207 | } |
| 208 | |
Yifan Hong | 507815b | 2021-05-21 16:48:37 -0700 | [diff] [blame] | 209 | auto combined = CompatibilityMatrix::combine(deviceLevel, kernelLevel, &matrixFragments, error); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 210 | if (combined == nullptr) { |
| 211 | return BAD_VALUE; |
| 212 | } |
| 213 | *out = std::move(*combined); |
| 214 | return OK; |
| 215 | } |
| 216 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 217 | // Load and combine all of the manifests in a directory |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 218 | status_t VintfObject::addDirectoryManifests(const std::string& directory, HalManifest* manifest, |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 219 | std::string* error) { |
| 220 | std::vector<std::string> fileNames; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 221 | status_t err = getFileSystem()->listFiles(directory, &fileNames, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 222 | // if the directory isn't there, that's okay |
Xin Li | 1289643 | 2021-08-18 08:29:29 +0000 | [diff] [blame] | 223 | if (err == NAME_NOT_FOUND) { |
| 224 | if (error) { |
| 225 | error->clear(); |
| 226 | } |
| 227 | return OK; |
| 228 | } |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 229 | if (err != OK) return err; |
| 230 | |
| 231 | for (const std::string& file : fileNames) { |
| 232 | // Only adds HALs because all other things are added by libvintf |
| 233 | // itself for now. |
| 234 | HalManifest fragmentManifest; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 235 | err = fetchOneHalManifest(directory + file, &fragmentManifest, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 236 | if (err != OK) return err; |
| 237 | |
Yifan Hong | 4c6962d | 2019-01-30 15:50:46 -0800 | [diff] [blame] | 238 | if (!manifest->addAll(&fragmentManifest, error)) { |
| 239 | if (error) { |
Yifan Hong | 9f9a319 | 2020-04-13 16:39:45 -0700 | [diff] [blame] | 240 | error->insert(0, "Cannot add manifest fragment " + directory + file + ": "); |
Yifan Hong | 4c6962d | 2019-01-30 15:50:46 -0800 | [diff] [blame] | 241 | } |
| 242 | return UNKNOWN_ERROR; |
| 243 | } |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | return OK; |
| 247 | } |
| 248 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 249 | // Priority for loading vendor manifest: |
Roopesh Nataraja | d629d38 | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 250 | // 1. Vendor manifest + device fragments + ODM manifest (optional) + odm fragments |
| 251 | // 2. Vendor manifest + device fragments |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 252 | // 3. ODM manifest (optional) + odm fragments |
| 253 | // 4. /vendor/manifest.xml (legacy, no fragments) |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 254 | // where: |
Steven Moreland | 30a532c | 2018-11-01 08:46:32 -0700 | [diff] [blame] | 255 | // A + B means unioning <hal> tags from A and B. If B declares an override, then this takes priority |
| 256 | // over A. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 257 | status_t VintfObject::fetchDeviceHalManifest(HalManifest* out, std::string* error) { |
Roopesh Nataraja | d629d38 | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 258 | HalManifest vendorManifest; |
| 259 | status_t vendorStatus = fetchVendorHalManifest(&vendorManifest, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 260 | if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) { |
| 261 | return vendorStatus; |
| 262 | } |
| 263 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 264 | if (vendorStatus == OK) { |
Roopesh Nataraja | d629d38 | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 265 | *out = std::move(vendorManifest); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 266 | status_t fragmentStatus = addDirectoryManifests(kVendorManifestFragmentDir, out, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 267 | if (fragmentStatus != OK) { |
| 268 | return fragmentStatus; |
| 269 | } |
| 270 | } |
| 271 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 272 | HalManifest odmManifest; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 273 | status_t odmStatus = fetchOdmHalManifest(&odmManifest, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 274 | if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) { |
| 275 | return odmStatus; |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 278 | if (vendorStatus == OK) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 279 | if (odmStatus == OK) { |
Yifan Hong | 4c6962d | 2019-01-30 15:50:46 -0800 | [diff] [blame] | 280 | if (!out->addAll(&odmManifest, error)) { |
| 281 | if (error) { |
| 282 | error->insert(0, "Cannot add ODM manifest :"); |
| 283 | } |
| 284 | return UNKNOWN_ERROR; |
| 285 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 286 | } |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 287 | return addDirectoryManifests(kOdmManifestFragmentDir, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 290 | // vendorStatus != OK, "out" is not changed. |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 291 | if (odmStatus == OK) { |
| 292 | *out = std::move(odmManifest); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 293 | return addDirectoryManifests(kOdmManifestFragmentDir, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | // Use legacy /vendor/manifest.xml |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 297 | return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyManifest, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Roopesh Nataraja | d629d38 | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 300 | // Priority: |
| 301 | // 1. if {vendorSku} is defined, /vendor/etc/vintf/manifest_{vendorSku}.xml |
| 302 | // 2. /vendor/etc/vintf/manifest.xml |
| 303 | // where: |
| 304 | // {vendorSku} is the value of ro.boot.product.vendor.sku |
| 305 | status_t VintfObject::fetchVendorHalManifest(HalManifest* out, std::string* error) { |
| 306 | status_t status; |
| 307 | |
| 308 | std::string vendorSku; |
| 309 | vendorSku = getPropertyFetcher()->getProperty("ro.boot.product.vendor.sku", ""); |
| 310 | |
| 311 | if (!vendorSku.empty()) { |
| 312 | status = |
Yifan Hong | c7a9a29 | 2021-02-03 17:27:58 -0800 | [diff] [blame] | 313 | fetchOneHalManifest(kVendorVintfDir + "manifest_"s + vendorSku + ".xml", out, error); |
Roopesh Nataraja | d629d38 | 2020-02-26 09:51:38 -0800 | [diff] [blame] | 314 | if (status == OK || status != NAME_NOT_FOUND) { |
| 315 | return status; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | status = fetchOneHalManifest(kVendorManifest, out, error); |
| 320 | if (status == OK || status != NAME_NOT_FOUND) { |
| 321 | return status; |
| 322 | } |
| 323 | |
| 324 | return NAME_NOT_FOUND; |
| 325 | } |
| 326 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 327 | // "out" is written to iff return status is OK. |
| 328 | // Priority: |
| 329 | // 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml |
| 330 | // 2. /odm/etc/vintf/manifest.xml |
| 331 | // 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml |
| 332 | // 4. /odm/etc/manifest.xml |
| 333 | // where: |
| 334 | // {sku} is the value of ro.boot.product.hardware.sku |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 335 | status_t VintfObject::fetchOdmHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 336 | status_t status; |
| 337 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 338 | std::string productModel; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 339 | productModel = getPropertyFetcher()->getProperty("ro.boot.product.hardware.sku", ""); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 340 | |
| 341 | if (!productModel.empty()) { |
| 342 | status = |
Yifan Hong | c7a9a29 | 2021-02-03 17:27:58 -0800 | [diff] [blame] | 343 | fetchOneHalManifest(kOdmVintfDir + "manifest_"s + productModel + ".xml", out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 344 | if (status == OK || status != NAME_NOT_FOUND) { |
| 345 | return status; |
| 346 | } |
| 347 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 348 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 349 | status = fetchOneHalManifest(kOdmManifest, out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 350 | if (status == OK || status != NAME_NOT_FOUND) { |
| 351 | return status; |
| 352 | } |
| 353 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 354 | if (!productModel.empty()) { |
Yifan Hong | c7a9a29 | 2021-02-03 17:27:58 -0800 | [diff] [blame] | 355 | status = fetchOneHalManifest(kOdmLegacyVintfDir + "manifest_"s + productModel + ".xml", out, |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 356 | error); |
| 357 | if (status == OK || status != NAME_NOT_FOUND) { |
| 358 | return status; |
| 359 | } |
| 360 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 361 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 362 | status = fetchOneHalManifest(kOdmLegacyManifest, out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 363 | if (status == OK || status != NAME_NOT_FOUND) { |
| 364 | return status; |
| 365 | } |
| 366 | |
| 367 | return NAME_NOT_FOUND; |
| 368 | } |
| 369 | |
| 370 | // Fetch one manifest.xml file. "out" is written to iff return status is OK. |
| 371 | // Returns NAME_NOT_FOUND if file is missing. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 372 | status_t VintfObject::fetchOneHalManifest(const std::string& path, HalManifest* out, |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 373 | std::string* error) { |
| 374 | HalManifest ret; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 375 | status_t status = ret.fetchAllInformation(getFileSystem().get(), path, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 376 | if (status == OK) { |
| 377 | *out = std::move(ret); |
| 378 | } |
| 379 | return status; |
| 380 | } |
| 381 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 382 | status_t VintfObject::fetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) { |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 383 | CompatibilityMatrix etcMatrix; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 384 | if (etcMatrix.fetchAllInformation(getFileSystem().get(), kVendorMatrix, error) == OK) { |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 385 | *out = std::move(etcMatrix); |
| 386 | return OK; |
| 387 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 388 | return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyMatrix, error); |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 391 | // Priority: |
| 392 | // 1. /system/etc/vintf/manifest.xml |
| 393 | // + /system/etc/vintf/manifest/*.xml if they exist |
| 394 | // + /product/etc/vintf/manifest.xml if it exists |
| 395 | // + /product/etc/vintf/manifest/*.xml if they exist |
| 396 | // 2. (deprecated) /system/manifest.xml |
Yifan Hong | c735be9 | 2020-10-12 16:25:50 -0700 | [diff] [blame] | 397 | status_t VintfObject::fetchUnfilteredFrameworkHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 398 | auto systemEtcStatus = fetchOneHalManifest(kSystemManifest, out, error); |
| 399 | if (systemEtcStatus == OK) { |
| 400 | auto dirStatus = addDirectoryManifests(kSystemManifestFragmentDir, out, error); |
| 401 | if (dirStatus != OK) { |
| 402 | return dirStatus; |
| 403 | } |
| 404 | |
Yifan Hong | c7a9a29 | 2021-02-03 17:27:58 -0800 | [diff] [blame] | 405 | std::vector<std::pair<const char*, const char*>> extensions{ |
Yifan Hong | 659feac | 2020-03-19 18:09:54 -0700 | [diff] [blame] | 406 | {kProductManifest, kProductManifestFragmentDir}, |
| 407 | {kSystemExtManifest, kSystemExtManifestFragmentDir}, |
| 408 | }; |
| 409 | for (auto&& [manifestPath, frags] : extensions) { |
| 410 | HalManifest halManifest; |
| 411 | auto status = fetchOneHalManifest(manifestPath, &halManifest, error); |
| 412 | if (status != OK && status != NAME_NOT_FOUND) { |
| 413 | return status; |
| 414 | } |
| 415 | if (status == OK) { |
| 416 | if (!out->addAll(&halManifest, error)) { |
| 417 | if (error) { |
Yifan Hong | c7a9a29 | 2021-02-03 17:27:58 -0800 | [diff] [blame] | 418 | error->insert(0, "Cannot add "s + manifestPath + ":"); |
Yifan Hong | 659feac | 2020-03-19 18:09:54 -0700 | [diff] [blame] | 419 | } |
| 420 | return UNKNOWN_ERROR; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 421 | } |
Yifan Hong | 659feac | 2020-03-19 18:09:54 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | auto fragmentStatus = addDirectoryManifests(frags, out, error); |
| 425 | if (fragmentStatus != OK) { |
| 426 | return fragmentStatus; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
Yifan Hong | c735be9 | 2020-10-12 16:25:50 -0700 | [diff] [blame] | 429 | |
Yifan Hong | 659feac | 2020-03-19 18:09:54 -0700 | [diff] [blame] | 430 | return OK; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 431 | } else { |
| 432 | LOG(WARNING) << "Cannot fetch " << kSystemManifest << ": " |
| 433 | << (error ? *error : strerror(-systemEtcStatus)); |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 434 | } |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 435 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 436 | return out->fetchAllInformation(getFileSystem().get(), kSystemLegacyManifest, error); |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Yifan Hong | c735be9 | 2020-10-12 16:25:50 -0700 | [diff] [blame] | 439 | status_t VintfObject::fetchFrameworkHalManifest(HalManifest* out, std::string* error) { |
| 440 | status_t status = fetchUnfilteredFrameworkHalManifest(out, error); |
| 441 | if (status != OK) { |
| 442 | return status; |
| 443 | } |
| 444 | filterHalsByDeviceManifestLevel(out); |
| 445 | return OK; |
| 446 | } |
| 447 | |
| 448 | void VintfObject::filterHalsByDeviceManifestLevel(HalManifest* out) { |
| 449 | auto deviceManifest = getDeviceHalManifest(); |
| 450 | if (deviceManifest == nullptr) { |
| 451 | LOG(WARNING) << "Cannot fetch device manifest to determine target FCM version to " |
| 452 | "filter framework manifest HALs."; |
| 453 | return; |
| 454 | } |
| 455 | Level deviceManifestLevel = deviceManifest->level(); |
| 456 | if (deviceManifestLevel == Level::UNSPECIFIED) { |
| 457 | LOG(WARNING) |
| 458 | << "Not filtering framework manifest HALs because target FCM version is unspecified."; |
| 459 | return; |
| 460 | } |
| 461 | out->removeHalsIf([deviceManifestLevel](const ManifestHal& hal) { |
| 462 | if (hal.getMaxLevel() == Level::UNSPECIFIED) { |
| 463 | return false; |
| 464 | } |
| 465 | return hal.getMaxLevel() < deviceManifestLevel; |
| 466 | }); |
| 467 | } |
| 468 | |
Yifan Hong | 9f8f656 | 2018-11-06 16:26:20 -0800 | [diff] [blame] | 469 | static void appendLine(std::string* error, const std::string& message) { |
| 470 | if (error != nullptr) { |
| 471 | if (!error->empty()) *error += "\n"; |
| 472 | *error += message; |
| 473 | } |
| 474 | } |
| 475 | |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 476 | status_t VintfObject::getOneMatrix(const std::string& path, CompatibilityMatrix* out, |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 477 | std::string* error) { |
| 478 | std::string content; |
| 479 | status_t status = getFileSystem()->fetch(path, &content, error); |
| 480 | if (status != OK) { |
| 481 | return status; |
| 482 | } |
Yifan Hong | 25e2a77 | 2021-04-16 18:34:28 -0700 | [diff] [blame] | 483 | if (!fromXml(out, content, error)) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 484 | if (error) { |
| 485 | error->insert(0, "Cannot parse " + path + ": "); |
| 486 | } |
| 487 | return BAD_VALUE; |
| 488 | } |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 489 | out->setFileName(path); |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 490 | return OK; |
| 491 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 492 | |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 493 | status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<CompatibilityMatrix>* results, |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 494 | std::string* error) { |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 495 | std::vector<std::string> dirs = { |
| 496 | kSystemVintfDir, |
Yifan Hong | a0968e8 | 2019-12-19 14:08:13 -0800 | [diff] [blame] | 497 | kSystemExtVintfDir, |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 498 | kProductVintfDir, |
| 499 | }; |
| 500 | for (const auto& dir : dirs) { |
| 501 | std::vector<std::string> fileNames; |
| 502 | status_t listStatus = getFileSystem()->listFiles(dir, &fileNames, error); |
| 503 | if (listStatus == NAME_NOT_FOUND) { |
Xin Li | 1289643 | 2021-08-18 08:29:29 +0000 | [diff] [blame] | 504 | if (error) { |
| 505 | error->clear(); |
| 506 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 507 | continue; |
| 508 | } |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 509 | if (listStatus != OK) { |
| 510 | return listStatus; |
| 511 | } |
| 512 | for (const std::string& fileName : fileNames) { |
| 513 | std::string path = dir + fileName; |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 514 | CompatibilityMatrix namedMatrix; |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 515 | std::string matrixError; |
| 516 | status_t matrixStatus = getOneMatrix(path, &namedMatrix, &matrixError); |
| 517 | if (matrixStatus != OK) { |
| 518 | // Manifests and matrices share the same dir. Client may not have enough |
| 519 | // permissions to read system manifests, or may not be able to parse it. |
| 520 | auto logLevel = matrixStatus == BAD_VALUE ? base::DEBUG : base::ERROR; |
| 521 | LOG(logLevel) << "Framework Matrix: Ignore file " << path << ": " << matrixError; |
| 522 | continue; |
| 523 | } |
| 524 | results->emplace_back(std::move(namedMatrix)); |
| 525 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 526 | |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 527 | if (dir == kSystemVintfDir && results->empty()) { |
| 528 | if (error) { |
| 529 | *error = "No framework matrices under " + dir + " can be fetched or parsed.\n"; |
| 530 | } |
| 531 | return NAME_NOT_FOUND; |
| 532 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 535 | if (results->empty()) { |
| 536 | if (error) { |
| 537 | *error = |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 538 | "No framework matrices can be fetched or parsed. " |
| 539 | "The following directories are searched:\n " + |
| 540 | android::base::Join(dirs, "\n "); |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 541 | } |
| 542 | return NAME_NOT_FOUND; |
| 543 | } |
| 544 | return OK; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Yifan Hong | a192fa5 | 2020-07-21 12:09:20 -0700 | [diff] [blame] | 547 | std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(RuntimeInfo::FetchFlags flags) { |
| 548 | return GetInstance()->getRuntimeInfo(flags); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 549 | } |
Yifan Hong | a192fa5 | 2020-07-21 12:09:20 -0700 | [diff] [blame] | 550 | std::shared_ptr<const RuntimeInfo> VintfObject::getRuntimeInfo(RuntimeInfo::FetchFlags flags) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 551 | std::unique_lock<std::mutex> _lock(mDeviceRuntimeInfo.mutex); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 552 | |
Yifan Hong | a192fa5 | 2020-07-21 12:09:20 -0700 | [diff] [blame] | 553 | // Skip fetching information that has already been fetched previously. |
| 554 | flags &= (~mDeviceRuntimeInfo.fetchedFlags); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 555 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 556 | if (mDeviceRuntimeInfo.object == nullptr) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 557 | mDeviceRuntimeInfo.object = getRuntimeInfoFactory()->make_shared(); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 560 | status_t status = mDeviceRuntimeInfo.object->fetchAllInformation(flags); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 561 | if (status != OK) { |
Yifan Hong | 7becb06 | 2020-11-13 15:54:58 -0800 | [diff] [blame] | 562 | // If only kernel FCM is needed, ignore errors when fetching RuntimeInfo because RuntimeInfo |
| 563 | // is not available on host. On host, the kernel level can still be inferred from device |
| 564 | // manifest. |
| 565 | // If other information is needed, flag the error by returning nullptr. |
| 566 | auto allExceptKernelFcm = RuntimeInfo::FetchFlag::ALL & ~RuntimeInfo::FetchFlag::KERNEL_FCM; |
| 567 | bool needDeviceRuntimeInfo = flags & allExceptKernelFcm; |
| 568 | if (needDeviceRuntimeInfo) { |
| 569 | mDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched" |
| 570 | return nullptr; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | // To support devices without GKI, RuntimeInfo::fetchAllInformation does not report errors |
| 575 | // if kernel level cannot be retrieved. If so, fetch kernel FCM version from device HAL |
| 576 | // manifest and store it in RuntimeInfo too. |
| 577 | if (flags & RuntimeInfo::FetchFlag::KERNEL_FCM) { |
| 578 | Level deviceManifestKernelLevel = Level::UNSPECIFIED; |
| 579 | auto manifest = getDeviceHalManifest(); |
| 580 | if (manifest) { |
| 581 | deviceManifestKernelLevel = manifest->inferredKernelLevel(); |
| 582 | } |
| 583 | if (deviceManifestKernelLevel != Level::UNSPECIFIED) { |
| 584 | Level kernelLevel = mDeviceRuntimeInfo.object->kernelLevel(); |
| 585 | if (kernelLevel == Level::UNSPECIFIED) { |
| 586 | mDeviceRuntimeInfo.object->setKernelLevel(deviceManifestKernelLevel); |
| 587 | } else if (kernelLevel != deviceManifestKernelLevel) { |
| 588 | LOG(WARNING) << "uname() reports kernel level " << kernelLevel |
| 589 | << " but device manifest sets kernel level " |
| 590 | << deviceManifestKernelLevel << ". Using kernel level " << kernelLevel; |
| 591 | } |
| 592 | } |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 595 | mDeviceRuntimeInfo.fetchedFlags |= flags; |
| 596 | return mDeviceRuntimeInfo.object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 599 | int32_t VintfObject::checkCompatibility(std::string* error, CheckFlags::Type flags) { |
| 600 | status_t status = OK; |
| 601 | // null checks for files and runtime info |
| 602 | if (getFrameworkHalManifest() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 603 | appendLine(error, "No framework manifest file from device or from update package"); |
| 604 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 605 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 606 | if (getDeviceHalManifest() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 607 | appendLine(error, "No device manifest file from device or from update package"); |
| 608 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 609 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 610 | if (getFrameworkCompatibilityMatrix() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 611 | appendLine(error, "No framework matrix file from device or from update package"); |
| 612 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 613 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 614 | if (getDeviceCompatibilityMatrix() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 615 | appendLine(error, "No device matrix file from device or from update package"); |
| 616 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 617 | } |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 618 | |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 619 | if (flags.isRuntimeInfoEnabled()) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 620 | if (getRuntimeInfo() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 621 | appendLine(error, "No runtime info from device"); |
| 622 | status = NO_INIT; |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 623 | } |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 624 | } |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 625 | if (status != OK) return status; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 626 | |
| 627 | // compatiblity check. |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 628 | if (!getDeviceHalManifest()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error)) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 629 | if (error) { |
| 630 | error->insert(0, |
| 631 | "Device manifest and framework compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 632 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 633 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 634 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 635 | if (!getFrameworkHalManifest()->checkCompatibility(*getDeviceCompatibilityMatrix(), error)) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 636 | if (error) { |
| 637 | error->insert(0, |
| 638 | "Framework manifest and device compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 639 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 640 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 641 | } |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 642 | |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 643 | if (flags.isRuntimeInfoEnabled()) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 644 | if (!getRuntimeInfo()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error, |
Yifan Hong | 85e589e | 2019-12-18 13:12:29 -0800 | [diff] [blame] | 645 | flags)) { |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 646 | if (error) { |
| 647 | error->insert(0, |
| 648 | "Runtime info and framework compatibility matrix are incompatible: "); |
| 649 | } |
| 650 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | return COMPATIBLE; |
| 655 | } |
| 656 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 657 | namespace details { |
| 658 | |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 659 | std::vector<std::string> dumpFileList() { |
| 660 | return { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 661 | // clang-format off |
| 662 | kSystemVintfDir, |
| 663 | kVendorVintfDir, |
| 664 | kOdmVintfDir, |
| 665 | kProductVintfDir, |
Yifan Hong | a0968e8 | 2019-12-19 14:08:13 -0800 | [diff] [blame] | 666 | kSystemExtVintfDir, |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 667 | kOdmLegacyVintfDir, |
| 668 | kVendorLegacyManifest, |
| 669 | kVendorLegacyMatrix, |
| 670 | kSystemLegacyManifest, |
| 671 | kSystemLegacyMatrix, |
| 672 | // clang-format on |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 673 | }; |
| 674 | } |
| 675 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 676 | } // namespace details |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 677 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 678 | bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal, |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 679 | const CompatibilityMatrix& targetMatrix, |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 680 | const ListInstances& listInstances, |
| 681 | const ChildrenMap& childrenMap, std::string* appendedError) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 682 | bool isDeprecated = false; |
| 683 | oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) { |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 684 | if (IsInstanceDeprecated(oldMatrixInstance, targetMatrix, listInstances, childrenMap, |
| 685 | appendedError)) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 686 | isDeprecated = true; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 687 | } |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 688 | return true; // continue to check next instance |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 689 | }); |
| 690 | return isDeprecated; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 691 | } |
| 692 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 693 | // Let oldMatrixInstance = package@x.y-w::interface/instancePattern. |
| 694 | // If any "@servedVersion::interface/servedInstance" in listInstances(package@x.y::interface) |
| 695 | // matches instancePattern, return true iff for all child interfaces (from |
| 696 | // GetListedInstanceInheritance), IsFqInstanceDeprecated returns false. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 697 | bool VintfObject::IsInstanceDeprecated(const MatrixInstance& oldMatrixInstance, |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 698 | const CompatibilityMatrix& targetMatrix, |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 699 | const ListInstances& listInstances, |
| 700 | const ChildrenMap& childrenMap, std::string* appendedError) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 701 | const std::string& package = oldMatrixInstance.package(); |
| 702 | const Version& version = oldMatrixInstance.versionRange().minVer(); |
| 703 | const std::string& interface = oldMatrixInstance.interface(); |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 704 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 705 | std::vector<std::string> instanceHint; |
| 706 | if (!oldMatrixInstance.isRegex()) { |
| 707 | instanceHint.push_back(oldMatrixInstance.exactInstance()); |
| 708 | } |
| 709 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 710 | std::vector<std::string> accumulatedErrors; |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 711 | auto list = listInstances(package, version, interface, instanceHint); |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 712 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 713 | for (const auto& pair : list) { |
| 714 | const std::string& servedInstance = pair.first; |
| 715 | Version servedVersion = pair.second; |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 716 | std::string servedFqInstanceString = |
| 717 | toFQNameString(package, servedVersion, interface, servedInstance); |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 718 | if (!oldMatrixInstance.matchInstance(servedInstance)) { |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 719 | // ignore unrelated instance |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 720 | continue; |
| 721 | } |
| 722 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 723 | auto inheritance = GetListedInstanceInheritance(package, servedVersion, interface, |
| 724 | servedInstance, listInstances, childrenMap); |
| 725 | if (!inheritance.has_value()) { |
| 726 | accumulatedErrors.push_back(inheritance.error().message()); |
| 727 | continue; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 728 | } |
| 729 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 730 | std::vector<std::string> errors; |
| 731 | for (const auto& fqInstance : *inheritance) { |
| 732 | auto result = IsFqInstanceDeprecated(targetMatrix, oldMatrixInstance.format(), |
| 733 | fqInstance, listInstances); |
| 734 | if (result.ok()) { |
| 735 | errors.clear(); |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 736 | break; |
| 737 | } |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 738 | errors.push_back(result.error().message()); |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 739 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 740 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 741 | if (errors.empty()) { |
| 742 | continue; |
| 743 | } |
| 744 | accumulatedErrors.insert(accumulatedErrors.end(), errors.begin(), errors.end()); |
| 745 | } |
| 746 | |
| 747 | if (accumulatedErrors.empty()) { |
| 748 | return false; |
| 749 | } |
| 750 | appendLine(appendedError, android::base::Join(accumulatedErrors, "\n")); |
| 751 | return true; |
| 752 | } |
| 753 | |
| 754 | // Check if fqInstance is listed in |listInstances|. |
| 755 | bool VintfObject::IsInstanceListed(const ListInstances& listInstances, |
| 756 | const FqInstance& fqInstance) { |
| 757 | auto list = |
| 758 | listInstances(fqInstance.getPackage(), fqInstance.getVersion(), fqInstance.getInterface(), |
| 759 | {fqInstance.getInstance()} /* instanceHint*/); |
| 760 | return std::any_of(list.begin(), list.end(), |
| 761 | [&](const auto& pair) { return pair.first == fqInstance.getInstance(); }); |
| 762 | } |
| 763 | |
| 764 | // Return a list of FqInstance, where each element: |
| 765 | // - is listed in |listInstances|; AND |
| 766 | // - is, or inherits from, package@version::interface/instance (as specified by |childrenMap|) |
| 767 | android::base::Result<std::vector<FqInstance>> VintfObject::GetListedInstanceInheritance( |
| 768 | const std::string& package, const Version& version, const std::string& interface, |
| 769 | const std::string& instance, const ListInstances& listInstances, |
| 770 | const ChildrenMap& childrenMap) { |
| 771 | FqInstance fqInstance; |
| 772 | if (!fqInstance.setTo(package, version.majorVer, version.minorVer, interface, instance)) { |
| 773 | return android::base::Error() << toFQNameString(package, version, interface, instance) |
| 774 | << " is not a valid FqInstance"; |
| 775 | } |
| 776 | |
| 777 | if (!IsInstanceListed(listInstances, fqInstance)) { |
| 778 | return {}; |
| 779 | } |
| 780 | |
| 781 | const FQName& fqName = fqInstance.getFqName(); |
| 782 | |
| 783 | std::vector<FqInstance> ret; |
| 784 | ret.push_back(fqInstance); |
| 785 | |
| 786 | auto childRange = childrenMap.equal_range(fqName.string()); |
| 787 | for (auto it = childRange.first; it != childRange.second; ++it) { |
| 788 | const auto& childFqNameString = it->second; |
| 789 | FQName childFqName; |
| 790 | if (!childFqName.setTo(childFqNameString)) { |
| 791 | return android::base::Error() << "Cannot parse " << childFqNameString << " as FQName"; |
| 792 | } |
| 793 | FqInstance childFqInstance; |
| 794 | if (!childFqInstance.setTo(childFqName, fqInstance.getInstance())) { |
| 795 | return android::base::Error() << "Cannot merge " << childFqName.string() << "/" |
| 796 | << fqInstance.getInstance() << " as FqInstance"; |
| 797 | continue; |
| 798 | } |
| 799 | if (!IsInstanceListed(listInstances, childFqInstance)) { |
| 800 | continue; |
| 801 | } |
| 802 | ret.push_back(childFqInstance); |
| 803 | } |
| 804 | return ret; |
| 805 | } |
| 806 | |
| 807 | // Check if |fqInstance| is in |targetMatrix|; essentially equal to |
| 808 | // targetMatrix.matchInstance(fqInstance), but provides richer error message. In details: |
| 809 | // 1. package@x.?::interface/servedInstance is not in targetMatrix; OR |
| 810 | // 2. package@x.z::interface/servedInstance is in targetMatrix but |
| 811 | // servedInstance is not in listInstances(package@x.z::interface) |
| 812 | android::base::Result<void> VintfObject::IsFqInstanceDeprecated( |
| 813 | const CompatibilityMatrix& targetMatrix, HalFormat format, const FqInstance& fqInstance, |
| 814 | const ListInstances& listInstances) { |
| 815 | // Find minimum package@x.? in target matrix, and check if instance is in target matrix. |
| 816 | bool foundInstance = false; |
| 817 | Version targetMatrixMinVer{SIZE_MAX, SIZE_MAX}; |
| 818 | targetMatrix.forEachInstanceOfPackage( |
| 819 | format, fqInstance.getPackage(), [&](const auto& targetMatrixInstance) { |
| 820 | if (targetMatrixInstance.versionRange().majorVer == fqInstance.getMajorVersion() && |
| 821 | targetMatrixInstance.interface() == fqInstance.getInterface() && |
| 822 | targetMatrixInstance.matchInstance(fqInstance.getInstance())) { |
| 823 | targetMatrixMinVer = |
| 824 | std::min(targetMatrixMinVer, targetMatrixInstance.versionRange().minVer()); |
| 825 | foundInstance = true; |
| 826 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 827 | return true; |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 828 | }); |
| 829 | if (!foundInstance) { |
| 830 | return android::base::Error() |
| 831 | << fqInstance.string() << " is deprecated in compatibility matrix at FCM Version " |
| 832 | << targetMatrix.level() << "; it should not be served."; |
| 833 | } |
| 834 | |
| 835 | // Assuming that targetMatrix requires @x.u-v, require that at least @x.u is served. |
| 836 | bool targetVersionServed = false; |
| 837 | for (const auto& newPair : |
| 838 | listInstances(fqInstance.getPackage(), targetMatrixMinVer, fqInstance.getInterface(), |
| 839 | {fqInstance.getInstance()} /* instanceHint */)) { |
| 840 | if (newPair.first == fqInstance.getInstance()) { |
| 841 | targetVersionServed = true; |
| 842 | break; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 843 | } |
| 844 | } |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 845 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 846 | if (!targetVersionServed) { |
| 847 | return android::base::Error() |
| 848 | << fqInstance.string() << " is deprecated; requires at least " << targetMatrixMinVer; |
| 849 | } |
| 850 | return {}; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 851 | } |
| 852 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 853 | int32_t VintfObject::checkDeprecation(const ListInstances& listInstances, |
| 854 | const std::vector<HidlInterfaceMetadata>& hidlMetadata, |
| 855 | std::string* error) { |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 856 | std::vector<CompatibilityMatrix> matrixFragments; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 857 | auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error); |
| 858 | if (matrixFragmentsStatus != OK) { |
| 859 | return matrixFragmentsStatus; |
| 860 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 861 | if (matrixFragments.empty()) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 862 | if (error && error->empty()) { |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 863 | *error = "Cannot get framework matrix for each FCM version for unknown error."; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 864 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 865 | return NAME_NOT_FOUND; |
| 866 | } |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 867 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 868 | if (deviceManifest == nullptr) { |
| 869 | if (error) *error = "No device manifest."; |
| 870 | return NAME_NOT_FOUND; |
| 871 | } |
| 872 | Level deviceLevel = deviceManifest->level(); |
| 873 | if (deviceLevel == Level::UNSPECIFIED) { |
| 874 | if (error) *error = "Device manifest does not specify Shipping FCM Version."; |
| 875 | return BAD_VALUE; |
| 876 | } |
Yifan Hong | 507815b | 2021-05-21 16:48:37 -0700 | [diff] [blame] | 877 | std::string kernelLevelError; |
| 878 | Level kernelLevel = getKernelLevel(&kernelLevelError); |
| 879 | if (kernelLevel == Level::UNSPECIFIED) { |
| 880 | LOG(WARNING) << kernelLevelError; |
| 881 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 882 | |
Daniel Norman | edf8040 | 2021-03-29 16:49:22 -0700 | [diff] [blame] | 883 | std::vector<CompatibilityMatrix> targetMatrices; |
| 884 | // Partition matrixFragments into two groups, where the second group |
| 885 | // contains all matrices whose level == deviceLevel. |
| 886 | auto targetMatricesPartition = std::partition( |
| 887 | matrixFragments.begin(), matrixFragments.end(), |
| 888 | [&](const CompatibilityMatrix& matrix) { return matrix.level() != deviceLevel; }); |
| 889 | // Move these matrices into the targetMatrices vector... |
| 890 | std::move(targetMatricesPartition, matrixFragments.end(), std::back_inserter(targetMatrices)); |
| 891 | if (targetMatrices.empty()) { |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 892 | if (error) |
| 893 | *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + "."; |
| 894 | return NAME_NOT_FOUND; |
| 895 | } |
Daniel Norman | edf8040 | 2021-03-29 16:49:22 -0700 | [diff] [blame] | 896 | // so that they can be combined into one matrix for deprecation checking. |
Yifan Hong | 507815b | 2021-05-21 16:48:37 -0700 | [diff] [blame] | 897 | auto targetMatrix = |
| 898 | CompatibilityMatrix::combine(deviceLevel, kernelLevel, &targetMatrices, error); |
Daniel Norman | edf8040 | 2021-03-29 16:49:22 -0700 | [diff] [blame] | 899 | if (targetMatrix == nullptr) { |
| 900 | return BAD_VALUE; |
| 901 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 902 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 903 | std::multimap<std::string, std::string> childrenMap; |
| 904 | for (const auto& child : hidlMetadata) { |
| 905 | for (const auto& parent : child.inherited) { |
| 906 | childrenMap.emplace(parent, child.name); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | // Find a list of possibly deprecated HALs by comparing |listInstances| with older matrices. |
| 911 | // Matrices with unspecified level are considered "current". |
| 912 | bool isDeprecated = false; |
Daniel Norman | edf8040 | 2021-03-29 16:49:22 -0700 | [diff] [blame] | 913 | for (auto it = matrixFragments.begin(); it < targetMatricesPartition; ++it) { |
| 914 | const auto& namedMatrix = *it; |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 915 | if (namedMatrix.level() == Level::UNSPECIFIED) continue; |
Daniel Norman | edf8040 | 2021-03-29 16:49:22 -0700 | [diff] [blame] | 916 | if (namedMatrix.level() > deviceLevel) continue; |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 917 | for (const MatrixHal& hal : namedMatrix.getHals()) { |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 918 | if (IsHalDeprecated(hal, *targetMatrix, listInstances, childrenMap, error)) { |
| 919 | isDeprecated = true; |
| 920 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 924 | return isDeprecated ? DEPRECATED : NO_DEPRECATED_HALS; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 925 | } |
| 926 | |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 927 | int32_t VintfObject::checkDeprecation(const std::vector<HidlInterfaceMetadata>& hidlMetadata, |
| 928 | std::string* error) { |
Yifan Hong | 2a90ffe | 2018-03-05 17:45:34 -0800 | [diff] [blame] | 929 | using namespace std::placeholders; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 930 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 931 | ListInstances inManifest = |
| 932 | [&deviceManifest](const std::string& package, Version version, const std::string& interface, |
| 933 | const std::vector<std::string>& /* hintInstances */) { |
| 934 | std::vector<std::pair<std::string, Version>> ret; |
| 935 | deviceManifest->forEachInstanceOfInterface( |
Yifan Hong | ac62148 | 2019-09-10 19:27:20 -0700 | [diff] [blame] | 936 | HalFormat::HIDL, package, version, interface, |
| 937 | [&ret](const ManifestInstance& manifestInstance) { |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 938 | ret.push_back( |
| 939 | std::make_pair(manifestInstance.instance(), manifestInstance.version())); |
| 940 | return true; |
| 941 | }); |
| 942 | return ret; |
| 943 | }; |
Yifan Hong | 03ea428 | 2020-03-17 17:58:35 -0700 | [diff] [blame] | 944 | return checkDeprecation(inManifest, hidlMetadata, error); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 945 | } |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 946 | |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 947 | Level VintfObject::getKernelLevel(std::string* error) { |
Yifan Hong | 2d64411 | 2020-11-12 16:11:24 -0800 | [diff] [blame] | 948 | auto runtimeInfo = getRuntimeInfo(RuntimeInfo::FetchFlag::KERNEL_FCM); |
| 949 | if (!runtimeInfo) { |
| 950 | if (error) *error = "Cannot retrieve runtime info with kernel level."; |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 951 | return Level::UNSPECIFIED; |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 952 | } |
Yifan Hong | 2d64411 | 2020-11-12 16:11:24 -0800 | [diff] [blame] | 953 | if (runtimeInfo->kernelLevel() != Level::UNSPECIFIED) { |
| 954 | return runtimeInfo->kernelLevel(); |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 955 | } |
Yifan Hong | 2d64411 | 2020-11-12 16:11:24 -0800 | [diff] [blame] | 956 | if (error) { |
| 957 | *error = "Both device manifest and kernel release do not specify kernel FCM version."; |
| 958 | } |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 959 | return Level::UNSPECIFIED; |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 962 | const std::unique_ptr<FileSystem>& VintfObject::getFileSystem() { |
| 963 | return mFileSystem; |
| 964 | } |
| 965 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 966 | const std::unique_ptr<PropertyFetcher>& VintfObject::getPropertyFetcher() { |
| 967 | return mPropertyFetcher; |
| 968 | } |
| 969 | |
Yifan Hong | d038b2b | 2018-11-27 13:57:56 -0800 | [diff] [blame] | 970 | const std::unique_ptr<ObjectFactory<RuntimeInfo>>& VintfObject::getRuntimeInfoFactory() { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 971 | return mRuntimeInfoFactory; |
Yifan Hong | 10d8622 | 2018-04-06 15:41:05 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 974 | android::base::Result<bool> VintfObject::hasFrameworkCompatibilityMatrixExtensions() { |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 975 | std::vector<CompatibilityMatrix> matrixFragments; |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 976 | std::string error; |
| 977 | status_t status = getAllFrameworkMatrixLevels(&matrixFragments, &error); |
| 978 | if (status != OK) { |
| 979 | return android::base::Error(-status) |
| 980 | << "Cannot get all framework matrix fragments: " << error; |
| 981 | } |
| 982 | for (const auto& namedMatrix : matrixFragments) { |
| 983 | // Returns true if product matrix exists. |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 984 | if (android::base::StartsWith(namedMatrix.fileName(), kProductVintfDir)) { |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 985 | return true; |
| 986 | } |
Yifan Hong | f6ff427 | 2020-03-12 22:56:16 -0700 | [diff] [blame] | 987 | // Returns true if system_ext matrix exists. |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 988 | if (android::base::StartsWith(namedMatrix.fileName(), kSystemExtVintfDir)) { |
Yifan Hong | f6ff427 | 2020-03-12 22:56:16 -0700 | [diff] [blame] | 989 | return true; |
| 990 | } |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 991 | // Returns true if device system matrix exists. |
Yifan Hong | a83d0e4 | 2020-04-13 13:07:31 -0700 | [diff] [blame] | 992 | if (android::base::StartsWith(namedMatrix.fileName(), kSystemVintfDir) && |
| 993 | namedMatrix.level() == Level::UNSPECIFIED && !namedMatrix.getHals().empty()) { |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 994 | return true; |
| 995 | } |
| 996 | } |
| 997 | return false; |
| 998 | } |
| 999 | |
Yifan Hong | d7924ff | 2020-03-17 14:09:10 -0700 | [diff] [blame] | 1000 | android::base::Result<void> VintfObject::checkUnusedHals( |
| 1001 | const std::vector<HidlInterfaceMetadata>& hidlMetadata) { |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 1002 | auto matrix = getFrameworkCompatibilityMatrix(); |
| 1003 | if (matrix == nullptr) { |
| 1004 | return android::base::Error(-NAME_NOT_FOUND) << "Missing framework matrix."; |
| 1005 | } |
| 1006 | auto manifest = getDeviceHalManifest(); |
| 1007 | if (manifest == nullptr) { |
| 1008 | return android::base::Error(-NAME_NOT_FOUND) << "Missing device manifest."; |
| 1009 | } |
Yifan Hong | d7924ff | 2020-03-17 14:09:10 -0700 | [diff] [blame] | 1010 | auto unused = manifest->checkUnusedHals(*matrix, hidlMetadata); |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 1011 | if (!unused.empty()) { |
| 1012 | return android::base::Error() |
| 1013 | << "The following instances are in the device manifest but " |
| 1014 | << "not specified in framework compatibility matrix: \n" |
| 1015 | << " " << android::base::Join(unused, "\n ") << "\n" |
| 1016 | << "Suggested fix:\n" |
Yifan Hong | 5a220b1 | 2020-04-07 15:22:24 -0700 | [diff] [blame] | 1017 | << "1. Update deprecated HALs to the latest version.\n" |
| 1018 | << "2. Check for any typos in device manifest or framework compatibility " |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 1019 | << "matrices with FCM version >= " << matrix->level() << ".\n" |
Yifan Hong | 5a220b1 | 2020-04-07 15:22:24 -0700 | [diff] [blame] | 1020 | << "3. For new platform HALs, add them to any framework compatibility matrix " |
| 1021 | << "with FCM version >= " << matrix->level() << " where applicable.\n" |
| 1022 | << "4. For device-specific HALs, add to DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE " |
Yifan Hong | 6b86085 | 2020-03-19 23:12:07 +0000 | [diff] [blame] | 1023 | << "or DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE."; |
| 1024 | } |
| 1025 | return {}; |
| 1026 | } |
| 1027 | |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1028 | namespace { |
| 1029 | |
| 1030 | // Insert |name| into |ret| if shouldCheck(name). |
| 1031 | void InsertIf(const std::string& name, const std::function<bool(const std::string&)>& shouldCheck, |
| 1032 | std::set<std::string>* ret) { |
| 1033 | if (shouldCheck(name)) ret->insert(name); |
| 1034 | } |
| 1035 | |
| 1036 | std::string StripHidlInterface(const std::string& fqNameString) { |
| 1037 | FQName fqName; |
| 1038 | if (!fqName.setTo(fqNameString)) { |
| 1039 | return ""; |
| 1040 | } |
| 1041 | return fqName.getPackageAndVersion().string(); |
| 1042 | } |
| 1043 | |
| 1044 | std::string StripAidlType(const std::string& type) { |
| 1045 | auto items = android::base::Split(type, "."); |
| 1046 | if (items.empty()) { |
| 1047 | return ""; |
| 1048 | } |
| 1049 | items.erase(items.end() - 1); |
| 1050 | return android::base::Join(items, "."); |
| 1051 | } |
| 1052 | |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1053 | // android.hardware.foo@1.0 |
| 1054 | std::set<std::string> HidlMetadataToPackagesAndVersions( |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1055 | const std::vector<HidlInterfaceMetadata>& hidlMetadata, |
| 1056 | const std::function<bool(const std::string&)>& shouldCheck) { |
| 1057 | std::set<std::string> ret; |
| 1058 | for (const auto& item : hidlMetadata) { |
| 1059 | InsertIf(StripHidlInterface(item.name), shouldCheck, &ret); |
| 1060 | } |
| 1061 | return ret; |
| 1062 | } |
| 1063 | |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1064 | // android.hardware.foo |
| 1065 | std::set<std::string> AidlMetadataToPackages( |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1066 | const std::vector<AidlInterfaceMetadata>& aidlMetadata, |
| 1067 | const std::function<bool(const std::string&)>& shouldCheck) { |
| 1068 | std::set<std::string> ret; |
| 1069 | for (const auto& item : aidlMetadata) { |
| 1070 | for (const auto& type : item.types) { |
| 1071 | InsertIf(StripAidlType(type), shouldCheck, &ret); |
| 1072 | } |
| 1073 | } |
| 1074 | return ret; |
| 1075 | } |
| 1076 | |
Yifan Hong | 9db8ab1 | 2021-02-01 19:21:30 -0800 | [diff] [blame] | 1077 | // android.hardware.foo@1.0::IFoo. |
| 1078 | // Note that UDTs are not filtered out, so there might be non-interface types. |
| 1079 | std::set<std::string> HidlMetadataToNames(const std::vector<HidlInterfaceMetadata>& hidlMetadata) { |
| 1080 | std::set<std::string> ret; |
| 1081 | for (const auto& item : hidlMetadata) { |
| 1082 | ret.insert(item.name); |
| 1083 | } |
| 1084 | return ret; |
| 1085 | } |
| 1086 | |
| 1087 | // android.hardware.foo.IFoo |
| 1088 | // Note that UDTs are not filtered out, so there might be non-interface types. |
| 1089 | std::set<std::string> AidlMetadataToNames(const std::vector<AidlInterfaceMetadata>& aidlMetadata) { |
| 1090 | std::set<std::string> ret; |
| 1091 | for (const auto& item : aidlMetadata) { |
| 1092 | for (const auto& type : item.types) { |
| 1093 | ret.insert(type); |
| 1094 | } |
| 1095 | } |
| 1096 | return ret; |
| 1097 | } |
| 1098 | |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1099 | } // anonymous namespace |
| 1100 | |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1101 | android::base::Result<std::vector<CompatibilityMatrix>> VintfObject::getAllFrameworkMatrixLevels() { |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1102 | // Get all framework matrix fragments instead of the combined framework compatibility matrix |
| 1103 | // because the latter may omit interfaces from the latest FCM if device target-level is not |
| 1104 | // the latest. |
| 1105 | std::vector<CompatibilityMatrix> matrixFragments; |
| 1106 | std::string error; |
| 1107 | auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, &error); |
| 1108 | if (matrixFragmentsStatus != OK) { |
| 1109 | return android::base::Error(-matrixFragmentsStatus) |
| 1110 | << "Unable to get all framework matrix fragments: " << error; |
| 1111 | } |
| 1112 | if (matrixFragments.empty()) { |
| 1113 | if (error.empty()) { |
| 1114 | error = "Cannot get framework matrix for each FCM version for unknown error."; |
| 1115 | } |
| 1116 | return android::base::Error(-NAME_NOT_FOUND) << error; |
| 1117 | } |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1118 | return matrixFragments; |
| 1119 | } |
| 1120 | |
| 1121 | android::base::Result<void> VintfObject::checkMissingHalsInMatrices( |
| 1122 | const std::vector<HidlInterfaceMetadata>& hidlMetadata, |
| 1123 | const std::vector<AidlInterfaceMetadata>& aidlMetadata, |
| 1124 | std::function<bool(const std::string&)> shouldCheck) { |
| 1125 | if (!shouldCheck) { |
| 1126 | shouldCheck = [](const auto&) { return true; }; |
| 1127 | } |
| 1128 | |
| 1129 | auto matrixFragments = getAllFrameworkMatrixLevels(); |
| 1130 | if (!matrixFragments.ok()) return matrixFragments.error(); |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1131 | |
| 1132 | // Filter aidlMetadata and hidlMetadata with shouldCheck. |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1133 | auto allAidlPackages = AidlMetadataToPackages(aidlMetadata, shouldCheck); |
| 1134 | auto allHidlPackagesAndVersions = HidlMetadataToPackagesAndVersions(hidlMetadata, shouldCheck); |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1135 | |
| 1136 | // Filter out instances in allAidlMetadata and allHidlMetadata that are in the matrices. |
| 1137 | std::vector<std::string> errors; |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1138 | for (const auto& matrix : matrixFragments.value()) { |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1139 | matrix.forEachInstance([&](const MatrixInstance& matrixInstance) { |
| 1140 | switch (matrixInstance.format()) { |
| 1141 | case HalFormat::AIDL: { |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1142 | allAidlPackages.erase(matrixInstance.package()); |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1143 | return true; // continue to next instance |
| 1144 | } |
| 1145 | case HalFormat::HIDL: { |
| 1146 | for (Version v = matrixInstance.versionRange().minVer(); |
| 1147 | v <= matrixInstance.versionRange().maxVer(); ++v.minorVer) { |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1148 | allHidlPackagesAndVersions.erase( |
| 1149 | toFQNameString(matrixInstance.package(), v)); |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1150 | } |
| 1151 | return true; // continue to next instance |
| 1152 | } |
| 1153 | default: { |
| 1154 | if (shouldCheck(matrixInstance.package())) { |
| 1155 | errors.push_back("HAL package " + matrixInstance.package() + |
| 1156 | " is not allowed to have format " + |
| 1157 | to_string(matrixInstance.format()) + "."); |
| 1158 | } |
| 1159 | return true; // continue to next instance |
| 1160 | } |
| 1161 | } |
| 1162 | }); |
| 1163 | } |
| 1164 | |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1165 | if (!allHidlPackagesAndVersions.empty()) { |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1166 | errors.push_back( |
| 1167 | "The following HIDL packages are not found in any compatibility matrix fragments:\t\n" + |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1168 | android::base::Join(allHidlPackagesAndVersions, "\t\n")); |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1169 | } |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1170 | if (!allAidlPackages.empty()) { |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1171 | errors.push_back( |
| 1172 | "The following AIDL packages are not found in any compatibility matrix fragments:\t\n" + |
Yifan Hong | 8c61c75 | 2021-02-01 19:21:03 -0800 | [diff] [blame] | 1173 | android::base::Join(allAidlPackages, "\t\n")); |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | if (!errors.empty()) { |
| 1177 | return android::base::Error() << android::base::Join(errors, "\n"); |
| 1178 | } |
| 1179 | |
| 1180 | return {}; |
| 1181 | } |
| 1182 | |
Yifan Hong | 9db8ab1 | 2021-02-01 19:21:30 -0800 | [diff] [blame] | 1183 | android::base::Result<void> VintfObject::checkMatrixHalsHasDefinition( |
| 1184 | const std::vector<HidlInterfaceMetadata>& hidlMetadata, |
| 1185 | const std::vector<AidlInterfaceMetadata>& aidlMetadata) { |
| 1186 | auto matrixFragments = getAllFrameworkMatrixLevels(); |
| 1187 | if (!matrixFragments.ok()) return matrixFragments.error(); |
| 1188 | |
| 1189 | auto allAidlNames = AidlMetadataToNames(aidlMetadata); |
| 1190 | auto allHidlNames = HidlMetadataToNames(hidlMetadata); |
| 1191 | std::set<std::string> badAidlInterfaces; |
| 1192 | std::set<std::string> badHidlInterfaces; |
| 1193 | |
| 1194 | std::vector<std::string> errors; |
| 1195 | for (const auto& matrix : matrixFragments.value()) { |
| 1196 | if (matrix.level() == Level::UNSPECIFIED) { |
| 1197 | LOG(INFO) << "Skip checkMatrixHalsHasDefinition() on " << matrix.fileName() |
| 1198 | << " with no level."; |
| 1199 | continue; |
| 1200 | } |
| 1201 | |
| 1202 | matrix.forEachInstance([&](const MatrixInstance& matrixInstance) { |
| 1203 | switch (matrixInstance.format()) { |
| 1204 | case HalFormat::AIDL: { |
| 1205 | auto matrixInterface = |
| 1206 | toAidlFqnameString(matrixInstance.package(), matrixInstance.interface()); |
| 1207 | if (allAidlNames.find(matrixInterface) == allAidlNames.end()) { |
| 1208 | errors.push_back( |
| 1209 | "AIDL interface " + matrixInterface + " is referenced in " + |
| 1210 | matrix.fileName() + |
| 1211 | ", but there is no corresponding .aidl definition associated with an " |
| 1212 | "aidl_interface module in this build. Typo?"); |
| 1213 | } |
| 1214 | return true; // continue to next instance |
| 1215 | } |
| 1216 | case HalFormat::HIDL: { |
| 1217 | for (Version v = matrixInstance.versionRange().minVer(); |
| 1218 | v <= matrixInstance.versionRange().maxVer(); ++v.minorVer) { |
| 1219 | auto matrixInterface = matrixInstance.interfaceDescription(v); |
| 1220 | if (allHidlNames.find(matrixInterface) == allHidlNames.end()) { |
| 1221 | errors.push_back( |
| 1222 | "HIDL interface " + matrixInterface + " is referenced in " + |
| 1223 | matrix.fileName() + |
| 1224 | ", but there is no corresponding .hal definition associated with " |
| 1225 | "a hidl_interface module in this build. Typo?"); |
| 1226 | } |
| 1227 | } |
| 1228 | return true; // continue to next instance |
| 1229 | } |
| 1230 | default: { |
| 1231 | // We do not have data for native HALs. |
| 1232 | return true; // continue to next instance |
| 1233 | } |
| 1234 | } |
| 1235 | }); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | if (!errors.empty()) { |
| 1239 | return android::base::Error() << android::base::Join(errors, "\n"); |
| 1240 | } |
| 1241 | |
| 1242 | return {}; |
| 1243 | } |
| 1244 | |
| 1245 | // make_unique does not work because VintfObject constructor is private. |
Yifan Hong | 9d4c59c | 2021-11-29 18:37:42 -0800 | [diff] [blame^] | 1246 | VintfObject::Builder::Builder() |
| 1247 | : VintfObjectBuilder(std::unique_ptr<VintfObject>(new VintfObject())) {} |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 1248 | |
Yifan Hong | 9d4c59c | 2021-11-29 18:37:42 -0800 | [diff] [blame^] | 1249 | namespace details { |
| 1250 | |
| 1251 | VintfObjectBuilder::~VintfObjectBuilder() {} |
| 1252 | |
| 1253 | VintfObjectBuilder& VintfObjectBuilder::setFileSystem(std::unique_ptr<FileSystem>&& e) { |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 1254 | mObject->mFileSystem = std::move(e); |
| 1255 | return *this; |
| 1256 | } |
| 1257 | |
Yifan Hong | 9d4c59c | 2021-11-29 18:37:42 -0800 | [diff] [blame^] | 1258 | VintfObjectBuilder& VintfObjectBuilder::setRuntimeInfoFactory( |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 1259 | std::unique_ptr<ObjectFactory<RuntimeInfo>>&& e) { |
| 1260 | mObject->mRuntimeInfoFactory = std::move(e); |
| 1261 | return *this; |
| 1262 | } |
| 1263 | |
Yifan Hong | 9d4c59c | 2021-11-29 18:37:42 -0800 | [diff] [blame^] | 1264 | VintfObjectBuilder& VintfObjectBuilder::setPropertyFetcher(std::unique_ptr<PropertyFetcher>&& e) { |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 1265 | mObject->mPropertyFetcher = std::move(e); |
| 1266 | return *this; |
| 1267 | } |
| 1268 | |
Yifan Hong | 9d4c59c | 2021-11-29 18:37:42 -0800 | [diff] [blame^] | 1269 | std::unique_ptr<VintfObject> VintfObjectBuilder::buildInternal() { |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 1270 | if (!mObject->mFileSystem) mObject->mFileSystem = createDefaultFileSystem(); |
| 1271 | if (!mObject->mRuntimeInfoFactory) |
| 1272 | mObject->mRuntimeInfoFactory = std::make_unique<ObjectFactory<RuntimeInfo>>(); |
| 1273 | if (!mObject->mPropertyFetcher) mObject->mPropertyFetcher = createDefaultPropertyFetcher(); |
| 1274 | return std::move(mObject); |
| 1275 | } |
| 1276 | |
Yifan Hong | 9d4c59c | 2021-11-29 18:37:42 -0800 | [diff] [blame^] | 1277 | } // namespace details |
| 1278 | |
Yifan Hong | d704397 | 2020-03-30 13:27:46 -0700 | [diff] [blame] | 1279 | } // namespace vintf |
| 1280 | } // namespace android |