Android. media. AudioManager contains the cross-process AIDL call encapsulation for android. media. AudioService.
Normal handling process:
1. To adjust the volume, AudioManager indirectly calls AudioService. adjustStreamVolume to complete logical processing;
2. AudioService calls VolumePanel to draw the volume adjustment interface and send a broadcast message of volume change,
3. StatusBarPolicy: receives broadcast messages and determines whether the mute or vibrating icon is displayed on the status bar.
Problem:
1. How does AudioManager receive volume adjustment events?
A: PhoneWindowManager. interceptKeyBeforeQueueing
WindowManagerService cyclically reads the following messages and then delivers them to the window for receiving. Before message distribution, there is a class for message filtering, namely PhoneWindowManager. interceptKeyBeforeQueueing;
For example, the volume adjustment and Home key are all specially processed in this class. The details will be added later in other cases.
2. Who handles the volume display?
A: AudioManager calls AudioService for display. Events are triggered in AudioManager, and code execution is implemented in AudioService. The status bar is handled by receiving broadcast messages in the StatusBarPolicy of the APK package of SystemUI.
Source code location:
/Frameworks/base/media/java/android/media/AudioManager. java
/Frameworks/base/media/java/android/media/AudioService. java
/Framework/base/core/java/Android/view/VolumePanel. java
/Frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy. java
The AudioService. adjustStreamVolume method provides the following functions:
I. Volume Adjustment
There are two steps to adjust the volume: Check whether the mode needs to be adjusted first? Then call to adjust the volume.
The adjustment mode is implemented by calling checkForRingerModeChange (oldIndex, direction,
Adjust the volume by calling streamState. adjustIndex (direction.
2. display the page for adjusting the volume to the user
Call mVolumePanel. postVolumeChanged (streamType, flags); send the volume change message to show the change result to the user.
Call procedure VolumePanel. postVolumeChanged-> VolumePanel. onVolumeChanged-> VolumePanel. onShowVolumeChanged-> mToast
3. system events with broadcast volume changes
AudioService. sendVolumeUpdate (streamType); broadcast a system event with a changed volume. the status bar displays a mute or vibrating icon based on this broadcast event.
How to display the mute or vibrating icon in the status bar
StatusBarPolicy is mainly responsible for displaying an icon in the right of the status bar in silent mode and vibrate mode.
1. After the system is started, StatusBarPolicy registers a Receiver, which can receive many kinds of broadcasts. Among them, AudioService sends two broadcast events every time the mode and volume are updated.
Private BroadcastReceiver mIntentReceiver = new BroadcastReceiver () // a new broadcast receiving Class'
Filter. addAction (AudioManager. RINGER_MODE_CHANGED_ACTION); // Add the received broadcast message
Filter. addAction (AudioManager. VIBRATE_SETTING_CHANGED_ACTION );
MContext. registerReceiver (mIntentReceiver, filter, null, mHandler); // register a Receiver to receive broadcast messages
2. Receive the broadcast and call updateVolume to adjust the status bar display.
Else if (action. equals (AudioManager. RINGER_MODE_CHANGED_ACTION) |
Action. equals (AudioManager. VIBRATE_SETTING_CHANGED_ACTION )){
UpdateVolume (); // call volume status bar display
}
From Android brick house