mirror of
https://gitee.com/openharmony/multimedia_audio_standard
synced 2024-12-04 02:42:55 +00:00
xts test case failure fix
Signed-off-by: Geevarghese V K <geevarghese.v.k1@huawei.com>
This commit is contained in:
parent
a446c4b896
commit
1e686ed35b
@ -33,7 +33,6 @@ constexpr int32_t MINIMUM_BUFFER_SIZE_MSEC = 5;
|
||||
constexpr int32_t MAXIMUM_BUFFER_SIZE_MSEC = 20;
|
||||
constexpr int32_t MIN_SERVICE_COUNT = 2;
|
||||
|
||||
|
||||
enum DeviceFlag {
|
||||
/**
|
||||
* Device flag none.
|
||||
|
@ -118,6 +118,7 @@ private:
|
||||
void TriggerDeviceChangedCallback(const std::vector<sptr<AudioDeviceDescriptor>> &devChangeDesc, bool connection);
|
||||
|
||||
bool interruptEnabled_ = true;
|
||||
int32_t mDefaultDeviceCount = 0;
|
||||
std::bitset<MIN_SERVICE_COUNT> serviceFlag_;
|
||||
DeviceType mCurrentActiveDevice = DEVICE_TYPE_NONE;
|
||||
IAudioPolicyInterface& mAudioPolicyManager;
|
||||
|
@ -306,12 +306,17 @@ int32_t AudioPolicyService::SetDeviceActive(InternalDeviceType deviceType, bool
|
||||
int32_t result = SUCCESS;
|
||||
|
||||
if (!active) {
|
||||
deviceType = FetchHighPriorityDevice();
|
||||
CHECK_AND_RETURN_RET_LOG(deviceType == mCurrentActiveDevice, SUCCESS, "This device is not active");
|
||||
if (mConnectedDevices.size() == mDefaultDeviceCount && deviceType == DEVICE_TYPE_SPEAKER) {
|
||||
deviceType = DEVICE_TYPE_BLUETOOTH_SCO;
|
||||
} else {
|
||||
deviceType = FetchHighPriorityDevice();
|
||||
}
|
||||
}
|
||||
|
||||
if (deviceType == mCurrentActiveDevice) {
|
||||
MEDIA_ERR_LOG("Device already activated %{public}d", mCurrentActiveDevice);
|
||||
return ERR_INVALID_OPERATION;
|
||||
MEDIA_ERR_LOG("Device already activated %{public}d. No need to activate again", mCurrentActiveDevice);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
if (deviceType == DEVICE_TYPE_SPEAKER) {
|
||||
@ -493,12 +498,13 @@ void AudioPolicyService::OnServiceConnected(AudioServiceIndex serviceIndex)
|
||||
MEDIA_ERR_LOG("[module_load]::Device failed %{public}d", devType);
|
||||
break;
|
||||
}
|
||||
// add new device into active device list
|
||||
sptr<AudioDeviceDescriptor> audioDescriptor = new(std::nothrow) AudioDeviceDescriptor(devType,
|
||||
GetDeviceRole(moduleInfo.role));
|
||||
mConnectedDevices.insert(mConnectedDevices.begin(), audioDescriptor);
|
||||
}
|
||||
|
||||
// add new device into active device list
|
||||
sptr<AudioDeviceDescriptor> audioDescriptor = new(std::nothrow) AudioDeviceDescriptor(devType,
|
||||
GetDeviceRole(moduleInfo.role));
|
||||
mConnectedDevices.insert(mConnectedDevices.begin(), audioDescriptor);
|
||||
mDefaultDeviceCount++;
|
||||
mIOHandles[moduleInfo.name] = ioHandle;
|
||||
}
|
||||
}
|
||||
@ -561,12 +567,16 @@ AudioIOHandle AudioPolicyService::GetAudioIOHandle(InternalDeviceType deviceType
|
||||
|
||||
InternalDeviceType AudioPolicyService::GetDeviceType(const std::string &deviceName)
|
||||
{
|
||||
if (deviceName == "Speaker")
|
||||
return InternalDeviceType::DEVICE_TYPE_SPEAKER;
|
||||
if (deviceName == "Built_in_mic")
|
||||
return InternalDeviceType::DEVICE_TYPE_MIC;
|
||||
InternalDeviceType devType = InternalDeviceType::DEVICE_TYPE_NONE;
|
||||
if (deviceName == "Speaker") {
|
||||
devType = InternalDeviceType::DEVICE_TYPE_SPEAKER;
|
||||
} else if (deviceName == "Built_in_mic") {
|
||||
devType = InternalDeviceType::DEVICE_TYPE_MIC;
|
||||
} else if (deviceName == "fifo_output" || deviceName == "fifo_input") {
|
||||
devType = DEVICE_TYPE_BLUETOOTH_SCO;
|
||||
}
|
||||
|
||||
return InternalDeviceType::DEVICE_TYPE_NONE;
|
||||
return devType;
|
||||
}
|
||||
|
||||
void AudioPolicyService::TriggerDeviceChangedCallback(const vector<sptr<AudioDeviceDescriptor>> &desc, bool isConnected)
|
||||
|
@ -158,13 +158,9 @@ AudioIOHandle AudioAdapterManager::OpenAudioPort(const AudioModuleInfo &audioMod
|
||||
if (!audioModuleInfo.fileName.empty() && access(audioModuleInfo.fileName.c_str(), F_OK) == 0) {
|
||||
int32_t ret = std::remove(audioModuleInfo.fileName.c_str());
|
||||
if (ret) {
|
||||
MEDIA_ERR_LOG("[AudioAdapterManager] Error Removing file: %{public}s Failed! ret val: %{public}d",
|
||||
audioModuleInfo.fileName.c_str(), ret);
|
||||
MEDIA_ERR_LOG("Removing pipe file failed!. Ret val: %{public}d", ret);
|
||||
return ERR_OPERATION_FAILED;
|
||||
}
|
||||
} else {
|
||||
MEDIA_ERR_LOG("[AudioAdapterManager] Error audioModuleInfo.fileName is null! or file not exists");
|
||||
return ERR_OPERATION_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,23 +82,61 @@ HWTEST(AudioManagerUnitTest, GetConnectedDevicesList_003, TestSize.Level0)
|
||||
/**
|
||||
* @tc.name : Test SetDeviceActive API
|
||||
* @tc.number: SetDeviceActive_001
|
||||
* @tc.desc : Test SetDeviceActive interface. Deactivate default speaker should not be success
|
||||
* @tc.desc : Test SetDeviceActive interface. Activate bluetooth sco device by deactivating speaker
|
||||
*/
|
||||
HWTEST(AudioManagerUnitTest, SetDeviceActive_001, TestSize.Level0)
|
||||
{
|
||||
auto ret = AudioSystemManager::GetInstance()->SetDeviceActive(ActiveDeviceType::SPEAKER, false);
|
||||
EXPECT_NE(SUCCESS, ret);
|
||||
auto isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::SPEAKER);
|
||||
EXPECT_TRUE(isActive);
|
||||
|
||||
auto ret = AudioSystemManager::GetInstance()->SetDeviceActive(ActiveDeviceType::BLUETOOTH_SCO, true);
|
||||
EXPECT_EQ(SUCCESS, ret);
|
||||
|
||||
isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::BLUETOOTH_SCO);
|
||||
EXPECT_TRUE(isActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name : Test IsDeviceActive API
|
||||
* @tc.number: IsDeviceActive_001
|
||||
* @tc.desc : Test IsDeviceActive interface. Returns whether the mentioned device is currently active
|
||||
* @tc.name : Test SetDeviceActive API
|
||||
* @tc.number: SetDeviceActive_002
|
||||
* @tc.desc : Test SetDeviceActive interface. Activate speaker device
|
||||
*/
|
||||
HWTEST(AudioManagerUnitTest, IsDeviceActive_001, TestSize.Level0)
|
||||
HWTEST(AudioManagerUnitTest, SetDeviceActive_002, TestSize.Level0)
|
||||
{
|
||||
auto isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::SPEAKER);
|
||||
auto isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::BLUETOOTH_SCO);
|
||||
EXPECT_TRUE(isActive);
|
||||
|
||||
auto ret = AudioSystemManager::GetInstance()->SetDeviceActive(ActiveDeviceType::SPEAKER, true);
|
||||
EXPECT_EQ(SUCCESS, ret);
|
||||
|
||||
isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::SPEAKER);
|
||||
EXPECT_TRUE(isActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name : Test SetDeviceActive API
|
||||
* @tc.number: SetDeviceActive_003
|
||||
* @tc.desc : Test SetDeviceActive interface. Switch between SPEAKER and BT SCO automatically
|
||||
*/
|
||||
HWTEST(AudioManagerUnitTest, SetDeviceActive_003, TestSize.Level0)
|
||||
{
|
||||
auto ret = AudioSystemManager::GetInstance()->SetDeviceActive(ActiveDeviceType::SPEAKER, false);
|
||||
EXPECT_EQ(SUCCESS, ret);
|
||||
|
||||
auto isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::SPEAKER);
|
||||
EXPECT_FALSE(isActive);
|
||||
|
||||
isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::BLUETOOTH_SCO);
|
||||
EXPECT_TRUE(isActive);
|
||||
|
||||
ret = AudioSystemManager::GetInstance()->SetDeviceActive(ActiveDeviceType::BLUETOOTH_SCO, false);
|
||||
EXPECT_EQ(SUCCESS, ret);
|
||||
|
||||
isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::SPEAKER);
|
||||
EXPECT_TRUE(isActive);
|
||||
|
||||
isActive = AudioSystemManager::GetInstance()->IsDeviceActive(ActiveDeviceType::BLUETOOTH_SCO);
|
||||
EXPECT_FALSE(isActive);
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user