android调节系统音量之修改默认音量、最大音量和最小音量

时间:2025-01-25 15:32:44
//frameworks/base/services/core/java/com/android/server/audio/ public AudioService(Context context) { …… int maxCallVolume = SystemProperties.getInt(".vc_call_vol_steps", -1); if (maxCallVolume != -1) { MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = maxCallVolume; } int defaultCallVolume = SystemProperties.getInt(".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] = (maxCallVolume * 3) / 4; } int maxMusicVolume = SystemProperties.getInt(".media_vol_steps", -1); if (maxMusicVolume != -1) { MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = maxMusicVolume; } if(isBox() ||isTablet()){ mFixedVolumeDevices = 0; } int defaultMusicVolume = SystemProperties.getInt(".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(".alarm_vol_steps", -1); if (maxAlarmVolume != -1) { MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM] = maxAlarmVolume; } int defaultAlarmVolume = SystemProperties.getInt(".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(".system_vol_steps", -1); if (maxSystemVolume != -1) { MAX_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM] = maxSystemVolume; } int defaultSystemVolume = SystemProperties.getInt(".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]; } ……