Andorid 13 默认音量区间是 [0,15] ,默认音量 5。
需求是:音量区间为 [0,100] ,默认音量 30 。
找到对应产品的 device.mk ,添加如下
#default volume
PRODUCT_PROPERTY_OVERRIDES += \ro.config.media_vol_steps=100 \ro.config.media_vol_default=30
意思是音量区间为 [0,100] ,默认音量 30 。
这两个属性可以追溯到 frameworks/base/services/core/java/com/android/server/audio/AudioService.java
,
/** Maximum volume index values for audio streams */protected static int[] MAX_STREAM_VOLUME = new int[] {5, // STREAM_VOICE_CALL7, // STREAM_SYSTEM7, // STREAM_RING // configured by config_audio_ring_vol_steps15, // STREAM_MUSIC7, // STREAM_ALARM7, // STREAM_NOTIFICATION // configured by config_audio_notif_vol_steps15, // STREAM_BLUETOOTH_SCO7, // STREAM_SYSTEM_ENFORCED15, // STREAM_DTMF15, // STREAM_TTS15, // STREAM_ACCESSIBILITY15 // STREAM_ASSISTANT};/** Minimum volume index values for audio streams */protected static int[] MIN_STREAM_VOLUME = new int[] {1, // STREAM_VOICE_CALL0, // STREAM_SYSTEM0, // STREAM_RING0, // STREAM_MUSIC1, // STREAM_ALARM0, // STREAM_NOTIFICATION0, // STREAM_BLUETOOTH_SCO0, // STREAM_SYSTEM_ENFORCED0, // STREAM_DTMF0, // STREAM_TTS1, // STREAM_ACCESSIBILITY0 // STREAM_ASSISTANT};// ...int maxMusicVolume = SystemProperties.getInt("ro.config.media_vol_steps", -1);if (maxMusicVolume != -1) {MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = maxMusicVolume;}int defaultMusicVolume = SystemProperties.getInt("ro.config.media_vol_default", -1);if (defaultMusicVolume != -1 &&defaultMusicVolume <= MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] &&defaultMusicVolume >= MIN_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]) {AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = defaultMusicVolume;} else {if (isPlatformTelevision()) {AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] =MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] / 4;} else {AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] =MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] / 3;}}
默认音量值定义在 frameworks/base/media/java/android/media/AudioSystem.java
,
/** @hide */public static int[] DEFAULT_STREAM_VOLUME = new int[] {4, // STREAM_VOICE_CALL7, // STREAM_SYSTEM5, // STREAM_RING // configured in AudioService by config_audio_notif_vol_default5, // STREAM_MUSIC6, // STREAM_ALARM5, // STREAM_NOTIFICATION // configured in AudioService by config_audio_ring_vol_default7, // STREAM_BLUETOOTH_SCO7, // STREAM_SYSTEM_ENFORCED5, // STREAM_DTMF5, // STREAM_TTS5, // STREAM_ACCESSIBILITY5, // STREAM_ASSISTANT};
可以看到,
- 最大音量是读取
ro.config.media_vol_steps
属性的值,未赋值就用MAX_STREAM_VOLUME
数组里定义的,数组里的值按照声音通道区分。 - 默认音量是读取
ro.config.media_vol_default
属性的值,未赋值就用DEFAULT_STREAM_VOLUME
数组里定义的,数组里的值按照声音通道区分。