diff --git a/res/drawable-land-xhdpi/route_bluetooth_off_default.png b/res/drawable-land-xhdpi/route_bluetooth_off_default.png new file mode 100644 index 000000000..84a001275 Binary files /dev/null and b/res/drawable-land-xhdpi/route_bluetooth_off_default.png differ diff --git a/res/drawable-land-xhdpi/route_bluetooth_off_disabled.png b/res/drawable-land-xhdpi/route_bluetooth_off_disabled.png new file mode 100644 index 000000000..f523bd6c3 Binary files /dev/null and b/res/drawable-land-xhdpi/route_bluetooth_off_disabled.png differ diff --git a/res/drawable-land-xhdpi/route_bluetooth_off_over.png b/res/drawable-land-xhdpi/route_bluetooth_off_over.png new file mode 100644 index 000000000..ebaffea54 Binary files /dev/null and b/res/drawable-land-xhdpi/route_bluetooth_off_over.png differ diff --git a/res/drawable-land-xhdpi/route_bluetooth_on_default.png b/res/drawable-land-xhdpi/route_bluetooth_on_default.png new file mode 100644 index 000000000..9cbdf574d Binary files /dev/null and b/res/drawable-land-xhdpi/route_bluetooth_on_default.png differ diff --git a/res/drawable-land-xhdpi/route_phone_off_default.png b/res/drawable-land-xhdpi/route_phone_off_default.png new file mode 100644 index 000000000..e9b944cc6 Binary files /dev/null and b/res/drawable-land-xhdpi/route_phone_off_default.png differ diff --git a/res/drawable-land-xhdpi/route_phone_off_disabled.png b/res/drawable-land-xhdpi/route_phone_off_disabled.png new file mode 100644 index 000000000..1d58d39c8 Binary files /dev/null and b/res/drawable-land-xhdpi/route_phone_off_disabled.png differ diff --git a/res/drawable-land-xhdpi/route_phone_off_over.png b/res/drawable-land-xhdpi/route_phone_off_over.png new file mode 100644 index 000000000..f9b8f9734 Binary files /dev/null and b/res/drawable-land-xhdpi/route_phone_off_over.png differ diff --git a/res/drawable-land-xhdpi/route_phone_on_default.png b/res/drawable-land-xhdpi/route_phone_on_default.png new file mode 100644 index 000000000..b35b9aa64 Binary files /dev/null and b/res/drawable-land-xhdpi/route_phone_on_default.png differ diff --git a/res/drawable-land-xhdpi/route_speaker_off_default.png b/res/drawable-land-xhdpi/route_speaker_off_default.png new file mode 100644 index 000000000..d6c7eacde Binary files /dev/null and b/res/drawable-land-xhdpi/route_speaker_off_default.png differ diff --git a/res/drawable-land-xhdpi/route_speaker_off_disabled.png b/res/drawable-land-xhdpi/route_speaker_off_disabled.png new file mode 100644 index 000000000..f750b1610 Binary files /dev/null and b/res/drawable-land-xhdpi/route_speaker_off_disabled.png differ diff --git a/res/drawable-land-xhdpi/route_speaker_off_over.png b/res/drawable-land-xhdpi/route_speaker_off_over.png new file mode 100644 index 000000000..74bf86fa1 Binary files /dev/null and b/res/drawable-land-xhdpi/route_speaker_off_over.png differ diff --git a/res/drawable-land-xhdpi/route_speaker_on_default.png b/res/drawable-land-xhdpi/route_speaker_on_default.png new file mode 100644 index 000000000..293e675e2 Binary files /dev/null and b/res/drawable-land-xhdpi/route_speaker_on_default.png differ diff --git a/res/drawable-land-xhdpi/routes_default.png b/res/drawable-land-xhdpi/routes_default.png new file mode 100644 index 000000000..cc68859a8 Binary files /dev/null and b/res/drawable-land-xhdpi/routes_default.png differ diff --git a/res/drawable-land-xhdpi/routes_disabled.png b/res/drawable-land-xhdpi/routes_disabled.png new file mode 100644 index 000000000..437bdcb35 Binary files /dev/null and b/res/drawable-land-xhdpi/routes_disabled.png differ diff --git a/res/drawable-land-xhdpi/routes_over.png b/res/drawable-land-xhdpi/routes_over.png new file mode 100644 index 000000000..958cdc28c Binary files /dev/null and b/res/drawable-land-xhdpi/routes_over.png differ diff --git a/res/drawable-land-xhdpi/routes_selected.png b/res/drawable-land-xhdpi/routes_selected.png new file mode 100644 index 000000000..54a0aa48c Binary files /dev/null and b/res/drawable-land-xhdpi/routes_selected.png differ diff --git a/res/drawable-xhdpi/route_bluetooth_off_default.png b/res/drawable-xhdpi/route_bluetooth_off_default.png new file mode 100644 index 000000000..01bc1f291 Binary files /dev/null and b/res/drawable-xhdpi/route_bluetooth_off_default.png differ diff --git a/res/drawable-xhdpi/route_bluetooth_off_disabled.png b/res/drawable-xhdpi/route_bluetooth_off_disabled.png new file mode 100644 index 000000000..3d03f1cba Binary files /dev/null and b/res/drawable-xhdpi/route_bluetooth_off_disabled.png differ diff --git a/res/drawable-xhdpi/route_bluetooth_off_over.png b/res/drawable-xhdpi/route_bluetooth_off_over.png new file mode 100644 index 000000000..66112a8d7 Binary files /dev/null and b/res/drawable-xhdpi/route_bluetooth_off_over.png differ diff --git a/res/drawable-xhdpi/route_bluetooth_on_default.png b/res/drawable-xhdpi/route_bluetooth_on_default.png new file mode 100644 index 000000000..841c93b65 Binary files /dev/null and b/res/drawable-xhdpi/route_bluetooth_on_default.png differ diff --git a/res/drawable-xhdpi/route_phone_off_default.png b/res/drawable-xhdpi/route_phone_off_default.png new file mode 100644 index 000000000..4510f0bcb Binary files /dev/null and b/res/drawable-xhdpi/route_phone_off_default.png differ diff --git a/res/drawable-xhdpi/route_phone_off_disabled.png b/res/drawable-xhdpi/route_phone_off_disabled.png new file mode 100644 index 000000000..8c9405533 Binary files /dev/null and b/res/drawable-xhdpi/route_phone_off_disabled.png differ diff --git a/res/drawable-xhdpi/route_phone_off_over.png b/res/drawable-xhdpi/route_phone_off_over.png new file mode 100644 index 000000000..bc383167e Binary files /dev/null and b/res/drawable-xhdpi/route_phone_off_over.png differ diff --git a/res/drawable-xhdpi/route_phone_on_default.png b/res/drawable-xhdpi/route_phone_on_default.png new file mode 100644 index 000000000..16cc9e2f3 Binary files /dev/null and b/res/drawable-xhdpi/route_phone_on_default.png differ diff --git a/res/drawable-xhdpi/route_speaker_off_default.png b/res/drawable-xhdpi/route_speaker_off_default.png new file mode 100644 index 000000000..908031972 Binary files /dev/null and b/res/drawable-xhdpi/route_speaker_off_default.png differ diff --git a/res/drawable-xhdpi/route_speaker_off_disabled.png b/res/drawable-xhdpi/route_speaker_off_disabled.png new file mode 100644 index 000000000..8294f5251 Binary files /dev/null and b/res/drawable-xhdpi/route_speaker_off_disabled.png differ diff --git a/res/drawable-xhdpi/route_speaker_off_over.png b/res/drawable-xhdpi/route_speaker_off_over.png new file mode 100644 index 000000000..f6c5ce9f6 Binary files /dev/null and b/res/drawable-xhdpi/route_speaker_off_over.png differ diff --git a/res/drawable-xhdpi/route_speaker_on_default.png b/res/drawable-xhdpi/route_speaker_on_default.png new file mode 100644 index 000000000..8cfdc036a Binary files /dev/null and b/res/drawable-xhdpi/route_speaker_on_default.png differ diff --git a/res/drawable-xhdpi/routes_default.png b/res/drawable-xhdpi/routes_default.png new file mode 100644 index 000000000..a0502e293 Binary files /dev/null and b/res/drawable-xhdpi/routes_default.png differ diff --git a/res/drawable-xhdpi/routes_disabled.png b/res/drawable-xhdpi/routes_disabled.png new file mode 100644 index 000000000..aa54e1ab5 Binary files /dev/null and b/res/drawable-xhdpi/routes_disabled.png differ diff --git a/res/drawable-xhdpi/routes_over.png b/res/drawable-xhdpi/routes_over.png new file mode 100644 index 000000000..c6e555a46 Binary files /dev/null and b/res/drawable-xhdpi/routes_over.png differ diff --git a/res/drawable-xhdpi/routes_selected.png b/res/drawable-xhdpi/routes_selected.png new file mode 100644 index 000000000..9930fd81e Binary files /dev/null and b/res/drawable-xhdpi/routes_selected.png differ diff --git a/res/drawable/options.xml b/res/drawable/options.xml index 1f6f7ffeb..add45465b 100644 --- a/res/drawable/options.xml +++ b/res/drawable/options.xml @@ -3,9 +3,9 @@ + android:drawable="@drawable/options_disabled" /> + android:drawable="@drawable/options_selected" /> diff --git a/res/drawable/route_bluetooth_off.xml b/res/drawable/route_bluetooth_off.xml new file mode 100644 index 000000000..56ca08591 --- /dev/null +++ b/res/drawable/route_bluetooth_off.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/res/drawable/route_bluetooth_on.xml b/res/drawable/route_bluetooth_on.xml new file mode 100644 index 000000000..14b68aa46 --- /dev/null +++ b/res/drawable/route_bluetooth_on.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/res/drawable/route_receiver_off.xml b/res/drawable/route_receiver_off.xml new file mode 100644 index 000000000..534279dab --- /dev/null +++ b/res/drawable/route_receiver_off.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/res/drawable/route_receiver_on.xml b/res/drawable/route_receiver_on.xml new file mode 100644 index 000000000..b8012f68e --- /dev/null +++ b/res/drawable/route_receiver_on.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/res/drawable/route_speaker_off.xml b/res/drawable/route_speaker_off.xml new file mode 100644 index 000000000..0fdc55818 --- /dev/null +++ b/res/drawable/route_speaker_off.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/res/drawable/route_speaker_on.xml b/res/drawable/route_speaker_on.xml new file mode 100644 index 000000000..578561c78 --- /dev/null +++ b/res/drawable/route_speaker_on.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/res/drawable/routes.xml b/res/drawable/routes.xml new file mode 100644 index 000000000..227067f91 --- /dev/null +++ b/res/drawable/routes.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/res/layout-land/incall.xml b/res/layout-land/incall.xml index 5783b6df2..4acbe4f79 100644 --- a/res/layout-land/incall.xml +++ b/res/layout-land/incall.xml @@ -55,10 +55,10 @@ @@ -126,6 +126,59 @@ android:layout_height="wrap_content" android:layout_weight="1" /> + + + + + + + + + + + + + android:orientation="vertical"> - - - + + + + + + + + + + + + + + + + + + + + + + + + android:layout_weight="0.5"/> + + + + + + + + + + + + + + + + + android:layout_weight="0.5" /> @@ -96,19 +151,37 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="invisible" - android:layout_weight="0.25"/> + android:layout_weight="0.5"/> + + + + + android:layout_weight="0.5" /> @@ -150,6 +223,18 @@ android:layout_height="wrap_content" android:layout_weight="1" /> + + Vidéo Micro HP + Route + Ecouteur + Bluetooth Options Envoyer diff --git a/res/values/non_localizable_custom.xml b/res/values/non_localizable_custom.xml index 0b8446b57..11b0698f2 100644 --- a/res/values/non_localizable_custom.xml +++ b/res/values/non_localizable_custom.xml @@ -55,8 +55,6 @@ true - true - false false false diff --git a/res/values/strings.xml b/res/values/strings.xml index 26560350a..c6000aa2c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -363,6 +363,9 @@ Video Micro Speaker + Route + Receiver + Bluetooth Options Send diff --git a/src/org/linphone/BluetoothManager.java b/src/org/linphone/BluetoothManager.java index 0e0d8885c..86c5b7070 100644 --- a/src/org/linphone/BluetoothManager.java +++ b/src/org/linphone/BluetoothManager.java @@ -14,10 +14,6 @@ import android.os.Build; public class BluetoothManager extends BroadcastReceiver { @SuppressWarnings("deprecation") public void onReceive(Context context, Intent intent) { - boolean routeToBT = context.getResources().getBoolean(R.bool.route_audio_to_bluetooth_if_available); - if (!routeToBT) - return; - String action = intent.getAction(); LinphoneManager lm = LinphoneManager.getInstance(); @@ -26,7 +22,6 @@ public class BluetoothManager extends BroadcastReceiver { Log.e("Bluetooth Received Event" + " ACTION_ACL_DISCONNECTED" ); if (lm != null) { - lm.isBluetoothScoConnected = false; lm.scoDisconnected(); lm.routeAudioToReceiver(); } @@ -35,7 +30,6 @@ public class BluetoothManager extends BroadcastReceiver { Log.e("Bluetooth Received Event" + " ACTION_ACL_CONNECTED" ); if (lm != null) { - lm.isBluetoothScoConnected = true; lm.scoConnected(); } } @@ -44,12 +38,10 @@ public class BluetoothManager extends BroadcastReceiver { Log.e("Bluetooth sco state changed : " + state); if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { if (lm != null) { - lm.isBluetoothScoConnected = true; lm.scoConnected(); } } else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) { if (lm != null) { - lm.isBluetoothScoConnected = false; lm.scoDisconnected(); lm.routeAudioToReceiver(); } @@ -61,7 +53,6 @@ public class BluetoothManager extends BroadcastReceiver { 0); //BluetoothAdapter.STATE_DISCONNECTED Log.e("Bluetooth state changed: " + currentConnState); if (lm != null && currentConnState == 2) { //BluetoothAdapter.STATE_CONNECTED - lm.isBluetoothScoConnected = true; lm.startBluetooth(); } } diff --git a/src/org/linphone/InCallActivity.java b/src/org/linphone/InCallActivity.java index 706a920bb..fc4892a19 100644 --- a/src/org/linphone/InCallActivity.java +++ b/src/org/linphone/InCallActivity.java @@ -87,6 +87,8 @@ public class InCallActivity extends FragmentActivity implements private Runnable mControls; private ImageView pause, hangUp, dialer, switchCamera, conference; private TextView video, micro, speaker, options, addCall, transfer; + private TextView audioRoute, routeSpeaker, routeReceiver, routeBluetooth; + private LinearLayout routeLayout; private StatusFragment status; private AudioCallFragment audioCallFragment; private VideoCallFragment videoCallFragment; @@ -166,10 +168,6 @@ public class InCallActivity extends FragmentActivity implements callFragment.setArguments(getIntent().getExtras()); getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, callFragment).commitAllowingStateLoss(); } - - boolean routeToBT = getResources().getBoolean(R.bool.route_audio_to_bluetooth_if_available); - if (routeToBT && LinphoneManager.isInstanciated() && !isSpeakerEnabled) - LinphoneManager.getInstance().routeToBluetoothIfAvailable(); } @Override @@ -219,6 +217,20 @@ public class InCallActivity extends FragmentActivity implements dialer.setEnabled(false); numpad = (Numpad) findViewById(R.id.numpad); + try { + routeLayout = (LinearLayout) findViewById(R.id.routesLayout); + audioRoute = (TextView) findViewById(R.id.audioRoute); + audioRoute.setOnClickListener(this); + routeSpeaker = (TextView) findViewById(R.id.routeSpeaker); + routeSpeaker.setOnClickListener(this); + routeReceiver = (TextView) findViewById(R.id.routeReceiver); + routeReceiver.setOnClickListener(this); + routeBluetooth = (TextView) findViewById(R.id.routeBluetooth); + routeBluetooth.setOnClickListener(this); + } catch (NullPointerException npe) { + Log.e("Audio routes menu disabled on tablets for now"); + } + switchCamera = (ImageView) findViewById(R.id.switchCamera); switchCamera.setOnClickListener(this); @@ -255,10 +267,39 @@ public class InCallActivity extends FragmentActivity implements } } - if (isSpeakerEnabled) { - speaker.setBackgroundResource(R.drawable.speaker_on); + if (LinphoneManager.getInstance().isBluetoothScoConnected) { + try { + routeLayout.setVisibility(View.VISIBLE); + } catch (NullPointerException npe) {} + audioRoute.setVisibility(View.VISIBLE); + speaker.setVisibility(View.GONE); } else { - speaker.setBackgroundResource(R.drawable.speaker_off); + try { + routeLayout.setVisibility(View.GONE); + } catch (NullPointerException npe) {} + audioRoute.setVisibility(View.GONE); + speaker.setVisibility(View.VISIBLE); + } + + try { + if (isSpeakerEnabled) { + speaker.setBackgroundResource(R.drawable.speaker_on); + routeSpeaker.setBackgroundResource(R.drawable.route_speaker_on); + routeReceiver.setBackgroundResource(R.drawable.route_receiver_off); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off); + } else { + speaker.setBackgroundResource(R.drawable.speaker_off); + routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off); + if (LinphoneManager.getInstance().isUsingBluetoothAudioRoute) { + routeReceiver.setBackgroundResource(R.drawable.route_receiver_off); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_on); + } else { + routeReceiver.setBackgroundResource(R.drawable.route_receiver_on); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off); + } + } + } catch (NullPointerException npe) { + Log.e("Audio routes menu disabled on tablets for now"); } if (isMicMuted) { @@ -360,8 +401,32 @@ public class InCallActivity extends FragmentActivity implements } else if (id == R.id.options) { hideOrDisplayCallOptions(); - } - + } + else if (id == R.id.audioRoute) { + hideOrDisplayAudioRoutes(); + } + else if (id == R.id.routeBluetooth) { + LinphoneManager.getInstance().routeAudioToBluetooth(); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_on); + routeReceiver.setBackgroundResource(R.drawable.route_receiver_off); + routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off); + hideOrDisplayAudioRoutes(); + } + else if (id == R.id.routeReceiver) { + LinphoneManager.getInstance().routeAudioToReceiver(); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off); + routeReceiver.setBackgroundResource(R.drawable.route_receiver_on); + routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off); + hideOrDisplayAudioRoutes(); + } + else if (id == R.id.routeSpeaker) { + LinphoneManager.getInstance().routeAudioToSpeaker(); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off); + routeReceiver.setBackgroundResource(R.drawable.route_receiver_off); + routeSpeaker.setBackgroundResource(R.drawable.route_speaker_on); + hideOrDisplayAudioRoutes(); + } + else if (id == R.id.callStatus) { LinphoneCall call = (LinphoneCall) v.getTag(); pauseOrResumeCall(call); @@ -483,10 +548,6 @@ public class InCallActivity extends FragmentActivity implements } else { LinphoneManager.getInstance().routeAudioToReceiver(); speaker.setBackgroundResource(R.drawable.speaker_off); - - boolean routeToBT = getResources().getBoolean(R.bool.route_audio_to_bluetooth_if_available); - if (!routeToBT) - LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled); } } @@ -878,6 +939,38 @@ public class InCallActivity extends FragmentActivity implements addCall.startAnimation(animation); } + private void hideOrDisplayAudioRoutes() + { + if (isSpeakerEnabled) { + speaker.setBackgroundResource(R.drawable.speaker_on); + routeSpeaker.setBackgroundResource(R.drawable.route_speaker_on); + routeReceiver.setBackgroundResource(R.drawable.route_receiver_off); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off); + } else { + speaker.setBackgroundResource(R.drawable.speaker_off); + routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off); + if (LinphoneManager.getInstance().isUsingBluetoothAudioRoute) { + routeReceiver.setBackgroundResource(R.drawable.route_receiver_off); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_on); + } else { + routeReceiver.setBackgroundResource(R.drawable.route_receiver_on); + routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off); + } + } + + if (routeSpeaker.getVisibility() == View.VISIBLE) { + routeSpeaker.setVisibility(View.INVISIBLE); + routeBluetooth.setVisibility(View.INVISIBLE); + routeReceiver.setVisibility(View.INVISIBLE); + audioRoute.setSelected(false); + } else { + routeSpeaker.setVisibility(View.VISIBLE); + routeBluetooth.setVisibility(View.VISIBLE); + routeReceiver.setVisibility(View.VISIBLE); + audioRoute.setSelected(true); + } + } + private void hideOrDisplayCallOptions() { boolean isOrientationLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; @@ -895,6 +988,7 @@ public class InCallActivity extends FragmentActivity implements hideAnimatedPortraitCallOptions(); } } + options.setSelected(false); } else { if (isAnimationDisabled) { if (isTransferAllowed) { @@ -909,6 +1003,7 @@ public class InCallActivity extends FragmentActivity implements showAnimatedPortraitCallOptions(); } } + options.setSelected(true); transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null); } } @@ -977,13 +1072,7 @@ public class InCallActivity extends FragmentActivity implements switchVideo(isVideoEnabled, false); } - boolean routeToBT = getResources().getBoolean(R.bool.route_audio_to_bluetooth_if_available); - if (routeToBT && LinphoneManager.isInstanciated() && !isSpeakerEnabled) { - LinphoneManager.getInstance().routeToBluetoothIfAvailable(); - } else { - // The following should not be needed except some devices need it (e.g. Galaxy S). - LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled); - } + LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled); isMicMuted = LinphoneManager.getLc().isMicMuted(); enableAndRefreshInCallActions(); diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 229c416b6..c35e20966 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -155,6 +155,7 @@ public final class LinphoneManager implements LinphoneCoreListener { private BluetoothProfile.ServiceListener mProfileListener; private BroadcastReceiver bluetoothReiceiver = new BluetoothManager(); public boolean isBluetoothScoConnected; + public boolean isUsingBluetoothAudioRoute; private static List simpleListeners = new ArrayList(); public static void addListener(LinphoneSimpleListener listener) { @@ -204,30 +205,27 @@ public final class LinphoneManager implements LinphoneCoreListener { private BroadcastReceiver mKeepAliveReceiver = new KeepAliveReceiver(); private void routeAudioToSpeakerHelper(boolean speakerOn) { - boolean routeToBluetoothEnabled = false; + isUsingBluetoothAudioRoute = false; + if (mAudioManager != null) { + mAudioManager.setMode(AudioManager.MODE_NORMAL); + mAudioManager.stopBluetoothSco(); + mAudioManager.setBluetoothScoOn(false); + } + if (!speakerOn) { - boolean routeToBT = mServiceContext.getResources().getBoolean(R.bool.route_audio_to_bluetooth_if_available); - if (!routeToBT || (routeToBT && !routeToBluetoothIfAvailable())) { - mLc.enableSpeaker(false); - scoDisconnected(); - } else { - Log.d("Routing audio to bluetooth headset"); - routeToBluetoothEnabled = true; - } + mLc.enableSpeaker(false); } else { mLc.enableSpeaker(true); - scoDisconnected(); } for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) { - listener.onAudioStateChanged(speakerOn ? AudioState.SPEAKER : (routeToBluetoothEnabled ? AudioState.BLUETOOTH : AudioState.EARPIECE)); + listener.onAudioStateChanged(speakerOn ? AudioState.SPEAKER : AudioState.EARPIECE); } } public void routeAudioToSpeaker() { routeAudioToSpeakerHelper(true); } - public String getUserAgent() throws NameNotFoundException { StringBuilder userAgent = new StringBuilder(); userAgent.append("LinphoneAndroid/" + mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(),0).versionCode); @@ -256,7 +254,7 @@ public final class LinphoneManager implements LinphoneCoreListener { if (profile == BluetoothProfile.HEADSET) { mBluetoothHeadset = (BluetoothHeadset) proxy; Log.d("Bluetooth headset connected"); - routeToBluetoothIfAvailable(); + isBluetoothScoConnected = true; } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @@ -264,6 +262,7 @@ public final class LinphoneManager implements LinphoneCoreListener { if (profile == BluetoothProfile.HEADSET) { mBluetoothHeadset = null; Log.d("Bluetooth headset disconnected"); + isBluetoothScoConnected = false; routeAudioToReceiver(); } } @@ -276,40 +275,42 @@ public final class LinphoneManager implements LinphoneCoreListener { int state = currentValue == null ? 0 : currentValue.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, 0); if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { isBluetoothScoConnected = true; - scoConnected(); } } - } - else { + } else { + isBluetoothScoConnected = false; scoDisconnected(); routeAudioToReceiver(); } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public boolean routeToBluetoothIfAvailable() { + public boolean routeAudioToBluetooth() { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled() && mAudioManager.isBluetoothScoAvailableOffCall()) { mAudioManager.setBluetoothScoOn(true); mAudioManager.startBluetoothSco(); if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) { - boolean connected = false; + isUsingBluetoothAudioRoute = false; if (mBluetoothHeadset != null) { List devices = mBluetoothHeadset.getConnectedDevices(); for (final BluetoothDevice dev : devices) { - connected |= mBluetoothHeadset.getConnectionState(dev) == BluetoothHeadset.STATE_CONNECTED; + isUsingBluetoothAudioRoute |= mBluetoothHeadset.getConnectionState(dev) == BluetoothHeadset.STATE_CONNECTED; } } - if (!connected) { + if (!isUsingBluetoothAudioRoute) { Log.d("No bluetooth device available"); scoDisconnected(); + } else { + mAudioManager.setMode(AudioManager.MODE_IN_CALL); + for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) { + listener.onAudioStateChanged(AudioState.SPEAKER); + } } - return connected; - } else { - return isBluetoothScoConnected; } + return isUsingBluetoothAudioRoute; } return false; @@ -317,12 +318,13 @@ public final class LinphoneManager implements LinphoneCoreListener { public void scoConnected() { Log.e("Bluetooth sco connected!"); - mAudioManager.setMode(AudioManager.MODE_IN_CALL); - routeToBluetoothIfAvailable(); + isBluetoothScoConnected = true; } public void scoDisconnected() { Log.e("Bluetooth sco disconnected!"); + isUsingBluetoothAudioRoute = false; + isBluetoothScoConnected = false; if (mAudioManager != null) { mAudioManager.setMode(AudioManager.MODE_NORMAL); mAudioManager.stopBluetoothSco(); @@ -578,10 +580,7 @@ public final class LinphoneManager implements LinphoneCoreListener { lFilter.addAction(Intent.ACTION_SCREEN_OFF); mServiceContext.registerReceiver(mKeepAliveReceiver, lFilter); - boolean routeToBT = mServiceContext.getResources().getBoolean(R.bool.route_audio_to_bluetooth_if_available); - if (routeToBT) { - startBluetooth(); - } + startBluetooth(); resetCameraFromPreferences(); } catch (Exception e) {