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