赞
踩
需求是需要更改默认的媒体音没因为喇叭功率较小,所以需要直接开机就默认拉满的音量
frameworks/base/media/java/android/media/AudioSystem.java
frameworks/base/services/core/java/com/android/server/audio/AudioService.java
1.话不多说系统音量默认初始值在AudioSystem.java中定义,代码如下:
/** @hide */
public static int[] DEFAULT_STREAM_VOLUME = new int[] {
4, // STREAM_VOICE_CALL
7, // STREAM_SYSTEM
5, // STREAM_RING
5, // STREAM_MUSIC
6, // STREAM_ALARM
5, // STREAM_NOTIFICATION
7, // STREAM_BLUETOOTH_SCO
7, // STREAM_SYSTEM_ENFORCED
5, // STREAM_DTMF
5, // STREAM_TTS
5, // STREAM_ACCESSIBILITY
5, // STREAM_ASSISTANT
};
2.系统音量最大值和最小值定义在AudioService.java 中,代码如下:
/** Maximum volume index values for audio streams */ protected static int[] MAX_STREAM_VOLUME = new int[] { 5, // STREAM_VOICE_CALL 7, // STREAM_SYSTEM 7, // STREAM_RING 15, // STREAM_MUSIC 7, // STREAM_ALARM 7, // STREAM_NOTIFICATION 15, // STREAM_BLUETOOTH_SCO 7, // STREAM_SYSTEM_ENFORCED 15, // STREAM_DTMF 15, // STREAM_TTS 15, // STREAM_ACCESSIBILITY 15 // STREAM_ASSISTANT }; /** Minimum volume index values for audio streams */ protected static int[] MIN_STREAM_VOLUME = new int[] { 1, // STREAM_VOICE_CALL 0, // STREAM_SYSTEM 0, // STREAM_RING 0, // STREAM_MUSIC 1, // STREAM_ALARM 0, // STREAM_NOTIFICATION 0, // STREAM_BLUETOOTH_SCO 0, // STREAM_SYSTEM_ENFORCED 0, // STREAM_DTMF 0, // STREAM_TTS 1, // STREAM_ACCESSIBILITY 0 // STREAM_ASSISTANT };
/** @hide */ public static int[] DEFAULT_STREAM_VOLUME = new int[] { 5, // STREAM_VOICE_CALL 7, // STREAM_SYSTEM 7, // STREAM_RING 15, // STREAM_MUSIC 7, // STREAM_ALARM 7, // STREAM_NOTIFICATION 15, // STREAM_BLUETOOTH_SCO 7, // STREAM_SYSTEM_ENFORCED 15, // STREAM_DTMF 15, // STREAM_TTS 15, // STREAM_ACCESSIBILITY 15, // STREAM_ASSISTANT };
如上,直接把所有的值都改为了AudioService.java的上限
// Initialize volume // Priority 1 - Android Property // Priority 2 - Audio Policy Service // Priority 3 - Default Value if (AudioProductStrategy.getAudioProductStrategies().size() > 0) { int numStreamTypes = AudioSystem.getNumStreamTypes(); for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { AudioAttributes attr = AudioProductStrategy.getAudioAttributesForStrategyWithLegacyStreamType( streamType); int maxVolume = AudioSystem.getMaxVolumeIndexForAttributes(attr); if (maxVolume != -1) { MAX_STREAM_VOLUME[streamType] = maxVolume; } int minVolume = AudioSystem.getMinVolumeIndexForAttributes(attr); if (minVolume != -1) { MIN_STREAM_VOLUME[streamType] = minVolume; } } if (mUseVolumeGroupAliases) { // Set all default to uninitialized. for (int stream = 0; stream < AudioSystem.DEFAULT_STREAM_VOLUME.length; stream++) { AudioSystem.DEFAULT_STREAM_VOLUME[stream] = UNSET_INDEX; } } } /*注释开始 int maxCallVolume = SystemProperties.getInt("ro.config.vc_call_vol_steps", -1); if (maxCallVolume != -1) { MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = maxCallVolume; } int defaultCallVolume = SystemProperties.getInt("ro.config.vc_call_vol_default", -1); if (defaultCallVolume != -1 && defaultCallVolume <= MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] && defaultCallVolume >= MIN_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]) { AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = defaultCallVolume; } else { AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = (MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] * 3) / 4; } 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; } } int maxAlarmVolume = SystemProperties.getInt("ro.config.alarm_vol_steps", -1); if (maxAlarmVolume != -1) { MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM] = maxAlarmVolume; } int defaultAlarmVolume = SystemProperties.getInt("ro.config.alarm_vol_default", -1); if (defaultAlarmVolume != -1 && defaultAlarmVolume <= MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM]) { AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_ALARM] = defaultAlarmVolume; } else { // Default is 6 out of 7 (default maximum), so scale accordingly. AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_ALARM] = 6 * MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM] / 7; } int maxSystemVolume = SystemProperties.getInt("ro.config.system_vol_steps", -1); if (maxSystemVolume != -1) { MAX_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM] = maxSystemVolume; } int defaultSystemVolume = SystemProperties.getInt("ro.config.system_vol_default", -1); if (defaultSystemVolume != -1 && defaultSystemVolume <= MAX_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM]) { AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM] = defaultSystemVolume; } else { // Default is to use maximum. AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM] = MAX_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM]; } 注释结束*/ createAudioSystemThread();
因为AudioService.java在构造函数中,会覆盖最大值和默认初始值,所以需要把构造函数中从配置文件中取值的代码注释掉,才能让步骤一中修改的数组的值起作用。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。