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