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

Commit 90682ff7 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

New intent action for speakerphone state change

New intent action ACTION_SPEAKERPHONE_STATE_CHANGED to indicate
  speakerphone state changed.

Bug: 74541410
Test: m -j ; make -j api-stubs-docs-update-current-api ; m -j ; atest android.media.cts.AudioManagerTest#testSpeakerphoneIntent
Change-Id: I01963493001e31b1edf1f1ba85b5744eb924d887
parent 04b8032d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23293,6 +23293,7 @@ package android.media {
    field public static final String ACTION_MICROPHONE_MUTE_CHANGED = "android.media.action.MICROPHONE_MUTE_CHANGED";
    field @Deprecated public static final String ACTION_SCO_AUDIO_STATE_CHANGED = "android.media.SCO_AUDIO_STATE_CHANGED";
    field public static final String ACTION_SCO_AUDIO_STATE_UPDATED = "android.media.ACTION_SCO_AUDIO_STATE_UPDATED";
    field public static final String ACTION_SPEAKERPHONE_STATE_CHANGED = "android.media.action.SPEAKERPHONE_STATE_CHANGED";
    field public static final int ADJUST_LOWER = -1; // 0xffffffff
    field public static final int ADJUST_MUTE = -100; // 0xffffff9c
    field public static final int ADJUST_RAISE = 1; // 0x1
+15 −0
Original line number Diff line number Diff line
@@ -1819,6 +1819,21 @@ public class AudioManager {
    public static final String ACTION_MICROPHONE_MUTE_CHANGED =
            "android.media.action.MICROPHONE_MUTE_CHANGED";

    /**
     * Broadcast Action: speakerphone 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 #isSpeakerphoneOn} to check whether the
     * speakerphone functionality is enabled or not.
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_SPEAKERPHONE_STATE_CHANGED =
            "android.media.action.SPEAKERPHONE_STATE_CHANGED";

    /**
     * Sets the audio mode.
     * <p>
+9 −1
Original line number Diff line number Diff line
@@ -170,8 +170,15 @@ import java.util.ArrayList;
        }
    }

    /*package*/ void setSpeakerphoneOn(boolean on, String eventSource) {
    /**
     * Turns speakerphone on/off
     * @param on
     * @param eventSource for logging purposes
     * @return true if speakerphone state changed
     */
    /*package*/ boolean setSpeakerphoneOn(boolean on, String eventSource) {
        synchronized (mDeviceStateLock) {
            final boolean wasOn = isSpeakerphoneOn();
            if (on) {
                if (mForcedUseForComm == AudioSystem.FORCE_BT_SCO) {
                    setForceUse_Async(AudioSystem.FOR_RECORD, AudioSystem.FORCE_NONE, eventSource);
@@ -183,6 +190,7 @@ import java.util.ArrayList;

            mForcedUseForCommExt = mForcedUseForComm;
            setForceUse_Async(AudioSystem.FOR_COMMUNICATION, mForcedUseForComm, eventSource);
            return (wasOn != isSpeakerphoneOn());
        }
    }

+5 −1
Original line number Diff line number Diff line
@@ -3331,7 +3331,11 @@ public class AudioService extends IAudioService.Stub
        final String eventSource = new StringBuilder("setSpeakerphoneOn(").append(on)
                .append(") from u/pid:").append(Binder.getCallingUid()).append("/")
                .append(Binder.getCallingPid()).toString();
        mDeviceBroker.setSpeakerphoneOn(on, eventSource);
        final boolean stateChanged = mDeviceBroker.setSpeakerphoneOn(on, eventSource);
        if (stateChanged) {
            mContext.sendBroadcast(new Intent(AudioManager.ACTION_SPEAKERPHONE_STATE_CHANGED)
                    .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY));
        }
    }

    /** @see AudioManager#isSpeakerphoneOn() */