From 04c9f39b3a123f242cf08c7a75d6ad297bd1986a Mon Sep 17 00:00:00 2001 From: Vaidegi B Date: Wed, 8 Sep 2021 14:50:14 +0530 Subject: [PATCH] Update DeviceType values and use new enum ActiveDeviceType enum for DeviceActive APIs Signed-off-by: Vaidegi B --- .../1.0/include/audio_policy_test.h | 117 +-- .../audiopolicy/1.0/src/audio_policy_test.cpp | 960 +++++++++--------- .../src/audio_device_descriptor_napi.cpp | 53 +- .../audio_manager/src/audio_manager_napi.cpp | 136 ++- .../native/audiocommon/include/audio_info.h | 48 +- .../include/audio_system_manager.h | 48 +- .../include/audio_policy_manager.h | 7 +- .../audio_manager/@ohos.multimedia.audio.d.ts | 37 +- .../include/audio_device_descriptor_napi.h | 14 - .../include/audio_manager_napi.h | 8 +- services/BUILD.gn | 1 + .../audio_policy/client/audio_policy_base.h | 5 +- .../audio_policy/client/audio_policy_proxy.h | 4 +- .../audio_policy/server/audio_policy_server.h | 4 +- .../client/audio_policy_manager.cpp | 4 +- .../client/audio_policy_proxy.cpp | 4 +- .../server/audio_policy_manager_stub.cpp | 4 +- .../server/audio_policy_server.cpp | 4 +- .../service/include/audio_policy_service.h | 25 +- .../service/include/config/xml_parser.h | 2 +- .../interface/iaudio_policy_interface.h | 4 +- .../include/interface/iport_observer.h | 4 +- .../include/manager/audio_adapter_manager.h | 2 +- .../service/src/audio_policy_service.cpp | 55 +- .../server/service/src/config/xml_parser.cpp | 9 +- .../src/manager/audio_adapter_manager.cpp | 9 +- services/src/client/audio_system_manager.cpp | 14 +- services/test/audio_policy_test.cpp | 11 +- 28 files changed, 741 insertions(+), 852 deletions(-) diff --git a/frameworks/innerkitsimpl/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h b/frameworks/innerkitsimpl/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h index 472f942660..c93f2b0e9a 100644 --- a/frameworks/innerkitsimpl/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h +++ b/frameworks/innerkitsimpl/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h @@ -1,58 +1,59 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * 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 -#include -#include -#include -#include - -namespace OHOS { -namespace AudioStandard { -namespace V1_0 { -using namespace std; -using namespace testing; - -struct PolicyParam { - float volume; - AudioStreamType streamType; - AudioRingerMode ringerMode; - AudioStandard::DeviceType deviceType; - AudioStandard::AudioDeviceDescriptor::DeviceFlag deviceFlag; - AudioStandard::AudioDeviceDescriptor::DeviceRole deviceRole; - bool active; - bool mute; - string key; - string value; -}; - -class AudioPolicyTest : public TestWithParam { -public: - AudioPolicyTest() {} - - virtual ~AudioPolicyTest() {} - - // SetUpTestCase: Called before all test cases - static void SetUpTestCase(void); - // TearDownTestCase: Called after all test case - static void TearDownTestCase(void); - // SetUp: Called before each test cases - void SetUp(void) override; - // TearDown: Called after each test cases - void TearDown(void) override; -}; -} -} -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 +#include +#include +#include +#include + +namespace OHOS { +namespace AudioStandard { +namespace V1_0 { +using namespace std; +using namespace testing; + +struct PolicyParam { + float volume; + AudioStreamType streamType; + AudioRingerMode ringerMode; + ActiveDeviceType actDeviceType; + AudioDeviceDescriptor::DeviceType deviceType; + AudioDeviceDescriptor::DeviceFlag deviceFlag; + AudioDeviceDescriptor::DeviceRole deviceRole; + bool active; + bool mute; + string key; + string value; +}; + +class AudioPolicyTest : public TestWithParam { +public: + AudioPolicyTest() {} + + virtual ~AudioPolicyTest() {} + + // SetUpTestCase: Called before all test cases + static void SetUpTestCase(void); + // TearDownTestCase: Called after all test case + static void TearDownTestCase(void); + // SetUp: Called before each test cases + void SetUp(void) override; + // TearDown: Called after each test cases + void TearDown(void) override; +}; +} +} +} diff --git a/frameworks/innerkitsimpl/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp b/frameworks/innerkitsimpl/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp index f2d5fb8efa..1aba9b58c7 100644 --- a/frameworks/innerkitsimpl/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp +++ b/frameworks/innerkitsimpl/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp @@ -1,493 +1,467 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * 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 "audio_policy_test.h" -#include "audio_system_manager.h" - -using namespace std; -using namespace OHOS::AudioStandard; -using namespace testing::ext; - -namespace OHOS { -namespace AudioStandard { -namespace V1_0 { -void AudioPolicyTest::SetUpTestCase(void) -{ - ASSERT_NE(nullptr, AudioSystemManager::GetInstance()); -} - -void AudioPolicyTest::TearDownTestCase(void) {} - -void AudioPolicyTest::SetUp(void) {} - -void AudioPolicyTest::TearDown(void) {} - -namespace { -const PolicyParam VOLUME_PARAMS[] = { - { - .volume = 0.5, - .streamType = STREAM_MUSIC - }, - { - .volume = 0.5, - .streamType = STREAM_RING - } -}; - -const PolicyParam MUTE_PARAMS[] = { - { - .streamType = STREAM_MUSIC, - .mute = true - }, - { - .streamType = STREAM_MUSIC, - .mute = false - } -}; - -const PolicyParam STREAM_PARAMS[] = { - { - .streamType = STREAM_MUSIC, - .active = true - }, - { - .streamType = STREAM_RING, - .active = false - } -}; - -const PolicyParam DEVICE_PARAMS[] = { - { - .deviceType = SPEAKER, - .active = true - }, - { - .deviceType = MIC, - .active = true - }, - { - .deviceType = BLUETOOTH_A2DP, - .active = true - }, - { - .deviceType = BLUETOOTH_A2DP, - .active = false - }, - { - .deviceType = BLUETOOTH_SCO, - .active = true - }, - { - .deviceType = BLUETOOTH_SCO, - .active = false - }, - { - .deviceType = MIC, - .active = true - }, - { - .deviceType = BLUETOOTH_SCO, - .active = true - }, - { - .deviceType = SPEAKER, - .active = true - }, - { - .deviceType = BLUETOOTH_A2DP, - .active = true - }, -}; - -const PolicyParam RINGER_MODE_PARAMS[] = { - { - .ringerMode = RINGER_MODE_NORMAL - }, - { - .ringerMode = RINGER_MODE_SILENT - }, - { - .ringerMode = RINGER_MODE_VIBRATE - }, -}; - -const PolicyParam MIC_MUTE_PARAMS[] = { - { - .mute = true - }, - { - .mute = false - } -}; - -const PolicyParam VOLUME_RANGE_PARAMS[] = { - { - .streamType = STREAM_MUSIC - }, - { - .streamType = STREAM_RING - } -}; - -const PolicyParam AUDIO_PARAMS[] = { - { - .key = "sampling_rate", - .value = "8000" - }, - { - .key = "sampling_rate", - .value = "44100" - }, - { - .key = "sampling_rate", - .value = "96000" - } -}; - -const PolicyParam DEVICES_PARAMS[] = { - { - .deviceType = MIC, - .deviceFlag = AudioDeviceDescriptor::DeviceFlag::INPUT_DEVICES_FLAG, - .deviceRole = AudioDeviceDescriptor::DeviceRole::INPUT_DEVICE - }, - { - .deviceType = SPEAKER, - .deviceFlag = AudioDeviceDescriptor::DeviceFlag::OUTPUT_DEVICES_FLAG, - .deviceRole = AudioDeviceDescriptor::DeviceRole::OUTPUT_DEVICE - } -}; -} // namespace - -/* - * Set Volume - * - */ -class AudioPolicySetVolumeTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicySetVolumeTest, SetVolume, TestSize.Level1) -{ - PolicyParam params = GetParam(); - - AudioSystemManager::AudioVolumeType volumeType - = static_cast(params.streamType); - float volume = params.volume; - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetVolume(volumeType, volume)); -} - -INSTANTIATE_TEST_CASE_P( - SetVolume, - AudioPolicySetVolumeTest, - ValuesIn(VOLUME_PARAMS)); - -/* - * Get Volume - * - */ - -class AudioPolicyGetVolumeTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyGetVolumeTest, GetVolume, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioSystemManager::AudioVolumeType volumeType - = static_cast(params.streamType); - float volume = params.volume; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetVolume(volumeType, volume)); - EXPECT_EQ(volume, AudioSystemManager::GetInstance()->GetVolume(volumeType)); -} - -INSTANTIATE_TEST_CASE_P( - GetVolume, - AudioPolicyGetVolumeTest, - ValuesIn(VOLUME_PARAMS)); - -/* - * Set Mute - * - */ -class AudioPolicySetMuteTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicySetMuteTest, SetMute, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioSystemManager::AudioVolumeType volumeType - = static_cast(params.streamType); - bool mute = params.mute; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetMute(volumeType, mute)); -} - - -INSTANTIATE_TEST_CASE_P( - SetMute, - AudioPolicySetMuteTest, - ValuesIn(MUTE_PARAMS)); - -/* - * Is Mute - * - */ -class AudioPolicyGetMuteTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyGetMuteTest, IsStreamMute, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioSystemManager::AudioVolumeType volumeType - = static_cast(params.streamType); - bool mute = params.mute; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetMute(volumeType, mute)); - EXPECT_EQ(mute, AudioSystemManager::GetInstance()->IsStreamMute(volumeType)); -} - -INSTANTIATE_TEST_CASE_P( - IsStreamMute, - AudioPolicyGetMuteTest, - ValuesIn(MUTE_PARAMS)); - -/* - * Is Stream Active - * - */ -class AudioPolicyIsStreamActiveTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyIsStreamActiveTest, IsStreamActive, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioSystemManager::AudioVolumeType volumeType - = static_cast(params.streamType); - - // review this code - EXPECT_EQ(params.active, AudioSystemManager::GetInstance()->IsStreamActive(volumeType)); -} - -INSTANTIATE_TEST_CASE_P( - IsStreamActive, - AudioPolicyIsStreamActiveTest, - ValuesIn(STREAM_PARAMS)); - -/* - * Set Device Active - * - */ -class AudioPolicySetDeviceActiveTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicySetDeviceActiveTest, SetDeviceActive, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioDeviceDescriptor::DeviceType deviceType = static_cast(params.deviceType); - bool active = params.active; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetDeviceActive(deviceType, active)); -} - -INSTANTIATE_TEST_CASE_P( - SetDeviceActive, - AudioPolicySetDeviceActiveTest, - ValuesIn(DEVICE_PARAMS)); - -/* - * Is Device Active - * - */ - -class AudioPolicyIsDeviceActiveTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyIsDeviceActiveTest, IsDeviceActive, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioDeviceDescriptor::DeviceType deviceType = static_cast(params.deviceType); - bool active = params.active; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetDeviceActive(deviceType, active)); - EXPECT_EQ(active, AudioSystemManager::GetInstance()->IsDeviceActive(deviceType)); -} - - -INSTANTIATE_TEST_CASE_P( - IsDeviceActive, - AudioPolicyIsDeviceActiveTest, - ValuesIn(DEVICE_PARAMS)); - -/* - * Set Ringer Mode - * - */ -class AudioPolicySetRingerModeTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicySetRingerModeTest, SetRingerMode, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioRingerMode ringerMode = params.ringerMode; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetRingerMode(ringerMode)); -} - - -INSTANTIATE_TEST_CASE_P( - SetRingerMode, - AudioPolicySetRingerModeTest, - ValuesIn(RINGER_MODE_PARAMS)); - -/* - * Get Ringer Mode - * - */ - -class AudioPolicyGetRingerModeTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyGetRingerModeTest, GetRingerMode, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioRingerMode ringerMode = params.ringerMode; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetRingerMode(ringerMode)); - EXPECT_EQ(ringerMode, AudioSystemManager::GetInstance()->GetRingerMode()); -} - -INSTANTIATE_TEST_CASE_P( - GetRingerMode, - AudioPolicyGetRingerModeTest, - ValuesIn(RINGER_MODE_PARAMS)); - - -/* - * Set microphone mute - * - */ -class AudioPolicySetMicrophoneMuteTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicySetMicrophoneMuteTest, SetMicrophoneMute, TestSize.Level1) -{ - PolicyParam params = GetParam(); - bool mute = params.mute; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetMicrophoneMute(mute)); -} - -INSTANTIATE_TEST_CASE_P( - SetMicrophoneMute, - AudioPolicySetMicrophoneMuteTest, - ValuesIn(MIC_MUTE_PARAMS)); - -/* - * Is Microphone Mute - * - */ -class AudioPolicyGetMicrophoneMuteTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyGetMicrophoneMuteTest, IsMicrophoneMute, TestSize.Level1) -{ - PolicyParam params = GetParam(); - bool mute = params.mute; - - EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetMicrophoneMute(mute)); - EXPECT_EQ(mute, AudioSystemManager::GetInstance()->IsMicrophoneMute()); -} - -INSTANTIATE_TEST_CASE_P( - IsMicrophoneMute, - AudioPolicyGetMicrophoneMuteTest, - ValuesIn(MIC_MUTE_PARAMS)); - -/* - * Check volume range - * - */ -class AudioPolicyVolumeRangeTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyVolumeRangeTest, GetMaxVolume, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioSystemManager::AudioVolumeType volumeType - = static_cast(params.streamType); - EXPECT_EQ(1.0, AudioSystemManager::GetInstance()->GetMaxVolume(volumeType)); -} - -HWTEST_P(AudioPolicyVolumeRangeTest, GetMinVolume, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioSystemManager::AudioVolumeType volumeType - = static_cast(params.streamType); - EXPECT_EQ(0, AudioSystemManager::GetInstance()->GetMinVolume(volumeType)); -} - -INSTANTIATE_TEST_CASE_P( - GetMaxVolume, - AudioPolicyVolumeRangeTest, - ValuesIn(VOLUME_RANGE_PARAMS)); - -INSTANTIATE_TEST_CASE_P( - GetMinVolume, - AudioPolicyVolumeRangeTest, - ValuesIn(VOLUME_RANGE_PARAMS)); - -/* - * Check volume range - * - */ -class AudioPolicyAudioParameterTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyAudioParameterTest, SetAudioParameter, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioSystemManager::GetInstance()->SetAudioParameter(params.key, params.value); - EXPECT_EQ(params.value, AudioSystemManager::GetInstance()->GetAudioParameter(params.key)); -} - -INSTANTIATE_TEST_CASE_P( - SetAudioParameter, - AudioPolicyAudioParameterTest, - ValuesIn(AUDIO_PARAMS)); - -HWTEST_P(AudioPolicyAudioParameterTest, GetAudioParameter, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioSystemManager::GetInstance()->SetAudioParameter(params.key, params.value); - EXPECT_EQ(params.value, AudioSystemManager::GetInstance()->GetAudioParameter(params.key)); -} - -INSTANTIATE_TEST_CASE_P( - GetAudioParameter, - AudioPolicyAudioParameterTest, - ValuesIn(AUDIO_PARAMS)); - -/* - * Check volume range - * - */ -class AudioPolicyGetDevicesTest : public AudioPolicyTest {}; - -HWTEST_P(AudioPolicyGetDevicesTest, GetDevices, TestSize.Level1) -{ - PolicyParam params = GetParam(); - AudioDeviceDescriptor::DeviceFlag deviceFlag = static_cast(params.deviceFlag); - AudioDeviceDescriptor::DeviceType deviceType = static_cast(params.deviceType); - AudioDeviceDescriptor::DeviceRole deviceRole = static_cast(params.deviceRole); - vector> audioDeviceDescriptors - = AudioSystemManager::GetInstance()->GetDevices(deviceFlag); - sptr audioDeviceDescriptor = audioDeviceDescriptors[0]; - EXPECT_EQ(deviceType, audioDeviceDescriptor->deviceType_); - EXPECT_EQ(deviceRole, audioDeviceDescriptor->deviceRole_); -} - -INSTANTIATE_TEST_CASE_P( - GetDevices, - AudioPolicyGetDevicesTest, - ValuesIn(DEVICES_PARAMS)); -} -} -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * 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 "audio_policy_test.h" +#include "audio_system_manager.h" + +using namespace std; +using namespace OHOS::AudioStandard; +using namespace testing::ext; + +namespace OHOS { +namespace AudioStandard { +namespace V1_0 { +void AudioPolicyTest::SetUpTestCase(void) +{ + ASSERT_NE(nullptr, AudioSystemManager::GetInstance()); +} + +void AudioPolicyTest::TearDownTestCase(void) {} + +void AudioPolicyTest::SetUp(void) {} + +void AudioPolicyTest::TearDown(void) {} + +namespace { +const PolicyParam VOLUME_PARAMS[] = { + { + .volume = 8, + .streamType = STREAM_MUSIC + }, + { + .volume = 8, + .streamType = STREAM_RING + } +}; + +const PolicyParam MUTE_PARAMS[] = { + { + .streamType = STREAM_MUSIC, + .mute = true + }, + { + .streamType = STREAM_MUSIC, + .mute = false + } +}; + +const PolicyParam STREAM_PARAMS[] = { + { + .streamType = STREAM_MUSIC, + .active = true + }, + { + .streamType = STREAM_RING, + .active = false + } +}; + +const PolicyParam ACTIVE_DEVICE_PARAMS[] = { + { + .actDeviceType = SPEAKER, + .active = true + }, + { + .actDeviceType = BLUETOOTH_SCO, + .active = true + }, + { + .actDeviceType = BLUETOOTH_SCO, + .active = false + }, + { + .actDeviceType = SPEAKER, + .active = true + }, + { + .actDeviceType = BLUETOOTH_SCO, + .active = true + }, +}; + +const PolicyParam RINGER_MODE_PARAMS[] = { + { + .ringerMode = RINGER_MODE_NORMAL + }, + { + .ringerMode = RINGER_MODE_SILENT + }, + { + .ringerMode = RINGER_MODE_VIBRATE + }, +}; + +const PolicyParam MIC_MUTE_PARAMS[] = { + { + .mute = true + }, + { + .mute = false + } +}; + +const PolicyParam VOLUME_RANGE_PARAMS[] = { + { + .streamType = STREAM_MUSIC + }, + { + .streamType = STREAM_RING + } +}; + +const PolicyParam AUDIO_PARAMS[] = { + { + .key = "sampling_rate", + .value = "8000" + }, + { + .key = "sampling_rate", + .value = "44100" + }, + { + .key = "sampling_rate", + .value = "96000" + } +}; + +const PolicyParam DEVICES_PARAMS[] = { + { + .deviceType = AudioDeviceDescriptor::MIC, + .deviceFlag = AudioDeviceDescriptor::DeviceFlag::INPUT_DEVICES_FLAG, + .deviceRole = AudioDeviceDescriptor::DeviceRole::INPUT_DEVICE + }, + { + .deviceType = AudioDeviceDescriptor::SPEAKER, + .deviceFlag = AudioDeviceDescriptor::DeviceFlag::OUTPUT_DEVICES_FLAG, + .deviceRole = AudioDeviceDescriptor::DeviceRole::OUTPUT_DEVICE + } +}; +} // namespace + +/* + * Set Volume + * + */ +class AudioPolicySetVolumeTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicySetVolumeTest, SetVolume, TestSize.Level1) +{ + PolicyParam params = GetParam(); + + AudioSystemManager::AudioVolumeType volumeType + = static_cast(params.streamType); + float volume = params.volume; + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetVolume(volumeType, volume)); +} + +INSTANTIATE_TEST_CASE_P( + SetVolume, + AudioPolicySetVolumeTest, + ValuesIn(VOLUME_PARAMS)); + +/* + * Get Volume + * + */ +class AudioPolicyGetVolumeTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyGetVolumeTest, GetVolume, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioSystemManager::AudioVolumeType volumeType + = static_cast(params.streamType); + float volume = params.volume; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetVolume(volumeType, volume)); + EXPECT_EQ(volume, AudioSystemManager::GetInstance()->GetVolume(volumeType)); +} + +INSTANTIATE_TEST_CASE_P( + GetVolume, + AudioPolicyGetVolumeTest, + ValuesIn(VOLUME_PARAMS)); + +/* + * Set Mute + * + */ +class AudioPolicySetMuteTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicySetMuteTest, SetMute, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioSystemManager::AudioVolumeType volumeType + = static_cast(params.streamType); + bool mute = params.mute; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetMute(volumeType, mute)); +} + +INSTANTIATE_TEST_CASE_P( + SetMute, + AudioPolicySetMuteTest, + ValuesIn(MUTE_PARAMS)); + +/* + * Is Mute + * + */ +class AudioPolicyGetMuteTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyGetMuteTest, IsStreamMute, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioSystemManager::AudioVolumeType volumeType + = static_cast(params.streamType); + bool mute = params.mute; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetMute(volumeType, mute)); + EXPECT_EQ(mute, AudioSystemManager::GetInstance()->IsStreamMute(volumeType)); +} + +INSTANTIATE_TEST_CASE_P( + IsStreamMute, + AudioPolicyGetMuteTest, + ValuesIn(MUTE_PARAMS)); + +/* + * Is Stream Active + * + */ +class AudioPolicyIsStreamActiveTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyIsStreamActiveTest, IsStreamActive, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioSystemManager::AudioVolumeType volumeType + = static_cast(params.streamType); + + // review this code + EXPECT_EQ(params.active, AudioSystemManager::GetInstance()->IsStreamActive(volumeType)); +} + +INSTANTIATE_TEST_CASE_P( + IsStreamActive, + AudioPolicyIsStreamActiveTest, + ValuesIn(STREAM_PARAMS)); + +/* + * Set Device Active + * + */ +class AudioPolicySetDeviceActiveTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicySetDeviceActiveTest, SetDeviceActive, TestSize.Level1) +{ + PolicyParam params = GetParam(); + ActiveDeviceType deviceType = params.actDeviceType; + bool active = params.active; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetDeviceActive(deviceType, active)); +} + +INSTANTIATE_TEST_CASE_P( + SetDeviceActive, + AudioPolicySetDeviceActiveTest, + ValuesIn(ACTIVE_DEVICE_PARAMS)); + +/* + * Is Device Active + * + */ +class AudioPolicyIsDeviceActiveTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyIsDeviceActiveTest, IsDeviceActive, TestSize.Level1) +{ + PolicyParam params = GetParam(); + ActiveDeviceType deviceType = params.actDeviceType; + bool active = params.active; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetDeviceActive(deviceType, active)); + EXPECT_EQ(active, AudioSystemManager::GetInstance()->IsDeviceActive(deviceType)); +} + +INSTANTIATE_TEST_CASE_P( + IsDeviceActive, + AudioPolicyIsDeviceActiveTest, + ValuesIn(ACTIVE_DEVICE_PARAMS)); + +/* + * Set Ringer Mode + * + */ +class AudioPolicySetRingerModeTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicySetRingerModeTest, SetRingerMode, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioRingerMode ringerMode = params.ringerMode; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetRingerMode(ringerMode)); +} + + +INSTANTIATE_TEST_CASE_P( + SetRingerMode, + AudioPolicySetRingerModeTest, + ValuesIn(RINGER_MODE_PARAMS)); + +/* + * Get Ringer Mode + * + */ +class AudioPolicyGetRingerModeTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyGetRingerModeTest, GetRingerMode, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioRingerMode ringerMode = params.ringerMode; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetRingerMode(ringerMode)); + EXPECT_EQ(ringerMode, AudioSystemManager::GetInstance()->GetRingerMode()); +} + +INSTANTIATE_TEST_CASE_P( + GetRingerMode, + AudioPolicyGetRingerModeTest, + ValuesIn(RINGER_MODE_PARAMS)); + +/* + * Set microphone mute + * + */ +class AudioPolicySetMicrophoneMuteTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicySetMicrophoneMuteTest, SetMicrophoneMute, TestSize.Level1) +{ + PolicyParam params = GetParam(); + bool mute = params.mute; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetMicrophoneMute(mute)); +} + +INSTANTIATE_TEST_CASE_P( + SetMicrophoneMute, + AudioPolicySetMicrophoneMuteTest, + ValuesIn(MIC_MUTE_PARAMS)); + +/* + * Is Microphone Mute + * + */ +class AudioPolicyGetMicrophoneMuteTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyGetMicrophoneMuteTest, IsMicrophoneMute, TestSize.Level1) +{ + PolicyParam params = GetParam(); + bool mute = params.mute; + + EXPECT_EQ(MEDIA_OK, AudioSystemManager::GetInstance()->SetMicrophoneMute(mute)); + EXPECT_EQ(mute, AudioSystemManager::GetInstance()->IsMicrophoneMute()); +} + +INSTANTIATE_TEST_CASE_P( + IsMicrophoneMute, + AudioPolicyGetMicrophoneMuteTest, + ValuesIn(MIC_MUTE_PARAMS)); + +/* + * Check volume range + * + */ +class AudioPolicyVolumeRangeTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyVolumeRangeTest, GetMaxVolume, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioSystemManager::AudioVolumeType volumeType + = static_cast(params.streamType); + EXPECT_EQ(1.0, AudioSystemManager::GetInstance()->GetMaxVolume(volumeType)); +} + +HWTEST_P(AudioPolicyVolumeRangeTest, GetMinVolume, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioSystemManager::AudioVolumeType volumeType + = static_cast(params.streamType); + EXPECT_EQ(0, AudioSystemManager::GetInstance()->GetMinVolume(volumeType)); +} + +INSTANTIATE_TEST_CASE_P( + GetMaxVolume, + AudioPolicyVolumeRangeTest, + ValuesIn(VOLUME_RANGE_PARAMS)); + +INSTANTIATE_TEST_CASE_P( + GetMinVolume, + AudioPolicyVolumeRangeTest, + ValuesIn(VOLUME_RANGE_PARAMS)); + +/* + * Check volume range + * + */ +class AudioPolicyAudioParameterTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyAudioParameterTest, SetAudioParameter, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioSystemManager::GetInstance()->SetAudioParameter(params.key, params.value); + EXPECT_EQ(params.value, AudioSystemManager::GetInstance()->GetAudioParameter(params.key)); +} + +INSTANTIATE_TEST_CASE_P( + SetAudioParameter, + AudioPolicyAudioParameterTest, + ValuesIn(AUDIO_PARAMS)); + +HWTEST_P(AudioPolicyAudioParameterTest, GetAudioParameter, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioSystemManager::GetInstance()->SetAudioParameter(params.key, params.value); + EXPECT_EQ(params.value, AudioSystemManager::GetInstance()->GetAudioParameter(params.key)); +} + +INSTANTIATE_TEST_CASE_P( + GetAudioParameter, + AudioPolicyAudioParameterTest, + ValuesIn(AUDIO_PARAMS)); + +/* + * Check volume range + * + */ +class AudioPolicyGetDevicesTest : public AudioPolicyTest {}; + +HWTEST_P(AudioPolicyGetDevicesTest, GetDevices, TestSize.Level1) +{ + PolicyParam params = GetParam(); + AudioDeviceDescriptor::DeviceFlag deviceFlag = params.deviceFlag; + AudioDeviceDescriptor::DeviceType deviceType = params.deviceType; + AudioDeviceDescriptor::DeviceRole deviceRole = params.deviceRole; + vector> audioDeviceDescriptors + = AudioSystemManager::GetInstance()->GetDevices(deviceFlag); + sptr audioDeviceDescriptor = audioDeviceDescriptors[0]; + EXPECT_EQ(deviceType, audioDeviceDescriptor->deviceType_); + EXPECT_EQ(deviceRole, audioDeviceDescriptor->deviceRole_); +} + +INSTANTIATE_TEST_CASE_P( + GetDevices, + AudioPolicyGetDevicesTest, + ValuesIn(DEVICES_PARAMS)); +} +} +} diff --git a/frameworks/kitsimpl/audio_manager/src/audio_device_descriptor_napi.cpp b/frameworks/kitsimpl/audio_manager/src/audio_device_descriptor_napi.cpp index 2ee0823282..02d7d6e7a4 100644 --- a/frameworks/kitsimpl/audio_manager/src/audio_device_descriptor_napi.cpp +++ b/frameworks/kitsimpl/audio_manager/src/audio_device_descriptor_napi.cpp @@ -50,55 +50,6 @@ void AudioDeviceDescriptorNapi::Destructor(napi_env env, void *nativeObject, voi } } -static AudioDeviceDescriptorNapi::DeviceType GetJSDeviceType(AudioDeviceDescriptor::DeviceType deviceType) -{ - AudioDeviceDescriptorNapi::DeviceType result; - - switch (deviceType) { - case AudioDeviceDescriptor::SPEAKER: - result = AudioDeviceDescriptorNapi::SPEAKER; - break; - case AudioDeviceDescriptor::WIRED_HEADSET: - result = AudioDeviceDescriptorNapi::WIRED_HEADSET; - break; - case AudioDeviceDescriptor::BLUETOOTH_SCO: - result = AudioDeviceDescriptorNapi::BLUETOOTH_SCO; - break; - case AudioDeviceDescriptor::BLUETOOTH_A2DP: - result = AudioDeviceDescriptorNapi::BLUETOOTH_A2DP; - break; - case AudioDeviceDescriptor::MIC: - result = AudioDeviceDescriptorNapi::MIC; - break; - default: - result = AudioDeviceDescriptorNapi::INVALID; - HiLog::Error(LABEL, "Unknown device type!"); - break; - } - - return result; -} - -static AudioDeviceDescriptorNapi::DeviceRole GetJSDeviceRole(AudioDeviceDescriptor::DeviceRole deviceRole) -{ - AudioDeviceDescriptorNapi::DeviceRole result; - - switch (deviceRole) { - case AudioDeviceDescriptor::INPUT_DEVICE: - result = AudioDeviceDescriptorNapi::INPUT_DEVICE; - break; - case AudioDeviceDescriptor::OUTPUT_DEVICE: - result = AudioDeviceDescriptorNapi::OUTPUT_DEVICE; - break; - default: - result = AudioDeviceDescriptorNapi::INPUT_DEVICE; - HiLog::Error(LABEL, "Unknown device role!"); - break; - } - - return result; -} - napi_value AudioDeviceDescriptorNapi::Init(napi_env env, napi_value exports) { napi_status status; @@ -193,7 +144,7 @@ napi_value AudioDeviceDescriptorNapi::GetDeviceRole(napi_env env, napi_callback_ status = napi_unwrap(env, thisVar, (void **)&deviceDescriptor); if (status == napi_ok) { deviceRole = deviceDescriptor->audioDescriptor_->deviceRole_; - status = napi_create_int32(env, GetJSDeviceRole(deviceRole), &jsResult); + status = napi_create_int32(env, deviceRole, &jsResult); if (status == napi_ok) { return jsResult; } @@ -216,7 +167,7 @@ napi_value AudioDeviceDescriptorNapi::GetDeviceType(napi_env env, napi_callback_ status = napi_unwrap(env, thisVar, (void **)&deviceDescriptor); if (status == napi_ok) { deviceType = deviceDescriptor->audioDescriptor_->deviceType_; - status = napi_create_int32(env, GetJSDeviceType(deviceType), &jsResult); + status = napi_create_int32(env, deviceType, &jsResult); if (status == napi_ok) { return jsResult; } diff --git a/frameworks/kitsimpl/audio_manager/src/audio_manager_napi.cpp b/frameworks/kitsimpl/audio_manager/src/audio_manager_napi.cpp index 1170dd5a61..e67cc4fff7 100644 --- a/frameworks/kitsimpl/audio_manager/src/audio_manager_napi.cpp +++ b/frameworks/kitsimpl/audio_manager/src/audio_manager_napi.cpp @@ -28,6 +28,7 @@ napi_ref AudioManagerNapi::audioVolumeTypeRef_ = nullptr; napi_ref AudioManagerNapi::deviceFlagRef_ = nullptr; napi_ref AudioManagerNapi::deviceRoleRef_ = nullptr; napi_ref AudioManagerNapi::deviceTypeRef_ = nullptr; +napi_ref AudioManagerNapi::activeDeviceTypeRef_ = nullptr; napi_ref AudioManagerNapi::audioRingModeRef_ = nullptr; #define GET_PARAMS(env, info, num) \ @@ -106,60 +107,6 @@ static AudioSystemManager::AudioVolumeType GetNativeAudioVolumeType(int32_t volu return result; } -static AudioDeviceDescriptor::DeviceType GetNativeDeviceType(int32_t deviceType) -{ - AudioDeviceDescriptor::DeviceType result = AudioDeviceDescriptor::DEVICE_TYPE_NONE; - - switch (deviceType) { - case AudioDeviceDescriptorNapi::SPEAKER: - result = AudioDeviceDescriptor::SPEAKER; - break; - case AudioDeviceDescriptorNapi::WIRED_HEADSET: - result = AudioDeviceDescriptor::WIRED_HEADSET; - break; - case AudioDeviceDescriptorNapi::BLUETOOTH_SCO: - result = AudioDeviceDescriptor::BLUETOOTH_SCO; - break; - case AudioDeviceDescriptorNapi::BLUETOOTH_A2DP: - result = AudioDeviceDescriptor::BLUETOOTH_A2DP; - break; - case AudioDeviceDescriptorNapi::MIC: - result = AudioDeviceDescriptor::MIC; - break; - case AudioDeviceDescriptorNapi::INVALID: - default: - result = AudioDeviceDescriptor::DEVICE_TYPE_NONE; - HiLog::Error(LABEL, "Unknown device type!"); - break; - } - - return result; -} - -static AudioDeviceDescriptor::DeviceFlag GetNativeDeviceFlag(int32_t deviceFlag) -{ - AudioDeviceDescriptor::DeviceFlag result = AudioDeviceDescriptor::ALL_DEVICES_FLAG; - - switch (deviceFlag) { - case AudioManagerNapi::OUTPUT_DEVICES_FLAG: - result = AudioDeviceDescriptor::OUTPUT_DEVICES_FLAG; - break; - case AudioManagerNapi::INPUT_DEVICES_FLAG: - result = AudioDeviceDescriptor::INPUT_DEVICES_FLAG; - break; - case AudioManagerNapi::ALL_DEVICES_FLAG: - result = AudioDeviceDescriptor::ALL_DEVICES_FLAG; - break; - default: - result = AudioDeviceDescriptor::ALL_DEVICES_FLAG; - HiLog::Error(LABEL, "Unknown device flag!, %{public}d", deviceFlag); - break; - } - - return result; -} - - static AudioRingerMode GetNativeAudioRingerMode(int32_t ringMode) { AudioRingerMode result = RINGER_MODE_NORMAL; @@ -269,15 +216,15 @@ napi_value AudioManagerNapi::CreateDeviceFlagObject(napi_env env) status = napi_create_object(env, &result); if (status == napi_ok) { - for (int i = AudioManagerNapi::OUTPUT_DEVICES_FLAG; i <= AudioManagerNapi::ALL_DEVICES_FLAG; i++) { + for (int i = AudioDeviceDescriptor::DEVICE_FLAG_NONE + 1; i < AudioDeviceDescriptor::DEVICE_FLAG_MAX; i++) { switch (i) { - case AudioManagerNapi::OUTPUT_DEVICES_FLAG: + case AudioDeviceDescriptor::OUTPUT_DEVICES_FLAG: propName = "OUTPUT_DEVICES_FLAG"; break; - case AudioManagerNapi::INPUT_DEVICES_FLAG: + case AudioDeviceDescriptor::INPUT_DEVICES_FLAG: propName = "INPUT_DEVICES_FLAG"; break; - case AudioManagerNapi::ALL_DEVICES_FLAG: + case AudioDeviceDescriptor::ALL_DEVICES_FLAG: propName = "ALL_DEVICES_FLAG"; break; default: @@ -313,12 +260,12 @@ napi_value AudioManagerNapi::CreateDeviceRoleObject(napi_env env) status = napi_create_object(env, &result); if (status == napi_ok) { - for (int i = AudioDeviceDescriptorNapi::INPUT_DEVICE; i <= AudioDeviceDescriptorNapi::OUTPUT_DEVICE; i++) { + for (int i = AudioDeviceDescriptor::DEVICE_ROLE_NONE + 1; i < AudioDeviceDescriptor::DEVICE_ROLE_MAX; i++) { switch (i) { - case AudioDeviceDescriptorNapi::INPUT_DEVICE: + case AudioDeviceDescriptor::INPUT_DEVICE: propName = "INPUT_DEVICE"; break; - case AudioDeviceDescriptorNapi::OUTPUT_DEVICE: + case AudioDeviceDescriptor::OUTPUT_DEVICE: propName = "OUTPUT_DEVICE"; break; default: @@ -354,24 +301,27 @@ napi_value AudioManagerNapi::CreateDeviceTypeObject(napi_env env) status = napi_create_object(env, &result); if (status == napi_ok) { - for (int i = AudioDeviceDescriptorNapi::INVALID; i <= AudioDeviceDescriptorNapi::MIC; i++) { + for (int i = AudioDeviceDescriptor::DEVICE_TYPE_NONE + 1; i < AudioDeviceDescriptor::DEVICE_TYPE_MAX; i++) { switch (i) { - case AudioDeviceDescriptorNapi::INVALID: + case AudioDeviceDescriptor::INVALID: propName = "INVALID"; break; - case AudioDeviceDescriptorNapi::SPEAKER: + case AudioDeviceDescriptor::EARPIECE: + propName = "EARPIECE"; + break; + case AudioDeviceDescriptor::SPEAKER: propName = "SPEAKER"; break; - case AudioDeviceDescriptorNapi::WIRED_HEADSET: + case AudioDeviceDescriptor::WIRED_HEADSET: propName = "WIRED_HEADSET"; break; - case AudioDeviceDescriptorNapi::BLUETOOTH_SCO: + case AudioDeviceDescriptor::BLUETOOTH_SCO: propName = "BLUETOOTH_SCO"; break; - case AudioDeviceDescriptorNapi::BLUETOOTH_A2DP: + case AudioDeviceDescriptor::BLUETOOTH_A2DP: propName = "BLUETOOTH_A2DP"; break; - case AudioDeviceDescriptorNapi::MIC: + case AudioDeviceDescriptor::MIC: propName = "MIC"; break; default: @@ -398,6 +348,47 @@ napi_value AudioManagerNapi::CreateDeviceTypeObject(napi_env env) return result; } +napi_value AudioManagerNapi::CreateActiveDeviceTypeObject(napi_env env) +{ + napi_value result = nullptr; + napi_status status; + int32_t refCount = 1; + string propName; + + status = napi_create_object(env, &result); + if (status == napi_ok) { + for (int i = ACTIVE_DEVICE_TYPE_NONE + 1; i < ACTIVE_DEVICE_TYPE_MAX; i++) { + switch (i) { + case SPEAKER: + propName = "SPEAKER"; + break; + case BLUETOOTH_SCO: + propName = "BLUETOOTH_SCO"; + break; + default: + HiLog::Error(LABEL, "No prop with this value!"); + continue; + } + status = AddNamedProperty(env, result, propName, i); + if (status != napi_ok) { + HiLog::Error(LABEL, "Failed to add named prop!"); + break; + } + propName.clear(); + } + if (status == napi_ok) { + status = napi_create_reference(env, result, refCount, &activeDeviceTypeRef_); + if (status == napi_ok) { + return result; + } + } + } + HiLog::Error(LABEL, "CreateActiveDeviceTypeObject is Failed!"); + napi_get_undefined(env, &result); + + return result; +} + napi_value AudioManagerNapi::CreateAudioRingModeObject(napi_env env) { napi_value result = nullptr; @@ -474,6 +465,7 @@ napi_value AudioManagerNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_PROPERTY("DeviceFlag", CreateDeviceFlagObject(env)), DECLARE_NAPI_PROPERTY("DeviceRole", CreateDeviceRoleObject(env)), DECLARE_NAPI_PROPERTY("DeviceType", CreateDeviceTypeObject(env)), + DECLARE_NAPI_PROPERTY("ActiveDeviceType", CreateActiveDeviceTypeObject(env)), DECLARE_NAPI_PROPERTY("AudioRingMode", CreateAudioRingModeObject(env)) }; @@ -1133,7 +1125,7 @@ napi_value AudioManagerNapi::SetDeviceActive(napi_env env, napi_callback_info in [](napi_env env, void *data) { auto context = static_cast(data); context->status = context->objectInfo->audioMngr_->SetDeviceActive( - GetNativeDeviceType(context->deviceType), context->isActive); + static_cast(context->deviceType), context->isActive); }, SetFunctionAsyncCallbackComplete, static_cast(asyncContext.get()), &asyncContext->work); if (status != napi_ok) { @@ -1192,7 +1184,7 @@ napi_value AudioManagerNapi::IsDeviceActive(napi_env env, napi_callback_info inf [](napi_env env, void *data) { auto context = static_cast(data); context->isActive = - context->objectInfo->audioMngr_->IsDeviceActive(GetNativeDeviceType(context->deviceType)); + context->objectInfo->audioMngr_->IsDeviceActive(static_cast(context->deviceType)); context->isTrue = context->isActive; context->status = 0; }, @@ -1646,8 +1638,8 @@ napi_value AudioManagerNapi::GetDevices(napi_env env, napi_callback_info info) env, nullptr, resource, [](napi_env env, void *data) { auto context = static_cast(data); - context->deviceDescriptors = - context->objectInfo->audioMngr_->GetDevices(GetNativeDeviceFlag(context->deviceFlag)); + context->deviceDescriptors = context->objectInfo->audioMngr_->GetDevices( + static_cast(context->deviceFlag)); context->status = 0; }, GetDevicesAsyncCallbackComplete, static_cast(asyncContext.get()), &asyncContext->work); diff --git a/interfaces/innerkits/native/audiocommon/include/audio_info.h b/interfaces/innerkits/native/audiocommon/include/audio_info.h index bf35bc9ead..3a9a6583e3 100644 --- a/interfaces/innerkits/native/audiocommon/include/audio_info.h +++ b/interfaces/innerkits/native/audiocommon/include/audio_info.h @@ -24,48 +24,11 @@ namespace OHOS { namespace AudioStandard { -// Audio Device Types -enum DeviceType { - /** - * Indicates device type none. - */ - DEVICE_TYPE_NONE = -1, - /** - * Indicates a speaker built in a device. - */ - SPEAKER = 0, - /** - * Indicates a headset, which is the combination of a pair of headphones and a microphone. - */ - WIRED_HEADSET = 1, - /** - * Indicates a Bluetooth device used for telephony. - */ - BLUETOOTH_SCO = 2, - /** - * Indicates a Bluetooth device supporting the Advanced Audio Distribution Profile (A2DP). - */ - BLUETOOTH_A2DP = 3, - /** - * Indicates a microphone built in a device. - */ - MIC = 4 -}; - -// Audio Role -enum DeviceRole { - /** - * Device role none. - */ - DEVICE_ROLE_NONE = -1, - /** - * Input device role. - */ - INPUT_DEVICE = 0, - /** - * Output device role. - */ - OUTPUT_DEVICE = 1 +enum ActiveDeviceType { + ACTIVE_DEVICE_TYPE_NONE = -1, + SPEAKER = 2, + BLUETOOTH_SCO = 7, + ACTIVE_DEVICE_TYPE_MAX }; enum AudioStreamType { @@ -238,6 +201,7 @@ const std::vector AUDIO_SUPPORTED_SAMPLING_RATES { SAMPLE_RATE_64000, SAMPLE_RATE_96000 }; + typedef uint32_t AudioIOHandle; } // namespace AudioStandard } // namespace OHOS diff --git a/interfaces/innerkits/native/audiomanager/include/audio_system_manager.h b/interfaces/innerkits/native/audiomanager/include/audio_system_manager.h index 0a57e8956e..ac16359ef0 100644 --- a/interfaces/innerkits/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/innerkits/native/audiomanager/include/audio_system_manager.h @@ -28,18 +28,26 @@ class AudioDeviceDescriptor : public Parcelable { friend class AudioSystemManager; public: enum DeviceFlag { + /** + * Device flag none. + */ + DEVICE_FLAG_NONE = -1, /** * Indicates all output audio devices. */ - OUTPUT_DEVICES_FLAG = 0, + OUTPUT_DEVICES_FLAG = 1, /** * Indicates all input audio devices. */ - INPUT_DEVICES_FLAG = 1, + INPUT_DEVICES_FLAG = 2, /** * Indicates all audio devices. */ - ALL_DEVICES_FLAG = 2 + ALL_DEVICES_FLAG = 3, + /** + * Device flag max count. + */ + DEVICE_FLAG_MAX }; enum DeviceRole { @@ -50,11 +58,15 @@ enum DeviceRole { /** * Input device role. */ - INPUT_DEVICE = 0, + INPUT_DEVICE = 1, /** * Output device role. */ - OUTPUT_DEVICE = 1 + OUTPUT_DEVICE = 2, + /** + * Device role max count. + */ + DEVICE_ROLE_MAX }; enum DeviceType { @@ -62,26 +74,38 @@ enum DeviceType { * Indicates device type none. */ DEVICE_TYPE_NONE = -1, + /** + * Indicates invalid device + */ + INVALID = 0, + /** + * Indicates earpiece + */ + EARPIECE = 1, /** * Indicates a speaker built in a device. */ - SPEAKER = 0, + SPEAKER = 2, /** * Indicates a headset, which is the combination of a pair of headphones and a microphone. */ - WIRED_HEADSET = 1, + WIRED_HEADSET = 3, /** * Indicates a Bluetooth device used for telephony. */ - BLUETOOTH_SCO = 2, + BLUETOOTH_SCO = 7, /** * Indicates a Bluetooth device supporting the Advanced Audio Distribution Profile (A2DP). */ - BLUETOOTH_A2DP = 3, + BLUETOOTH_A2DP = 8, /** * Indicates a microphone built in a device. */ - MIC = 4 + MIC = 15, + /** + * Indicates device type max count. + */ + DEVICE_TYPE_MAX }; DeviceType getType(); @@ -157,8 +181,8 @@ enum AudioVolumeType { std::vector> GetDevices(AudioDeviceDescriptor::DeviceFlag deviceFlag) const; const std::string GetAudioParameter(const std::string key) const; void SetAudioParameter(const std::string key, const std::string value) const; - int32_t SetDeviceActive(AudioDeviceDescriptor::DeviceType deviceType, bool flag) const; - bool IsDeviceActive(AudioDeviceDescriptor::DeviceType deviceType) const; + int32_t SetDeviceActive(ActiveDeviceType deviceType, bool flag) const; + bool IsDeviceActive(ActiveDeviceType deviceType) const; bool IsStreamActive(AudioSystemManager::AudioVolumeType volumeType) const; bool SetRingerMode(AudioRingerMode ringMode) const; AudioRingerMode GetRingerMode() const; diff --git a/interfaces/innerkits/native/audiopolicy/include/audio_policy_manager.h b/interfaces/innerkits/native/audiopolicy/include/audio_policy_manager.h index cf677eefea..3386122b34 100644 --- a/interfaces/innerkits/native/audiopolicy/include/audio_policy_manager.h +++ b/interfaces/innerkits/native/audiopolicy/include/audio_policy_manager.h @@ -18,9 +18,12 @@ #include #include "audio_info.h" +#include "audio_system_manager.h" namespace OHOS { namespace AudioStandard { +using InternalDeviceType = AudioDeviceDescriptor::DeviceType; + class AudioPolicyManager { public: static AudioPolicyManager& GetInstance() @@ -39,9 +42,9 @@ public: bool IsStreamActive(AudioStreamType streamType); - int32_t SetDeviceActive(DeviceType deviceType, bool active); + int32_t SetDeviceActive(InternalDeviceType deviceType, bool active); - bool IsDeviceActive(DeviceType deviceType); + bool IsDeviceActive(InternalDeviceType deviceType); int32_t SetRingerMode(AudioRingerMode ringMode); diff --git a/interfaces/kits/js/audio_manager/@ohos.multimedia.audio.d.ts b/interfaces/kits/js/audio_manager/@ohos.multimedia.audio.d.ts index 4ed98a3abc..683c676801 100644 --- a/interfaces/kits/js/audio_manager/@ohos.multimedia.audio.d.ts +++ b/interfaces/kits/js/audio_manager/@ohos.multimedia.audio.d.ts @@ -90,26 +90,45 @@ declare namespace audio { * Invalid device */ INVALID = 0, + /** + * earpiece + */ + EARPIECE = 1, /** * Speaker */ - SPEAKER = 1, + SPEAKER = 2, /** * Wired headset */ - WIRED_HEADSET = 2, + WIRED_HEADSET = 3, /** * Bluetooth device using the synchronous connection oriented link (SCO) */ - BLUETOOTH_SCO = 3, + BLUETOOTH_SCO = 7, /** * Bluetooth device using advanced audio distribution profile (A2DP) */ - BLUETOOTH_A2DP = 4, + BLUETOOTH_A2DP = 8, /** * Microphone */ - MIC = 5, + MIC = 15, + } + /** + * Enumerates Active device types. + * @devices + * @sysCap SystemCapability.Multimedia.Audio + */ + enum ActiveDeviceType { + /** + * Speaker + */ + SPEAKER = 2, + /** + * Bluetooth device using the synchronous connection oriented link (SCO) + */ + BLUETOOTH_SCO = 7, } /** * Enumerates Audio Ringer modes @@ -310,25 +329,25 @@ declare namespace audio { * @devices * @sysCap SystemCapability.Multimedia.Audio */ - setDeviceActive(deviceType: DeviceType, active: boolean, callback: AsyncCallback): void; + setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback): void; /** * Activates the device. This method uses a promise to return the execution result. * @sysCap SystemCapability.Multimedia.Audio * @devices */ - setDeviceActive(deviceType: DeviceType, active: boolean): Promise; + setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise; /** * Checks whether the device is active. This method uses an asynchronous callback to return the execution result. * @sysCap SystemCapability.Multimedia.Audio * @devices */ - isDeviceActive(deviceType: DeviceType, callback: AsyncCallback): void; + isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback): void; /** * Checks whether the device is active. This method uses a promise to return the execution result. * @sysCap SystemCapability.Multimedia.Audio * @devices */ - isDeviceActive(deviceType: DeviceType): Promise; + isDeviceActive(deviceType: ActiveDeviceType): Promise; } /** diff --git a/interfaces/kits/js/audio_manager/include/audio_device_descriptor_napi.h b/interfaces/kits/js/audio_manager/include/audio_device_descriptor_napi.h index 9b9bcbb864..7192dfffa6 100644 --- a/interfaces/kits/js/audio_manager/include/audio_device_descriptor_napi.h +++ b/interfaces/kits/js/audio_manager/include/audio_device_descriptor_napi.h @@ -31,20 +31,6 @@ public: AudioDeviceDescriptorNapi(); ~AudioDeviceDescriptorNapi(); - enum DeviceType { - INVALID = 0, - SPEAKER = 1, - WIRED_HEADSET = 2, - BLUETOOTH_SCO = 3, - BLUETOOTH_A2DP = 4, - MIC = 5 - }; - - enum DeviceRole { - INPUT_DEVICE = 1, - OUTPUT_DEVICE = 2 - }; - static napi_value Init(napi_env env, napi_value exports); static napi_value CreateAudioDeviceDescriptorWrapper(napi_env env, sptr deviceDescriptor); diff --git a/interfaces/kits/js/audio_manager/include/audio_manager_napi.h b/interfaces/kits/js/audio_manager/include/audio_manager_napi.h index 416e59bbe2..4a0f34303f 100644 --- a/interfaces/kits/js/audio_manager/include/audio_manager_napi.h +++ b/interfaces/kits/js/audio_manager/include/audio_manager_napi.h @@ -36,12 +36,6 @@ public: MEDIA = 3 }; - enum DeviceFlag { - OUTPUT_DEVICES_FLAG = 1, - INPUT_DEVICES_FLAG = 2, - ALL_DEVICES_FLAG = 3 - }; - enum AudioRingMode { RINGER_MODE_SILENT = 0, RINGER_MODE_VIBRATE, @@ -77,6 +71,7 @@ private: static napi_value CreateDeviceFlagObject(napi_env env); static napi_value CreateDeviceRoleObject(napi_env env); static napi_value CreateDeviceTypeObject(napi_env env); + static napi_value CreateActiveDeviceTypeObject(napi_env env); static napi_value CreateAudioRingModeObject(napi_env env); static napi_ref sConstructor_; @@ -84,6 +79,7 @@ private: static napi_ref deviceFlagRef_; static napi_ref deviceRoleRef_; static napi_ref deviceTypeRef_; + static napi_ref activeDeviceTypeRef_; static napi_ref audioRingModeRef_; AudioSystemManager *audioMngr_; diff --git a/services/BUILD.gn b/services/BUILD.gn index 01325817db..3eb7dbafae 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -99,6 +99,7 @@ config("audio_policy_public_config") { "//foundation/multimedia/audio_standard/frameworks/innerkitsimpl/common/include", "//foundation/multimedia/audio_standard/interfaces/innerkits/native/audioadapter/include", "//foundation/multimedia/audio_standard/interfaces/innerkits/native/audiocommon/include", + "//foundation/multimedia/audio_standard/interfaces/innerkits/native/audiopolicy/include", "//foundation/multimedia/audio_standard/interfaces/innerkits/native/audiomanager/include", "//foundation/multimedia/audio_standard/services/src/audio_policy/server/service/include/common", "//foundation/multimedia/audio_standard/services/src/audio_policy/server/service/include/interface", diff --git a/services/include/audio_policy/client/audio_policy_base.h b/services/include/audio_policy/client/audio_policy_base.h index 1fd80b4ed0..8d5cad2286 100644 --- a/services/include/audio_policy/client/audio_policy_base.h +++ b/services/include/audio_policy/client/audio_policy_base.h @@ -17,6 +17,7 @@ #define I_AUDIO_POLICY_BASE_H #include "audio_policy_types.h" +#include "audio_policy_manager.h" #include "ipc_types.h" #include "iremote_broker.h" #include "iremote_proxy.h" @@ -37,9 +38,9 @@ public: virtual bool IsStreamActive(AudioStreamType streamType) = 0; - virtual int32_t SetDeviceActive(DeviceType deviceType, bool active) = 0; + virtual int32_t SetDeviceActive(InternalDeviceType deviceType, bool active) = 0; - virtual bool IsDeviceActive(DeviceType deviceType) = 0; + virtual bool IsDeviceActive(InternalDeviceType deviceType) = 0; virtual int32_t SetRingerMode(AudioRingerMode ringMode) = 0; diff --git a/services/include/audio_policy/client/audio_policy_proxy.h b/services/include/audio_policy/client/audio_policy_proxy.h index 913ee455ae..38226388fd 100644 --- a/services/include/audio_policy/client/audio_policy_proxy.h +++ b/services/include/audio_policy/client/audio_policy_proxy.h @@ -36,9 +36,9 @@ public: bool IsStreamActive(AudioStreamType streamType) override; - int32_t SetDeviceActive(DeviceType deviceType, bool active) override; + int32_t SetDeviceActive(InternalDeviceType deviceType, bool active) override; - bool IsDeviceActive(DeviceType deviceType) override; + bool IsDeviceActive(InternalDeviceType deviceType) override; int32_t SetRingerMode(AudioRingerMode ringMode) override; diff --git a/services/include/audio_policy/server/audio_policy_server.h b/services/include/audio_policy/server/audio_policy_server.h index 290e35aa3d..695f1f30a4 100644 --- a/services/include/audio_policy/server/audio_policy_server.h +++ b/services/include/audio_policy/server/audio_policy_server.h @@ -49,9 +49,9 @@ public: bool IsStreamActive(AudioStreamType streamType) override; - int32_t SetDeviceActive(DeviceType deviceType, bool active) override; + int32_t SetDeviceActive(InternalDeviceType deviceType, bool active) override; - bool IsDeviceActive(DeviceType deviceType) override; + bool IsDeviceActive(InternalDeviceType deviceType) override; int32_t SetRingerMode(AudioRingerMode ringMode) override; diff --git a/services/src/audio_policy/client/audio_policy_manager.cpp b/services/src/audio_policy/client/audio_policy_manager.cpp index aafbd0b7bf..bc5820f369 100644 --- a/services/src/audio_policy/client/audio_policy_manager.cpp +++ b/services/src/audio_policy/client/audio_policy_manager.cpp @@ -78,12 +78,12 @@ bool AudioPolicyManager::IsStreamActive(AudioStreamType streamType) return g_sProxy->IsStreamActive(streamType); } -int32_t AudioPolicyManager::SetDeviceActive(DeviceType deviceType, bool active) +int32_t AudioPolicyManager::SetDeviceActive(InternalDeviceType deviceType, bool active) { return g_sProxy->SetDeviceActive(deviceType, active); } -bool AudioPolicyManager::IsDeviceActive(DeviceType deviceType) +bool AudioPolicyManager::IsDeviceActive(InternalDeviceType deviceType) { return g_sProxy->IsDeviceActive(deviceType); } diff --git a/services/src/audio_policy/client/audio_policy_proxy.cpp b/services/src/audio_policy/client/audio_policy_proxy.cpp index b5b59b099b..95c1f7483f 100644 --- a/services/src/audio_policy/client/audio_policy_proxy.cpp +++ b/services/src/audio_policy/client/audio_policy_proxy.cpp @@ -130,7 +130,7 @@ bool AudioPolicyProxy::IsStreamActive(AudioStreamType streamType) return reply.ReadBool(); } -int32_t AudioPolicyProxy::SetDeviceActive(DeviceType deviceType, bool active) +int32_t AudioPolicyProxy::SetDeviceActive(InternalDeviceType deviceType, bool active) { MessageParcel data; MessageParcel reply; @@ -146,7 +146,7 @@ int32_t AudioPolicyProxy::SetDeviceActive(DeviceType deviceType, bool active) return reply.ReadInt32(); } -bool AudioPolicyProxy::IsDeviceActive(DeviceType deviceType) +bool AudioPolicyProxy::IsDeviceActive(InternalDeviceType deviceType) { MessageParcel data; MessageParcel reply; diff --git a/services/src/audio_policy/server/audio_policy_manager_stub.cpp b/services/src/audio_policy/server/audio_policy_manager_stub.cpp index 2594769d58..0cad74985c 100644 --- a/services/src/audio_policy/server/audio_policy_manager_stub.cpp +++ b/services/src/audio_policy/server/audio_policy_manager_stub.cpp @@ -79,7 +79,7 @@ void AudioPolicyManagerStub::IsStreamActiveInternal(MessageParcel &data, Message void AudioPolicyManagerStub::SetDeviceActiveInternal(MessageParcel &data, MessageParcel &reply) { - DeviceType deviceType = static_cast(data.ReadInt32()); + InternalDeviceType deviceType = static_cast(data.ReadInt32()); bool active = data.ReadBool(); int32_t result = SetDeviceActive(deviceType, active); if (result == SUCCESS) @@ -90,7 +90,7 @@ void AudioPolicyManagerStub::SetDeviceActiveInternal(MessageParcel &data, Messag void AudioPolicyManagerStub::IsDeviceActiveInternal(MessageParcel &data, MessageParcel &reply) { - DeviceType deviceType = static_cast(data.ReadInt32()); + InternalDeviceType deviceType = static_cast(data.ReadInt32()); bool result = IsDeviceActive(deviceType); reply.WriteBool(result); } diff --git a/services/src/audio_policy/server/audio_policy_server.cpp b/services/src/audio_policy/server/audio_policy_server.cpp index 0cfcdb5816..eafd87a223 100644 --- a/services/src/audio_policy/server/audio_policy_server.cpp +++ b/services/src/audio_policy/server/audio_policy_server.cpp @@ -77,12 +77,12 @@ bool AudioPolicyServer::IsStreamActive(AudioStreamType streamType) return mPolicyService.IsStreamActive(streamType); } -int32_t AudioPolicyServer::SetDeviceActive(DeviceType deviceType, bool active) +int32_t AudioPolicyServer::SetDeviceActive(InternalDeviceType deviceType, bool active) { return mPolicyService.SetDeviceActive(deviceType, active); } -bool AudioPolicyServer::IsDeviceActive(DeviceType deviceType) +bool AudioPolicyServer::IsDeviceActive(InternalDeviceType deviceType) { return mPolicyService.IsDeviceActive(deviceType); } diff --git a/services/src/audio_policy/server/service/include/audio_policy_service.h b/services/src/audio_policy/server/service/include/audio_policy_service.h index f5f99f1f4b..3ffb3b1911 100644 --- a/services/src/audio_policy/server/service/include/audio_policy_service.h +++ b/services/src/audio_policy/server/service/include/audio_policy_service.h @@ -55,9 +55,9 @@ public: bool IsStreamActive(AudioStreamType streamType) const; - int32_t SetDeviceActive(DeviceType deviceType, bool active); + int32_t SetDeviceActive(InternalDeviceType deviceType, bool active); - bool IsDeviceActive(DeviceType deviceType) const; + bool IsDeviceActive(InternalDeviceType deviceType) const; int32_t SetRingerMode(AudioRingerMode ringMode); @@ -68,9 +68,9 @@ public: void OnAudioPortPinAvailable(std::shared_ptr portInfo); - void OnDefaultOutputPortPin(DeviceType device); + void OnDefaultOutputPortPin(InternalDeviceType device); - void OnDefaultInputPortPin(DeviceType device); + void OnDefaultInputPortPin(InternalDeviceType device); private: @@ -82,15 +82,14 @@ private: virtual ~AudioPolicyService() {} - AudioIOHandle GetAudioIOHandle(DeviceType deviceType); - std::list& GetActiveDevicesList(DeviceType deviceType) + AudioIOHandle GetAudioIOHandle(InternalDeviceType deviceType); + std::list& GetActiveDevicesList(InternalDeviceType deviceType) { switch (deviceType) { - case SPEAKER: - case BLUETOOTH_A2DP: + case InternalDeviceType::SPEAKER: + case InternalDeviceType::BLUETOOTH_SCO: return mActiveOutputDevices; - case MIC: - case BLUETOOTH_SCO: + case InternalDeviceType::MIC: return mActiveInputDevices; default: return mActiveOutputDevices; // Default case return Output device @@ -100,9 +99,9 @@ private: IAudioPolicyInterface& mAudioPolicyManager; Parser& mConfigParser; std::unordered_map mIOHandles; - std::list mActiveOutputDevices; - std::list mActiveInputDevices; - std::string GetPortName(DeviceType deviceType); + std::list mActiveOutputDevices; + std::list mActiveInputDevices; + std::string GetPortName(InternalDeviceType deviceType); }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_policy/server/service/include/config/xml_parser.h b/services/src/audio_policy/server/service/include/config/xml_parser.h index b9a117f4c6..5ac727d5eb 100644 --- a/services/src/audio_policy/server/service/include/config/xml_parser.h +++ b/services/src/audio_policy/server/service/include/config/xml_parser.h @@ -57,7 +57,7 @@ private: void ParseDefaultInputDevice(xmlNode* node); void ParseAudioPorts(xmlNode* node); void ParseAudioPortPins(xmlNode* node); - DeviceType GetDeviceType(xmlChar* device); + InternalDeviceType GetDeviceType(xmlChar *device); IPortObserver& mPortObserver; xmlDoc* mDoc; diff --git a/services/src/audio_policy/server/service/include/interface/iaudio_policy_interface.h b/services/src/audio_policy/server/service/include/interface/iaudio_policy_interface.h index b026d2e097..51f36771d4 100644 --- a/services/src/audio_policy/server/service/include/interface/iaudio_policy_interface.h +++ b/services/src/audio_policy/server/service/include/interface/iaudio_policy_interface.h @@ -18,6 +18,7 @@ #include "audio_config.h" #include "audio_info.h" +#include "audio_policy_manager.h" #include "audio_policy_types.h" #include @@ -45,7 +46,8 @@ public: virtual int32_t CloseAudioPort(AudioIOHandle ioHandle) = 0; - virtual int32_t SetDeviceActive(AudioIOHandle ioHandle, DeviceType deviceType, std::string name, bool active) = 0; + virtual int32_t SetDeviceActive(AudioIOHandle ioHandle, InternalDeviceType deviceType, + std::string name, bool active) = 0; virtual int32_t SetRingerMode(AudioRingerMode ringerMode) = 0; diff --git a/services/src/audio_policy/server/service/include/interface/iport_observer.h b/services/src/audio_policy/server/service/include/interface/iport_observer.h index af7ef9ab68..8e53159172 100644 --- a/services/src/audio_policy/server/service/include/interface/iport_observer.h +++ b/services/src/audio_policy/server/service/include/interface/iport_observer.h @@ -25,8 +25,8 @@ class IPortObserver { public: virtual void OnAudioPortAvailable(std::shared_ptr portInfo) = 0; virtual void OnAudioPortPinAvailable(std::shared_ptr portInfo) = 0; - virtual void OnDefaultOutputPortPin(DeviceType device) = 0; - virtual void OnDefaultInputPortPin(DeviceType device) = 0; + virtual void OnDefaultOutputPortPin(InternalDeviceType device) = 0; + virtual void OnDefaultInputPortPin(InternalDeviceType device) = 0; }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_policy/server/service/include/manager/audio_adapter_manager.h b/services/src/audio_policy/server/service/include/manager/audio_adapter_manager.h index 9a46c15f43..97cb41663c 100644 --- a/services/src/audio_policy/server/service/include/manager/audio_adapter_manager.h +++ b/services/src/audio_policy/server/service/include/manager/audio_adapter_manager.h @@ -62,7 +62,7 @@ public: int32_t CloseAudioPort(AudioIOHandle ioHandle); - int32_t SetDeviceActive(AudioIOHandle ioHandle, DeviceType deviceType, std::string name, bool active); + int32_t SetDeviceActive(AudioIOHandle ioHandle, InternalDeviceType deviceType, std::string name, bool active); int32_t SetRingerMode(AudioRingerMode ringerMode); diff --git a/services/src/audio_policy/server/service/src/audio_policy_service.cpp b/services/src/audio_policy/server/service/src/audio_policy_service.cpp index dc78bb0d30..a704fb3eea 100644 --- a/services/src/audio_policy/server/service/src/audio_policy_service.cpp +++ b/services/src/audio_policy/server/service/src/audio_policy_service.cpp @@ -67,22 +67,19 @@ bool AudioPolicyService::IsStreamActive(AudioStreamType streamType) const return mAudioPolicyManager.IsStreamActive(streamType); } -std::string AudioPolicyService::GetPortName(DeviceType deviceType) +std::string AudioPolicyService::GetPortName(InternalDeviceType deviceType) { std::string portName = PORT_NONE; switch (deviceType) { - case BLUETOOTH_A2DP: + case InternalDeviceType::BLUETOOTH_SCO: portName = BLUEZ_SINK; break; - case SPEAKER: + case InternalDeviceType::SPEAKER: portName = HDI_SINK; break; - case MIC: + case InternalDeviceType::MIC: portName = HDI_SOURCE; break; - case BLUETOOTH_SCO: - portName = BLUEZ_SOURCE; - break; default: portName = PORT_NONE; break; @@ -90,16 +87,16 @@ std::string AudioPolicyService::GetPortName(DeviceType deviceType) return portName; } -int32_t AudioPolicyService::SetDeviceActive(DeviceType deviceType, bool active) +int32_t AudioPolicyService::SetDeviceActive(InternalDeviceType deviceType, bool active) { MEDIA_DEBUG_LOG("[Policy Service] deviceType %{public}d, activate?: %{public}d", deviceType, active); - if (deviceType == DEVICE_TYPE_NONE) + if (deviceType == InternalDeviceType::DEVICE_TYPE_NONE) return ERR_DEVICE_NOT_SUPPORTED; bool updateActiveDevices = true; AudioIOHandle ioHandle = GetAudioIOHandle(deviceType); - list &activeDevices = GetActiveDevicesList(deviceType); + list &activeDevices = GetActiveDevicesList(deviceType); if (!active) { if (activeDevices.size() <= 1) { @@ -107,7 +104,7 @@ int32_t AudioPolicyService::SetDeviceActive(DeviceType deviceType, bool active) return ERROR; } - list::const_iterator iter = activeDevices.begin(); + list::const_iterator iter = activeDevices.begin(); while (iter != activeDevices.end()) { if (*iter == deviceType) { iter = activeDevices.erase(iter); @@ -134,7 +131,7 @@ int32_t AudioPolicyService::SetDeviceActive(DeviceType deviceType, bool active) } if (updateActiveDevices) { - list::const_iterator iter = activeDevices.begin(); + list::const_iterator iter = activeDevices.begin(); while (iter != activeDevices.end()) { if (*iter == deviceType) { iter = activeDevices.erase(iter); @@ -148,14 +145,14 @@ int32_t AudioPolicyService::SetDeviceActive(DeviceType deviceType, bool active) return SUCCESS; } -bool AudioPolicyService::IsDeviceActive(DeviceType deviceType) const +bool AudioPolicyService::IsDeviceActive(InternalDeviceType deviceType) const { bool result = false; switch (deviceType) { - case SPEAKER: - case BLUETOOTH_A2DP: - for (list::const_iterator iter = mActiveOutputDevices.begin(); + case InternalDeviceType::SPEAKER: + case InternalDeviceType::BLUETOOTH_SCO: + for (list::const_iterator iter = mActiveOutputDevices.begin(); iter != mActiveOutputDevices.end(); ++iter) { if (*iter == deviceType) { result = true; @@ -163,16 +160,6 @@ bool AudioPolicyService::IsDeviceActive(DeviceType deviceType) const } } break; - case MIC: - case BLUETOOTH_SCO: - for (list::const_iterator iter = mActiveInputDevices.begin(); - iter != mActiveInputDevices.end(); ++iter) { - if (*iter == deviceType) { - result = true; - break; - } - } - break; default: break; } @@ -204,7 +191,7 @@ void AudioPolicyService::OnAudioPortPinAvailable(shared_ptr po return; } -void AudioPolicyService::OnDefaultOutputPortPin(DeviceType deviceType) +void AudioPolicyService::OnDefaultOutputPortPin(InternalDeviceType deviceType) { AudioIOHandle ioHandle = GetAudioIOHandle(deviceType); mAudioPolicyManager.SetDeviceActive(ioHandle, deviceType, HDI_SINK, true); @@ -213,7 +200,7 @@ void AudioPolicyService::OnDefaultOutputPortPin(DeviceType deviceType) return; } -void AudioPolicyService::OnDefaultInputPortPin(DeviceType deviceType) +void AudioPolicyService::OnDefaultInputPortPin(InternalDeviceType deviceType) { MEDIA_DEBUG_LOG("OnDefaultInputPortPin DeviceType: %{public}d", deviceType); AudioIOHandle ioHandle = GetAudioIOHandle(deviceType); @@ -223,23 +210,19 @@ void AudioPolicyService::OnDefaultInputPortPin(DeviceType deviceType) } // private methods -AudioIOHandle AudioPolicyService::GetAudioIOHandle(DeviceType deviceType) +AudioIOHandle AudioPolicyService::GetAudioIOHandle(InternalDeviceType deviceType) { AudioIOHandle ioHandle; switch (deviceType) { - case SPEAKER: - case WIRED_HEADSET: + case InternalDeviceType::SPEAKER: ioHandle = mIOHandles[HDI_SINK]; break; - case BLUETOOTH_A2DP: + case InternalDeviceType::BLUETOOTH_SCO: ioHandle = mIOHandles[BLUEZ_SINK]; break; - case MIC: + case InternalDeviceType::MIC: ioHandle = mIOHandles[HDI_SOURCE]; break; - case BLUETOOTH_SCO: - ioHandle = mIOHandles[BLUEZ_SOURCE]; - break; default: ioHandle = mIOHandles[HDI_SINK]; break; diff --git a/services/src/audio_policy/server/service/src/config/xml_parser.cpp b/services/src/audio_policy/server/service/src/config/xml_parser.cpp index 5bb9e7d3e4..a76bcf85ed 100644 --- a/services/src/audio_policy/server/service/src/config/xml_parser.cpp +++ b/services/src/audio_policy/server/service/src/config/xml_parser.cpp @@ -227,13 +227,14 @@ void XMLParser::ParseAudioPortPins(xmlNode* node) return; } -DeviceType XMLParser::GetDeviceType(xmlChar* device) +InternalDeviceType XMLParser::GetDeviceType(xmlChar *device) { if (!xmlStrcmp(device, reinterpret_cast("Speaker"))) - return SPEAKER; + return InternalDeviceType::SPEAKER; if (!xmlStrcmp(device, reinterpret_cast("Built-In Mic"))) - return MIC; - return DEVICE_TYPE_NONE; + return InternalDeviceType::MIC; + + return InternalDeviceType::DEVICE_TYPE_NONE; } } // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_policy/server/service/src/manager/audio_adapter_manager.cpp b/services/src/audio_policy/server/service/src/manager/audio_adapter_manager.cpp index 2293ac5e52..960db0ca6b 100644 --- a/services/src/audio_policy/server/service/src/manager/audio_adapter_manager.cpp +++ b/services/src/audio_policy/server/service/src/manager/audio_adapter_manager.cpp @@ -100,16 +100,15 @@ bool AudioAdapterManager::IsStreamActive(AudioStreamType streamType) bool result = mAudioServiceAdapter->IsStreamActive(streamType); return result; } -int32_t AudioAdapterManager::SetDeviceActive(AudioIOHandle ioHandle, DeviceType deviceType, +int32_t AudioAdapterManager::SetDeviceActive(AudioIOHandle ioHandle, InternalDeviceType deviceType, std::string name, bool active) { switch (deviceType) { - case SPEAKER: - case BLUETOOTH_A2DP: { + case InternalDeviceType::SPEAKER: + case InternalDeviceType::BLUETOOTH_SCO: { return mAudioServiceAdapter->SetDefaultSink(name); } - case MIC: - case BLUETOOTH_SCO: { + case InternalDeviceType::MIC: { return mAudioServiceAdapter->SetDefaultSource(name); } default: diff --git a/services/src/client/audio_system_manager.cpp b/services/src/client/audio_system_manager.cpp index d63d8fe1da..bc76591f37 100644 --- a/services/src/client/audio_system_manager.cpp +++ b/services/src/client/audio_system_manager.cpp @@ -76,12 +76,10 @@ AudioRingerMode AudioSystemManager::GetRingerMode() const return (AudioPolicyManager::GetInstance().GetRingerMode()); } -int32_t AudioSystemManager::SetDeviceActive(AudioDeviceDescriptor::DeviceType deviceType, bool flag) const +int32_t AudioSystemManager::SetDeviceActive(ActiveDeviceType deviceType, bool flag) const { switch (deviceType) { case SPEAKER: - case BLUETOOTH_A2DP: - case MIC: case BLUETOOTH_SCO: break; default: @@ -90,16 +88,13 @@ int32_t AudioSystemManager::SetDeviceActive(AudioDeviceDescriptor::DeviceType de } /* Call Audio Policy SetDeviceActive */ - DeviceType devType = (DeviceType)deviceType; - return (AudioPolicyManager::GetInstance().SetDeviceActive(devType, flag)); + return (AudioPolicyManager::GetInstance().SetDeviceActive(static_cast(deviceType), flag)); } -bool AudioSystemManager::IsDeviceActive(AudioDeviceDescriptor::DeviceType deviceType) const +bool AudioSystemManager::IsDeviceActive(ActiveDeviceType deviceType) const { switch (deviceType) { case SPEAKER: - case BLUETOOTH_A2DP: - case MIC: case BLUETOOTH_SCO: break; default: @@ -108,8 +103,7 @@ bool AudioSystemManager::IsDeviceActive(AudioDeviceDescriptor::DeviceType device } /* Call Audio Policy IsDeviceActive */ - DeviceType devType = (DeviceType)deviceType; - return (AudioPolicyManager::GetInstance().IsDeviceActive(devType)); + return (AudioPolicyManager::GetInstance().IsDeviceActive(static_cast(deviceType))); } bool AudioSystemManager::IsStreamActive(AudioSystemManager::AudioVolumeType volumeType) const diff --git a/services/test/audio_policy_test.cpp b/services/test/audio_policy_test.cpp index c06bf32a36..346f39c85c 100644 --- a/services/test/audio_policy_test.cpp +++ b/services/test/audio_policy_test.cpp @@ -41,7 +41,7 @@ static void PrintUsage(void) cout << "\taudio_policy_test - Audio Policy Test " << endl << endl; cout << "SYNOPSIS" << endl << endl; cout << "\t#include " << endl << endl; - cout << "\t./audio_playback_test [OPTIONS]..." << endl << endl; + cout << "\t./audio_policy_test [OPTIONS]..." << endl << endl; cout << "DESCRIPTION" << endl << endl; cout << "\tControls audio volume, audio routing, audio mute" << endl << endl; cout << "-V\n\tSets Volume for streams, -S to setStream" << endl << endl; @@ -52,9 +52,8 @@ static void PrintUsage(void) cout << "\t3\tRING" << endl << endl; cout << "-D\n\tSets Device Active" << endl << endl; cout << "\tSupported Devices are" << endl << endl; - cout << "\t0\tSPEAKER" << endl << endl; - cout << "\t3\tBLUETOOTH_A2DP" << endl << endl; - cout << "\t4\tMIC" << endl << endl; + cout << "\t2\tSPEAKER" << endl << endl; + cout << "\t7\tBLUETOOTH_SCO" << endl << endl; cout << "-d\n\tGets Device Active" << endl << endl; cout << "-M\n\tSets Mute for streams, -S to setStream" << endl << endl; cout << "-m\n\tGets Mute for streams, -S to setStream" << endl << endl; @@ -118,7 +117,7 @@ static void SetDeviceActive(const AudioSystemManager *audioSystemMgr, int argc, } cout << "Active : " << active << endl << endl; - int32_t result = audioSystemMgr->SetDeviceActive(AudioDeviceDescriptor::DeviceType(device), + int32_t result = audioSystemMgr->SetDeviceActive(ActiveDeviceType(device), (active) ? true : false); cout << "Set DeviceActive Result: " << result << endl; } @@ -126,7 +125,7 @@ static void SetDeviceActive(const AudioSystemManager *audioSystemMgr, int argc, static void IsDeviceActive(const AudioSystemManager *audioSystemMgr) { int device = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE); - bool devActiveStatus = audioSystemMgr->IsDeviceActive(AudioDeviceDescriptor::DeviceType(device)); + bool devActiveStatus = audioSystemMgr->IsDeviceActive(ActiveDeviceType(device)); cout << "GetDevice Active : " << devActiveStatus << endl; } -- Gitee