【Bug-Fixes】【Audio】{Launcher下遥控器按mute,然后再按音量+,之后无按键音} [SWPL-26283]
程序员文章站
2022-06-19 15:22:47
项目场景: Android TV,Android Q 1、在Launcher下通过遥控器按mute,然后再按音量+,之后系统音无声音(按键音) 2、在Launcher下通过遥控器按mute,然后再按mute,之后系统音是正常有声音的问题描述:在Launcher下通过遥控器按mute,然后再按音量+,之后系统音无声音(按键音) frameworks/base/services/core/java/com/android/server/audio/AudioService....
项目场景:
Android TV,Android Q 1、在Launcher下通过遥控器按mute,然后再按音量+,之后系统音无声音(按键音) 2、在Launcher下通过遥控器按mute,然后再按mute,之后系统音是正常有声音的问题描述:
在Launcher下通过遥控器按mute,然后再按音量+,之后系统音无声音(按键音)frameworks/base/services/core/java/com/android/server/audio/AudioService.java
/* 这里是TV平台所以是STREAM_VOLUME_ALIAS_TELEVISION的别称数组 */
private final int[] STREAM_VOLUME_ALIAS_TELEVISION = new int[] {
AudioSystem.STREAM_MUSIC, // STREAM_VOICE_CALL
AudioSystem.STREAM_MUSIC, // STREAM_SYSTEM
AudioSystem.STREAM_MUSIC, // STREAM_RING
AudioSystem.STREAM_MUSIC, // STREAM_MUSIC
AudioSystem.STREAM_MUSIC, // STREAM_ALARM
AudioSystem.STREAM_MUSIC, // STREAM_NOTIFICATION
AudioSystem.STREAM_BLUETOOTH_SCO, // STREAM_BLUETOOTH_SCO
AudioSystem.STREAM_MUSIC, // STREAM_SYSTEM_ENFORCED
AudioSystem.STREAM_MUSIC, // STREAM_DTMF
AudioSystem.STREAM_MUSIC, // STREAM_TTS
AudioSystem.STREAM_MUSIC, // STREAM_ACCESSIBILITY
AudioSystem.STREAM_MUSIC // STREAM_ASSISTANT
};
...
protected void adjustStreamVolume(int streamType, int direction, int flags,
String callingPackage, String caller, int uid) {
...
if (isMuteAdjust) {
boolean state;
if (direction == AudioManager.ADJUST_TOGGLE_MUTE) {
state = !streamState.mIsMuted;
} else {
state = direction == AudioManager.ADJUST_MUTE;
}
if (streamTypeAlias == AudioSystem.STREAM_MUSIC) {
setSystemAudioMute(state);
}
/* 当设置music的type音量mute和unmute时,将所有别名跟music一致的stream都在这里设置mute和unmute */
for (int stream = 0; stream < mStreamStates.length; stream++) {
if (streamTypeAlias == mStreamVolumeAlias[stream]) {
if (!(readCameraSoundForced() && (mStreamStates[stream].getStreamType()
== AudioSystem.STREAM_SYSTEM_ENFORCED))) {
mStreamStates[stream].mute(state);
}
}
}
} else if ((direction == AudioManager.ADJUST_RAISE) &&
!checkSafeMediaVolume(streamTypeAlias, aliasIndex + step, device)) {
Log.e(TAG, "adjustStreamVolume() safe volume index = " + oldIndex);
mVolumeController.postDisplaySafeVolumeWarning(flags);
} else if (((device & mFullVolumeDevices) == 0)
&& (streamState.adjustIndex(direction * step, device, caller)
|| streamState.mIsMuted)) {
// Post message to set system volume (it in turn will post a
// message to persist).
if (streamState.mIsMuted) {
// Unmute the stream if it was previously muted
if (direction == AudioManager.ADJUST_RAISE) {
// unmute immediately for volume up
/* 当设置音量+时,此处不会将所有别名跟music一致的stream unmute。 问题单在这。 */
streamState.mute(false);
} else if (direction == AudioManager.ADJUST_LOWER) {
if (mIsSingleVolume) {
sendMsg(mAudioHandler, MSG_UNMUTE_STREAM, SENDMSG_QUEUE,
streamTypeAlias, flags, null, UNMUTE_STREAM_DELAY);
}
}
}
sendMsg(mAudioHandler,
MSG_SET_DEVICE_VOLUME,
SENDMSG_QUEUE,
device,
0,
streamState,
0);
}
原因分析:
Google的STREAM_VOLUME_ALIAS_TELEVISION数组中system stream默认是follow music的,但是在设置音量+时,不会将所有别名跟music一致的stream unmute。导致用户通过音量+无法unmute system的系统音。解决方案:
TV产品不允许用户通过遥控器设置System type的音量。 将STREAM_VOLUME_ALIAS_TELEVISION数组中的AudioSystem.STREAM_MUSIC, // STREAM_SYSTEM
修改为
AudioSystem.STREAM_SYSTEM, // STREAM_SYSTEM
本文地址:https://blog.csdn.net/u013120422/article/details/111035549