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

Commit db965e56 authored by zhuw's avatar zhuw Committed by Arne Coucheron
Browse files

Fix can't enable speaker with bluetooth headset

config value is 10 when using bt headset

Change-Id: Ie8b817af291d07270ffed9cdbcd200515bb3599f
parent 6aeaf8ad
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -369,7 +369,8 @@ public class ApiHelper {


    public static class AudioSystem {
    public static class AudioSystem {
        public static final int FORCE_NONE = 0;
        public static final int FORCE_NONE = 0;
        public static final int FORCE_SPEAKER = 1;
        public static final int FORCE_SPEAKER_HEADSET = 1;
        public static final int FORCE_SPEAKER_BT = 10;


        public static final int FOR_MEDIA = 1;
        public static final int FOR_MEDIA = 1;


+20 −5
Original line number Original line Diff line number Diff line
@@ -28,8 +28,10 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
package org.codeaurora.gallery3d.video;
package org.codeaurora.gallery3d.video;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -154,7 +156,7 @@ public class SpeakerHooker extends MovieHooker {
        if (isSpeakerOn()) {
        if (isSpeakerOn()) {
            turnSpeakerOff();
            turnSpeakerOff();
        } else {
        } else {
            if (mIsHeadsetOn) {
            if (mIsHeadsetOn || isBtHeadsetConnected()) {
                turnSpeakerOn();
                turnSpeakerOn();
            } else {
            } else {
                Toast.makeText(getContext(), getContext().getString(R.string.speaker_need_headset),
                Toast.makeText(getContext(), getContext().getString(R.string.speaker_need_headset),
@@ -164,12 +166,25 @@ public class SpeakerHooker extends MovieHooker {
        updateSpeakerButton();
        updateSpeakerButton();
    }
    }


    private boolean isBtHeadsetConnected() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            if ((BluetoothProfile.STATE_CONNECTED ==
                    adapter.getProfileConnectionState(BluetoothProfile.HEADSET)) ||
                    (BluetoothProfile.STATE_CONNECTED ==
                            adapter.getProfileConnectionState(BluetoothProfile.A2DP))) {
                return true;
            }
        }
        return false;
    }

    private void turnSpeakerOn() {
    private void turnSpeakerOn() {
        if (mAudioManager == null) {
        if (mAudioManager == null) {
            initAudioManager();
            initAudioManager();
        }
        }
        AudioSystem.setForceUse(AudioSystem.FOR_MEDIA,
        AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, isBtHeadsetConnected() ?
                AudioSystem.FORCE_SPEAKER);
                AudioSystem.FORCE_SPEAKER_BT : AudioSystem.FORCE_SPEAKER_HEADSET);
    }
    }


    private void turnSpeakerOff() {
    private void turnSpeakerOff() {
@@ -198,8 +213,8 @@ public class SpeakerHooker extends MovieHooker {
    }
    }


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


}
}