Android通过AudioFlinger限制音量最大值

限制Android最大音量的实际大小:

--- a/frameworks/av/services/audioflinger/AudioFlinger.cpp
+++ b/frameworks/av/services/audioflinger/AudioFlinger.cpp
@@ -917,6 +917,10 @@ status_t AudioFlinger::checkStreamType(audio_stream_type_t stream) const
status_t AudioFlinger::setStreamVolume(audio_stream_type_t stream, float value,
         audio_io_handle_t output)
{
+       ALOGW("AudioFlinger.setStreamVolume()stream=%d,value=%f", stream, value);
+       if (value > 0.58)
+               value = 0.58;
     // check calling permissions
     if (!settingsAllowed()) {
         return PERMISSION_DENIED;

Android上层将音量分为16个等级,底层对应的值:

Level    value
0        0.000000
1        0.003087
2        0.007848
3        0.019953
4        0.029683
5        0.047479
6        0.074990
7        0.111558
8        0.177318
9        0.281839
10      0.340801
11      0.425354
12      0.530805
13      0.641949
14      0.801217
15      1.000000

你可能感兴趣的:(Android源码分析)