Merge "Simplify logic for disconnect and getConnectionStatus in MapProfile"
am: beeb35f0de
Change-Id: Id3180db7835d637c352f795a52e4c59b3801714d
This commit is contained in:
@@ -32,11 +32,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MapProfile handles Bluetooth MAP profile.
|
* MapProfile handles the Bluetooth MAP MSE role
|
||||||
*/
|
*/
|
||||||
public class MapProfile implements LocalBluetoothProfile {
|
public class MapProfile implements LocalBluetoothProfile {
|
||||||
private static final String TAG = "MapProfile";
|
private static final String TAG = "MapProfile";
|
||||||
private static boolean V = true;
|
|
||||||
|
|
||||||
private BluetoothMap mService;
|
private BluetoothMap mService;
|
||||||
private boolean mIsProfileReady;
|
private boolean mIsProfileReady;
|
||||||
@@ -60,7 +59,7 @@ public class MapProfile implements LocalBluetoothProfile {
|
|||||||
implements BluetoothProfile.ServiceListener {
|
implements BluetoothProfile.ServiceListener {
|
||||||
|
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
if (V) Log.d(TAG,"Bluetooth service connected");
|
Log.d(TAG, "Bluetooth service connected");
|
||||||
mService = (BluetoothMap) proxy;
|
mService = (BluetoothMap) proxy;
|
||||||
// We just bound to the service, so refresh the UI for any connected MAP devices.
|
// We just bound to the service, so refresh the UI for any connected MAP devices.
|
||||||
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
||||||
@@ -82,14 +81,14 @@ public class MapProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onServiceDisconnected(int profile) {
|
public void onServiceDisconnected(int profile) {
|
||||||
if (V) Log.d(TAG,"Bluetooth service disconnected");
|
Log.d(TAG, "Bluetooth service disconnected");
|
||||||
mProfileManager.callServiceDisconnectedListeners();
|
mProfileManager.callServiceDisconnectedListeners();
|
||||||
mIsProfileReady=false;
|
mIsProfileReady=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProfileReady() {
|
public boolean isProfileReady() {
|
||||||
if(V) Log.d(TAG,"isProfileReady(): "+ mIsProfileReady);
|
Log.d(TAG, "isProfileReady(): " + mIsProfileReady);
|
||||||
return mIsProfileReady;
|
return mIsProfileReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,45 +116,45 @@ public class MapProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(BluetoothDevice device) {
|
public boolean connect(BluetoothDevice device) {
|
||||||
if(V)Log.d(TAG,"connect() - should not get called");
|
Log.d(TAG, "connect() - should not get called");
|
||||||
return false; // MAP never connects out
|
return false; // MAP never connects out
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean disconnect(BluetoothDevice device) {
|
public boolean disconnect(BluetoothDevice device) {
|
||||||
if (mService == null) return false;
|
if (mService == null) {
|
||||||
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
|
||||||
if (!deviceList.isEmpty() && deviceList.get(0).equals(device)) {
|
|
||||||
if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
|
|
||||||
mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
|
|
||||||
}
|
|
||||||
return mService.disconnect(device);
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
|
||||||
|
mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
|
||||||
|
}
|
||||||
|
return mService.disconnect(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getConnectionStatus(BluetoothDevice device) {
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
if (mService == null) return BluetoothProfile.STATE_DISCONNECTED;
|
if (mService == null) {
|
||||||
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
return BluetoothProfile.STATE_DISCONNECTED;
|
||||||
if(V) Log.d(TAG,"getConnectionStatus: status is: "+ mService.getConnectionState(device));
|
}
|
||||||
|
return mService.getConnectionState(device);
|
||||||
return !deviceList.isEmpty() && deviceList.get(0).equals(device)
|
|
||||||
? mService.getConnectionState(device)
|
|
||||||
: BluetoothProfile.STATE_DISCONNECTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreferred(BluetoothDevice device) {
|
public boolean isPreferred(BluetoothDevice device) {
|
||||||
if (mService == null) return false;
|
if (mService == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
|
return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreferred(BluetoothDevice device) {
|
public int getPreferred(BluetoothDevice device) {
|
||||||
if (mService == null) return BluetoothProfile.PRIORITY_OFF;
|
if (mService == null) {
|
||||||
|
return BluetoothProfile.PRIORITY_OFF;
|
||||||
|
}
|
||||||
return mService.getPriority(device);
|
return mService.getPriority(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
||||||
if (mService == null) return;
|
if (mService == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (preferred) {
|
if (preferred) {
|
||||||
if (mService.getPriority(device) < BluetoothProfile.PRIORITY_ON) {
|
if (mService.getPriority(device) < BluetoothProfile.PRIORITY_ON) {
|
||||||
mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
|
mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
|
||||||
@@ -166,7 +165,9 @@ public class MapProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<BluetoothDevice> getConnectedDevices() {
|
public List<BluetoothDevice> getConnectedDevices() {
|
||||||
if (mService == null) return new ArrayList<BluetoothDevice>(0);
|
if (mService == null) {
|
||||||
|
return new ArrayList<BluetoothDevice>(0);
|
||||||
|
}
|
||||||
return mService.getDevicesMatchingConnectionStates(
|
return mService.getDevicesMatchingConnectionStates(
|
||||||
new int[] {BluetoothProfile.STATE_CONNECTED,
|
new int[] {BluetoothProfile.STATE_CONNECTED,
|
||||||
BluetoothProfile.STATE_CONNECTING,
|
BluetoothProfile.STATE_CONNECTING,
|
||||||
@@ -204,7 +205,7 @@ public class MapProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void finalize() {
|
protected void finalize() {
|
||||||
if (V) Log.d(TAG, "finalize()");
|
Log.d(TAG, "finalize()");
|
||||||
if (mService != null) {
|
if (mService != null) {
|
||||||
try {
|
try {
|
||||||
BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.MAP,
|
BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.MAP,
|
||||||
|
|||||||
Reference in New Issue
Block a user