diff options
author | Jason Monk <jmonk@google.com> | 2015-03-12 14:23:49 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-12 14:23:51 +0000 |
commit | 78981e0393fa767035b0d84b0f0222e20a002917 (patch) | |
tree | 3bcb06175a9c7ddec33713fe82e01c0ba6c02dba /packages/SettingsLib | |
parent | af66416e4b7dd4be1d674cb660108a308a713221 (diff) | |
parent | be3c5dbee66758517a8198f98ed2e20c80af326b (diff) | |
download | frameworks_base-78981e0393fa767035b0d84b0f0222e20a002917.zip frameworks_base-78981e0393fa767035b0d84b0f0222e20a002917.tar.gz frameworks_base-78981e0393fa767035b0d84b0f0222e20a002917.tar.bz2 |
Merge "Make QS use SettingsLib's BT code"
Diffstat (limited to 'packages/SettingsLib')
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, |