1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <thread>
#include <gtest/gtest.h>
#include <gui/AidlUtil.h>
#include <gui/SurfaceComposerClient.h>
#include <private/gui/ComposerService.h>
#include <private/gui/ComposerServiceAIDL.h>
#include <chrono>
namespace android {
using gui::aidl_utils::statusTFromBinderStatus;
struct BootDisplayModeTest : public ::testing::Test {
protected:
void SetUp() override {
mSf = ComposerServiceAIDL::getComposerService();
const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
ASSERT_FALSE(ids.empty());
mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front());
bool bootModeSupport = false;
binder::Status status = mSf->getBootDisplayModeSupport(&bootModeSupport);
ASSERT_NO_FATAL_FAILURE(statusTFromBinderStatus(status));
if (!bootModeSupport) {
GTEST_SKIP() << "Boot mode not supported";
}
gui::DynamicDisplayInfo info;
status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info);
ASSERT_EQ(NO_ERROR, statusTFromBinderStatus(status));
mOldMode = info.preferredBootDisplayMode;
const auto newMode = [&]() -> std::optional<ui::DisplayModeId> {
for (const auto& mode : info.supportedDisplayModes) {
if (mode.id != mOldMode) {
return std::optional(mode.id);
}
}
return std::nullopt;
}();
if (!newMode) {
GTEST_SKIP() << "Only a single mode is supported";
}
mNewMode = *newMode;
}
void TearDown() override {
binder::Status status = mSf->setBootDisplayMode(mDisplayToken, mOldMode);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
gui::DynamicDisplayInfo info;
status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
EXPECT_EQ(mOldMode, info.preferredBootDisplayMode);
}
ui::DisplayModeId mOldMode;
ui::DisplayModeId mNewMode;
sp<gui::ISurfaceComposer> mSf;
sp<IBinder> mDisplayToken;
};
TEST_F(BootDisplayModeTest, setBootDisplayMode) {
// Set a new mode and check that it got applied
binder::Status status = mSf->setBootDisplayMode(mDisplayToken, mNewMode);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
gui::DynamicDisplayInfo info;
status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
EXPECT_EQ(mNewMode, info.preferredBootDisplayMode);
}
TEST_F(BootDisplayModeTest, clearBootDisplayMode) {
// Clear once to figure out what the system default is
binder::Status status = mSf->clearBootDisplayMode(mDisplayToken);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
gui::DynamicDisplayInfo info;
status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
const ui::DisplayModeId systemMode = info.preferredBootDisplayMode;
const ui::DisplayModeId newMode = systemMode == mOldMode ? mNewMode : mOldMode;
// Now set a new mode and clear the boot mode again to figure out if the api worked.
status = mSf->setBootDisplayMode(mDisplayToken, newMode);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
EXPECT_EQ(newMode, info.preferredBootDisplayMode);
status = mSf->clearBootDisplayMode(mDisplayToken);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info);
EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status));
EXPECT_EQ(systemMode, info.preferredBootDisplayMode);
}
} // namespace android
|