Bug 1249437 - Remove workaround of volume control r=alwu
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -1356,49 +1356,37 @@ AudioManager::VolumeStreamState::SetVolu
bool exist = mVolumeIndexes.Get(device, &oldVolumeIndex);
if (exist && aIndex == oldVolumeIndex) {
// No update
return NS_OK;
}
// AudioPolicyManager::setStreamVolumeIndex() set volumes of all active
// devices for stream.
- nsresult rv = SetVolumeIndex(aIndex, device);
+ nsresult rv;
+ rv = SetVolumeIndexToConsistentDeviceIfNeeded(aIndex, device);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- // Workaround to make audio volume control consisitent.
- // Active devices of AUDIO_STREAM_NOTIFICATION are affected by
- // AUDIO_STREAM_MUSIC's activity. It makes audio volume control inconsistent.
- // See Bug 1196724
- if (device != AUDIO_DEVICE_OUT_SPEAKER &&
- mStreamType == AUDIO_STREAM_NOTIFICATION) {
- // Rescaling of index is not necessary.
- rv = SetVolumeIndex(aIndex, AUDIO_DEVICE_OUT_SPEAKER);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return rv;
- }
- }
-
return NS_OK;
}
nsresult
AudioManager::VolumeStreamState::SetVolumeIndexToAliasStreams(uint32_t aIndex,
uint32_t aDevice)
{
uint32_t oldVolumeIndex = 0;
bool exist = mVolumeIndexes.Get(aDevice, &oldVolumeIndex);
if (exist && aIndex == oldVolumeIndex) {
// No update
return NS_OK;
}
- nsresult rv = SetVolumeIndex(aIndex, aDevice);
+ nsresult rv = SetVolumeIndexToConsistentDeviceIfNeeded(aIndex, aDevice);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
for (int32_t streamType = 0; streamType < AUDIO_STREAM_MAX; streamType++) {
if ((streamType != mStreamType) &&
sStreamVolumeAliasTbl[streamType] == mStreamType) {
// Rescaling of index is not necessary.
@@ -1409,16 +1397,37 @@ AudioManager::VolumeStreamState::SetVolu
}
}
}
return NS_OK;
}
nsresult
+AudioManager::VolumeStreamState::SetVolumeIndexToConsistentDeviceIfNeeded(uint32_t aIndex, uint32_t aDevice)
+{
+ nsresult rv;
+ if (aDevice == AUDIO_DEVICE_OUT_SPEAKER || aDevice == AUDIO_DEVICE_OUT_EARPIECE) {
+ // Set AUDIO_DEVICE_OUT_SPEAKER and AUDIO_DEVICE_OUT_EARPIECE to same volume.
+ rv = SetVolumeIndex(aIndex, AUDIO_DEVICE_OUT_SPEAKER);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
+ rv = SetVolumeIndex(aIndex, AUDIO_DEVICE_OUT_EARPIECE);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
+ } else {
+ // No alias device
+ rv = SetVolumeIndex(aIndex, aDevice);
+ }
+ return rv;
+}
+
+nsresult
AudioManager::VolumeStreamState::SetVolumeIndex(uint32_t aIndex,
uint32_t aDevice,
bool aUpdateCache)
{
status_t rv;
#if ANDROID_VERSION >= 17
if (aUpdateCache) {
mVolumeIndexes.Put(aDevice, aIndex);
--- a/dom/system/gonk/AudioManager.h
+++ b/dom/system/gonk/AudioManager.h
@@ -82,16 +82,17 @@ public:
uint32_t GetVolumeIndex();
uint32_t GetVolumeIndex(uint32_t aDevice);
void ClearCurrentVolumeUpdated();
// Set volume index to all active devices.
// Active devices are chosen by android AudioPolicyManager.
nsresult SetVolumeIndexToActiveDevices(uint32_t aIndex);
// Set volume index to all alias streams for device. Alias streams have same volume.
nsresult SetVolumeIndexToAliasStreams(uint32_t aIndex, uint32_t aDevice);
+ nsresult SetVolumeIndexToConsistentDeviceIfNeeded(uint32_t aIndex, uint32_t aDevice);
nsresult SetVolumeIndex(uint32_t aIndex, uint32_t aDevice, bool aUpdateCache = true);
// Restore volume index to all devices. Called when AudioFlinger is restarted.
void RestoreVolumeIndexToAllDevices();
private:
AudioManager& mManager;
const int32_t mStreamType;
uint32_t mLastDevices;
bool mIsDevicesChanged;