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 | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 21 | #include <functional> |
| 22 | #include <memory> |
| 23 | #include <mutex> |
| 24 | |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 25 | #include <android-base/logging.h> |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 26 | #include <android-base/strings.h> |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 27 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 28 | #include "CompatibilityMatrix.h" |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 29 | #include "parse_string.h" |
| 30 | #include "parse_xml.h" |
| 31 | #include "utils.h" |
| 32 | |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 33 | using std::placeholders::_1; |
| 34 | using std::placeholders::_2; |
| 35 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 36 | namespace android { |
| 37 | namespace vintf { |
| 38 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 39 | using namespace details; |
| 40 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 41 | #ifdef LIBVINTF_TARGET |
| 42 | static constexpr bool kIsTarget = true; |
| 43 | #else |
| 44 | static constexpr bool kIsTarget = false; |
| 45 | #endif |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 46 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 47 | template <typename T, typename F> |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 48 | static std::shared_ptr<const T> Get( |
| 49 | LockedSharedPtr<T> *ptr, |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 50 | bool skipCache, |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 51 | const F &fetchAllInformation) { |
| 52 | std::unique_lock<std::mutex> _lock(ptr->mutex); |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 53 | if (skipCache || !ptr->fetchedOnce) { |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 54 | ptr->object = std::make_unique<T>(); |
Yifan Hong | 6021703 | 2018-01-08 16:19:42 -0800 | [diff] [blame] | 55 | std::string error; |
| 56 | if (fetchAllInformation(ptr->object.get(), &error) != OK) { |
| 57 | LOG(WARNING) << error; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 58 | ptr->object = nullptr; // frees the old object |
| 59 | } |
Yifan Hong | 7219ba1 | 2018-01-08 16:23:49 -0800 | [diff] [blame] | 60 | ptr->fetchedOnce = true; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 61 | } |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 62 | return ptr->object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 65 | static std::unique_ptr<FileSystem> createDefaultFileSystem() { |
| 66 | std::unique_ptr<FileSystem> fileSystem; |
| 67 | if (kIsTarget) { |
| 68 | fileSystem = std::make_unique<details::FileSystemImpl>(); |
| 69 | } else { |
| 70 | fileSystem = std::make_unique<details::FileSystemNoOp>(); |
| 71 | } |
| 72 | return fileSystem; |
| 73 | } |
| 74 | |
| 75 | static std::unique_ptr<PropertyFetcher> createDefaultPropertyFetcher() { |
| 76 | std::unique_ptr<PropertyFetcher> propertyFetcher; |
| 77 | if (kIsTarget) { |
| 78 | propertyFetcher = std::make_unique<details::PropertyFetcherImpl>(); |
| 79 | } else { |
| 80 | propertyFetcher = std::make_unique<details::PropertyFetcherNoOp>(); |
| 81 | } |
| 82 | return propertyFetcher; |
| 83 | } |
| 84 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 85 | details::LockedSharedPtr<VintfObject> VintfObject::sInstance{}; |
| 86 | std::shared_ptr<VintfObject> VintfObject::GetInstance() { |
| 87 | std::unique_lock<std::mutex> lock(sInstance.mutex); |
| 88 | if (sInstance.object == nullptr) { |
Yifan Hong | 78f5b57 | 2018-11-27 14:05:03 -0800 | [diff] [blame] | 89 | sInstance.object = std::shared_ptr<VintfObject>(VintfObject::Builder().build().release()); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 90 | } |
| 91 | return sInstance.object; |
| 92 | } |
| 93 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 94 | std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 95 | return GetInstance()->getDeviceHalManifest(skipCache); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 98 | std::shared_ptr<const HalManifest> VintfObject::getDeviceHalManifest(bool skipCache) { |
| 99 | return Get(&mDeviceManifest, skipCache, |
| 100 | std::bind(&VintfObject::fetchDeviceHalManifest, this, _1, _2)); |
| 101 | } |
| 102 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 103 | std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 104 | return GetInstance()->getFrameworkHalManifest(skipCache); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 107 | std::shared_ptr<const HalManifest> VintfObject::getFrameworkHalManifest(bool skipCache) { |
| 108 | return Get(&mFrameworkManifest, skipCache, |
| 109 | std::bind(&VintfObject::fetchFrameworkHalManifest, this, _1, _2)); |
| 110 | } |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 111 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 112 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 113 | return GetInstance()->getDeviceCompatibilityMatrix(skipCache); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 116 | std::shared_ptr<const CompatibilityMatrix> VintfObject::getDeviceCompatibilityMatrix( |
| 117 | bool skipCache) { |
| 118 | return Get(&mDeviceMatrix, skipCache, std::bind(&VintfObject::fetchDeviceMatrix, this, _1, _2)); |
| 119 | } |
| 120 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 121 | std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 122 | return GetInstance()->getFrameworkCompatibilityMatrix(skipCache); |
| 123 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 124 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 125 | std::shared_ptr<const CompatibilityMatrix> VintfObject::getFrameworkCompatibilityMatrix( |
| 126 | bool skipCache) { |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 127 | // To avoid deadlock, get device manifest before any locks. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 128 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 129 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 130 | std::unique_lock<std::mutex> _lock(mFrameworkCompatibilityMatrixMutex); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 131 | |
| 132 | auto combined = |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 133 | Get(&mCombinedFrameworkMatrix, skipCache, |
| 134 | std::bind(&VintfObject::getCombinedFrameworkMatrix, this, deviceManifest, _1, _2)); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 135 | if (combined != nullptr) { |
| 136 | return combined; |
| 137 | } |
| 138 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 139 | return Get(&mFrameworkMatrix, skipCache, |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 140 | std::bind(&CompatibilityMatrix::fetchAllInformation, _1, getFileSystem().get(), |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 141 | kSystemLegacyMatrix, _2)); |
Yifan Hong | 2272bf8 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 144 | status_t VintfObject::getCombinedFrameworkMatrix( |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 145 | const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out, |
| 146 | std::string* error) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 147 | std::vector<Named<CompatibilityMatrix>> matrixFragments; |
| 148 | auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error); |
| 149 | if (matrixFragmentsStatus != OK) { |
| 150 | return matrixFragmentsStatus; |
| 151 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 152 | if (matrixFragments.empty()) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 153 | if (error && error->empty()) { |
| 154 | *error = "Cannot get framework matrix for each FCM version for unknown error."; |
| 155 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 156 | return NAME_NOT_FOUND; |
| 157 | } |
| 158 | |
| 159 | Level deviceLevel = Level::UNSPECIFIED; |
| 160 | |
| 161 | if (deviceManifest != nullptr) { |
| 162 | deviceLevel = deviceManifest->level(); |
| 163 | } |
| 164 | |
| 165 | // TODO(b/70628538): Do not infer from Shipping API level. |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 166 | if (deviceLevel == Level::UNSPECIFIED) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 167 | auto shippingApi = getPropertyFetcher()->getUintProperty("ro.product.first_api_level", 0u); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 168 | if (shippingApi != 0u) { |
| 169 | deviceLevel = details::convertFromApiLevel(shippingApi); |
| 170 | } |
| 171 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 172 | |
| 173 | if (deviceLevel == Level::UNSPECIFIED) { |
| 174 | // Cannot infer FCM version. Combine all matrices by assuming |
| 175 | // Shipping FCM Version == min(all supported FCM Versions in the framework) |
| 176 | for (auto&& pair : matrixFragments) { |
| 177 | Level fragmentLevel = pair.object.level(); |
| 178 | if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) { |
| 179 | deviceLevel = fragmentLevel; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if (deviceLevel == Level::UNSPECIFIED) { |
| 185 | // None of the fragments specify any FCM version. Should never happen except |
| 186 | // for inconsistent builds. |
| 187 | if (error) { |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 188 | *error = "No framework compatibility matrix files under " + kSystemVintfDir + |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 189 | " declare FCM version."; |
| 190 | } |
| 191 | return NAME_NOT_FOUND; |
| 192 | } |
| 193 | |
Yifan Hong | e7837b1 | 2018-10-11 10:38:57 -0700 | [diff] [blame] | 194 | auto combined = CompatibilityMatrix::combine(deviceLevel, &matrixFragments, error); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 195 | if (combined == nullptr) { |
| 196 | return BAD_VALUE; |
| 197 | } |
| 198 | *out = std::move(*combined); |
| 199 | return OK; |
| 200 | } |
| 201 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 202 | // Load and combine all of the manifests in a directory |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 203 | status_t VintfObject::addDirectoryManifests(const std::string& directory, HalManifest* manifest, |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 204 | std::string* error) { |
| 205 | std::vector<std::string> fileNames; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 206 | status_t err = getFileSystem()->listFiles(directory, &fileNames, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 207 | // if the directory isn't there, that's okay |
| 208 | if (err == NAME_NOT_FOUND) return OK; |
| 209 | if (err != OK) return err; |
| 210 | |
| 211 | for (const std::string& file : fileNames) { |
| 212 | // Only adds HALs because all other things are added by libvintf |
| 213 | // itself for now. |
| 214 | HalManifest fragmentManifest; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 215 | err = fetchOneHalManifest(directory + file, &fragmentManifest, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 216 | if (err != OK) return err; |
| 217 | |
Yifan Hong | 4c6962d | 2019-01-30 15:50:46 -0800 | [diff] [blame] | 218 | if (!manifest->addAll(&fragmentManifest, error)) { |
| 219 | if (error) { |
| 220 | error->insert(0, "Cannot add manifest fragment " + directory + file + ":"); |
| 221 | } |
| 222 | return UNKNOWN_ERROR; |
| 223 | } |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | return OK; |
| 227 | } |
| 228 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 229 | // Priority for loading vendor manifest: |
Roopesh Nataraja | fe7068d | 2020-02-26 09:51:38 -0800 | [diff] [blame^] | 230 | // 1. Vendor manifest + device fragments + ODM manifest (optional) + odm fragments |
| 231 | // 2. Vendor manifest + device fragments |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 232 | // 3. ODM manifest (optional) + odm fragments |
| 233 | // 4. /vendor/manifest.xml (legacy, no fragments) |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 234 | // where: |
Steven Moreland | 30a532c | 2018-11-01 08:46:32 -0700 | [diff] [blame] | 235 | // A + B means unioning <hal> tags from A and B. If B declares an override, then this takes priority |
| 236 | // over A. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 237 | status_t VintfObject::fetchDeviceHalManifest(HalManifest* out, std::string* error) { |
Roopesh Nataraja | fe7068d | 2020-02-26 09:51:38 -0800 | [diff] [blame^] | 238 | HalManifest vendorManifest; |
| 239 | status_t vendorStatus = fetchVendorHalManifest(&vendorManifest, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 240 | if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) { |
| 241 | return vendorStatus; |
| 242 | } |
| 243 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 244 | if (vendorStatus == OK) { |
Roopesh Nataraja | fe7068d | 2020-02-26 09:51:38 -0800 | [diff] [blame^] | 245 | *out = std::move(vendorManifest); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 246 | status_t fragmentStatus = addDirectoryManifests(kVendorManifestFragmentDir, out, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 247 | if (fragmentStatus != OK) { |
| 248 | return fragmentStatus; |
| 249 | } |
| 250 | } |
| 251 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 252 | HalManifest odmManifest; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 253 | status_t odmStatus = fetchOdmHalManifest(&odmManifest, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 254 | if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) { |
| 255 | return odmStatus; |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 258 | if (vendorStatus == OK) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 259 | if (odmStatus == OK) { |
Yifan Hong | 4c6962d | 2019-01-30 15:50:46 -0800 | [diff] [blame] | 260 | if (!out->addAll(&odmManifest, error)) { |
| 261 | if (error) { |
| 262 | error->insert(0, "Cannot add ODM manifest :"); |
| 263 | } |
| 264 | return UNKNOWN_ERROR; |
| 265 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 266 | } |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 267 | return addDirectoryManifests(kOdmManifestFragmentDir, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 270 | // vendorStatus != OK, "out" is not changed. |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 271 | if (odmStatus == OK) { |
| 272 | *out = std::move(odmManifest); |
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 | |
| 276 | // Use legacy /vendor/manifest.xml |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 277 | return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyManifest, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Roopesh Nataraja | fe7068d | 2020-02-26 09:51:38 -0800 | [diff] [blame^] | 280 | // Priority: |
| 281 | // 1. if {vendorSku} is defined, /vendor/etc/vintf/manifest_{vendorSku}.xml |
| 282 | // 2. /vendor/etc/vintf/manifest.xml |
| 283 | // where: |
| 284 | // {vendorSku} is the value of ro.boot.product.vendor.sku |
| 285 | status_t VintfObject::fetchVendorHalManifest(HalManifest* out, std::string* error) { |
| 286 | status_t status; |
| 287 | |
| 288 | std::string vendorSku; |
| 289 | vendorSku = getPropertyFetcher()->getProperty("ro.boot.product.vendor.sku", ""); |
| 290 | |
| 291 | if (!vendorSku.empty()) { |
| 292 | status = |
| 293 | fetchOneHalManifest(kVendorVintfDir + "manifest_" + vendorSku + ".xml", out, error); |
| 294 | if (status == OK || status != NAME_NOT_FOUND) { |
| 295 | return status; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | status = fetchOneHalManifest(kVendorManifest, out, error); |
| 300 | if (status == OK || status != NAME_NOT_FOUND) { |
| 301 | return status; |
| 302 | } |
| 303 | |
| 304 | return NAME_NOT_FOUND; |
| 305 | } |
| 306 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 307 | // "out" is written to iff return status is OK. |
| 308 | // Priority: |
| 309 | // 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml |
| 310 | // 2. /odm/etc/vintf/manifest.xml |
| 311 | // 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml |
| 312 | // 4. /odm/etc/manifest.xml |
| 313 | // where: |
| 314 | // {sku} is the value of ro.boot.product.hardware.sku |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 315 | status_t VintfObject::fetchOdmHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 316 | status_t status; |
| 317 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 318 | std::string productModel; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 319 | productModel = getPropertyFetcher()->getProperty("ro.boot.product.hardware.sku", ""); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 320 | |
| 321 | if (!productModel.empty()) { |
| 322 | status = |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 323 | fetchOneHalManifest(kOdmVintfDir + "manifest_" + productModel + ".xml", out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 324 | if (status == OK || status != NAME_NOT_FOUND) { |
| 325 | return status; |
| 326 | } |
| 327 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 328 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 329 | status = fetchOneHalManifest(kOdmManifest, 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 | if (!productModel.empty()) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 335 | status = fetchOneHalManifest(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", out, |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 336 | error); |
| 337 | if (status == OK || status != NAME_NOT_FOUND) { |
| 338 | return status; |
| 339 | } |
| 340 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 341 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 342 | status = fetchOneHalManifest(kOdmLegacyManifest, out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 343 | if (status == OK || status != NAME_NOT_FOUND) { |
| 344 | return status; |
| 345 | } |
| 346 | |
| 347 | return NAME_NOT_FOUND; |
| 348 | } |
| 349 | |
| 350 | // Fetch one manifest.xml file. "out" is written to iff return status is OK. |
| 351 | // Returns NAME_NOT_FOUND if file is missing. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 352 | status_t VintfObject::fetchOneHalManifest(const std::string& path, HalManifest* out, |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 353 | std::string* error) { |
| 354 | HalManifest ret; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 355 | status_t status = ret.fetchAllInformation(getFileSystem().get(), path, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 356 | if (status == OK) { |
| 357 | *out = std::move(ret); |
| 358 | } |
| 359 | return status; |
| 360 | } |
| 361 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 362 | status_t VintfObject::fetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) { |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 363 | CompatibilityMatrix etcMatrix; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 364 | if (etcMatrix.fetchAllInformation(getFileSystem().get(), kVendorMatrix, error) == OK) { |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 365 | *out = std::move(etcMatrix); |
| 366 | return OK; |
| 367 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 368 | return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyMatrix, error); |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 371 | // Priority: |
| 372 | // 1. /system/etc/vintf/manifest.xml |
| 373 | // + /system/etc/vintf/manifest/*.xml if they exist |
| 374 | // + /product/etc/vintf/manifest.xml if it exists |
| 375 | // + /product/etc/vintf/manifest/*.xml if they exist |
| 376 | // 2. (deprecated) /system/manifest.xml |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 377 | status_t VintfObject::fetchFrameworkHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 378 | auto systemEtcStatus = fetchOneHalManifest(kSystemManifest, out, error); |
| 379 | if (systemEtcStatus == OK) { |
| 380 | auto dirStatus = addDirectoryManifests(kSystemManifestFragmentDir, out, error); |
| 381 | if (dirStatus != OK) { |
| 382 | return dirStatus; |
| 383 | } |
| 384 | |
| 385 | HalManifest productManifest; |
| 386 | auto productStatus = fetchOneHalManifest(kProductManifest, &productManifest, error); |
| 387 | if (productStatus != OK && productStatus != NAME_NOT_FOUND) { |
| 388 | return productStatus; |
| 389 | } |
| 390 | if (productStatus == OK) { |
| 391 | if (!out->addAll(&productManifest, error)) { |
| 392 | if (error) { |
| 393 | error->insert(0, "Cannot add " + kProductManifest + ":"); |
| 394 | } |
| 395 | return UNKNOWN_ERROR; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | return addDirectoryManifests(kProductManifestFragmentDir, out, error); |
| 400 | } else { |
| 401 | LOG(WARNING) << "Cannot fetch " << kSystemManifest << ": " |
| 402 | << (error ? *error : strerror(-systemEtcStatus)); |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 403 | } |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 404 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 405 | return out->fetchAllInformation(getFileSystem().get(), kSystemLegacyManifest, error); |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Yifan Hong | 9f8f656 | 2018-11-06 16:26:20 -0800 | [diff] [blame] | 408 | static void appendLine(std::string* error, const std::string& message) { |
| 409 | if (error != nullptr) { |
| 410 | if (!error->empty()) *error += "\n"; |
| 411 | *error += message; |
| 412 | } |
| 413 | } |
| 414 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 415 | status_t VintfObject::getOneMatrix(const std::string& path, Named<CompatibilityMatrix>* out, |
| 416 | std::string* error) { |
| 417 | std::string content; |
| 418 | status_t status = getFileSystem()->fetch(path, &content, error); |
| 419 | if (status != OK) { |
| 420 | return status; |
| 421 | } |
| 422 | if (!gCompatibilityMatrixConverter(&out->object, content, error)) { |
| 423 | if (error) { |
| 424 | error->insert(0, "Cannot parse " + path + ": "); |
| 425 | } |
| 426 | return BAD_VALUE; |
| 427 | } |
| 428 | out->name = path; |
| 429 | return OK; |
| 430 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 431 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 432 | status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<Named<CompatibilityMatrix>>* results, |
| 433 | std::string* error) { |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 434 | std::vector<std::string> dirs = { |
| 435 | kSystemVintfDir, |
Yifan Hong | a0968e8 | 2019-12-19 14:08:13 -0800 | [diff] [blame] | 436 | kSystemExtVintfDir, |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 437 | kProductVintfDir, |
| 438 | }; |
| 439 | for (const auto& dir : dirs) { |
| 440 | std::vector<std::string> fileNames; |
| 441 | status_t listStatus = getFileSystem()->listFiles(dir, &fileNames, error); |
| 442 | if (listStatus == NAME_NOT_FOUND) { |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 443 | continue; |
| 444 | } |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 445 | if (listStatus != OK) { |
| 446 | return listStatus; |
| 447 | } |
| 448 | for (const std::string& fileName : fileNames) { |
| 449 | std::string path = dir + fileName; |
| 450 | Named<CompatibilityMatrix> namedMatrix; |
| 451 | std::string matrixError; |
| 452 | status_t matrixStatus = getOneMatrix(path, &namedMatrix, &matrixError); |
| 453 | if (matrixStatus != OK) { |
| 454 | // Manifests and matrices share the same dir. Client may not have enough |
| 455 | // permissions to read system manifests, or may not be able to parse it. |
| 456 | auto logLevel = matrixStatus == BAD_VALUE ? base::DEBUG : base::ERROR; |
| 457 | LOG(logLevel) << "Framework Matrix: Ignore file " << path << ": " << matrixError; |
| 458 | continue; |
| 459 | } |
| 460 | results->emplace_back(std::move(namedMatrix)); |
| 461 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 462 | |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 463 | if (dir == kSystemVintfDir && results->empty()) { |
| 464 | if (error) { |
| 465 | *error = "No framework matrices under " + dir + " can be fetched or parsed.\n"; |
| 466 | } |
| 467 | return NAME_NOT_FOUND; |
| 468 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 471 | if (results->empty()) { |
| 472 | if (error) { |
| 473 | *error = |
Yifan Hong | b02d87d | 2019-12-19 11:15:27 -0800 | [diff] [blame] | 474 | "No framework matrices can be fetched or parsed. " |
| 475 | "The following directories are searched:\n " + |
| 476 | android::base::Join(dirs, "\n "); |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 477 | } |
| 478 | return NAME_NOT_FOUND; |
| 479 | } |
| 480 | return OK; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 483 | std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache, |
| 484 | RuntimeInfo::FetchFlags flags) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 485 | return GetInstance()->getRuntimeInfo(skipCache, flags); |
| 486 | } |
| 487 | std::shared_ptr<const RuntimeInfo> VintfObject::getRuntimeInfo(bool skipCache, |
| 488 | RuntimeInfo::FetchFlags flags) { |
| 489 | std::unique_lock<std::mutex> _lock(mDeviceRuntimeInfo.mutex); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 490 | |
| 491 | if (!skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 492 | flags &= (~mDeviceRuntimeInfo.fetchedFlags); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 495 | if (mDeviceRuntimeInfo.object == nullptr) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 496 | mDeviceRuntimeInfo.object = getRuntimeInfoFactory()->make_shared(); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Yifan Hong | f324798 | 2019-12-12 12:11:36 -0800 | [diff] [blame] | 499 | // Fetch kernel FCM version from device HAL manifest and store it in RuntimeInfo too. |
| 500 | if ((flags & RuntimeInfo::FetchFlag::KERNEL_FCM) != 0) { |
| 501 | auto manifest = getDeviceHalManifest(); |
| 502 | if (!manifest) { |
| 503 | mDeviceRuntimeInfo.fetchedFlags &= ~RuntimeInfo::FetchFlag::KERNEL_FCM; |
| 504 | return nullptr; |
| 505 | } |
| 506 | Level level = Level::UNSPECIFIED; |
| 507 | if (manifest->kernel().has_value()) { |
| 508 | level = manifest->kernel()->level(); |
| 509 | } |
| 510 | mDeviceRuntimeInfo.object->setKernelLevel(level); |
| 511 | flags &= ~RuntimeInfo::FetchFlag::KERNEL_FCM; |
| 512 | } |
| 513 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 514 | status_t status = mDeviceRuntimeInfo.object->fetchAllInformation(flags); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 515 | if (status != OK) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 516 | mDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched" |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 517 | return nullptr; |
| 518 | } |
| 519 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 520 | mDeviceRuntimeInfo.fetchedFlags |= flags; |
| 521 | return mDeviceRuntimeInfo.object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 524 | int32_t VintfObject::checkCompatibility(std::string* error, CheckFlags::Type flags) { |
| 525 | status_t status = OK; |
| 526 | // null checks for files and runtime info |
| 527 | if (getFrameworkHalManifest() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 528 | appendLine(error, "No framework manifest file from device or from update package"); |
| 529 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 530 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 531 | if (getDeviceHalManifest() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 532 | appendLine(error, "No device manifest file from device or from update package"); |
| 533 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 534 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 535 | if (getFrameworkCompatibilityMatrix() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 536 | appendLine(error, "No framework matrix file from device or from update package"); |
| 537 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 538 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 539 | if (getDeviceCompatibilityMatrix() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 540 | appendLine(error, "No device matrix file from device or from update package"); |
| 541 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 542 | } |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 543 | |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 544 | if (flags.isRuntimeInfoEnabled()) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 545 | if (getRuntimeInfo() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 546 | appendLine(error, "No runtime info from device"); |
| 547 | status = NO_INIT; |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 548 | } |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 549 | } |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 550 | if (status != OK) return status; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 551 | |
| 552 | // compatiblity check. |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 553 | if (!getDeviceHalManifest()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error)) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 554 | if (error) { |
| 555 | error->insert(0, |
| 556 | "Device manifest and framework compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 557 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 558 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 559 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 560 | if (!getFrameworkHalManifest()->checkCompatibility(*getDeviceCompatibilityMatrix(), error)) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 561 | if (error) { |
| 562 | error->insert(0, |
| 563 | "Framework manifest and device compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 564 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 565 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 566 | } |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 567 | |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 568 | if (flags.isRuntimeInfoEnabled()) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 569 | if (!getRuntimeInfo()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error, |
Yifan Hong | 85e589e | 2019-12-18 13:12:29 -0800 | [diff] [blame] | 570 | flags)) { |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 571 | if (error) { |
| 572 | error->insert(0, |
| 573 | "Runtime info and framework compatibility matrix are incompatible: "); |
| 574 | } |
| 575 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
| 579 | return COMPATIBLE; |
| 580 | } |
| 581 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 582 | namespace details { |
| 583 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 584 | const std::string kSystemVintfDir = "/system/etc/vintf/"; |
Yifan Hong | ccbea05 | 2018-01-18 18:48:46 -0800 | [diff] [blame] | 585 | const std::string kVendorVintfDir = "/vendor/etc/vintf/"; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 586 | const std::string kOdmVintfDir = "/odm/etc/vintf/"; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 587 | const std::string kProductVintfDir = "/product/etc/vintf/"; |
Yifan Hong | 5bbc4ae | 2020-01-09 14:30:27 -0800 | [diff] [blame] | 588 | const std::string kSystemExtVintfDir = "/system_ext/etc/vintf/"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 589 | |
| 590 | const std::string kVendorManifest = kVendorVintfDir + "manifest.xml"; |
Yifan Hong | a5ddddf | 2018-01-18 18:50:13 -0800 | [diff] [blame] | 591 | const std::string kSystemManifest = kSystemVintfDir + "manifest.xml"; |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 592 | const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml"; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 593 | const std::string kOdmManifest = kOdmVintfDir + "manifest.xml"; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 594 | const std::string kProductMatrix = kProductVintfDir + "compatibility_matrix.xml"; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 595 | const std::string kProductManifest = kProductVintfDir + "manifest.xml"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 596 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 597 | const std::string kVendorManifestFragmentDir = kVendorVintfDir + "manifest/"; |
| 598 | const std::string kSystemManifestFragmentDir = kSystemVintfDir + "manifest/"; |
| 599 | const std::string kOdmManifestFragmentDir = kOdmVintfDir + "manifest/"; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 600 | const std::string kProductManifestFragmentDir = kProductVintfDir + "manifest/"; |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 601 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 602 | const std::string kVendorLegacyManifest = "/vendor/manifest.xml"; |
| 603 | const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml"; |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 604 | const std::string kSystemLegacyManifest = "/system/manifest.xml"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 605 | const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml"; |
| 606 | const std::string kOdmLegacyVintfDir = "/odm/etc/"; |
| 607 | const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml"; |
| 608 | |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 609 | std::vector<std::string> dumpFileList() { |
| 610 | return { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 611 | // clang-format off |
| 612 | kSystemVintfDir, |
| 613 | kVendorVintfDir, |
| 614 | kOdmVintfDir, |
| 615 | kProductVintfDir, |
Yifan Hong | a0968e8 | 2019-12-19 14:08:13 -0800 | [diff] [blame] | 616 | kSystemExtVintfDir, |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 617 | kOdmLegacyVintfDir, |
| 618 | kVendorLegacyManifest, |
| 619 | kVendorLegacyMatrix, |
| 620 | kSystemLegacyManifest, |
| 621 | kSystemLegacyMatrix, |
| 622 | // clang-format on |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 623 | }; |
| 624 | } |
| 625 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 626 | } // namespace details |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 627 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 628 | bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal, |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 629 | const CompatibilityMatrix& targetMatrix, |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 630 | const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 631 | bool isDeprecated = false; |
| 632 | oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 633 | if (IsInstanceDeprecated(oldMatrixInstance, targetMatrix, listInstances, error)) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 634 | isDeprecated = true; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 635 | } |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 636 | return !isDeprecated; // continue if no deprecated instance is found. |
| 637 | }); |
| 638 | return isDeprecated; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 641 | // Let oldMatrixInstance = package@x.y-w::interface with instancePattern. |
| 642 | // If any "servedInstance" in listInstances(package@x.y::interface) matches instancePattern, return |
| 643 | // true iff: |
| 644 | // 1. package@x.?::interface/servedInstance is not in targetMatrix; OR |
| 645 | // 2. package@x.z::interface/servedInstance is in targetMatrix but |
| 646 | // servedInstance is not in listInstances(package@x.z::interface) |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 647 | bool VintfObject::IsInstanceDeprecated(const MatrixInstance& oldMatrixInstance, |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 648 | const CompatibilityMatrix& targetMatrix, |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 649 | const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 650 | const std::string& package = oldMatrixInstance.package(); |
| 651 | const Version& version = oldMatrixInstance.versionRange().minVer(); |
| 652 | const std::string& interface = oldMatrixInstance.interface(); |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 653 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 654 | std::vector<std::string> instanceHint; |
| 655 | if (!oldMatrixInstance.isRegex()) { |
| 656 | instanceHint.push_back(oldMatrixInstance.exactInstance()); |
| 657 | } |
| 658 | |
| 659 | auto list = listInstances(package, version, interface, instanceHint); |
| 660 | for (const auto& pair : list) { |
| 661 | const std::string& servedInstance = pair.first; |
| 662 | Version servedVersion = pair.second; |
| 663 | if (!oldMatrixInstance.matchInstance(servedInstance)) { |
| 664 | continue; |
| 665 | } |
| 666 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 667 | // Find any package@x.? in target matrix, and check if instance is in target matrix. |
Yifan Hong | 217f47e | 2018-03-15 12:34:05 -0700 | [diff] [blame] | 668 | bool foundInstance = false; |
| 669 | Version targetMatrixMinVer; |
Yifan Hong | 0b1916f | 2019-09-10 19:04:52 -0700 | [diff] [blame] | 670 | targetMatrix.forEachHidlInstanceOfPackage(package, [&](const auto& targetMatrixInstance) { |
Yifan Hong | 217f47e | 2018-03-15 12:34:05 -0700 | [diff] [blame] | 671 | if (targetMatrixInstance.versionRange().majorVer == version.majorVer && |
| 672 | targetMatrixInstance.interface() == interface && |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 673 | targetMatrixInstance.matchInstance(servedInstance)) { |
Yifan Hong | 217f47e | 2018-03-15 12:34:05 -0700 | [diff] [blame] | 674 | targetMatrixMinVer = targetMatrixInstance.versionRange().minVer(); |
| 675 | foundInstance = true; |
| 676 | } |
| 677 | return !foundInstance; // continue if not found |
| 678 | }); |
| 679 | if (!foundInstance) { |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 680 | if (error) { |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 681 | *error = toFQNameString(package, servedVersion, interface, servedInstance) + |
Steven Moreland | a1b984c | 2018-03-09 13:09:15 -0800 | [diff] [blame] | 682 | " is deprecated in compatibility matrix at FCM Version " + |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 683 | to_string(targetMatrix.level()) + "; it should not be served."; |
| 684 | } |
| 685 | return true; |
| 686 | } |
| 687 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 688 | // Assuming that targetMatrix requires @x.u-v, require that at least @x.u is served. |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 689 | bool targetVersionServed = false; |
| 690 | for (const auto& newPair : |
| 691 | listInstances(package, targetMatrixMinVer, interface, instanceHint)) { |
| 692 | if (newPair.first == servedInstance) { |
| 693 | targetVersionServed = true; |
| 694 | break; |
| 695 | } |
| 696 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 697 | |
| 698 | if (!targetVersionServed) { |
Yifan Hong | 9f8f656 | 2018-11-06 16:26:20 -0800 | [diff] [blame] | 699 | appendLine(error, toFQNameString(package, servedVersion, interface, servedInstance) + |
| 700 | " is deprecated; requires at least " + |
| 701 | to_string(targetMatrixMinVer)); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 702 | return true; |
| 703 | } |
| 704 | } |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 705 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 706 | return false; |
| 707 | } |
| 708 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 709 | int32_t VintfObject::CheckDeprecation(const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 710 | return GetInstance()->checkDeprecation(listInstances, error); |
| 711 | } |
| 712 | int32_t VintfObject::checkDeprecation(const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 713 | std::vector<Named<CompatibilityMatrix>> matrixFragments; |
| 714 | auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error); |
| 715 | if (matrixFragmentsStatus != OK) { |
| 716 | return matrixFragmentsStatus; |
| 717 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 718 | if (matrixFragments.empty()) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 719 | if (error && error->empty()) { |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 720 | *error = "Cannot get framework matrix for each FCM version for unknown error."; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 721 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 722 | return NAME_NOT_FOUND; |
| 723 | } |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 724 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 725 | if (deviceManifest == nullptr) { |
| 726 | if (error) *error = "No device manifest."; |
| 727 | return NAME_NOT_FOUND; |
| 728 | } |
| 729 | Level deviceLevel = deviceManifest->level(); |
| 730 | if (deviceLevel == Level::UNSPECIFIED) { |
| 731 | if (error) *error = "Device manifest does not specify Shipping FCM Version."; |
| 732 | return BAD_VALUE; |
| 733 | } |
| 734 | |
| 735 | const CompatibilityMatrix* targetMatrix = nullptr; |
| 736 | for (const auto& namedMatrix : matrixFragments) { |
| 737 | if (namedMatrix.object.level() == deviceLevel) { |
| 738 | targetMatrix = &namedMatrix.object; |
| 739 | } |
| 740 | } |
| 741 | if (targetMatrix == nullptr) { |
| 742 | if (error) |
| 743 | *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + "."; |
| 744 | return NAME_NOT_FOUND; |
| 745 | } |
| 746 | |
| 747 | bool hasDeprecatedHals = false; |
| 748 | for (const auto& namedMatrix : matrixFragments) { |
| 749 | if (namedMatrix.object.level() == Level::UNSPECIFIED) continue; |
| 750 | if (namedMatrix.object.level() >= deviceLevel) continue; |
| 751 | |
| 752 | const auto& oldMatrix = namedMatrix.object; |
| 753 | for (const MatrixHal& hal : oldMatrix.getHals()) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 754 | hasDeprecatedHals |= IsHalDeprecated(hal, *targetMatrix, listInstances, error); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | |
| 758 | return hasDeprecatedHals ? DEPRECATED : NO_DEPRECATED_HALS; |
| 759 | } |
| 760 | |
| 761 | int32_t VintfObject::CheckDeprecation(std::string* error) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 762 | return GetInstance()->checkDeprecation(error); |
| 763 | } |
| 764 | int32_t VintfObject::checkDeprecation(std::string* error) { |
Yifan Hong | 2a90ffe | 2018-03-05 17:45:34 -0800 | [diff] [blame] | 765 | using namespace std::placeholders; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 766 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 767 | ListInstances inManifest = |
| 768 | [&deviceManifest](const std::string& package, Version version, const std::string& interface, |
| 769 | const std::vector<std::string>& /* hintInstances */) { |
| 770 | std::vector<std::pair<std::string, Version>> ret; |
| 771 | deviceManifest->forEachInstanceOfInterface( |
Yifan Hong | ac62148 | 2019-09-10 19:27:20 -0700 | [diff] [blame] | 772 | HalFormat::HIDL, package, version, interface, |
| 773 | [&ret](const ManifestInstance& manifestInstance) { |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 774 | ret.push_back( |
| 775 | std::make_pair(manifestInstance.instance(), manifestInstance.version())); |
| 776 | return true; |
| 777 | }); |
| 778 | return ret; |
| 779 | }; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 780 | return checkDeprecation(inManifest, error); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 781 | } |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 782 | |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 783 | Level VintfObject::getKernelLevel(std::string* error) { |
| 784 | auto manifest = getDeviceHalManifest(); |
| 785 | if (!manifest) { |
| 786 | if (error) *error = "Cannot retrieve device manifest."; |
| 787 | return Level::UNSPECIFIED; |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 788 | } |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 789 | if (manifest->kernel().has_value() && manifest->kernel()->level() != Level::UNSPECIFIED) { |
| 790 | return manifest->kernel()->level(); |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 791 | } |
Yifan Hong | 378c408 | 2019-12-23 13:10:57 -0800 | [diff] [blame] | 792 | if (error) *error = "Device manifest does not specify kernel FCM version."; |
| 793 | return Level::UNSPECIFIED; |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 796 | const std::unique_ptr<FileSystem>& VintfObject::getFileSystem() { |
| 797 | return mFileSystem; |
| 798 | } |
| 799 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 800 | const std::unique_ptr<PropertyFetcher>& VintfObject::getPropertyFetcher() { |
| 801 | return mPropertyFetcher; |
| 802 | } |
| 803 | |
Yifan Hong | d038b2b | 2018-11-27 13:57:56 -0800 | [diff] [blame] | 804 | const std::unique_ptr<ObjectFactory<RuntimeInfo>>& VintfObject::getRuntimeInfoFactory() { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 805 | return mRuntimeInfoFactory; |
Yifan Hong | 10d8622 | 2018-04-06 15:41:05 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Yifan Hong | 78f5b57 | 2018-11-27 14:05:03 -0800 | [diff] [blame] | 808 | // make_unique does not work because VintfObject constructor is private. |
| 809 | VintfObject::Builder::Builder() : mObject(std::unique_ptr<VintfObject>(new VintfObject())) {} |
| 810 | |
| 811 | VintfObject::Builder& VintfObject::Builder::setFileSystem(std::unique_ptr<FileSystem>&& e) { |
| 812 | mObject->mFileSystem = std::move(e); |
| 813 | return *this; |
| 814 | } |
| 815 | |
| 816 | VintfObject::Builder& VintfObject::Builder::setRuntimeInfoFactory( |
| 817 | std::unique_ptr<ObjectFactory<RuntimeInfo>>&& e) { |
| 818 | mObject->mRuntimeInfoFactory = std::move(e); |
| 819 | return *this; |
| 820 | } |
| 821 | |
| 822 | VintfObject::Builder& VintfObject::Builder::setPropertyFetcher( |
| 823 | std::unique_ptr<PropertyFetcher>&& e) { |
| 824 | mObject->mPropertyFetcher = std::move(e); |
| 825 | return *this; |
| 826 | } |
| 827 | |
| 828 | std::unique_ptr<VintfObject> VintfObject::Builder::build() { |
| 829 | if (!mObject->mFileSystem) mObject->mFileSystem = createDefaultFileSystem(); |
| 830 | if (!mObject->mRuntimeInfoFactory) |
| 831 | mObject->mRuntimeInfoFactory = std::make_unique<ObjectFactory<RuntimeInfo>>(); |
| 832 | if (!mObject->mPropertyFetcher) mObject->mPropertyFetcher = createDefaultPropertyFetcher(); |
| 833 | return std::move(mObject); |
| 834 | } |
| 835 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 836 | } // namespace vintf |
| 837 | } // namespace android |