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