Loading packages/SettingsLib/res/values/strings.xml +11 −0 Original line number Diff line number Diff line Loading @@ -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> Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java +1 −0 Original line number Diff line number Diff line Loading @@ -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); } packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +22 −3 Original line number Diff line number Diff line Loading @@ -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)); Loading Loading @@ -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); Loading @@ -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); Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +60 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } } packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -88,6 +90,7 @@ public final class CachedBluetoothDeviceManager { profileManager, device); synchronized (mCachedDevices) { mCachedDevices.add(newDevice); mBtManager.getEventManager().dispatchDeviceAdded(newDevice); } return newDevice; } Loading Loading
packages/SettingsLib/res/values/strings.xml +11 −0 Original line number Diff line number Diff line Loading @@ -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> Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothCallback.java +1 −0 Original line number Diff line number Diff line Loading @@ -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); }
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +22 −3 Original line number Diff line number Diff line Loading @@ -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)); Loading Loading @@ -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); Loading @@ -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); Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +60 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } }
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -88,6 +90,7 @@ public final class CachedBluetoothDeviceManager { profileManager, device); synchronized (mCachedDevices) { mCachedDevices.add(newDevice); mBtManager.getEventManager().dispatchDeviceAdded(newDevice); } return newDevice; } Loading