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