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 #ifndef ANDROID_VINTF_VINTF_OBJECT_H_ 18 #define ANDROID_VINTF_VINTF_OBJECT_H_ 19 20 #include "CompatibilityMatrix.h" 21 #include "HalManifest.h" 22 #include "RuntimeInfo.h" 23 24 namespace android { 25 namespace vintf { 26 /* 27 * The top level class for libvintf. 28 * An overall diagram of the public API: 29 * VintfObject 30 * + GetDeviceHalManfiest 31 * | + getTransport 32 * | + getSupportedVersions 33 * | + checkIncompatibility 34 * + GetFrameworkHalManifest 35 * | + getTransport 36 * | + getSupportedVersions 37 * | + checkIncompatibility 38 * + GetRuntimeInfo 39 * + checkCompatibility 40 * 41 * Each of the function gathers all information and encapsulate it into the object. 42 * If no error, it return the same singleton object in the future, and the HAL manifest 43 * file won't be touched again. 44 * If any error, nullptr is returned, and Get will try to parse the HAL manifest 45 * again when it is called again. 46 * All these operations are thread-safe. 47 * If skipCache, always skip the cache in memory and read the files / get runtime information 48 * again from the device. 49 */ 50 class VintfObject { 51 public: 52 /* 53 * Return the API that access the device-side HAL manifest stored 54 * in /vendor/manifest.xml. 55 */ 56 static const HalManifest *GetDeviceHalManifest(bool skipCache = false); 57 58 /* 59 * Return the API that access the framework-side HAL manifest stored 60 * in /system/manfiest.xml. 61 */ 62 static const HalManifest *GetFrameworkHalManifest(bool skipCache = false); 63 64 /* 65 * Return the API that access the device-side compatibility matrix stored 66 * in /vendor/compatibility_matrix.xml. 67 */ 68 static const CompatibilityMatrix *GetDeviceCompatibilityMatrix(bool skipCache = false); 69 70 /* 71 * Return the API that access the device-side compatibility matrix stored 72 * in /system/compatibility_matrix.xml. 73 */ 74 static const CompatibilityMatrix *GetFrameworkCompatibilityMatrix(bool skipCache = false); 75 76 /* 77 * Return the API that access device runtime info. 78 */ 79 static const RuntimeInfo *GetRuntimeInfo(bool skipCache = false); 80 81 /** 82 * Check compatibility, given a set of manifests / matrices in packageInfo. 83 * They will be checked against the manifests / matrices on the device. 84 * 85 * @param packageInfo a list of XMLs of HalManifest / 86 * CompatibilityMatrix objects. 87 * 88 * @return = 0 if success (compatible) 89 * > 0 if incompatible 90 * < 0 if any error (mount partition fails, illformed XML, etc.) 91 */ 92 static int32_t CheckCompatibility( 93 const std::vector<std::string> &packageInfo, 94 std::string *error = nullptr); 95 }; 96 97 enum : int32_t { 98 COMPATIBLE = 0, 99 INCOMPATIBLE = 1, 100 }; 101 102 // exposed for testing and VintfObjectRecovery. 103 namespace details { 104 class PartitionMounter; 105 int32_t checkCompatibility(const std::vector<std::string> &xmls, bool mount, 106 const PartitionMounter& partitionMounter, 107 std::string *error); 108 } // namespace details 109 110 } // namespace vintf 111 } // namespace android 112 113 #endif // ANDROID_VINTF_VINTF_OBJECT_H_ 114