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