1 /*
2 * Copyright (C) 2016 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 "PrimaryDeviceHAL"
18
19 #include "PrimaryDevice.h"
20 #include "Util.h"
21
22 namespace android {
23 namespace hardware {
24 namespace audio {
25 namespace V2_0 {
26 namespace implementation {
27
PrimaryDevice(audio_hw_device_t * device)28 PrimaryDevice::PrimaryDevice(audio_hw_device_t* device)
29 : mDevice(new Device(device)) {
30 }
31
~PrimaryDevice()32 PrimaryDevice::~PrimaryDevice() {}
33
34 // Methods from ::android::hardware::audio::V2_0::IDevice follow.
initCheck()35 Return<Result> PrimaryDevice::initCheck() {
36 return mDevice->initCheck();
37 }
38
setMasterVolume(float volume)39 Return<Result> PrimaryDevice::setMasterVolume(float volume) {
40 return mDevice->setMasterVolume(volume);
41 }
42
getMasterVolume(getMasterVolume_cb _hidl_cb)43 Return<void> PrimaryDevice::getMasterVolume(getMasterVolume_cb _hidl_cb) {
44 return mDevice->getMasterVolume(_hidl_cb);
45 }
46
setMicMute(bool mute)47 Return<Result> PrimaryDevice::setMicMute(bool mute) {
48 return mDevice->setMicMute(mute);
49 }
50
getMicMute(getMicMute_cb _hidl_cb)51 Return<void> PrimaryDevice::getMicMute(getMicMute_cb _hidl_cb) {
52 return mDevice->getMicMute(_hidl_cb);
53 }
54
setMasterMute(bool mute)55 Return<Result> PrimaryDevice::setMasterMute(bool mute) {
56 return mDevice->setMasterMute(mute);
57 }
58
getMasterMute(getMasterMute_cb _hidl_cb)59 Return<void> PrimaryDevice::getMasterMute(getMasterMute_cb _hidl_cb) {
60 return mDevice->getMasterMute(_hidl_cb);
61 }
62
getInputBufferSize(const AudioConfig & config,getInputBufferSize_cb _hidl_cb)63 Return<void> PrimaryDevice::getInputBufferSize(const AudioConfig& config,
64 getInputBufferSize_cb _hidl_cb) {
65 return mDevice->getInputBufferSize(config, _hidl_cb);
66 }
67
openOutputStream(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,AudioOutputFlag flags,openOutputStream_cb _hidl_cb)68 Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle,
69 const DeviceAddress& device,
70 const AudioConfig& config,
71 AudioOutputFlag flags,
72 openOutputStream_cb _hidl_cb) {
73 return mDevice->openOutputStream(ioHandle, device, config, flags, _hidl_cb);
74 }
75
openInputStream(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,AudioInputFlag flags,AudioSource source,openInputStream_cb _hidl_cb)76 Return<void> PrimaryDevice::openInputStream(
77 int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
78 AudioInputFlag flags, AudioSource source, openInputStream_cb _hidl_cb) {
79 return mDevice->openInputStream(ioHandle, device, config, flags, source,
80 _hidl_cb);
81 }
82
supportsAudioPatches()83 Return<bool> PrimaryDevice::supportsAudioPatches() {
84 return mDevice->supportsAudioPatches();
85 }
86
createAudioPatch(const hidl_vec<AudioPortConfig> & sources,const hidl_vec<AudioPortConfig> & sinks,createAudioPatch_cb _hidl_cb)87 Return<void> PrimaryDevice::createAudioPatch(
88 const hidl_vec<AudioPortConfig>& sources,
89 const hidl_vec<AudioPortConfig>& sinks, createAudioPatch_cb _hidl_cb) {
90 return mDevice->createAudioPatch(sources, sinks, _hidl_cb);
91 }
92
releaseAudioPatch(int32_t patch)93 Return<Result> PrimaryDevice::releaseAudioPatch(int32_t patch) {
94 return mDevice->releaseAudioPatch(patch);
95 }
96
getAudioPort(const AudioPort & port,getAudioPort_cb _hidl_cb)97 Return<void> PrimaryDevice::getAudioPort(const AudioPort& port,
98 getAudioPort_cb _hidl_cb) {
99 return mDevice->getAudioPort(port, _hidl_cb);
100 }
101
setAudioPortConfig(const AudioPortConfig & config)102 Return<Result> PrimaryDevice::setAudioPortConfig(
103 const AudioPortConfig& config) {
104 return mDevice->setAudioPortConfig(config);
105 }
106
getHwAvSync()107 Return<AudioHwSync> PrimaryDevice::getHwAvSync() {
108 return mDevice->getHwAvSync();
109 }
110
setScreenState(bool turnedOn)111 Return<Result> PrimaryDevice::setScreenState(bool turnedOn) {
112 return mDevice->setScreenState(turnedOn);
113 }
114
getParameters(const hidl_vec<hidl_string> & keys,getParameters_cb _hidl_cb)115 Return<void> PrimaryDevice::getParameters(const hidl_vec<hidl_string>& keys,
116 getParameters_cb _hidl_cb) {
117 return mDevice->getParameters(keys, _hidl_cb);
118 }
119
setParameters(const hidl_vec<ParameterValue> & parameters)120 Return<Result> PrimaryDevice::setParameters(
121 const hidl_vec<ParameterValue>& parameters) {
122 return mDevice->setParameters(parameters);
123 }
124
debugDump(const hidl_handle & fd)125 Return<void> PrimaryDevice::debugDump(const hidl_handle& fd) {
126 return mDevice->debugDump(fd);
127 }
128
129 // Methods from ::android::hardware::audio::V2_0::IPrimaryDevice follow.
setVoiceVolume(float volume)130 Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
131 if (!isGainNormalized(volume)) {
132 ALOGW("Can not set a voice volume (%f) outside [0,1]", volume);
133 return Result::INVALID_ARGUMENTS;
134 }
135 return mDevice->analyzeStatus(
136 "set_voice_volume",
137 mDevice->device()->set_voice_volume(mDevice->device(), volume));
138 }
139
setMode(AudioMode mode)140 Return<Result> PrimaryDevice::setMode(AudioMode mode) {
141 // INVALID, CURRENT, CNT, MAX are reserved for internal use.
142 // TODO: remove the values from the HIDL interface
143 switch (mode) {
144 case AudioMode::NORMAL:
145 case AudioMode::RINGTONE:
146 case AudioMode::IN_CALL:
147 case AudioMode::IN_COMMUNICATION:
148 break; // Valid values
149 default:
150 return Result::INVALID_ARGUMENTS;
151 };
152
153 return mDevice->analyzeStatus(
154 "set_mode", mDevice->device()->set_mode(
155 mDevice->device(), static_cast<audio_mode_t>(mode)));
156 }
157
getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb)158 Return<void> PrimaryDevice::getBtScoNrecEnabled(
159 getBtScoNrecEnabled_cb _hidl_cb) {
160 bool enabled;
161 Result retval = mDevice->getParam(AudioParameter::keyBtNrec, &enabled);
162 _hidl_cb(retval, enabled);
163 return Void();
164 }
165
setBtScoNrecEnabled(bool enabled)166 Return<Result> PrimaryDevice::setBtScoNrecEnabled(bool enabled) {
167 return mDevice->setParam(AudioParameter::keyBtNrec, enabled);
168 }
169
getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb)170 Return<void> PrimaryDevice::getBtScoWidebandEnabled(
171 getBtScoWidebandEnabled_cb _hidl_cb) {
172 bool enabled;
173 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, &enabled);
174 _hidl_cb(retval, enabled);
175 return Void();
176 }
177
setBtScoWidebandEnabled(bool enabled)178 Return<Result> PrimaryDevice::setBtScoWidebandEnabled(bool enabled) {
179 return mDevice->setParam(AUDIO_PARAMETER_KEY_BT_SCO_WB, enabled);
180 }
181
getTtyMode(getTtyMode_cb _hidl_cb)182 Return<void> PrimaryDevice::getTtyMode(getTtyMode_cb _hidl_cb) {
183 int halMode;
184 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_TTY_MODE, &halMode);
185 TtyMode mode = retval == Result::OK ? TtyMode(halMode) : TtyMode::OFF;
186 _hidl_cb(retval, mode);
187 return Void();
188 }
189
setTtyMode(IPrimaryDevice::TtyMode mode)190 Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) {
191 return mDevice->setParam(AUDIO_PARAMETER_KEY_TTY_MODE,
192 static_cast<int>(mode));
193 }
194
getHacEnabled(getHacEnabled_cb _hidl_cb)195 Return<void> PrimaryDevice::getHacEnabled(getHacEnabled_cb _hidl_cb) {
196 bool enabled;
197 Result retval = mDevice->getParam(AUDIO_PARAMETER_KEY_HAC, &enabled);
198 _hidl_cb(retval, enabled);
199 return Void();
200 }
201
setHacEnabled(bool enabled)202 Return<Result> PrimaryDevice::setHacEnabled(bool enabled) {
203 return mDevice->setParam(AUDIO_PARAMETER_KEY_HAC, enabled);
204 }
205
206 } // namespace implementation
207 } // namespace V2_0
208 } // namespace audio
209 } // namespace hardware
210 } // namespace android
211