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

Commit 52785e27 authored by xianming wang's avatar xianming wang
Browse files

SnapdragonGallery: Set NO_BT_A2DP when connected BT headset

Set FORCE_NO_BT_A2DP when connected BT headset and click the
Speaker ON.

CRs-Fixed: 2530845
Change-Id: I9343566b9454765536dd17aa0f2b66bcb803770a
parent c4ddefcf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -370,6 +370,7 @@ public class ApiHelper {
    public static class AudioSystem {
        public static final int FORCE_NONE = 0;
        public static final int FORCE_SPEAKER = 1;
        public static final int FORCE_NO_BT_A2DP = 10;

        public static final int FOR_MEDIA = 1;

+20 −5
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class SpeakerHooker extends MovieHooker {

    private MenuItem mMenuSpeakerButton;

    private boolean mIsHeadsetOn = false;
    private static boolean mIsHeadsetOn = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
@@ -154,7 +154,12 @@ public class SpeakerHooker extends MovieHooker {
        if (isSpeakerOn()) {
            turnSpeakerOff();
        } else {
            if (mIsHeadsetOn) {
            if (mAudioManager == null) {
                initAudioManager();
            }
            boolean isBluetoothOn = mAudioManager.isBluetoothA2dpOn() ||
                    mAudioManager.isBluetoothScoOn();
            if (mIsHeadsetOn || isBluetoothOn) {
                turnSpeakerOn();
            } else {
                Toast.makeText(getContext(), getContext().getString(R.string.speaker_need_headset),
@@ -168,8 +173,16 @@ public class SpeakerHooker extends MovieHooker {
        if (mAudioManager == null) {
            initAudioManager();
        }
        boolean isBluetoothOn = mAudioManager.isBluetoothA2dpOn() ||
                mAudioManager.isBluetoothScoOn();
        if (isBluetoothOn) {
            AudioSystem.setForceUse(AudioSystem.FOR_MEDIA,
                    AudioSystem.FORCE_NO_BT_A2DP);
        } else {
            AudioSystem.setForceUse(AudioSystem.FOR_MEDIA,
                    AudioSystem.FORCE_SPEAKER);

        }
    }

    private void turnSpeakerOff() {
@@ -199,6 +212,8 @@ public class SpeakerHooker extends MovieHooker {

    private boolean isSpeakerOn() {
        return (AudioSystem.FORCE_SPEAKER
                == AudioSystem.getForceUse(AudioSystem.FOR_MEDIA)) ||
                (AudioSystem.FORCE_NO_BT_A2DP
                        == AudioSystem.getForceUse(AudioSystem.FOR_MEDIA));
    }