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