Skip to content

Commit 57978ed

Browse files
committed
Persists the master mute volume setting.
Persists the master mute volume setting across reboots. TESTED = runs on Tungsten. Change-Id: I9628b9369ca528b22413f62a9e7d697bae61d8ac
1 parent ade3350 commit 57978ed

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

core/java/android/provider/Settings.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,13 +1479,22 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
14791479
public static final String VOLUME_MASTER = "volume_master";
14801480

14811481
/**
1482-
* Whether the notifications should use the ring volume (value of 1) or a separate
1483-
* notification volume (value of 0). In most cases, users will have this enabled so the
1484-
* notification and ringer volumes will be the same. However, power users can disable this
1485-
* and use the separate notification volume control.
1482+
* Master volume mute (int 1 = mute, 0 = not muted).
1483+
*
1484+
* @hide
1485+
*/
1486+
public static final String VOLUME_MASTER_MUTE = "volume_master_mute";
1487+
1488+
/**
1489+
* Whether the notifications should use the ring volume (value of 1) or
1490+
* a separate notification volume (value of 0). In most cases, users
1491+
* will have this enabled so the notification and ringer volumes will be
1492+
* the same. However, power users can disable this and use the separate
1493+
* notification volume control.
14861494
* <p>
1487-
* Note: This is a one-off setting that will be removed in the future when there is profile
1488-
* support. For this reason, it is kept hidden from the public APIs.
1495+
* Note: This is a one-off setting that will be removed in the future
1496+
* when there is profile support. For this reason, it is kept hidden
1497+
* from the public APIs.
14891498
*
14901499
* @hide
14911500
* @deprecated

media/java/android/media/AudioService.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)