From 0d9609f198f3d2b1b42d766fd527d890f64dfaa7 Mon Sep 17 00:00:00 2001 From: sonora Date: Sat, 2 Jul 2016 19:09:16 +0200 Subject: [PATCH] Activate BT SCO only for STREAM_VOICE_CALL as per Android documentation --- OsmAnd/res/values/strings.xml | 4 ++-- .../voice/AbstractPrologCommandPlayer.java | 22 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 10e5292ed7..92ca64a938 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1226,7 +1226,7 @@ Auto zoom map Snap position to roads during navigation Snap to road - Interrupt music when making announcement (also as simulated phone calls to car BT stereos) + Interrupt music when making announcement Interrupt music OsmAnd Maps & Navigation Global Mobile Map Viewing & Navigation for Offline and Online OSM Maps @@ -1817,7 +1817,7 @@ If you need help with OsmAnd application, please contact our support team: suppo Offline vector map present for this location. \n\t\n\tTo use activate \'Menu\' → \'Configure map\' → \'Map Source…\' → \'Offline vector maps\'. Voice guidance output Choose speaker to play voice guidance (system-dependent) - Phone call audio + Phone call audio (also tries to interrupt car BT stereos) Notification audio Media/music audio Application cannot download map layer %1$s, please try to reinstall it. diff --git a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java index ecdf676a68..1ca00a5096 100644 --- a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java @@ -281,12 +281,10 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat if (mAudioFocusHelper != null) { mAudioFocusHelper.requestFocus(ctx, streamType); } - if (ctx.getSettings().INTERRUPT_MUSIC.get()) { + // If AudioManager.STREAM_VOICE_CALL try using BT SCO: + if (ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) { // TODO: Delay the prompts a bit until connection is established - startBtSco(ctx); - //if (btScoStatus == false) { - // Toast.makeText(this, R.string."BT connection error: ", Toast.LENGTH_SHORT).show(); - //} + startBtSco(); } } @@ -301,8 +299,8 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat protected void abandonAudioFocus() { log.debug("abandonAudioFocus"); - if (ctx.getSettings().INTERRUPT_MUSIC.get() || (btScoStatus == true)) { - stopBtSco(ctx); + if ((ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) || (btScoStatus == true)) { + stopBtSco(); } if (mAudioFocusHelper != null) { mAudioFocusHelper.abandonFocus(ctx, streamType); @@ -312,12 +310,12 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat private static boolean btScoStatus = false; - private boolean startBtSco(Context context) { + private boolean startBtSco() { // Establish a low quality Synchronous Connection-Oriented link to BT to e.g. interrupt a car stereo // http://stackoverflow.com/questions/2144694/routing-audio-to-bluetooth-headset-non-a2dp-on-android try { - AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - if (mAudioManager == null) { + AudioManager mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); + if (mAudioManager == null || !mAudioManager.isBluetoothScoAvailableOffCall()) { return false; } mAudioManager.setMode(0); @@ -333,9 +331,9 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat return btScoStatus; } - private boolean stopBtSco(Context context) { + private boolean stopBtSco() { btScoStatus = false; - AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + AudioManager mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); if (mAudioManager == null) { return false; }