Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7be17d26 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

New intent for microphone mute change notification

AudioManager: define ACTION_MICROPHONE_MUTE_CHANGED.
AudioService:
 - broadcast intent when setMicrophoneMute() is called
   with FLAG_RECEIVER_REGISTERED_ONLY.
 - remove outdated (invalid) comments.

Bug: 70857126
Test: m -j ; make -j offline-sdk-docs ; make -j cts ; \
      cts-tradefed run cts-dev -m CtsMediaTestCases -t android.media.cts.AudioManagerTest#testMicrophoneMuteIntent

Change-Id: I7391522f0195d06592e4f853e9b672fdec66d37a
parent 1878f0bd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21697,6 +21697,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
+15 −0
Original line number Diff line number Diff line
@@ -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>
+6 −3
Original line number Diff line number Diff line
@@ -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