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