From 2816b93f7207ca62e83dda35716e8ce267e84197 Mon Sep 17 00:00:00 2001 From: Benson Huang Date: Wed, 24 Dec 2014 16:25:46 +0800 Subject: [FM] "Speaker on/headset" should not be available while BT earphone is connected Launch FM Radio and play -> Turn on BT and connect with BT earphone -> Enter FM again and check "Speaker on/headset" , "Speaker on/headset" will be available. The fix is to also check BT headset is connected or not when enabling menu item. Bug 18795153 from: https://partner-android-review.googlesource.com/#/c/192377/2 Change-Id: Ia6d78b85563389f193860820447273a27e76d050 Signed-off-by: Benson Huang --- AndroidManifest.xml | 1 + src/com/android/fmradio/FmMainActivity.java | 3 ++- src/com/android/fmradio/FmService.java | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 1b68eba..cebce11 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -29,6 +29,7 @@ + diff --git a/src/com/android/fmradio/FmMainActivity.java b/src/com/android/fmradio/FmMainActivity.java index ec7baf0..09fca23 100644 --- a/src/com/android/fmradio/FmMainActivity.java +++ b/src/com/android/fmradio/FmMainActivity.java @@ -989,7 +989,8 @@ public class FmMainActivity extends Activity implements FmFavoriteEditDialog.Edi // if power down by other app, should disable station list, over // menu mMenuItemStationlList.setEnabled(enabled); - mMenuItemHeadset.setEnabled(enabled); + // If BT headset is in use, need to disable speaker/earphone switching menu. + mMenuItemHeadset.setEnabled(enabled && !mService.isBluetoothHeadsetInUse()); } } diff --git a/src/com/android/fmradio/FmService.java b/src/com/android/fmradio/FmService.java index d9ac99e..ca940fd 100644 --- a/src/com/android/fmradio/FmService.java +++ b/src/com/android/fmradio/FmService.java @@ -21,6 +21,8 @@ import android.app.Notification; import android.app.Notification.BigTextStyle; import android.app.PendingIntent; import android.app.Service; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothProfile; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.ContentValues; @@ -367,6 +369,17 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan setForceUse(isSpeaker); } + /** + * Check if BT headset is connected + * @return true if current is playing with BT headset + */ + public boolean isBluetoothHeadsetInUse() { + BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); + int a2dpState = btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET); + return (BluetoothProfile.STATE_CONNECTED == a2dpState + || BluetoothProfile.STATE_CONNECTING == a2dpState); + } + private synchronized void startRender() { Log.d(TAG, "startRender"); mIsRender = true; -- cgit v1.2.3