• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #include <android-base/properties.h>
17 #include <android-base/strings.h>
18 #include <android/api-level.h>
19 #include <android/hidl/manager/1.0/IServiceManager.h>
20 #include <gmock/gmock.h>
21 #include <hidl/ServiceManagement.h>
22 
23 namespace android {
24 namespace vintf {
25 namespace testing {
26 
27 static constexpr int kMaxNumberOfHidlHals = 100;
28 
29 // Tests that the device is not registering any HIDL interfaces.
30 // HIDL is being deprecated. Only applicable to devices launching with Android
31 // 14 and later.
32 class VintfNoHidlTest : public ::testing::Test {};
33 
34 // @VsrTest = VSR-3.2-001.001|VSR-3.2-001.002
TEST_F(VintfNoHidlTest,NoHidl)35 TEST_F(VintfNoHidlTest, NoHidl) {
36   if (std::stoi(android::base::GetProperty("ro.vendor.api_level", "0")) <
37       __ANDROID_API_U__) {
38     GTEST_SKIP() << "Not applicable to this device";
39     return;
40   }
41   sp<hidl::manager::V1_0::IServiceManager> sm =
42       ::android::hardware::defaultServiceManager();
43   ASSERT_NE(sm, nullptr);
44   hardware::Return<void> ret = sm->list([](const auto& interfaces) {
45     std::set<std::string> packages;
46     for (const auto& interface : interfaces) {
47       std::vector<std::string> splitInterface =
48           android::base::Split(interface, "@");
49       ASSERT_GE(splitInterface.size(), 1);
50       // We only care about packages, since HIDL HALs typically need to
51       // include all of the older minor versions as well as the version they
52       // are implementing
53       packages.insert(splitInterface[0]);
54     }
55     if (packages.size() > kMaxNumberOfHidlHals) {
56       ADD_FAILURE() << "There are " << packages.size()
57                     << " HIDL interfaces served on the device. "
58                     << "These must be converted to AIDL as part of HIDL's "
59                        "deprecation processes.";
60       for (const auto& package : packages) {
61         ADD_FAILURE() << package << " registered as a HIDL interface "
62                       << "but must be in AIDL";
63       }
64     }
65   });
66   ASSERT_TRUE(ret.isOk());
67 }
68 
69 }  // namespace testing
70 }  // namespace vintf
71 }  // namespace android
72