am 18c4317b
: Show correct A2DP connection status in Bluetooth settings.
* commit '18c4317b93fce47109017efdab089dec4b01f790': Show correct A2DP connection status in Bluetooth settings.
This commit is contained in:
@@ -38,6 +38,9 @@ final class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
private BluetoothA2dp mService;
|
private BluetoothA2dp mService;
|
||||||
private boolean mIsProfileReady;
|
private boolean mIsProfileReady;
|
||||||
|
|
||||||
|
private final LocalBluetoothAdapter mLocalAdapter;
|
||||||
|
private final CachedBluetoothDeviceManager mDeviceManager;
|
||||||
|
|
||||||
static final ParcelUuid[] SINK_UUIDS = {
|
static final ParcelUuid[] SINK_UUIDS = {
|
||||||
BluetoothUuid.AudioSink,
|
BluetoothUuid.AudioSink,
|
||||||
BluetoothUuid.AdvAudioDist,
|
BluetoothUuid.AdvAudioDist,
|
||||||
@@ -56,6 +59,19 @@ final class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
if (V) Log.d(TAG,"Bluetooth service connected");
|
if (V) Log.d(TAG,"Bluetooth service connected");
|
||||||
mService = (BluetoothA2dp) proxy;
|
mService = (BluetoothA2dp) proxy;
|
||||||
|
// We just bound to the service, so refresh the UI for any connected A2DP devices.
|
||||||
|
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
||||||
|
while (!deviceList.isEmpty()) {
|
||||||
|
BluetoothDevice nextDevice = deviceList.remove(0);
|
||||||
|
CachedBluetoothDevice device = mDeviceManager.findDevice(nextDevice);
|
||||||
|
// we may add a new device here, but generally this should not happen
|
||||||
|
if (device == null) {
|
||||||
|
Log.w(TAG, "A2dpProfile found new device: " + nextDevice);
|
||||||
|
device = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, nextDevice);
|
||||||
|
}
|
||||||
|
device.onProfileStateChanged(A2dpProfile.this, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
device.refresh();
|
||||||
|
}
|
||||||
mIsProfileReady=true;
|
mIsProfileReady=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,10 +84,14 @@ final class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
public boolean isProfileReady() {
|
public boolean isProfileReady() {
|
||||||
return mIsProfileReady;
|
return mIsProfileReady;
|
||||||
}
|
}
|
||||||
A2dpProfile(Context context, LocalBluetoothProfileManager profileManager) {
|
|
||||||
|
A2dpProfile(Context context, LocalBluetoothAdapter adapter,
|
||||||
|
CachedBluetoothDeviceManager deviceManager,
|
||||||
|
LocalBluetoothProfileManager profileManager) {
|
||||||
|
mLocalAdapter = adapter;
|
||||||
|
mDeviceManager = deviceManager;
|
||||||
mProfileManager = profileManager;
|
mProfileManager = profileManager;
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
mLocalAdapter.getProfileProxy(context, new A2dpServiceListener(),
|
||||||
adapter.getProfileProxy(context, new A2dpServiceListener(),
|
|
||||||
BluetoothProfile.A2DP);
|
BluetoothProfile.A2DP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,19 +62,19 @@ final class HeadsetProfile implements LocalBluetoothProfile {
|
|||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
if (V) Log.d(TAG,"Bluetooth service connected");
|
if (V) Log.d(TAG,"Bluetooth service connected");
|
||||||
mService = (BluetoothHeadset) proxy;
|
mService = (BluetoothHeadset) proxy;
|
||||||
// We just bound to the service, so refresh the UI of the
|
// We just bound to the service, so refresh the UI for any connected HFP devices.
|
||||||
// headset device.
|
|
||||||
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
||||||
if (!deviceList.isEmpty()) {
|
while (!deviceList.isEmpty()) {
|
||||||
BluetoothDevice firstDevice = deviceList.get(0);
|
BluetoothDevice nextDevice = deviceList.remove(0);
|
||||||
CachedBluetoothDevice device = mDeviceManager.findDevice(firstDevice);
|
CachedBluetoothDevice device = mDeviceManager.findDevice(nextDevice);
|
||||||
// we may add a new device here, but generally this should not happen
|
// we may add a new device here, but generally this should not happen
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
Log.w(TAG, "HeadsetProfile found new device: " + firstDevice);
|
Log.w(TAG, "HeadsetProfile found new device: " + nextDevice);
|
||||||
device = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, firstDevice);
|
device = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, nextDevice);
|
||||||
}
|
}
|
||||||
device.onProfileStateChanged(HeadsetProfile.this,
|
device.onProfileStateChanged(HeadsetProfile.this,
|
||||||
BluetoothProfile.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED);
|
||||||
|
device.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
mProfileManager.callServiceConnectedListeners();
|
mProfileManager.callServiceConnectedListeners();
|
||||||
|
@@ -38,6 +38,10 @@ final class HidProfile implements LocalBluetoothProfile {
|
|||||||
private BluetoothInputDevice mService;
|
private BluetoothInputDevice mService;
|
||||||
private boolean mIsProfileReady;
|
private boolean mIsProfileReady;
|
||||||
|
|
||||||
|
private final LocalBluetoothAdapter mLocalAdapter;
|
||||||
|
private final CachedBluetoothDeviceManager mDeviceManager;
|
||||||
|
private final LocalBluetoothProfileManager mProfileManager;
|
||||||
|
|
||||||
static final String NAME = "HID";
|
static final String NAME = "HID";
|
||||||
|
|
||||||
// Order of this profile in device profiles list
|
// Order of this profile in device profiles list
|
||||||
@@ -50,6 +54,19 @@ final class HidProfile implements LocalBluetoothProfile {
|
|||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
if (V) Log.d(TAG,"Bluetooth service connected");
|
if (V) Log.d(TAG,"Bluetooth service connected");
|
||||||
mService = (BluetoothInputDevice) proxy;
|
mService = (BluetoothInputDevice) proxy;
|
||||||
|
// We just bound to the service, so refresh the UI for any connected HID devices.
|
||||||
|
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
||||||
|
while (!deviceList.isEmpty()) {
|
||||||
|
BluetoothDevice nextDevice = deviceList.remove(0);
|
||||||
|
CachedBluetoothDevice device = mDeviceManager.findDevice(nextDevice);
|
||||||
|
// we may add a new device here, but generally this should not happen
|
||||||
|
if (device == null) {
|
||||||
|
Log.w(TAG, "HidProfile found new device: " + nextDevice);
|
||||||
|
device = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, nextDevice);
|
||||||
|
}
|
||||||
|
device.onProfileStateChanged(HidProfile.this, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
device.refresh();
|
||||||
|
}
|
||||||
mIsProfileReady=true;
|
mIsProfileReady=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +80,12 @@ final class HidProfile implements LocalBluetoothProfile {
|
|||||||
return mIsProfileReady;
|
return mIsProfileReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
HidProfile(Context context, LocalBluetoothAdapter adapter) {
|
HidProfile(Context context, LocalBluetoothAdapter adapter,
|
||||||
|
CachedBluetoothDeviceManager deviceManager,
|
||||||
|
LocalBluetoothProfileManager profileManager) {
|
||||||
|
mLocalAdapter = adapter;
|
||||||
|
mDeviceManager = deviceManager;
|
||||||
|
mProfileManager = profileManager;
|
||||||
adapter.getProfileProxy(context, new InputDeviceServiceListener(),
|
adapter.getProfileProxy(context, new InputDeviceServiceListener(),
|
||||||
BluetoothProfile.INPUT_DEVICE);
|
BluetoothProfile.INPUT_DEVICE);
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ final class LocalBluetoothProfileManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Always add HID and PAN profiles
|
// Always add HID and PAN profiles
|
||||||
mHidProfile = new HidProfile(context, mLocalAdapter);
|
mHidProfile = new HidProfile(context, mLocalAdapter, mDeviceManager, this);
|
||||||
addProfile(mHidProfile, HidProfile.NAME,
|
addProfile(mHidProfile, HidProfile.NAME,
|
||||||
BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED);
|
BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ final class LocalBluetoothProfileManager {
|
|||||||
if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.AudioSource)) {
|
if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.AudioSource)) {
|
||||||
if (mA2dpProfile == null) {
|
if (mA2dpProfile == null) {
|
||||||
Log.d(TAG, "Adding local A2DP profile");
|
Log.d(TAG, "Adding local A2DP profile");
|
||||||
mA2dpProfile = new A2dpProfile(mContext, this);
|
mA2dpProfile = new A2dpProfile(mContext, mLocalAdapter, mDeviceManager, this);
|
||||||
addProfile(mA2dpProfile, A2dpProfile.NAME,
|
addProfile(mA2dpProfile, A2dpProfile.NAME,
|
||||||
BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
|
BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user