天天看點

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
           

繼續閱讀