blob: 2e3b760709b98f53ae914afa84dc171d9f4c6f62 [file] [log] [blame]
Valerie Hau9cfc6d82019-09-23 13:54:07 -07001/*
2 * Copyright (C) 2019 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 <thread>
18#include "LayerTransactionTest.h"
19namespace android {
20
21using android::hardware::graphics::common::V1_1::BufferUsage;
22
23::testing::Environment* const binderEnv =
24 ::testing::AddGlobalTestEnvironment(new BinderEnvironment());
25
26class DisplayActiveConfigTest : public ::testing::Test {
27protected:
28 void SetUp() override {
29 mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
30 SurfaceComposerClient::getDisplayConfigs(mDisplayToken, &mDisplayconfigs);
31 EXPECT_GT(mDisplayconfigs.size(), 0);
32
33 // set display power to on to make sure config can be changed
34 SurfaceComposerClient::setDisplayPowerMode(mDisplayToken, HWC_POWER_MODE_NORMAL);
35 }
36
37 sp<IBinder> mDisplayToken;
38 Vector<DisplayInfo> mDisplayconfigs;
39};
40
41TEST_F(DisplayActiveConfigTest, allConfigsAllowed) {
42 std::vector<int32_t> allowedConfigs;
43
44 // Add all configs to the allowed configs
45 for (int i = 0; i < mDisplayconfigs.size(); i++) {
46 allowedConfigs.push_back(i);
47 }
48
49 status_t res = SurfaceComposerClient::setAllowedDisplayConfigs(mDisplayToken, allowedConfigs);
50 EXPECT_EQ(res, NO_ERROR);
51
52 std::vector<int32_t> outConfigs;
53 res = SurfaceComposerClient::getAllowedDisplayConfigs(mDisplayToken, &outConfigs);
54 EXPECT_EQ(res, NO_ERROR);
55 EXPECT_EQ(allowedConfigs, outConfigs);
56}
57
58TEST_F(DisplayActiveConfigTest, changeAllowedConfig) {
59 // we need at least 2 configs available for this test
60 if (mDisplayconfigs.size() <= 1) return;
61
62 int activeConfig = SurfaceComposerClient::getActiveConfig(mDisplayToken);
63
64 // We want to set the allowed config to everything but the active config
65 std::vector<int32_t> allowedConfigs;
66 for (int i = 0; i < mDisplayconfigs.size(); i++) {
67 if (i != activeConfig) {
68 allowedConfigs.push_back(i);
69 }
70 }
71
72 status_t res = SurfaceComposerClient::setAllowedDisplayConfigs(mDisplayToken, allowedConfigs);
73 EXPECT_EQ(res, NO_ERROR);
74
75 // Allow some time for the config change
76 std::this_thread::sleep_for(200ms);
77
78 int newActiveConfig = SurfaceComposerClient::getActiveConfig(mDisplayToken);
79 EXPECT_NE(activeConfig, newActiveConfig);
80
81 // Make sure the new config is part of allowed config
82 EXPECT_TRUE(std::find(allowedConfigs.begin(), allowedConfigs.end(), newActiveConfig) !=
83 allowedConfigs.end());
84}
85} // namespace android