1 //
2 // Copyright (C) 2020 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 #define LOG_TAG "VtsHalAutomotiveDisplayTest"
18 #include <android-base/logging.h>
19 
20 #include <android/frameworks/automotive/display/1.0/IAutomotiveDisplayProxyService.h>
21 #include <android/hardware/graphics/bufferqueue/2.0/IGraphicBufferProducer.h>
22 #include <ui/DisplayConfig.h>
23 #include <ui/DisplayState.h>
24 #include <utils/Log.h>
25 
26 #include <gtest/gtest.h>
27 #include <hidl/GtestPrinter.h>
28 #include <hidl/ServiceManagement.h>
29 
30 using namespace ::android::frameworks::automotive::display::V1_0;
31 using ::android::hardware::graphics::bufferqueue::V2_0::IGraphicBufferProducer;
32 using ::android::sp;
33 
34 // The main test class for Automotive Display Service
35 class AutomotiveDisplayHidlTest : public ::testing::TestWithParam<std::string> {
36 public:
SetUp()37     virtual void SetUp() override {
38         // Make sure we can connect to the service
39         mDisplayProxy = IAutomotiveDisplayProxyService::getService(GetParam());
40         ASSERT_NE(mDisplayProxy.get(), nullptr);
41     }
42 
TearDown()43     virtual void TearDown() override {}
44 
45     sp<IAutomotiveDisplayProxyService> mDisplayProxy;    // Every test needs access to the service
46 };
47 
TEST_P(AutomotiveDisplayHidlTest,getIGBP)48 TEST_P(AutomotiveDisplayHidlTest, getIGBP) {
49     ALOGI("Test getIGraphicBufferProducer method");
50 
51     android::hardware::hidl_vec<uint64_t> displayIdList;
52     mDisplayProxy->getDisplayIdList([&displayIdList](const auto& list) {
53         displayIdList.resize(list.size());
54         for (auto i = 0; i < list.size(); ++i) {
55             displayIdList[i] = list[i];
56         }
57     });
58 
59     for (const auto& id : displayIdList) {
60         // Get a display info
61         mDisplayProxy->getDisplayInfo(id, [](const auto& cfg, const auto& /*state*/) {
62             android::DisplayConfig* pConfig = (android::DisplayConfig*)cfg.data();
63             ASSERT_GT(pConfig->resolution.getWidth(), 0);
64             ASSERT_GT(pConfig->resolution.getHeight(), 0);
65         });
66 
67         sp<IGraphicBufferProducer> igbp = mDisplayProxy->getIGraphicBufferProducer(id);
68         ASSERT_NE(igbp, nullptr);
69     }
70 }
71 
TEST_P(AutomotiveDisplayHidlTest,showWindow)72 TEST_P(AutomotiveDisplayHidlTest, showWindow) {
73     ALOGI("Test showWindow method");
74 
75     android::hardware::hidl_vec<uint64_t> displayIdList;
76     mDisplayProxy->getDisplayIdList([&displayIdList](const auto& list) {
77         displayIdList.resize(list.size());
78         for (auto i = 0; i < list.size(); ++i) {
79             displayIdList[i] = list[i];
80         }
81     });
82 
83     for (const auto& id : displayIdList) {
84         ASSERT_EQ(mDisplayProxy->showWindow(id), true);
85     }
86 }
87 
TEST_P(AutomotiveDisplayHidlTest,hideWindow)88 TEST_P(AutomotiveDisplayHidlTest, hideWindow) {
89     ALOGI("Test hideWindow method");
90 
91     android::hardware::hidl_vec<uint64_t> displayIdList;
92     mDisplayProxy->getDisplayIdList([&displayIdList](const auto& list) {
93         displayIdList.resize(list.size());
94         for (auto i = 0; i < list.size(); ++i) {
95             displayIdList[i] = list[i];
96         }
97     });
98 
99     for (const auto& id : displayIdList) {
100         ASSERT_EQ(mDisplayProxy->hideWindow(id), true);
101     }
102 }
103 
104 INSTANTIATE_TEST_SUITE_P(
105     PerInstance,
106     AutomotiveDisplayHidlTest,
107     testing::ValuesIn(
108         android::hardware::getAllHalInstanceNames(IAutomotiveDisplayProxyService::descriptor)
109     ),
110     android::hardware::PrintInstanceNameToString
111 );
112