高通 msm8909
diff --git a/frameworks/base/media/java/android/media/AudioSystem.java b/frameworks/base/media/java/android/media/AudioSystem.java index af27d36..eeefcc0 100644 --- a/frameworks/base/media/java/android/media/AudioSystem.java +++ b/frameworks/base/media/java/android/media/AudioSystem.java @@ -695,12 +695,12 @@ public class AudioSystem ???? } ?//设置默认的音量值,方便调节的时候变动的格数相同; ???? public static int[] DEFAULT_STREAM_VOLUME = new int[] { -??????? 2,? // STREAM_VOICE_CALL +??????? 7,? // STREAM_VOICE_CALL ???????? 7,? // STREAM_SYSTEM ???????? 3,? // STREAM_RING ???????? 7, // STREAM_MUSIC -??????? 3,? // STREAM_ALARM -??????? 5,? // STREAM_NOTIFICATION +??????? 7,? // STREAM_ALARM +??????? 7,? // STREAM_NOTIFICATION ???????? 7,? // STREAM_BLUETOOTH_SCO ???????? 7,? // STREAM_SYSTEM_ENFORCED ???????? 7, // STREAM_DTMF diff --git a/frameworks/base/services/core/java/com/android/server/audio/AudioService.java b/frameworks/base/services/core/java/com/android/server/audio/Au index 9ec414b..5b654e2 100644 --- a/frameworks/base/services/core/java/com/android/server/audio/AudioService.java +++ b/frameworks/base/services/core/java/com/android/server/audio/AudioService.java @@ -281,27 +281,27 @@ public class AudioService extends IAudioService.Stub { ?
?//设置默认的最大音量值,格数相同; ??? /** Maximum volume index values for audio streams */ ???? private static int[] MAX_STREAM_VOLUME = new int[] { -??????? 5,? // STREAM_VOICE_CALL -??????? 7,? // STREAM_SYSTEM +??????? 15,? // STREAM_VOICE_CALL +??????? 15,? // STREAM_SYSTEM ???????? 7,? // STREAM_RING ???????? 15, // STREAM_MUSIC -??????? 7,? // STREAM_ALARM -??????? 7,? // STREAM_NOTIFICATION +??????? 15,? // STREAM_ALARM +??????? 15,? // STREAM_NOTIFICATION ???????? 15, // STREAM_BLUETOOTH_SCO -??????? 7,? // STREAM_SYSTEM_ENFORCED +??????? 15,? // STREAM_SYSTEM_ENFORCED ???????? 15, // STREAM_DTMF ???????? 15? // STREAM_TTS ???? }; ?//设置默认的最小音量值,格数相同; ???? /** Minimum volume index values for audio streams */ ???? private static int[] MIN_STREAM_VOLUME = new int[] { -??????? 1,? // STREAM_VOICE_CALL +??????? 0,? // STREAM_VOICE_CALL ???????? 0,? // STREAM_SYSTEM ???????? 0,? // STREAM_RING ???????? 0,? // STREAM_MUSIC ???????? 0,? // STREAM_ALARM ???????? 0,? // STREAM_NOTIFICATION -??????? 1,? // STREAM_BLUETOOTH_SCO +??????? 0,? // STREAM_BLUETOOTH_SCO ???????? 0,? // STREAM_SYSTEM_ENFORCED ???????? 0,? // STREAM_DTMF ???????? 0?? // STREAM_TTS
//我没有控制铃声,所以铃声没改;这里需要控制哪个音量就改哪个 @@ -320,13 +320,13 @@ public class AudioService extends IAudioService.Stub {
private final int[] STREAM_VOLUME_ALIAS_VOICE = new int[] { ???????? AudioSystem.STREAM_VOICE_CALL,????? // STREAM_VOICE_CALL ???????? AudioSystem.STREAM_RING,??????????? // STREAM_SYSTEM ???????? AudioSystem.STREAM_RING,??????????? // STREAM_RING -??????? AudioSystem.STREAM_MUSIC,?????????? // STREAM_MUSIC -??????? AudioSystem.STREAM_ALARM,?????????? // STREAM_ALARM +??????? AudioSystem.STREAM_VOICE_CALL,?????????? // STREAM_MUSIC +??????? AudioSystem.STREAM_VOICE_CALL,?????????? // STREAM_ALARM ???????? AudioSystem.STREAM_RING,??????????? // STREAM_NOTIFICATION -??????? AudioSystem.STREAM_BLUETOOTH_SCO,?? // STREAM_BLUETOOTH_SCO +??????? AudioSystem.STREAM_VOICE_CALL,?? // STREAM_BLUETOOTH_SCO ???????? AudioSystem.STREAM_RING,??????????? // STREAM_SYSTEM_ENFORCED ???????? AudioSystem.STREAM_RING,??????????? // STREAM_DTMF -??????? AudioSystem.STREAM_MUSIC??????????? // STREAM_TTS +??????? AudioSystem.STREAM_VOICE_CALL??????????? // STREAM_TTS ???? }; ???? private final int[] STREAM_VOLUME_ALIAS_TELEVISION = new int[] { ???????? AudioSystem.STREAM_MUSIC,?????? // STREAM_VOICE_CALL
下面是文章链接内容
?参考:https://www.freesion.com/article/8053740494/
需求
音量条控制时需要将媒体音量,电话铃声等统一控制,即移动一个音量条其他音量条也跟着变化。
修改
frameworks/base/services/core/java/com/android/server/audio/AudioService.java 修改STREAM_VOLUME_ALIAS_DEFAULT 数组改成跟STREAM_VOLUME_ALIAS_TELEVISION 数组内容一样所以音量条都属于music 分组
代码分析
Android 系统创建AudioTrack 时可以指定10 种stream
目录:frameworks/base/media/java/android/media/AudioSystem.java
各种stream 的音量也可以单独设置、互不影响。 比如"音乐音量"不应该影响到"来电振铃"、“闹钟”、"通话"的音量。
手机音量控制界面有5 种滑动条, 用于设置某种类型的声音音量. 这5种滑动条如何控制10 种stream ? 必须分组!在Android 源码中称之为"别名", 即alias
frameworks/base/services/core/java/com/android/server/audio/AudioService.java
在key-down 事件时调整音量,在key-up 时播放调节音量的声音 目录:frameworks/base/media/java/android/media/AudioManager.java
这里的flags 是FLAG_SHOW_UI | FLAG_VIBRATE ,会显示进度条,有震动。
这里的flags 是FLAG_PLAY_SOUND ,表示播放音乐
最终会调用到:
frameworks/base/services/core/java/com/android/server/audio/AudioService.java
先通过getActiveStreamType 获取当前活跃的流类型
接着看audioservice ,如何处理音量调节的。
//step1,为streamType查找alias归类,使用流类型别名是为了让有相同别名的流,有相同的行为。
int streamTypeAlias = mStreamVolumeAlias[streamType];
//step2,为streamtypealias寻找匹配的device。
final int device = getDeviceForStream(streamTypeAlias);
//step3,获取对应的aliasindex
int aliasIndex = streamState.getIndex(device);
// step4,调节index,把UI上的加1、减1的步骤,转成流别名上内部单元中的数字
// convert one UI step (+/-1) into a number of internal units on the stream alias
step = rescaleIndex(10, streamType, streamTypeAlias);
//step5,对音量模式的影响
// If either the client forces allowing ringer modes for this adjustment,
// or the stream type is one that is affected by ringer modes
if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
(streamTypeAlias == getUiSoundsStreamType())) {
//step6,将调节音量的事件发给下一个处理者。
sendMsg(mAudioHandler,
MSG_SET_DEVICE_VOLUME,
SENDMSG_QUEUE,
device,
0,
streamState,
0);
接下来看看MSG_SET_DEVICE_VOLUME 消息处理做了什么
版权声明:本文为qq_33487044原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_33487044/article/details/87449522
https://blog.csdn.net/bberdong/article/details/51792319
Android 4.4 音量的统一调节
https://blog.csdn.net/h1217256980/article/details/101211287
https://blog.csdn.net/bberdong/article/details/83068688
另外,通话音量无法设置为无声;
没法将通话音量调到最低的原因是,通话音量的最小就是1,这是在audioservice中设定的;
// VOICE_CALL stream has minVolumeIndex > 0 but can be muted directly by an // app that has MODIFY_PHONE_STATE permission. if (((index < mVolumeCurves>getVolumeIndexMin(stream)) && !(stream == AUDIO_STREAM_VOICE_CALL && index == 0)) || (index > mVolumeCurves->getVolumeIndexMax(stream))) { return BAD_VALUE; }
以下代码是android8.0原生代码,与项目中代码略有差异,但是基本一致;return BAD_VALUE; 之前增加了log,编译发现log的确打印出来了, mVolumeCurves->getVolumeIndexMin(stream) 音量曲线的最低点是大于0的;稍后继续验证分析下,您也可以尝试下; status_t AudioPolicyManager::setStreamVolumeIndex(audio_stream_type_t stream, int index, audio_devices_t device) { if ((index < mVolumeCurves>getVolumeIndexMin(stream)) || (index > mVolumeCurves->getVolumeIndexMax(stream))) { return BAD_VALUE; }
已经确认清楚了,audio驱动音频参数模块里面的设置的最低音量就是有声音的,项目这边最低是-15db;所以肯定是有声音的, 这个是可以通过修改ACDB文件来配置相关音频参数,将最低音量修改下就可以了;
|