Yifan Hong | 676447a | 2016-11-15 12:57:23 -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 <iostream> |
| 18 | #include <vintf/parse_xml.h> |
Yifan Hong | ccf967b | 2017-01-18 11:04:19 -0800 | [diff] [blame] | 19 | #include <vintf/parse_string.h> |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 20 | #include <vintf/VintfObject.h> |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 21 | |
Yifan Hong | 3eed7e1 | 2018-01-25 11:22:52 -0800 | [diff] [blame^] | 22 | using namespace ::android::vintf; |
| 23 | |
| 24 | std::string existString(bool value) { |
| 25 | return value ? "GOOD" : "DOES NOT EXIST"; |
| 26 | } |
| 27 | |
| 28 | std::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 | |
| 39 | std::string boolCompatString(bool value) { |
| 40 | return compatibleString(value ? COMPATIBLE : INCOMPATIBLE); |
| 41 | } |
| 42 | |
| 43 | std::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 Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 54 | // A convenience binary to dump information available through libvintf. |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 55 | int main(int, char **) { |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 56 | |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 57 | std::cout << "======== Device HAL Manifest =========" << std::endl; |
| 58 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 59 | std::shared_ptr<const HalManifest> vm = VintfObject::GetDeviceHalManifest(); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 60 | if (vm != nullptr) |
Yifan Hong | d2b7e64 | 2017-02-17 10:15:32 -0800 | [diff] [blame] | 61 | std::cout << gHalManifestConverter(*vm); |
Yifan Hong | ccf967b | 2017-01-18 11:04:19 -0800 | [diff] [blame] | 62 | |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 63 | std::cout << "======== Framework HAL Manifest =========" << std::endl; |
| 64 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 65 | std::shared_ptr<const HalManifest> fm = VintfObject::GetFrameworkHalManifest(); |
Yifan Hong | 3daec81 | 2017-02-27 18:49:11 -0800 | [diff] [blame] | 66 | if (fm != nullptr) |
| 67 | std::cout << gHalManifestConverter(*fm); |
| 68 | |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 69 | std::cout << "======== Device Compatibility Matrix =========" << std::endl; |
| 70 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 71 | std::shared_ptr<const CompatibilityMatrix> vcm = VintfObject::GetDeviceCompatibilityMatrix(); |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 72 | if (vcm != nullptr) |
| 73 | std::cout << gCompatibilityMatrixConverter(*vcm); |
| 74 | |
| 75 | std::cout << "======== Framework Compatibility Matrix =========" << std::endl; |
| 76 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 77 | std::shared_ptr<const CompatibilityMatrix> fcm = VintfObject::GetFrameworkCompatibilityMatrix(); |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 78 | if (fcm != nullptr) |
| 79 | std::cout << gCompatibilityMatrixConverter(*fcm); |
| 80 | |
Yifan Hong | 3f835d6 | 2017-05-16 13:10:11 -0700 | [diff] [blame] | 81 | std::cout << "======== Runtime Info =========" << std::endl; |
| 82 | |
Yifan Hong | fc73edf | 2017-08-29 11:39:07 -0700 | [diff] [blame] | 83 | std::shared_ptr<const RuntimeInfo> ki = VintfObject::GetRuntimeInfo(); |
Yifan Hong | 3f835d6 | 2017-05-16 13:10:11 -0700 | [diff] [blame] | 84 | if (ki != nullptr) std::cout << dump(*ki); |
| 85 | std::cout << std::endl; |
| 86 | |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 87 | std::cout << "======== Compatibility check =========" << std::endl; |
Yifan Hong | 3eed7e1 | 2018-01-25 11:22:52 -0800 | [diff] [blame^] | 88 | 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 Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 92 | std::string error; |
| 93 | if (vm && fcm) { |
| 94 | bool compatible = vm->checkCompatibility(*fcm, &error); |
| 95 | std::cout << "Device HAL Manifest <==> Framework Compatibility Matrix? " |
Yifan Hong | 3eed7e1 | 2018-01-25 11:22:52 -0800 | [diff] [blame^] | 96 | << boolCompatString(compatible); |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 97 | 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 Hong | 3eed7e1 | 2018-01-25 11:22:52 -0800 | [diff] [blame^] | 104 | << boolCompatString(compatible); |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 105 | if (!compatible) |
| 106 | std::cout << ", " << error; |
| 107 | std::cout << std::endl; |
| 108 | } |
Yifan Hong | 3f835d6 | 2017-05-16 13:10:11 -0700 | [diff] [blame] | 109 | if (ki && fcm) { |
| 110 | bool compatible = ki->checkCompatibility(*fcm, &error); |
Yifan Hong | 3eed7e1 | 2018-01-25 11:22:52 -0800 | [diff] [blame^] | 111 | std::cout << "Runtime info <==> Framework Compatibility Matrix? " |
| 112 | << boolCompatString(compatible); |
Yifan Hong | 3f835d6 | 2017-05-16 13:10:11 -0700 | [diff] [blame] | 113 | if (!compatible) std::cout << ", " << error; |
| 114 | std::cout << std::endl; |
| 115 | } |
Yifan Hong | 1e5a054 | 2017-04-28 14:37:56 -0700 | [diff] [blame] | 116 | |
Yifan Hong | 3f835d6 | 2017-05-16 13:10:11 -0700 | [diff] [blame] | 117 | { |
| 118 | auto compatible = VintfObject::CheckCompatibility({}, &error); |
Yifan Hong | 3eed7e1 | 2018-01-25 11:22:52 -0800 | [diff] [blame^] | 119 | std::cout << "VintfObject::CheckCompatibility? " |
| 120 | << compatibleString(compatible); |
Yifan Hong | 3f835d6 | 2017-05-16 13:10:11 -0700 | [diff] [blame] | 121 | if (compatible != COMPATIBLE) std::cout << ", " << error; |
| 122 | std::cout << std::endl; |
| 123 | } |
Yifan Hong | 3eed7e1 | 2018-01-25 11:22:52 -0800 | [diff] [blame^] | 124 | |
| 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 Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 132 | } |