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> |
| 26 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 27 | #include "CompatibilityMatrix.h" |
| 28 | #include "VintfObjectAfterUpdate.h" |
| 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: |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 230 | // 1. /vendor/etc/vintf/manifest.xml + device fragments + ODM manifest (optional) + odm fragments |
| 231 | // 2. /vendor/etc/vintf/manifest.xml + device fragments |
| 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) { |
| 238 | status_t vendorStatus = fetchOneHalManifest(kVendorManifest, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 239 | if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) { |
| 240 | return vendorStatus; |
| 241 | } |
| 242 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 243 | if (vendorStatus == OK) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 244 | status_t fragmentStatus = addDirectoryManifests(kVendorManifestFragmentDir, out, error); |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 245 | if (fragmentStatus != OK) { |
| 246 | return fragmentStatus; |
| 247 | } |
| 248 | } |
| 249 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 250 | HalManifest odmManifest; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 251 | status_t odmStatus = fetchOdmHalManifest(&odmManifest, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 252 | if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) { |
| 253 | return odmStatus; |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 256 | if (vendorStatus == OK) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 257 | if (odmStatus == OK) { |
Yifan Hong | 4c6962d | 2019-01-30 15:50:46 -0800 | [diff] [blame] | 258 | if (!out->addAll(&odmManifest, error)) { |
| 259 | if (error) { |
| 260 | error->insert(0, "Cannot add ODM manifest :"); |
| 261 | } |
| 262 | return UNKNOWN_ERROR; |
| 263 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 264 | } |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 265 | return addDirectoryManifests(kOdmManifestFragmentDir, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 268 | // vendorStatus != OK, "out" is not changed. |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 269 | if (odmStatus == OK) { |
| 270 | *out = std::move(odmManifest); |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 271 | return addDirectoryManifests(kOdmManifestFragmentDir, out, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | // Use legacy /vendor/manifest.xml |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 275 | return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyManifest, error); |
Yifan Hong | 5a93bf2 | 2018-01-17 18:22:32 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 278 | // "out" is written to iff return status is OK. |
| 279 | // Priority: |
| 280 | // 1. if {sku} is defined, /odm/etc/vintf/manifest_{sku}.xml |
| 281 | // 2. /odm/etc/vintf/manifest.xml |
| 282 | // 3. if {sku} is defined, /odm/etc/manifest_{sku}.xml |
| 283 | // 4. /odm/etc/manifest.xml |
| 284 | // where: |
| 285 | // {sku} is the value of ro.boot.product.hardware.sku |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 286 | status_t VintfObject::fetchOdmHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 287 | status_t status; |
| 288 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 289 | std::string productModel; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 290 | productModel = getPropertyFetcher()->getProperty("ro.boot.product.hardware.sku", ""); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 291 | |
| 292 | if (!productModel.empty()) { |
| 293 | status = |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 294 | fetchOneHalManifest(kOdmVintfDir + "manifest_" + productModel + ".xml", out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 295 | if (status == OK || status != NAME_NOT_FOUND) { |
| 296 | return status; |
| 297 | } |
| 298 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 299 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 300 | status = fetchOneHalManifest(kOdmManifest, out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 301 | if (status == OK || status != NAME_NOT_FOUND) { |
| 302 | return status; |
| 303 | } |
| 304 | |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 305 | if (!productModel.empty()) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 306 | status = fetchOneHalManifest(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", out, |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 307 | error); |
| 308 | if (status == OK || status != NAME_NOT_FOUND) { |
| 309 | return status; |
| 310 | } |
| 311 | } |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 312 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 313 | status = fetchOneHalManifest(kOdmLegacyManifest, out, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 314 | if (status == OK || status != NAME_NOT_FOUND) { |
| 315 | return status; |
| 316 | } |
| 317 | |
| 318 | return NAME_NOT_FOUND; |
| 319 | } |
| 320 | |
| 321 | // Fetch one manifest.xml file. "out" is written to iff return status is OK. |
| 322 | // Returns NAME_NOT_FOUND if file is missing. |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 323 | status_t VintfObject::fetchOneHalManifest(const std::string& path, HalManifest* out, |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 324 | std::string* error) { |
| 325 | HalManifest ret; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 326 | status_t status = ret.fetchAllInformation(getFileSystem().get(), path, error); |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 327 | if (status == OK) { |
| 328 | *out = std::move(ret); |
| 329 | } |
| 330 | return status; |
| 331 | } |
| 332 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 333 | status_t VintfObject::fetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) { |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 334 | CompatibilityMatrix etcMatrix; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 335 | if (etcMatrix.fetchAllInformation(getFileSystem().get(), kVendorMatrix, error) == OK) { |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 336 | *out = std::move(etcMatrix); |
| 337 | return OK; |
| 338 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 339 | return out->fetchAllInformation(getFileSystem().get(), kVendorLegacyMatrix, error); |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 342 | // Priority: |
| 343 | // 1. /system/etc/vintf/manifest.xml |
| 344 | // + /system/etc/vintf/manifest/*.xml if they exist |
| 345 | // + /product/etc/vintf/manifest.xml if it exists |
| 346 | // + /product/etc/vintf/manifest/*.xml if they exist |
| 347 | // 2. (deprecated) /system/manifest.xml |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 348 | status_t VintfObject::fetchFrameworkHalManifest(HalManifest* out, std::string* error) { |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 349 | auto systemEtcStatus = fetchOneHalManifest(kSystemManifest, out, error); |
| 350 | if (systemEtcStatus == OK) { |
| 351 | auto dirStatus = addDirectoryManifests(kSystemManifestFragmentDir, out, error); |
| 352 | if (dirStatus != OK) { |
| 353 | return dirStatus; |
| 354 | } |
| 355 | |
| 356 | HalManifest productManifest; |
| 357 | auto productStatus = fetchOneHalManifest(kProductManifest, &productManifest, error); |
| 358 | if (productStatus != OK && productStatus != NAME_NOT_FOUND) { |
| 359 | return productStatus; |
| 360 | } |
| 361 | if (productStatus == OK) { |
| 362 | if (!out->addAll(&productManifest, error)) { |
| 363 | if (error) { |
| 364 | error->insert(0, "Cannot add " + kProductManifest + ":"); |
| 365 | } |
| 366 | return UNKNOWN_ERROR; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | return addDirectoryManifests(kProductManifestFragmentDir, out, error); |
| 371 | } else { |
| 372 | LOG(WARNING) << "Cannot fetch " << kSystemManifest << ": " |
| 373 | << (error ? *error : strerror(-systemEtcStatus)); |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 374 | } |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 375 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 376 | return out->fetchAllInformation(getFileSystem().get(), kSystemLegacyManifest, error); |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Yifan Hong | 9f8f656 | 2018-11-06 16:26:20 -0800 | [diff] [blame] | 379 | static void appendLine(std::string* error, const std::string& message) { |
| 380 | if (error != nullptr) { |
| 381 | if (!error->empty()) *error += "\n"; |
| 382 | *error += message; |
| 383 | } |
| 384 | } |
| 385 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 386 | status_t VintfObject::getOneMatrix(const std::string& path, Named<CompatibilityMatrix>* out, |
| 387 | std::string* error) { |
| 388 | std::string content; |
| 389 | status_t status = getFileSystem()->fetch(path, &content, error); |
| 390 | if (status != OK) { |
| 391 | return status; |
| 392 | } |
| 393 | if (!gCompatibilityMatrixConverter(&out->object, content, error)) { |
| 394 | if (error) { |
| 395 | error->insert(0, "Cannot parse " + path + ": "); |
| 396 | } |
| 397 | return BAD_VALUE; |
| 398 | } |
| 399 | out->name = path; |
| 400 | return OK; |
| 401 | } |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 402 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 403 | status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<Named<CompatibilityMatrix>>* results, |
| 404 | std::string* error) { |
| 405 | std::vector<std::string> fileNames; |
| 406 | |
| 407 | status_t listStatus = getFileSystem()->listFiles(kSystemVintfDir, &fileNames, error); |
| 408 | if (listStatus != OK) { |
| 409 | return listStatus; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 410 | } |
| 411 | for (const std::string& fileName : fileNames) { |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 412 | std::string path = kSystemVintfDir + fileName; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 413 | Named<CompatibilityMatrix> namedMatrix; |
| 414 | std::string matrixError; |
| 415 | status_t matrixStatus = getOneMatrix(path, &namedMatrix, &matrixError); |
| 416 | if (matrixStatus != OK) { |
| 417 | // System manifests and matrices share the same dir. Client may not have enough |
| 418 | // permissions to read system manifests, or may not be able to parse it. |
| 419 | auto logLevel = matrixStatus == BAD_VALUE ? base::DEBUG : base::ERROR; |
| 420 | LOG(logLevel) << "Framework Matrix: Ignore file " << path << ": " << matrixError; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 421 | continue; |
| 422 | } |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 423 | results->emplace_back(std::move(namedMatrix)); |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 426 | Named<CompatibilityMatrix> productMatrix; |
| 427 | std::string productError; |
| 428 | status_t productStatus = getOneMatrix(kProductMatrix, &productMatrix, &productError); |
| 429 | if (productStatus == OK) { |
| 430 | results->emplace_back(std::move(productMatrix)); |
| 431 | } else if (productStatus == NAME_NOT_FOUND) { |
| 432 | LOG(DEBUG) << "Framework Matrix: missing " << kProductMatrix; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 433 | } else { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 434 | if (error) *error = std::move(productError); |
| 435 | return productStatus; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 438 | if (results->empty()) { |
| 439 | if (error) { |
| 440 | *error = |
| 441 | "No framework matrices under " + kSystemVintfDir + " can be fetched or parsed.\n"; |
| 442 | } |
| 443 | return NAME_NOT_FOUND; |
| 444 | } |
| 445 | return OK; |
Yifan Hong | d52bf3e | 2018-01-11 16:56:51 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 448 | std::shared_ptr<const RuntimeInfo> VintfObject::GetRuntimeInfo(bool skipCache, |
| 449 | RuntimeInfo::FetchFlags flags) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 450 | return GetInstance()->getRuntimeInfo(skipCache, flags); |
| 451 | } |
| 452 | std::shared_ptr<const RuntimeInfo> VintfObject::getRuntimeInfo(bool skipCache, |
| 453 | RuntimeInfo::FetchFlags flags) { |
| 454 | std::unique_lock<std::mutex> _lock(mDeviceRuntimeInfo.mutex); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 455 | |
| 456 | if (!skipCache) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 457 | flags &= (~mDeviceRuntimeInfo.fetchedFlags); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 460 | if (mDeviceRuntimeInfo.object == nullptr) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 461 | mDeviceRuntimeInfo.object = getRuntimeInfoFactory()->make_shared(); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 464 | status_t status = mDeviceRuntimeInfo.object->fetchAllInformation(flags); |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 465 | if (status != OK) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 466 | mDeviceRuntimeInfo.fetchedFlags &= (~flags); // mark the fields as "not fetched" |
Yifan Hong | 1fb004e | 2017-09-26 15:04:44 -0700 | [diff] [blame] | 467 | return nullptr; |
| 468 | } |
| 469 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 470 | mDeviceRuntimeInfo.fetchedFlags |= flags; |
| 471 | return mDeviceRuntimeInfo.object; |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 474 | namespace details { |
| 475 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 476 | enum class ParseStatus { |
| 477 | OK, |
| 478 | PARSE_ERROR, |
| 479 | DUPLICATED_FWK_ENTRY, |
| 480 | DUPLICATED_DEV_ENTRY, |
| 481 | }; |
| 482 | |
Yifan Hong | 9532bd2 | 2017-04-14 15:30:52 -0700 | [diff] [blame] | 483 | static std::string toString(ParseStatus status) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 484 | switch(status) { |
| 485 | case ParseStatus::OK: return "OK"; |
| 486 | case ParseStatus::PARSE_ERROR: return "parse error"; |
| 487 | case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework"; |
| 488 | case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device"; |
| 489 | } |
| 490 | return ""; |
| 491 | } |
| 492 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 493 | template <typename T> |
| 494 | static ParseStatus tryParse(const std::string& xml, const XmlConverter<T>& parse, |
| 495 | VintfObjectAfterUpdate* afterUpdate) { |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 496 | std::shared_ptr<T> ret = std::make_shared<T>(); |
Yifan Hong | 9475706 | 2018-02-09 16:36:31 -0800 | [diff] [blame] | 497 | if (!parse(ret.get(), xml, nullptr /* error */)) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 498 | return ParseStatus::PARSE_ERROR; |
| 499 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 500 | if (!afterUpdate->set(ret)) { |
| 501 | if (ret->type() == SchemaType::FRAMEWORK) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 502 | return ParseStatus::DUPLICATED_FWK_ENTRY; |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 503 | } else if (ret->type() == SchemaType::DEVICE) { |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 504 | return ParseStatus::DUPLICATED_DEV_ENTRY; |
| 505 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 506 | LOG(FATAL) << "unknown SchemaType: " |
| 507 | << static_cast<std::underlying_type_t<SchemaType>>(ret->type()); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 508 | } |
| 509 | return ParseStatus::OK; |
| 510 | } |
| 511 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 512 | } // namespace details |
| 513 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 514 | // Simulate applying xmls to VintfObject, then checkCompatibility as usual. |
Yifan Hong | af3713e | 2018-11-05 13:59:18 -0800 | [diff] [blame] | 515 | int32_t VintfObject::checkCompatibility(const std::vector<std::string>& xmls, std::string* error, |
| 516 | CheckFlags::Type flags) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 517 | VintfObjectAfterUpdate afterUpdate(this); |
| 518 | ParseStatus parseStatus = ParseStatus::OK; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 519 | |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 520 | // parse all information from package |
| 521 | for (const auto &xml : xmls) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 522 | parseStatus = tryParse(xml, gHalManifestConverter, &afterUpdate); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 523 | if (parseStatus == ParseStatus::OK) { |
| 524 | continue; // work on next one |
| 525 | } |
| 526 | if (parseStatus != ParseStatus::PARSE_ERROR) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 527 | appendLine(error, toString(parseStatus) + " manifest"); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 528 | return ALREADY_EXISTS; |
| 529 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 530 | parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &afterUpdate); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 531 | if (parseStatus == ParseStatus::OK) { |
| 532 | continue; // work on next one |
| 533 | } |
| 534 | if (parseStatus != ParseStatus::PARSE_ERROR) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 535 | appendLine(error, toString(parseStatus) + " matrix"); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 536 | return ALREADY_EXISTS; |
| 537 | } |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 538 | appendLine(error, toString(parseStatus)); // parse error |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 539 | return BAD_VALUE; |
| 540 | } |
| 541 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 542 | return afterUpdate.checkCompatibility(error, flags); |
| 543 | } |
Yifan Hong | 8640cd1 | 2017-05-17 12:02:28 -0700 | [diff] [blame] | 544 | |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 545 | int32_t VintfObject::checkCompatibility(std::string* error, CheckFlags::Type flags) { |
| 546 | status_t status = OK; |
| 547 | // null checks for files and runtime info |
| 548 | if (getFrameworkHalManifest() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 549 | appendLine(error, "No framework manifest file from device or from update package"); |
| 550 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 551 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 552 | if (getDeviceHalManifest() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 553 | appendLine(error, "No device manifest file from device or from update package"); |
| 554 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 555 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 556 | if (getFrameworkCompatibilityMatrix() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 557 | appendLine(error, "No framework matrix file from device or from update package"); |
| 558 | status = NO_INIT; |
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 (getDeviceCompatibilityMatrix() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 561 | appendLine(error, "No device matrix file from device or from update package"); |
| 562 | status = NO_INIT; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 563 | } |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 564 | |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 565 | if (flags.isRuntimeInfoEnabled()) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 566 | if (getRuntimeInfo() == nullptr) { |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 567 | appendLine(error, "No runtime info from device"); |
| 568 | status = NO_INIT; |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 569 | } |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 570 | } |
Yifan Hong | 878556e | 2018-07-13 13:45:30 -0700 | [diff] [blame] | 571 | if (status != OK) return status; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 572 | |
| 573 | // compatiblity check. |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 574 | if (!getDeviceHalManifest()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error)) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 575 | if (error) { |
| 576 | error->insert(0, |
| 577 | "Device manifest and framework compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 578 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 579 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 580 | } |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 581 | if (!getFrameworkHalManifest()->checkCompatibility(*getDeviceCompatibilityMatrix(), error)) { |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 582 | if (error) { |
| 583 | error->insert(0, |
| 584 | "Framework manifest and device compatibility matrix are incompatible: "); |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 585 | } |
Yifan Hong | ca386fe | 2018-02-07 11:29:03 -0800 | [diff] [blame] | 586 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 587 | } |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 588 | |
Yifan Hong | 40b7e62 | 2019-01-29 12:27:42 -0800 | [diff] [blame] | 589 | CheckFlags::Type runtimeInfoCheckFlags = flags; |
| 590 | if (!!getDeviceHalManifest()->kernel()) { |
| 591 | // Use kernel from incoming OTA package, but not on the device. |
| 592 | runtimeInfoCheckFlags = runtimeInfoCheckFlags.disableKernel(); |
| 593 | } |
| 594 | |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 595 | if (flags.isRuntimeInfoEnabled()) { |
Yifan Hong | 12e23c2 | 2018-11-05 14:53:30 -0800 | [diff] [blame] | 596 | if (!getRuntimeInfo()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error, |
Yifan Hong | 40b7e62 | 2019-01-29 12:27:42 -0800 | [diff] [blame] | 597 | runtimeInfoCheckFlags)) { |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 598 | if (error) { |
| 599 | error->insert(0, |
| 600 | "Runtime info and framework compatibility matrix are incompatible: "); |
| 601 | } |
| 602 | return INCOMPATIBLE; |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | return COMPATIBLE; |
| 607 | } |
| 608 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 609 | namespace details { |
| 610 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 611 | const std::string kSystemVintfDir = "/system/etc/vintf/"; |
Yifan Hong | ccbea05 | 2018-01-18 18:48:46 -0800 | [diff] [blame] | 612 | const std::string kVendorVintfDir = "/vendor/etc/vintf/"; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 613 | const std::string kOdmVintfDir = "/odm/etc/vintf/"; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 614 | const std::string kProductVintfDir = "/product/etc/vintf/"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 615 | |
| 616 | const std::string kVendorManifest = kVendorVintfDir + "manifest.xml"; |
Yifan Hong | a5ddddf | 2018-01-18 18:50:13 -0800 | [diff] [blame] | 617 | const std::string kSystemManifest = kSystemVintfDir + "manifest.xml"; |
Yifan Hong | b64ec9e | 2018-01-18 18:57:52 -0800 | [diff] [blame] | 618 | const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml"; |
Yifan Hong | 12a11ac | 2018-01-19 13:58:32 -0800 | [diff] [blame] | 619 | const std::string kOdmManifest = kOdmVintfDir + "manifest.xml"; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 620 | const std::string kProductMatrix = kProductVintfDir + "compatibility_matrix.xml"; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 621 | const std::string kProductManifest = kProductVintfDir + "manifest.xml"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 622 | |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 623 | const std::string kVendorManifestFragmentDir = kVendorVintfDir + "manifest/"; |
| 624 | const std::string kSystemManifestFragmentDir = kSystemVintfDir + "manifest/"; |
| 625 | const std::string kOdmManifestFragmentDir = kOdmVintfDir + "manifest/"; |
Yifan Hong | 5f4e57e | 2019-04-23 15:16:25 -0700 | [diff] [blame] | 626 | const std::string kProductManifestFragmentDir = kProductVintfDir + "manifest/"; |
Steven Moreland | eedf2d4 | 2018-04-04 16:36:27 -0700 | [diff] [blame] | 627 | |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 628 | const std::string kVendorLegacyManifest = "/vendor/manifest.xml"; |
| 629 | const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml"; |
Yifan Hong | de6d00e | 2018-02-27 17:11:28 -0800 | [diff] [blame] | 630 | const std::string kSystemLegacyManifest = "/system/manifest.xml"; |
Yifan Hong | 270b565 | 2018-01-18 18:46:01 -0800 | [diff] [blame] | 631 | const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml"; |
| 632 | const std::string kOdmLegacyVintfDir = "/odm/etc/"; |
| 633 | const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml"; |
| 634 | |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 635 | std::vector<std::string> dumpFileList() { |
| 636 | return { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 637 | // clang-format off |
| 638 | kSystemVintfDir, |
| 639 | kVendorVintfDir, |
| 640 | kOdmVintfDir, |
| 641 | kProductVintfDir, |
| 642 | kOdmLegacyVintfDir, |
| 643 | kVendorLegacyManifest, |
| 644 | kVendorLegacyMatrix, |
| 645 | kSystemLegacyManifest, |
| 646 | kSystemLegacyMatrix, |
| 647 | // clang-format on |
Yifan Hong | 69c1b11 | 2018-02-27 17:06:00 -0800 | [diff] [blame] | 648 | }; |
| 649 | } |
| 650 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 651 | } // namespace details |
Yifan Hong | 143cfe6 | 2017-04-13 20:18:01 -0700 | [diff] [blame] | 652 | |
Yifan Hong | db6423e | 2017-09-11 14:38:46 -0700 | [diff] [blame] | 653 | int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error, |
Yifan Hong | 072f12d | 2018-08-08 13:04:51 -0700 | [diff] [blame] | 654 | CheckFlags::Type flags) { |
| 655 | return GetInstance()->checkCompatibility(xmls, error, flags); |
Yifan Hong | fbbf047 | 2017-04-07 18:14:18 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 658 | bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal, |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 659 | const CompatibilityMatrix& targetMatrix, |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 660 | const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 661 | bool isDeprecated = false; |
| 662 | oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 663 | if (IsInstanceDeprecated(oldMatrixInstance, targetMatrix, listInstances, error)) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 664 | isDeprecated = true; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 665 | } |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 666 | return !isDeprecated; // continue if no deprecated instance is found. |
| 667 | }); |
| 668 | return isDeprecated; |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 671 | // Let oldMatrixInstance = package@x.y-w::interface with instancePattern. |
| 672 | // If any "servedInstance" in listInstances(package@x.y::interface) matches instancePattern, return |
| 673 | // true iff: |
| 674 | // 1. package@x.?::interface/servedInstance is not in targetMatrix; OR |
| 675 | // 2. package@x.z::interface/servedInstance is in targetMatrix but |
| 676 | // servedInstance is not in listInstances(package@x.z::interface) |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 677 | bool VintfObject::IsInstanceDeprecated(const MatrixInstance& oldMatrixInstance, |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 678 | const CompatibilityMatrix& targetMatrix, |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 679 | const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 680 | const std::string& package = oldMatrixInstance.package(); |
| 681 | const Version& version = oldMatrixInstance.versionRange().minVer(); |
| 682 | const std::string& interface = oldMatrixInstance.interface(); |
Yifan Hong | 7e9e04d | 2018-03-20 13:06:00 -0700 | [diff] [blame] | 683 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 684 | std::vector<std::string> instanceHint; |
| 685 | if (!oldMatrixInstance.isRegex()) { |
| 686 | instanceHint.push_back(oldMatrixInstance.exactInstance()); |
| 687 | } |
| 688 | |
| 689 | auto list = listInstances(package, version, interface, instanceHint); |
| 690 | for (const auto& pair : list) { |
| 691 | const std::string& servedInstance = pair.first; |
| 692 | Version servedVersion = pair.second; |
| 693 | if (!oldMatrixInstance.matchInstance(servedInstance)) { |
| 694 | continue; |
| 695 | } |
| 696 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 697 | // 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] | 698 | bool foundInstance = false; |
| 699 | Version targetMatrixMinVer; |
Yifan Hong | 0b1916f | 2019-09-10 19:04:52 -0700 | [diff] [blame] | 700 | targetMatrix.forEachHidlInstanceOfPackage(package, [&](const auto& targetMatrixInstance) { |
Yifan Hong | 217f47e | 2018-03-15 12:34:05 -0700 | [diff] [blame] | 701 | if (targetMatrixInstance.versionRange().majorVer == version.majorVer && |
| 702 | targetMatrixInstance.interface() == interface && |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 703 | targetMatrixInstance.matchInstance(servedInstance)) { |
Yifan Hong | 217f47e | 2018-03-15 12:34:05 -0700 | [diff] [blame] | 704 | targetMatrixMinVer = targetMatrixInstance.versionRange().minVer(); |
| 705 | foundInstance = true; |
| 706 | } |
| 707 | return !foundInstance; // continue if not found |
| 708 | }); |
| 709 | if (!foundInstance) { |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 710 | if (error) { |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 711 | *error = toFQNameString(package, servedVersion, interface, servedInstance) + |
Steven Moreland | a1b984c | 2018-03-09 13:09:15 -0800 | [diff] [blame] | 712 | " is deprecated in compatibility matrix at FCM Version " + |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 713 | to_string(targetMatrix.level()) + "; it should not be served."; |
| 714 | } |
| 715 | return true; |
| 716 | } |
| 717 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 718 | // 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] | 719 | bool targetVersionServed = false; |
| 720 | for (const auto& newPair : |
| 721 | listInstances(package, targetMatrixMinVer, interface, instanceHint)) { |
| 722 | if (newPair.first == servedInstance) { |
| 723 | targetVersionServed = true; |
| 724 | break; |
| 725 | } |
| 726 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 727 | |
| 728 | if (!targetVersionServed) { |
Yifan Hong | 9f8f656 | 2018-11-06 16:26:20 -0800 | [diff] [blame] | 729 | appendLine(error, toFQNameString(package, servedVersion, interface, servedInstance) + |
| 730 | " is deprecated; requires at least " + |
| 731 | to_string(targetMatrixMinVer)); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 732 | return true; |
| 733 | } |
| 734 | } |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 735 | |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 736 | return false; |
| 737 | } |
| 738 | |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 739 | int32_t VintfObject::CheckDeprecation(const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 740 | return GetInstance()->checkDeprecation(listInstances, error); |
| 741 | } |
| 742 | int32_t VintfObject::checkDeprecation(const ListInstances& listInstances, std::string* error) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 743 | std::vector<Named<CompatibilityMatrix>> matrixFragments; |
| 744 | auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error); |
| 745 | if (matrixFragmentsStatus != OK) { |
| 746 | return matrixFragmentsStatus; |
| 747 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 748 | if (matrixFragments.empty()) { |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 749 | if (error && error->empty()) { |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 750 | *error = "Cannot get framework matrix for each FCM version for unknown error."; |
Yifan Hong | 73bde59 | 2019-01-22 13:30:23 -0800 | [diff] [blame] | 751 | } |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 752 | return NAME_NOT_FOUND; |
| 753 | } |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 754 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 755 | if (deviceManifest == nullptr) { |
| 756 | if (error) *error = "No device manifest."; |
| 757 | return NAME_NOT_FOUND; |
| 758 | } |
| 759 | Level deviceLevel = deviceManifest->level(); |
| 760 | if (deviceLevel == Level::UNSPECIFIED) { |
| 761 | if (error) *error = "Device manifest does not specify Shipping FCM Version."; |
| 762 | return BAD_VALUE; |
| 763 | } |
| 764 | |
| 765 | const CompatibilityMatrix* targetMatrix = nullptr; |
| 766 | for (const auto& namedMatrix : matrixFragments) { |
| 767 | if (namedMatrix.object.level() == deviceLevel) { |
| 768 | targetMatrix = &namedMatrix.object; |
| 769 | } |
| 770 | } |
| 771 | if (targetMatrix == nullptr) { |
| 772 | if (error) |
| 773 | *error = "Cannot find framework matrix at FCM version " + to_string(deviceLevel) + "."; |
| 774 | return NAME_NOT_FOUND; |
| 775 | } |
| 776 | |
| 777 | bool hasDeprecatedHals = false; |
| 778 | for (const auto& namedMatrix : matrixFragments) { |
| 779 | if (namedMatrix.object.level() == Level::UNSPECIFIED) continue; |
| 780 | if (namedMatrix.object.level() >= deviceLevel) continue; |
| 781 | |
| 782 | const auto& oldMatrix = namedMatrix.object; |
| 783 | for (const MatrixHal& hal : oldMatrix.getHals()) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 784 | hasDeprecatedHals |= IsHalDeprecated(hal, *targetMatrix, listInstances, error); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | |
| 788 | return hasDeprecatedHals ? DEPRECATED : NO_DEPRECATED_HALS; |
| 789 | } |
| 790 | |
| 791 | int32_t VintfObject::CheckDeprecation(std::string* error) { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 792 | return GetInstance()->checkDeprecation(error); |
| 793 | } |
| 794 | int32_t VintfObject::checkDeprecation(std::string* error) { |
Yifan Hong | 2a90ffe | 2018-03-05 17:45:34 -0800 | [diff] [blame] | 795 | using namespace std::placeholders; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 796 | auto deviceManifest = getDeviceHalManifest(); |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 797 | ListInstances inManifest = |
| 798 | [&deviceManifest](const std::string& package, Version version, const std::string& interface, |
| 799 | const std::vector<std::string>& /* hintInstances */) { |
| 800 | std::vector<std::pair<std::string, Version>> ret; |
| 801 | deviceManifest->forEachInstanceOfInterface( |
Yifan Hong | ac62148 | 2019-09-10 19:27:20 -0700 | [diff] [blame^] | 802 | HalFormat::HIDL, package, version, interface, |
| 803 | [&ret](const ManifestInstance& manifestInstance) { |
Yifan Hong | a8a8fa9 | 2018-03-20 14:42:43 -0700 | [diff] [blame] | 804 | ret.push_back( |
| 805 | std::make_pair(manifestInstance.instance(), manifestInstance.version())); |
| 806 | return true; |
| 807 | }); |
| 808 | return ret; |
| 809 | }; |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 810 | return checkDeprecation(inManifest, error); |
Yifan Hong | f73ba51 | 2018-01-17 15:52:30 -0800 | [diff] [blame] | 811 | } |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 812 | |
Yifan Hong | 1e8febd | 2019-08-07 16:17:19 -0700 | [diff] [blame] | 813 | std::optional<KernelRequirement> VintfObject::getCompatibleKernelRequirement(std::string* error) { |
| 814 | auto matrix = getFrameworkCompatibilityMatrix(); |
| 815 | if (!matrix) { |
| 816 | if (error) *error = "Cannot retrieve framework compatibility matrix"; |
| 817 | return std::nullopt; |
| 818 | } |
| 819 | auto runtime_info = getRuntimeInfo(); |
| 820 | if (!runtime_info) { |
| 821 | if (error) *error = "Cannot retrieve runtime information"; |
| 822 | return std::nullopt; |
| 823 | } |
| 824 | auto reqs = |
| 825 | runtime_info->mKernel.getMatchedKernelRequirements(matrix->framework.mKernels, error); |
| 826 | if (reqs.empty()) { |
| 827 | if (error) error->insert(0, "Cannot find any matched kernel requirements: "); |
| 828 | return std::nullopt; |
| 829 | } |
| 830 | for (const MatrixKernel* matrixKernel : reqs) { |
| 831 | if (matrixKernel->conditions().empty()) { |
| 832 | return KernelRequirement(matrixKernel->minLts(), |
| 833 | matrix->getSourceMatrixLevel(matrixKernel)); |
| 834 | } |
| 835 | } |
| 836 | KernelRequirement ret(reqs[0]->minLts(), matrix->getSourceMatrixLevel(reqs[0])); |
| 837 | LOG(ERROR) << "Cannot find kernel requirement with empty conditions; " |
| 838 | << "this should not happen. Returning (" << ret.minLts() << ", " << ret.level() |
| 839 | << ") as a heuristic."; |
| 840 | return ret; |
| 841 | } |
| 842 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 843 | const std::unique_ptr<FileSystem>& VintfObject::getFileSystem() { |
| 844 | return mFileSystem; |
| 845 | } |
| 846 | |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 847 | const std::unique_ptr<PropertyFetcher>& VintfObject::getPropertyFetcher() { |
| 848 | return mPropertyFetcher; |
| 849 | } |
| 850 | |
Yifan Hong | d038b2b | 2018-11-27 13:57:56 -0800 | [diff] [blame] | 851 | const std::unique_ptr<ObjectFactory<RuntimeInfo>>& VintfObject::getRuntimeInfoFactory() { |
Yifan Hong | 9f78c18 | 2018-07-12 14:45:52 -0700 | [diff] [blame] | 852 | return mRuntimeInfoFactory; |
Yifan Hong | 10d8622 | 2018-04-06 15:41:05 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Yifan Hong | 78f5b57 | 2018-11-27 14:05:03 -0800 | [diff] [blame] | 855 | // make_unique does not work because VintfObject constructor is private. |
| 856 | VintfObject::Builder::Builder() : mObject(std::unique_ptr<VintfObject>(new VintfObject())) {} |
| 857 | |
| 858 | VintfObject::Builder& VintfObject::Builder::setFileSystem(std::unique_ptr<FileSystem>&& e) { |
| 859 | mObject->mFileSystem = std::move(e); |
| 860 | return *this; |
| 861 | } |
| 862 | |
| 863 | VintfObject::Builder& VintfObject::Builder::setRuntimeInfoFactory( |
| 864 | std::unique_ptr<ObjectFactory<RuntimeInfo>>&& e) { |
| 865 | mObject->mRuntimeInfoFactory = std::move(e); |
| 866 | return *this; |
| 867 | } |
| 868 | |
| 869 | VintfObject::Builder& VintfObject::Builder::setPropertyFetcher( |
| 870 | std::unique_ptr<PropertyFetcher>&& e) { |
| 871 | mObject->mPropertyFetcher = std::move(e); |
| 872 | return *this; |
| 873 | } |
| 874 | |
| 875 | std::unique_ptr<VintfObject> VintfObject::Builder::build() { |
| 876 | if (!mObject->mFileSystem) mObject->mFileSystem = createDefaultFileSystem(); |
| 877 | if (!mObject->mRuntimeInfoFactory) |
| 878 | mObject->mRuntimeInfoFactory = std::make_unique<ObjectFactory<RuntimeInfo>>(); |
| 879 | if (!mObject->mPropertyFetcher) mObject->mPropertyFetcher = createDefaultPropertyFetcher(); |
| 880 | return std::move(mObject); |
| 881 | } |
| 882 | |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 883 | } // namespace vintf |
| 884 | } // namespace android |