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