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