blob: f49e484c9a1be945b3be70e2e4468ad0fdb3f4b7 [file] [log] [blame]
Yifan Hong676447a2016-11-15 12:57:23 -08001/*
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 <iostream>
18#include <vintf/parse_xml.h>
Yifan Hongccf967b2017-01-18 11:04:19 -080019#include <vintf/parse_string.h>
Yifan Hong3daec812017-02-27 18:49:11 -080020#include <vintf/VintfObject.h>
Yifan Hong676447a2016-11-15 12:57:23 -080021
Yifan Hong3eed7e12018-01-25 11:22:52 -080022using namespace ::android::vintf;
23
24std::string existString(bool value) {
25 return value ? "GOOD" : "DOES NOT EXIST";
26}
27
28std::string compatibleString(int32_t value) {
29 switch (value) {
30 case COMPATIBLE:
31 return "GOOD";
32 case INCOMPATIBLE:
33 return "INCOMPATIBLE";
34 default:
35 return strerror(-value);
36 }
37}
38
39std::string boolCompatString(bool value) {
40 return compatibleString(value ? COMPATIBLE : INCOMPATIBLE);
41}
42
43std::string deprecateString(int32_t value) {
44 switch (value) {
45 case NO_DEPRECATED_HALS:
46 return "GOOD";
47 case DEPRECATED:
48 return "DEPRECATED";
49 default:
50 return strerror(-value);
51 }
52}
53
Yifan Hong1e5a0542017-04-28 14:37:56 -070054// A convenience binary to dump information available through libvintf.
Yifan Hong676447a2016-11-15 12:57:23 -080055int main(int, char **) {
Yifan Hong676447a2016-11-15 12:57:23 -080056
Yifan Hong1e5a0542017-04-28 14:37:56 -070057 std::cout << "======== Device HAL Manifest =========" << std::endl;
58
Yifan Hongfc73edf2017-08-29 11:39:07 -070059 std::shared_ptr<const HalManifest> vm = VintfObject::GetDeviceHalManifest();
Yifan Hong676447a2016-11-15 12:57:23 -080060 if (vm != nullptr)
Yifan Hongd2b7e642017-02-17 10:15:32 -080061 std::cout << gHalManifestConverter(*vm);
Yifan Hongccf967b2017-01-18 11:04:19 -080062
Yifan Hong1e5a0542017-04-28 14:37:56 -070063 std::cout << "======== Framework HAL Manifest =========" << std::endl;
64
Yifan Hongfc73edf2017-08-29 11:39:07 -070065 std::shared_ptr<const HalManifest> fm = VintfObject::GetFrameworkHalManifest();
Yifan Hong3daec812017-02-27 18:49:11 -080066 if (fm != nullptr)
67 std::cout << gHalManifestConverter(*fm);
68
Yifan Hong1e5a0542017-04-28 14:37:56 -070069 std::cout << "======== Device Compatibility Matrix =========" << std::endl;
70
Yifan Hongfc73edf2017-08-29 11:39:07 -070071 std::shared_ptr<const CompatibilityMatrix> vcm = VintfObject::GetDeviceCompatibilityMatrix();
Yifan Hong1e5a0542017-04-28 14:37:56 -070072 if (vcm != nullptr)
73 std::cout << gCompatibilityMatrixConverter(*vcm);
74
75 std::cout << "======== Framework Compatibility Matrix =========" << std::endl;
76
Yifan Hongfc73edf2017-08-29 11:39:07 -070077 std::shared_ptr<const CompatibilityMatrix> fcm = VintfObject::GetFrameworkCompatibilityMatrix();
Yifan Hong1e5a0542017-04-28 14:37:56 -070078 if (fcm != nullptr)
79 std::cout << gCompatibilityMatrixConverter(*fcm);
80
Yifan Hong3f835d62017-05-16 13:10:11 -070081 std::cout << "======== Runtime Info =========" << std::endl;
82
Yifan Hongfc73edf2017-08-29 11:39:07 -070083 std::shared_ptr<const RuntimeInfo> ki = VintfObject::GetRuntimeInfo();
Yifan Hong3f835d62017-05-16 13:10:11 -070084 if (ki != nullptr) std::cout << dump(*ki);
85 std::cout << std::endl;
86
Yifan Hong1e5a0542017-04-28 14:37:56 -070087 std::cout << "======== Compatibility check =========" << std::endl;
Yifan Hong3eed7e12018-01-25 11:22:52 -080088 std::cout << "Device Manifest? " << existString(vm != nullptr) << std::endl
89 << "Device Matrix? " << existString(vcm != nullptr) << std::endl
90 << "Framework Manifest? " << existString(fm != nullptr) << std::endl
91 << "Framework Matrix? " << existString(fcm != nullptr) << std::endl;
Yifan Hong1e5a0542017-04-28 14:37:56 -070092 std::string error;
93 if (vm && fcm) {
94 bool compatible = vm->checkCompatibility(*fcm, &error);
95 std::cout << "Device HAL Manifest <==> Framework Compatibility Matrix? "
Yifan Hong3eed7e12018-01-25 11:22:52 -080096 << boolCompatString(compatible);
Yifan Hong1e5a0542017-04-28 14:37:56 -070097 if (!compatible)
98 std::cout << ", " << error;
99 std::cout << std::endl;
100 }
101 if (fm && vcm) {
102 bool compatible = fm->checkCompatibility(*vcm, &error);
103 std::cout << "Framework HAL Manifest <==> Device Compatibility Matrix? "
Yifan Hong3eed7e12018-01-25 11:22:52 -0800104 << boolCompatString(compatible);
Yifan Hong1e5a0542017-04-28 14:37:56 -0700105 if (!compatible)
106 std::cout << ", " << error;
107 std::cout << std::endl;
108 }
Yifan Hong3f835d62017-05-16 13:10:11 -0700109 if (ki && fcm) {
110 bool compatible = ki->checkCompatibility(*fcm, &error);
Yifan Hong3eed7e12018-01-25 11:22:52 -0800111 std::cout << "Runtime info <==> Framework Compatibility Matrix? "
112 << boolCompatString(compatible);
Yifan Hong3f835d62017-05-16 13:10:11 -0700113 if (!compatible) std::cout << ", " << error;
114 std::cout << std::endl;
115 }
Yifan Hong1e5a0542017-04-28 14:37:56 -0700116
Yifan Hong3f835d62017-05-16 13:10:11 -0700117 {
118 auto compatible = VintfObject::CheckCompatibility({}, &error);
Yifan Hong3eed7e12018-01-25 11:22:52 -0800119 std::cout << "VintfObject::CheckCompatibility? "
120 << compatibleString(compatible);
Yifan Hong3f835d62017-05-16 13:10:11 -0700121 if (compatible != COMPATIBLE) std::cout << ", " << error;
122 std::cout << std::endl;
123 }
Yifan Hong3eed7e12018-01-25 11:22:52 -0800124
125 if (vm && fcm) {
126 auto deprecate = VintfObject::CheckDeprecation(&error);
127 std::cout << "VintfObject::CheckDeprecation (against device manifest)? "
128 << deprecateString(deprecate);
129 if (deprecate != NO_DEPRECATED_HALS) std::cout << ", " << error;
130 std::cout << std::endl;
131 }
Yifan Hong676447a2016-11-15 12:57:23 -0800132}