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