summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/bluetooth/LocalBluetoothManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/bluetooth/LocalBluetoothManager.java')
-rw-r--r--src/com/android/settings/bluetooth/LocalBluetoothManager.java35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
index 4fd708e..4671fac 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
@@ -23,6 +23,7 @@ import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
+import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
@@ -51,11 +52,13 @@ public class LocalBluetoothManager {
private Context mContext;
/** If a BT-related activity is in the foreground, this will be it. */
private Activity mForegroundActivity;
-
+ private AlertDialog mErrorDialog = null;
+
private BluetoothDevice mManager;
private LocalBluetoothDeviceManager mLocalDeviceManager;
private BluetoothEventRedirector mEventRedirector;
+ private BluetoothA2dp mBluetoothA2dp;
public static enum ExtendedBluetoothState { ENABLED, ENABLING, DISABLED, DISABLING, UNKNOWN }
private ExtendedBluetoothState mState = ExtendedBluetoothState.UNKNOWN;
@@ -95,7 +98,9 @@ public class LocalBluetoothManager {
mEventRedirector = new BluetoothEventRedirector(this);
mEventRedirector.start();
-
+
+ mBluetoothA2dp = new BluetoothA2dp(context);
+
return true;
}
@@ -112,6 +117,10 @@ public class LocalBluetoothManager {
}
public void setForegroundActivity(Activity activity) {
+ if (mErrorDialog != null) {
+ mErrorDialog.dismiss();
+ mErrorDialog = null;
+ }
mForegroundActivity = activity;
}
@@ -149,9 +158,23 @@ public class LocalBluetoothManager {
*/
dispatchScanningStateChanged(true);
} else {
-
- // Don't scan more than frequently than SCAN_EXPIRATION_MS, unless forced
- if (!force && mLastScan + SCAN_EXPIRATION_MS > System.currentTimeMillis()) return;
+ if (!force) {
+ // Don't scan more than frequently than SCAN_EXPIRATION_MS,
+ // unless forced
+ if (mLastScan + SCAN_EXPIRATION_MS > System.currentTimeMillis()) {
+ return;
+ }
+
+ // If we are playing music, don't scan unless forced.
+ List<String> sinks = mBluetoothA2dp.listConnectedSinks();
+ if (sinks != null) {
+ for (String address : sinks) {
+ if (mBluetoothA2dp.getSinkState(address) == BluetoothA2dp.STATE_PLAYING) {
+ return;
+ }
+ }
+ }
+ }
if (mManager.startDiscovery(true)) {
mLastScan = System.currentTimeMillis();
@@ -235,7 +258,7 @@ public class LocalBluetoothManager {
if (mForegroundActivity != null) {
// Need an activity context to show a dialog
- AlertDialog ad = new AlertDialog.Builder(mForegroundActivity)
+ mErrorDialog = new AlertDialog.Builder(mForegroundActivity)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(titleResId)
.setMessage(message)