@@ -127,6 +127,7 @@ public class AudioService extends IAudioService.Stub {
127127 private static final int MSG_BT_HEADSET_CNCT_FAILED = 12 ;
128128 private static final int MSG_RCDISPLAY_CLEAR = 13 ;
129129 private static final int MSG_RCDISPLAY_UPDATE = 14 ;
130+ private static final int MSG_PERSIST_MASTER_VOLUME_MUTE = 15 ;
130131
131132 private static final int BTA2DP_DOCK_TIMEOUT_MILLIS = 8000 ;
132133 // Timeout for connection to bluetooth headset service
@@ -485,6 +486,10 @@ private void readPersistedSettings() {
485486 System .MUTE_STREAMS_AFFECTED ,
486487 ((1 << AudioSystem .STREAM_MUSIC )|(1 << AudioSystem .STREAM_RING )|(1 << AudioSystem .STREAM_SYSTEM )));
487488
489+ boolean masterMute = System .getInt (cr , System .VOLUME_MASTER_MUTE , 0 ) == 1 ;
490+ AudioSystem .setMasterMute (masterMute );
491+ broadcastMasterMuteStatus (masterMute );
492+
488493 // Each stream will read its own persisted settings
489494
490495 // Broadcast the sticky intent
@@ -707,9 +712,14 @@ private void sendMasterVolumeUpdate(int flags, int oldVolume, int newVolume) {
707712 // UI update and Broadcast Intent
708713 private void sendMasterMuteUpdate (boolean muted , int flags ) {
709714 mVolumePanel .postMasterMuteChanged (flags );
715+ broadcastMasterMuteStatus (muted );
716+ }
710717
718+ private void broadcastMasterMuteStatus (boolean muted ) {
711719 Intent intent = new Intent (AudioManager .MASTER_MUTE_CHANGED_ACTION );
712720 intent .putExtra (AudioManager .EXTRA_MASTER_VOLUME_MUTED , muted );
721+ intent .addFlags (Intent .FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
722+ | Intent .FLAG_RECEIVER_REPLACE_PENDING );
713723 long origCallerIdentityToken = Binder .clearCallingIdentity ();
714724 mContext .sendStickyBroadcast (intent );
715725 Binder .restoreCallingIdentity (origCallerIdentityToken );
@@ -772,6 +782,9 @@ public boolean isStreamMute(int streamType) {
772782 public void setMasterMute (boolean state , IBinder cb ) {
773783 if (state != AudioSystem .getMasterMute ()) {
774784 AudioSystem .setMasterMute (state );
785+ // Post a persist master volume msg
786+ sendMsg (mAudioHandler , MSG_PERSIST_MASTER_VOLUME_MUTE , 0 , SENDMSG_REPLACE , state ? 1
787+ : 0 , 0 , null , PERSIST_DELAY );
775788 sendMasterMuteUpdate (state , AudioManager .FLAG_SHOW_UI );
776789 }
777790 }
@@ -2366,6 +2379,11 @@ public void handleMessage(Message msg) {
23662379 (float )msg .arg1 / (float )1000.0 );
23672380 break ;
23682381
2382+ case MSG_PERSIST_MASTER_VOLUME_MUTE :
2383+ Settings .System .putInt (mContentResolver , Settings .System .VOLUME_MASTER_MUTE ,
2384+ msg .arg1 );
2385+ break ;
2386+
23692387 case MSG_PERSIST_RINGER_MODE :
23702388 persistRingerMode ();
23712389 break ;
@@ -2852,11 +2870,6 @@ public void onReceive(Context context, Intent intent) {
28522870 adapter .getProfileProxy (mContext , mBluetoothProfileServiceListener ,
28532871 BluetoothProfile .A2DP );
28542872 }
2855-
2856- if (mUseMasterVolume ) {
2857- // Send sticky broadcast for initial master mute state
2858- sendMasterMuteUpdate (false , 0 );
2859- }
28602873 } else if (action .equals (Intent .ACTION_PACKAGE_REMOVED )) {
28612874 if (!intent .getBooleanExtra (Intent .EXTRA_REPLACING , false )) {
28622875 // a package is being removed, not replaced
0 commit comments