blob: ae53c685285b693c69b91cf1c9b3ad5aba12afb8 [file] [log] [blame]
Hayden Gomesa521acf2020-11-02 12:29:05 -08001/*
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#define LOG_TAG "VtsAidlHalAudioControlTest"
17
18#include <aidl/Gtest.h>
19#include <aidl/Vintf.h>
20#include <gmock/gmock.h>
21
22#include <android/hardware/automotive/audiocontrol/BnFocusListener.h>
23#include <android/hardware/automotive/audiocontrol/IAudioControl.h>
24#include <android/log.h>
25#include <binder/IServiceManager.h>
26#include <binder/ProcessState.h>
27
28using android::ProcessState;
29using android::sp;
30using android::String16;
31using android::binder::Status;
32using android::hardware::automotive::audiocontrol::AudioFocusChange;
33using android::hardware::automotive::audiocontrol::BnFocusListener;
Hayden Gomesad816702020-12-14 15:29:29 -080034using android::hardware::automotive::audiocontrol::DuckingInfo;
Hayden Gomesa521acf2020-11-02 12:29:05 -080035using android::hardware::automotive::audiocontrol::IAudioControl;
Oscar Azucenab8e5cd02020-12-16 13:53:14 -080036using android::hardware::automotive::audiocontrol::MutingInfo;
Hayden Gomesa521acf2020-11-02 12:29:05 -080037
Hayden Gomese502a602020-11-06 15:15:26 -080038#include "android_audio_policy_configuration_V7_0.h"
Hayden Gomesa521acf2020-11-02 12:29:05 -080039
40namespace xsd {
Hayden Gomese502a602020-11-06 15:15:26 -080041using namespace android::audio::policy::configuration::V7_0;
Hayden Gomesa521acf2020-11-02 12:29:05 -080042}
43
44class AudioControlAidl : public testing::TestWithParam<std::string> {
45 public:
46 virtual void SetUp() override {
47 audioControl = android::waitForDeclaredService<IAudioControl>(String16(GetParam().c_str()));
48 ASSERT_NE(audioControl, nullptr);
49 }
50
51 sp<IAudioControl> audioControl;
52 int32_t capabilities;
53};
54
55TEST_P(AudioControlAidl, OnSetFadeTowardsFront) {
56 ALOGI("Fader exercise test (silent)");
57
58 // Set the fader all the way to the back
59 ASSERT_TRUE(audioControl->setFadeTowardFront(-1.0f).isOk());
60
61 // Set the fader all the way to the front
62 ASSERT_TRUE(audioControl->setFadeTowardFront(1.0f).isOk());
63
64 // Set the fader part way toward the back
65 ASSERT_TRUE(audioControl->setFadeTowardFront(-0.333f).isOk());
66
67 // Set the fader to a out of bounds value (driver should clamp)
68 ASSERT_TRUE(audioControl->setFadeTowardFront(99999.9f).isOk());
69
70 // Set the fader to a negative out of bounds value (driver should clamp)
71 ASSERT_TRUE(audioControl->setFadeTowardFront(-99999.9f).isOk());
72
73 // Set the fader back to the middle
74 ASSERT_TRUE(audioControl->setFadeTowardFront(0.0f).isOk());
75}
76
77TEST_P(AudioControlAidl, OnSetBalanceTowardsRight) {
78 ALOGI("Balance exercise test (silent)");
79
80 // Set the balance all the way to the left
81 ASSERT_TRUE(audioControl->setBalanceTowardRight(-1.0f).isOk());
82
83 // Set the balance all the way to the right
84 ASSERT_TRUE(audioControl->setBalanceTowardRight(1.0f).isOk());
85
86 // Set the balance part way toward the left
87 ASSERT_TRUE(audioControl->setBalanceTowardRight(-0.333f).isOk());
88
89 // Set the balance to a out of bounds value (driver should clamp)
90 ASSERT_TRUE(audioControl->setBalanceTowardRight(99999.9f).isOk());
91
92 // Set the balance to a negative out of bounds value (driver should clamp)
93 ASSERT_TRUE(audioControl->setBalanceTowardRight(-99999.9f).isOk());
94
95 // Set the balance back to the middle
96 ASSERT_TRUE(audioControl->setBalanceTowardRight(0.0f).isOk());
97
98 // Set the balance back to the middle
99 audioControl->setBalanceTowardRight(0.0f).isOk();
100}
101
102struct FocusListenerMock : BnFocusListener {
103 MOCK_METHOD(Status, requestAudioFocus,
104 (const String16& usage, int32_t zoneId, AudioFocusChange focusGain));
105 MOCK_METHOD(Status, abandonAudioFocus, (const String16& usage, int32_t zoneId));
106};
107
108/*
109 * Test focus listener registration.
110 *
111 * Verifies that:
112 * - registerFocusListener succeeds;
113 * - registering a second listener succeeds in replacing the first;
114 * - closing handle does not crash;
115 */
116TEST_P(AudioControlAidl, FocusListenerRegistration) {
117 ALOGI("Focus listener test");
118
119 sp<FocusListenerMock> listener = new FocusListenerMock();
120 ASSERT_TRUE(audioControl->registerFocusListener(listener).isOk());
121
122 sp<FocusListenerMock> listener2 = new FocusListenerMock();
123 ASSERT_TRUE(audioControl->registerFocusListener(listener2).isOk());
124};
125
126TEST_P(AudioControlAidl, FocusChangeExercise) {
127 ALOGI("Focus Change test");
128
129 String16 usage = String16(xsd::toString(xsd::AudioUsage::AUDIO_USAGE_MEDIA).c_str());
130 ASSERT_TRUE(
131 audioControl->onAudioFocusChange(usage, 0, AudioFocusChange::GAIN_TRANSIENT).isOk());
132};
133
Oscar Azucenab8e5cd02020-12-16 13:53:14 -0800134TEST_P(AudioControlAidl, MuteChangeExercise) {
135 ALOGI("Mute change test");
136
137 MutingInfo mutingInfo;
138 mutingInfo.zoneId = 0;
139 mutingInfo.deviceAddressesToMute = {String16("address 1"), String16("address 2")};
140 mutingInfo.deviceAddressesToUnmute = {String16("address 3"), String16("address 4")};
141 std::vector<MutingInfo> mutingInfos = {mutingInfo};
142 ALOGI("Mute change test start");
143 ASSERT_TRUE(audioControl->onDevicesToMuteChange(mutingInfos).isOk());
144}
145
Hayden Gomesad816702020-12-14 15:29:29 -0800146TEST_P(AudioControlAidl, DuckChangeExercise) {
147 ALOGI("Duck change test");
148
149 DuckingInfo duckingInfo;
150 duckingInfo.zoneId = 0;
151 duckingInfo.deviceAddressesToDuck = {String16("address 1"), String16("address 2")};
152 duckingInfo.deviceAddressesToUnduck = {String16("address 3"), String16("address 4")};
153 duckingInfo.usagesHoldingFocus = {
154 String16(xsd::toString(xsd::AudioUsage::AUDIO_USAGE_MEDIA).c_str()),
155 String16(xsd::toString(xsd::AudioUsage::AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE)
156 .c_str())};
157 std::vector<DuckingInfo> duckingInfos = {duckingInfo};
158 ALOGI("Duck change test start");
159 ASSERT_TRUE(audioControl->onDevicesToDuckChange(duckingInfos).isOk());
160}
161
Hayden Gomesa521acf2020-11-02 12:29:05 -0800162GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioControlAidl);
163INSTANTIATE_TEST_SUITE_P(
164 Audiocontrol, AudioControlAidl,
165 testing::ValuesIn(android::getAidlHalInstanceNames(IAudioControl::descriptor)),
166 android::PrintInstanceNameToString);
167
168int main(int argc, char** argv) {
169 ::testing::InitGoogleTest(&argc, argv);
170 ProcessState::self()->setThreadPoolMaxThreadCount(1);
171 ProcessState::self()->startThreadPool();
172 return RUN_ALL_TESTS();
173}