Merge "New intent for microphone mute change notification"

This commit is contained in:
Jean-Michel Trivi
2017-12-29 21:25:46 +00:00
committed by Android (Google) Code Review
3 changed files with 22 additions and 3 deletions

View File

@@ -21718,6 +21718,7 @@ package android.media {
field public static final java.lang.String ACTION_AUDIO_BECOMING_NOISY = "android.media.AUDIO_BECOMING_NOISY";
field public static final java.lang.String ACTION_HDMI_AUDIO_PLUG = "android.media.action.HDMI_AUDIO_PLUG";
field public static final java.lang.String ACTION_HEADSET_PLUG = "android.intent.action.HEADSET_PLUG";
field public static final java.lang.String ACTION_MICROPHONE_MUTE_CHANGED = "android.media.action.MICROPHONE_MUTE_CHANGED";
field public static final deprecated java.lang.String ACTION_SCO_AUDIO_STATE_CHANGED = "android.media.SCO_AUDIO_STATE_CHANGED";
field public static final java.lang.String ACTION_SCO_AUDIO_STATE_UPDATED = "android.media.ACTION_SCO_AUDIO_STATE_UPDATED";
field public static final int ADJUST_LOWER = -1; // 0xffffffff

View File

@@ -1634,6 +1634,21 @@ public class AudioManager {
return AudioSystem.isMicrophoneMuted();
}
/**
* Broadcast Action: microphone muting state changed.
*
* You <em>cannot</em> receive this through components declared
* in manifests, only by explicitly registering for it with
* {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)
* Context.registerReceiver()}.
*
* <p>The intent has no extra values, use {@link #isMicrophoneMute} to check whether the
* microphone is muted.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_MICROPHONE_MUTE_CHANGED =
"android.media.action.MICROPHONE_MUTE_CHANGED";
/**
* Sets the audio mode.
* <p>

View File

@@ -2251,12 +2251,15 @@ public class AudioService extends IAudioService.Stub
if (DEBUG_VOL) {
Log.d(TAG, String.format("Mic mute %s, user=%d", on, userId));
}
// If mute is for current user actually mute, else just persist the setting
// which will be loaded on user switch.
// only mute for the current user
if (getCurrentUserId() == userId) {
final boolean currentMute = AudioSystem.isMicrophoneMuted();
AudioSystem.muteMicrophone(on);
if (on != currentMute) {
mContext.sendBroadcast(new Intent(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED)
.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY));
}
}
// Post a persist microphone msg.
}
@Override