summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2018-03-15 02:25:37 -0500
committerandroid-build-team Robot2018-03-15 02:25:37 -0500
commitd6100b32cf1707abf3d2382f4c42a83d0acc3b2a (patch)
tree7de49a580a757a70240ffdcf937a1448e08fc6f3
parent5ecbf2aedce2bcd722bd158aec42da5bf93a4188 (diff)
parentd89b968a6b34d67ac5462085add3a29346bcf3c4 (diff)
downloadplatform-system-libvintf-d6100b32cf1707abf3d2382f4c42a83d0acc3b2a.tar.gz
platform-system-libvintf-d6100b32cf1707abf3d2382f4c42a83d0acc3b2a.tar.xz
platform-system-libvintf-d6100b32cf1707abf3d2382f4c42a83d0acc3b2a.zip
Snap for 4656203 from d89b968a6b34d67ac5462085add3a29346bcf3c4 to pi-release
Change-Id: I2141d9e904997fa002136b9a494f26b4ad936fc6
-rw-r--r--HalManifest.cpp8
-rw-r--r--ManifestHal.cpp10
-rw-r--r--include/vintf/ManifestHal.h20
-rw-r--r--parse_xml.cpp6
-rw-r--r--test/LibVintfTest.cpp142
5 files changed, 100 insertions, 86 deletions
diff --git a/HalManifest.cpp b/HalManifest.cpp
index 454e0fc..a27e935 100644
--- a/HalManifest.cpp
+++ b/HalManifest.cpp
@@ -42,7 +42,7 @@ bool HalManifest::shouldAdd(const ManifestHal& hal) const {
42 if (!hal.isValid()) { 42 if (!hal.isValid()) {
43 return false; 43 return false;
44 } 44 }
45 if (hal.isOverride) { 45 if (hal.isOverride()) {
46 return true; 46 return true;
47 } 47 }
48 auto existingHals = mHals.equal_range(hal.name); 48 auto existingHals = mHals.equal_range(hal.name);
@@ -88,9 +88,9 @@ void HalManifest::removeHals(const std::string& name, size_t majorVer) {
88} 88}
89 89
90bool HalManifest::add(ManifestHal&& halToAdd) { 90bool HalManifest::add(ManifestHal&& halToAdd) {
91 if (halToAdd.isOverride) { 91 if (halToAdd.isOverride()) {
92 if (halToAdd.versions.empty()) { 92 if (halToAdd.isDisabledHal()) {
93 // Special syntax when there are no <version> tags at all. Remove all existing HALs 93 // Special syntax when there are no instances at all. Remove all existing HALs
94 // with the given name. 94 // with the given name.
95 mHals.erase(halToAdd.name); 95 mHals.erase(halToAdd.name);
96 } 96 }
diff --git a/ManifestHal.cpp b/ManifestHal.cpp
index d04d3e0..aa9d358 100644
--- a/ManifestHal.cpp
+++ b/ManifestHal.cpp
@@ -63,5 +63,15 @@ bool ManifestHal::forEachInstance(const std::function<bool(const ManifestInstanc
63 return true; 63 return true;
64} 64}
65 65
66bool ManifestHal::isDisabledHal() const {
67 if (!isOverride()) return false;
68 bool hasInstance = false;
69 forEachInstance([&hasInstance](const auto&) {
70 hasInstance = true;
71 return false; // has at least one instance, stop here.
72 });
73 return !hasInstance;
74}
75
66} // namespace vintf 76} // namespace vintf
67} // namespace android 77} // namespace android
diff --git a/include/vintf/ManifestHal.h b/include/vintf/ManifestHal.h
index a35c49a..36b173e 100644
--- a/include/vintf/ManifestHal.h
+++ b/include/vintf/ManifestHal.h
@@ -36,6 +36,16 @@ namespace vintf {
36struct ManifestHal { 36struct ManifestHal {
37 using InstanceType = ManifestInstance; 37 using InstanceType = ManifestInstance;
38 38
39 ManifestHal() = default;
40
41 ManifestHal(HalFormat fmt, std::string&& n, std::vector<Version>&& vs, TransportArch ta,
42 std::map<std::string, HalInterface>&& intf)
43 : format(fmt),
44 name(std::move(n)),
45 versions(std::move(vs)),
46 transportArch(ta),
47 interfaces(std::move(intf)) {}
48
39 bool operator==(const ManifestHal &other) const; 49 bool operator==(const ManifestHal &other) const;
40 // Check whether the ManifestHal contains the given version. 50 // Check whether the ManifestHal contains the given version.
41 // E.g. if hal has version "1.0" and "2.1", it contains version 51 // E.g. if hal has version "1.0" and "2.1", it contains version
@@ -47,7 +57,6 @@ struct ManifestHal {
47 std::vector<Version> versions; 57 std::vector<Version> versions;
48 TransportArch transportArch; 58 TransportArch transportArch;
49 std::map<std::string, HalInterface> interfaces; 59 std::map<std::string, HalInterface> interfaces;
50 bool isOverride = false;
51 60
52 inline bool hasInterface(const std::string& interface_name) const { 61 inline bool hasInterface(const std::string& interface_name) const {
53 return interfaces.find(interface_name) != interfaces.end(); 62 return interfaces.find(interface_name) != interfaces.end();
@@ -59,6 +68,13 @@ struct ManifestHal {
59 inline const std::string& getName() const { return name; } 68 inline const std::string& getName() const { return name; }
60 bool forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const; 69 bool forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const;
61 70
71 bool isOverride() const { return mIsOverride; }
72
73 // When true, the existence of this <hal> tag means the component does NOT
74 // exist on the device. This is useful for ODM manifests to specify that
75 // a HAL is disabled on certain products.
76 bool isDisabledHal() const;
77
62 private: 78 private:
63 friend struct LibVintfTest; 79 friend struct LibVintfTest;
64 friend struct ManifestHalConverter; 80 friend struct ManifestHalConverter;
@@ -68,6 +84,8 @@ struct ManifestHal {
68 // Whether this hal is a valid one. Note that an empty ManifestHal 84 // Whether this hal is a valid one. Note that an empty ManifestHal
69 // (constructed via ManifestHal()) is valid. 85 // (constructed via ManifestHal()) is valid.
70 bool isValid() const; 86 bool isValid() const;
87
88 bool mIsOverride = false;
71}; 89};
72 90
73} // namespace vintf 91} // namespace vintf
diff --git a/parse_xml.cpp b/parse_xml.cpp
index bca26e1..bf8889f 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -608,14 +608,14 @@ struct ManifestHalConverter : public XmlNodeConverter<ManifestHal> {
608 appendChild(root, transportArchConverter(hal.transportArch, d)); 608 appendChild(root, transportArchConverter(hal.transportArch, d));
609 appendChildren(root, versionConverter, hal.versions, d); 609 appendChildren(root, versionConverter, hal.versions, d);
610 appendChildren(root, halInterfaceConverter, iterateValues(hal.interfaces), d); 610 appendChildren(root, halInterfaceConverter, iterateValues(hal.interfaces), d);
611 if (hal.isOverride) { 611 if (hal.isOverride()) {
612 appendAttr(root, "override", hal.isOverride); 612 appendAttr(root, "override", hal.isOverride());
613 } 613 }
614 } 614 }
615 bool buildObject(ManifestHal* object, NodeType* root, std::string* error) const override { 615 bool buildObject(ManifestHal* object, NodeType* root, std::string* error) const override {
616 std::vector<HalInterface> interfaces; 616 std::vector<HalInterface> interfaces;
617 if (!parseOptionalAttr(root, "format", HalFormat::HIDL, &object->format, error) || 617 if (!parseOptionalAttr(root, "format", HalFormat::HIDL, &object->format, error) ||
618 !parseOptionalAttr(root, "override", false, &object->isOverride, error) || 618 !parseOptionalAttr(root, "override", false, &object->mIsOverride, error) ||
619 !parseTextElement(root, "name", &object->name, error) || 619 !parseTextElement(root, "name", &object->name, error) ||
620 !parseOptionalChild(root, transportArchConverter, {}, &object->transportArch, error) || 620 !parseOptionalChild(root, transportArchConverter, {}, &object->transportArch, error) ||
621 !parseChildren(root, versionConverter, &object->versions, error) || 621 !parseChildren(root, versionConverter, &object->versions, error) ||
diff --git a/test/LibVintfTest.cpp b/test/LibVintfTest.cpp
index ce3a656..f0f0423 100644
--- a/test/LibVintfTest.cpp
+++ b/test/LibVintfTest.cpp
@@ -125,25 +125,17 @@ public:
125 HalManifest vm; 125 HalManifest vm;
126 vm.mType = SchemaType::DEVICE; 126 vm.mType = SchemaType::DEVICE;
127 vm.device.mSepolicyVersion = {25, 0}; 127 vm.device.mSepolicyVersion = {25, 0};
128 vm.add(ManifestHal{ 128 vm.add(ManifestHal{HalFormat::HIDL,
129 .format = HalFormat::HIDL, 129 "android.hardware.camera",
130 .name = "android.hardware.camera", 130 {Version(2, 0)},
131 .versions = {Version(2, 0)}, 131 {Transport::HWBINDER, Arch::ARCH_EMPTY},
132 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY}, 132 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
133 .interfaces = { 133 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}});
134 {"ICamera", {"ICamera", {"legacy/0", "default"}}}, 134 vm.add(ManifestHal{HalFormat::HIDL,
135 {"IBetterCamera", {"IBetterCamera", {"camera"}}} 135 "android.hardware.nfc",
136 } 136 {Version(1, 0)},
137 }); 137 {Transport::PASSTHROUGH, Arch::ARCH_32_64},
138 vm.add(ManifestHal{ 138 {{"INfc", {"INfc", {"default"}}}}});
139 .format = HalFormat::HIDL,
140 .name = "android.hardware.nfc",
141 .versions = {Version(1, 0)},
142 .transportArch = {Transport::PASSTHROUGH, Arch::ARCH_32_64},
143 .interfaces = {
144 {"INfc", {"INfc", {"default"}}}
145 }
146 });
147 139
148 return vm; 140 return vm;
149 } 141 }
@@ -158,15 +150,13 @@ public:
158 HalManifest testFrameworkManfiest() { 150 HalManifest testFrameworkManfiest() {
159 HalManifest vm; 151 HalManifest vm;
160 vm.mType = SchemaType::FRAMEWORK; 152 vm.mType = SchemaType::FRAMEWORK;
161 vm.add(ManifestHal{ 153 vm.add(ManifestHal{HalFormat::HIDL,
162 .format = HalFormat::HIDL, 154 "android.hidl.manager",
163 .name = "android.hidl.manager", 155 {Version(1, 0)},
164 .versions = {Version(1, 0)}, 156 {Transport::HWBINDER, Arch::ARCH_EMPTY},
165 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY}, 157 {
166 .interfaces = { 158 {"IServiceManager", {"IServiceManager", {"default"}}},
167 {"IServiceManager", {"IServiceManager", {"default"}}}, 159 }});
168 }
169 });
170 Vndk vndk2505; 160 Vndk vndk2505;
171 vndk2505.mVersionRange = {25, 0, 5}; 161 vndk2505.mVersionRange = {25, 0, 5};
172 vndk2505.mLibraries = { "libjpeg.so", "libbase.so" }; 162 vndk2505.mLibraries = { "libjpeg.so", "libbase.so" };
@@ -234,11 +224,11 @@ TEST_F(LibVintfTest, GetTransport) {
234 224
235TEST_F(LibVintfTest, FutureManifestCompatible) { 225TEST_F(LibVintfTest, FutureManifestCompatible) {
236 HalManifest expectedManifest; 226 HalManifest expectedManifest;
237 expectedManifest.add(ManifestHal{.format = HalFormat::HIDL, 227 expectedManifest.add(ManifestHal{HalFormat::HIDL,
238 .name = "android.hardware.foo", 228 "android.hardware.foo",
239 .versions = {Version(1, 0)}, 229 {Version(1, 0)},
240 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY}, 230 {Transport::HWBINDER, Arch::ARCH_EMPTY},
241 .interfaces = { 231 {
242 {"IFoo", {"IFoo", {"default"}}}, 232 {"IFoo", {"IFoo", {"default"}}},
243 }}); 233 }});
244 std::string manifestXml = 234 std::string manifestXml =
@@ -680,12 +670,11 @@ TEST_F(LibVintfTest, DeviceCompatibilityMatrixCoverter) {
680TEST_F(LibVintfTest, IsValid) { 670TEST_F(LibVintfTest, IsValid) {
681 EXPECT_TRUE(isValid(ManifestHal())); 671 EXPECT_TRUE(isValid(ManifestHal()));
682 672
683 ManifestHal invalidHal{ 673 ManifestHal invalidHal{HalFormat::HIDL,
684 .format = HalFormat::HIDL, 674 "android.hardware.camera",
685 .name = "android.hardware.camera", 675 {{Version(2, 0), Version(2, 1)}},
686 .versions = {{Version(2, 0), Version(2, 1)}}, 676 {Transport::PASSTHROUGH, Arch::ARCH_32_64},
687 .transportArch = {Transport::PASSTHROUGH, Arch::ARCH_32_64} 677 {}};
688 };
689 678
690 EXPECT_FALSE(isValid(invalidHal)); 679 EXPECT_FALSE(isValid(invalidHal));
691 HalManifest vm2; 680 HalManifest vm2;
@@ -712,45 +701,42 @@ TEST_F(LibVintfTest, HalManifestGetAllHals) {
712 701
713TEST_F(LibVintfTest, HalManifestGetHals) { 702TEST_F(LibVintfTest, HalManifestGetHals) {
714 HalManifest vm; 703 HalManifest vm;
715 EXPECT_TRUE( 704 EXPECT_TRUE(add(vm, ManifestHal{HalFormat::HIDL,
716 add(vm, ManifestHal{.format = HalFormat::HIDL, 705 "android.hardware.camera",
717 .name = "android.hardware.camera", 706 {Version(1, 2)},
718 .versions = {Version(1, 2)}, 707 {Transport::HWBINDER, Arch::ARCH_EMPTY},
719 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY}, 708 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
720 .interfaces = {{"ICamera", {"ICamera", {"legacy/0", "default"}}}, 709 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}}));
721 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}})); 710 EXPECT_TRUE(add(vm, ManifestHal{HalFormat::HIDL,
722 EXPECT_TRUE( 711 "android.hardware.camera",
723 add(vm, ManifestHal{.format = HalFormat::HIDL, 712 {Version(2, 0)},
724 .name = "android.hardware.camera", 713 {Transport::HWBINDER, Arch::ARCH_EMPTY},
725 .versions = {Version(2, 0)}, 714 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
726 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY}, 715 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}}));
727 .interfaces = {{"ICamera", {"ICamera", {"legacy/0", "default"}}}, 716 EXPECT_TRUE(add(vm, ManifestHal{HalFormat::HIDL,
728 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}})); 717 "android.hardware.nfc",
729 EXPECT_TRUE(add(vm, ManifestHal{.format = HalFormat::HIDL, 718 {Version(1, 0), Version(2, 1)},
730 .name = "android.hardware.nfc", 719 {Transport::PASSTHROUGH, Arch::ARCH_32_64},
731 .versions = {Version(1, 0), Version(2, 1)}, 720 {{"INfc", {"INfc", {"default"}}}}}));
732 .transportArch = {Transport::PASSTHROUGH, Arch::ARCH_32_64},
733 .interfaces = {{"INfc", {"INfc", {"default"}}}}}));
734 ManifestHal expectedCameraHalV1_2 = 721 ManifestHal expectedCameraHalV1_2 =
735 ManifestHal{.format = HalFormat::HIDL, 722 ManifestHal{HalFormat::HIDL,
736 .name = "android.hardware.camera", 723 "android.hardware.camera",
737 .versions = {Version(1, 2)}, 724 {Version(1, 2)},
738 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY}, 725 {Transport::HWBINDER, Arch::ARCH_EMPTY},
739 .interfaces = {{"ICamera", {"ICamera", {"legacy/0", "default"}}}, 726 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
740 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}}; 727 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}};
741 ManifestHal expectedCameraHalV2_0 = 728 ManifestHal expectedCameraHalV2_0 =
742 ManifestHal{.format = HalFormat::HIDL, 729 ManifestHal{HalFormat::HIDL,
743 .name = "android.hardware.camera", 730 "android.hardware.camera",
744 .versions = {Version(2, 0)}, 731 {Version(2, 0)},
745 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY}, 732 {Transport::HWBINDER, Arch::ARCH_EMPTY},
746 .interfaces = {{"ICamera", {"ICamera", {"legacy/0", "default"}}}, 733 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
747 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}}; 734 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}};
748 ManifestHal expectedNfcHal = 735 ManifestHal expectedNfcHal = ManifestHal{HalFormat::HIDL,
749 ManifestHal{.format = HalFormat::HIDL, 736 "android.hardware.nfc",
750 .name = "android.hardware.nfc", 737 {Version(1, 0), Version(2, 1)},
751 .versions = {Version(1, 0), Version(2, 1)}, 738 {Transport::PASSTHROUGH, Arch::ARCH_32_64},
752 .transportArch = {Transport::PASSTHROUGH, Arch::ARCH_32_64}, 739 {{"INfc", {"INfc", {"default"}}}}};
753 .interfaces = {{"INfc", {"INfc", {"default"}}}}};
754 auto cameraHals = vm.getHals("android.hardware.camera"); 740 auto cameraHals = vm.getHals("android.hardware.camera");
755 EXPECT_EQ((int)cameraHals.size(), 2); 741 EXPECT_EQ((int)cameraHals.size(), 2);
756 EXPECT_EQ(*cameraHals[0], expectedCameraHalV1_2); 742 EXPECT_EQ(*cameraHals[0], expectedCameraHalV1_2);
@@ -2421,10 +2407,10 @@ TEST_F(LibVintfTest, ManifestHalOverride) {
2421 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError(); 2407 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2422 const auto& foo = manifest.getHals("android.hardware.foo"); 2408 const auto& foo = manifest.getHals("android.hardware.foo");
2423 ASSERT_FALSE(foo.empty()); 2409 ASSERT_FALSE(foo.empty());
2424 EXPECT_TRUE(foo.front()->isOverride); 2410 EXPECT_TRUE(foo.front()->isOverride());
2425 const auto& bar = manifest.getHals("android.hardware.bar"); 2411 const auto& bar = manifest.getHals("android.hardware.bar");
2426 ASSERT_FALSE(bar.empty()); 2412 ASSERT_FALSE(bar.empty());
2427 EXPECT_FALSE(bar.front()->isOverride); 2413 EXPECT_FALSE(bar.front()->isOverride());
2428} 2414}
2429 2415
2430// Test functionality of override="true" tag 2416// Test functionality of override="true" tag