summaryrefslogtreecommitdiffstats
path: root/packages/SettingsLib
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2015-02-04 13:00:55 -0500
committerJason Monk <jmonk@google.com>2015-03-02 10:40:21 -0500
commitbe3c5dbee66758517a8198f98ed2e20c80af326b (patch)
tree24cf7c862730a2f530710e9aaae33f52d932ee64 /packages/SettingsLib
parentc94ea96cb77b27d93e675912b2420bd43ae9b8fe (diff)
downloadframeworks_base-be3c5dbee66758517a8198f98ed2e20c80af326b.zip
frameworks_base-be3c5dbee66758517a8198f98ed2e20c80af326b.tar.gz
frameworks_base-be3c5dbee66758517a8198f98ed2e20c80af326b.tar.bz2
Make QS use SettingsLib's BT code
A couple of changes needed to be made to SettingsLib to support this. - SettingsLib needed to track ACTION_CONNECTION_STATE_CHANGED - The summary code needed to move from Settings up into SettingsLib - Added a getMaxConnectionState to CachedBluetoothDevice - This simplifies the states of all of the profiles into one. Change-Id: I7f828f0038ad0cf39274986ece6d486d545f0286
Diffstat (limited to 'packages/SettingsLib')
-rw-r--r--packages/SettingsLib/res/values/strings.xml11
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java1
-rwxr-xr-xpackages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java25
-rwxr-xr-xpackages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java60
-rwxr-xr-xpackages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java5
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothAdapter.java4
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java2
7 files changed, 103 insertions, 5 deletions
diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml
index 870afeb..b5e49ce 100644
--- a/packages/SettingsLib/res/values/strings.xml
+++ b/packages/SettingsLib/res/values/strings.xml
@@ -76,6 +76,17 @@
<string name="bluetooth_connecting">Connecting\u2026</string>
<!-- Bluetooth settings. Message when connected to a device. [CHAR LIMIT=40] -->
<string name="bluetooth_connected">Connected</string>
+ <!--Bluetooth settings screen, summary text under individual Bluetooth devices when pairing -->
+ <string name="bluetooth_pairing">Pairing\u2026</string>
+
+ <!-- Bluetooth settings. Message when connected to a device, except for phone audio. [CHAR LIMIT=40] -->
+ <string name="bluetooth_connected_no_headset">Connected (no phone)</string>
+ <!-- Bluetooth settings. Message when connected to a device, except for media audio. [CHAR LIMIT=40] -->
+ <string name="bluetooth_connected_no_a2dp">Connected (no media)</string>
+ <!-- Bluetooth settings. Message when connected to a device, except for map. [CHAR LIMIT=40] -->
+ <string name="bluetooth_connected_no_map">Connected (no message access)</string>
+ <!-- Bluetooth settings. Message when connected to a device, except for phone/media audio. [CHAR LIMIT=40] -->
+ <string name="bluetooth_connected_no_headset_no_a2dp">Connected (no phone or media)</string>
<!-- Bluetooth settings. The user-visible string that is used whenever referring to the A2DP profile. -->
<string name="bluetooth_profile_a2dp">Media audio</string>
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java
index b802f58..4c41b49 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java
@@ -27,4 +27,5 @@ public interface BluetoothCallback {
void onDeviceAdded(CachedBluetoothDevice cachedDevice);
void onDeviceDeleted(CachedBluetoothDevice cachedDevice);
void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState);
+ void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state);
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
index 7c92368..5d6b2f1 100755
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
@@ -81,6 +81,9 @@ public final class BluetoothEventManager {
// Bluetooth on/off broadcasts
addHandler(BluetoothAdapter.ACTION_STATE_CHANGED, new AdapterStateChangedHandler());
+ // Generic connected/not broadcast
+ addHandler(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED,
+ new ConnectionStateChangedHandler());
// Discovery broadcasts
addHandler(BluetoothAdapter.ACTION_DISCOVERY_STARTED, new ScanningStateChangedHandler(true));
@@ -183,8 +186,6 @@ public final class BluetoothEventManager {
cachedDevice = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, device);
Log.d(TAG, "DeviceFoundHandler created new CachedBluetoothDevice: "
+ cachedDevice);
- // callback to UI to create Preference for new device
- dispatchDeviceAdded(cachedDevice);
}
cachedDevice.setRssi(rssi);
cachedDevice.setBtClass(btClass);
@@ -193,7 +194,25 @@ public final class BluetoothEventManager {
}
}
- private void dispatchDeviceAdded(CachedBluetoothDevice cachedDevice) {
+ private class ConnectionStateChangedHandler implements Handler {
+ @Override
+ public void onReceive(Context context, Intent intent, BluetoothDevice device) {
+ CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
+ int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
+ BluetoothAdapter.ERROR);
+ dispatchConnectionStateChanged(cachedDevice, state);
+ }
+ }
+
+ private void dispatchConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
+ synchronized (mCallbacks) {
+ for (BluetoothCallback callback : mCallbacks) {
+ callback.onConnectionStateChanged(cachedDevice, state);
+ }
+ }
+ }
+
+ void dispatchDeviceAdded(CachedBluetoothDevice cachedDevice) {
synchronized (mCallbacks) {
for (BluetoothCallback callback : mCallbacks) {
callback.onDeviceAdded(cachedDevice);
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
index ddcc49f..e1cb878 100755
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
@@ -28,6 +28,8 @@ import android.text.TextUtils;
import android.util.Log;
import android.bluetooth.BluetoothAdapter;
+import com.android.settingslib.R;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -784,4 +786,62 @@ public final class CachedBluetoothDevice implements Comparable<CachedBluetoothDe
setPhonebookPermissionChoice(CachedBluetoothDevice.ACCESS_ALLOWED);
}
}
+
+ public int getMaxConnectionState() {
+ int maxState = BluetoothProfile.STATE_DISCONNECTED;
+ for (LocalBluetoothProfile profile : getProfiles()) {
+ int connectionStatus = getProfileConnectionState(profile);
+ if (connectionStatus > maxState) {
+ maxState = connectionStatus;
+ }
+ }
+ return maxState;
+ }
+
+ /**
+ * @return resource for string that discribes the connection state of this device.
+ */
+ public int getConnectionSummary() {
+ boolean profileConnected = false; // at least one profile is connected
+ boolean a2dpNotConnected = false; // A2DP is preferred but not connected
+ boolean headsetNotConnected = false; // Headset is preferred but not connected
+
+ for (LocalBluetoothProfile profile : getProfiles()) {
+ int connectionStatus = getProfileConnectionState(profile);
+
+ switch (connectionStatus) {
+ case BluetoothProfile.STATE_CONNECTING:
+ case BluetoothProfile.STATE_DISCONNECTING:
+ return Utils.getConnectionStateSummary(connectionStatus);
+
+ case BluetoothProfile.STATE_CONNECTED:
+ profileConnected = true;
+ break;
+
+ case BluetoothProfile.STATE_DISCONNECTED:
+ if (profile.isProfileReady()) {
+ if (profile instanceof A2dpProfile) {
+ a2dpNotConnected = true;
+ } else if (profile instanceof HeadsetProfile) {
+ headsetNotConnected = true;
+ }
+ }
+ break;
+ }
+ }
+
+ if (profileConnected) {
+ if (a2dpNotConnected && headsetNotConnected) {
+ return R.string.bluetooth_connected_no_headset_no_a2dp;
+ } else if (a2dpNotConnected) {
+ return R.string.bluetooth_connected_no_a2dp;
+ } else if (headsetNotConnected) {
+ return R.string.bluetooth_connected_no_headset;
+ } else {
+ return R.string.bluetooth_connected;
+ }
+ }
+
+ return getBondState() == BluetoothDevice.BOND_BONDING ? R.string.bluetooth_pairing : 0;
+ }
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java
index 65db95f..a9f4bd3 100755
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java
@@ -35,9 +35,11 @@ public final class CachedBluetoothDeviceManager {
private Context mContext;
private final List<CachedBluetoothDevice> mCachedDevices =
new ArrayList<CachedBluetoothDevice>();
+ private final LocalBluetoothManager mBtManager;
- CachedBluetoothDeviceManager(Context context) {
+ CachedBluetoothDeviceManager(Context context, LocalBluetoothManager localBtManager) {
mContext = context;
+ mBtManager = localBtManager;
}
public synchronized Collection<CachedBluetoothDevice> getCachedDevicesCopy() {
@@ -88,6 +90,7 @@ public final class CachedBluetoothDeviceManager {
profileManager, device);
synchronized (mCachedDevices) {
mCachedDevices.add(newDevice);
+ mBtManager.getEventManager().dispatchDeviceAdded(newDevice);
}
return newDevice;
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothAdapter.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothAdapter.java
index 0c1adec..e3d2a99 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothAdapter.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothAdapter.java
@@ -122,6 +122,10 @@ public final class LocalBluetoothAdapter {
return mAdapter.isEnabled();
}
+ public int getConnectionState() {
+ return mAdapter.getConnectionState();
+ }
+
public void setDiscoverableTimeout(int timeout) {
mAdapter.setDiscoverableTimeout(timeout);
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java
index 4adc62e..623ccc3 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java
@@ -68,7 +68,7 @@ public final class LocalBluetoothManager {
mContext = context;
mLocalAdapter = adapter;
- mCachedDeviceManager = new CachedBluetoothDeviceManager(context);
+ mCachedDeviceManager = new CachedBluetoothDeviceManager(context, this);
mEventManager = new BluetoothEventManager(mLocalAdapter,
mCachedDeviceManager, context);
mProfileManager = new LocalBluetoothProfileManager(context,