Merge "Add transport param to Connect APIs"
This commit is contained in:
@ -512,6 +512,25 @@ public final class BluetoothDevice implements Parcelable {
|
||||
*/
|
||||
public static final String EXTRA_UUID = "android.bluetooth.device.extra.UUID";
|
||||
|
||||
/**
|
||||
* No preferrence of physical transport for GATT connections to remote dual-mode devices
|
||||
* @hide
|
||||
*/
|
||||
public static final int TRANSPORT_AUTO = 0;
|
||||
|
||||
/**
|
||||
* Prefer BR/EDR transport for GATT connections to remote dual-mode devices
|
||||
* @hide
|
||||
*/
|
||||
public static final int TRANSPORT_BREDR = 1;
|
||||
|
||||
/**
|
||||
* Prefer LE transport for GATT connections to remote dual-mode devices
|
||||
* @hide
|
||||
*/
|
||||
public static final int TRANSPORT_LE = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Lazy initialization. Guaranteed final after first object constructed, or
|
||||
* getService() called.
|
||||
@ -1216,6 +1235,27 @@ public final class BluetoothDevice implements Parcelable {
|
||||
*/
|
||||
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
|
||||
BluetoothGattCallback callback) {
|
||||
return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to GATT Server hosted by this device. Caller acts as GATT client.
|
||||
* The callback is used to deliver results to Caller, such as connection status as well
|
||||
* as any further GATT client operations.
|
||||
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
|
||||
* GATT client operations.
|
||||
* @param callback GATT callback handler that will receive asynchronous callbacks.
|
||||
* @param autoConnect Whether to directly connect to the remote device (false)
|
||||
* or to automatically connect as soon as the remote
|
||||
* device becomes available (true).
|
||||
* @param transport preferred transport for GATT connections to remote dual-mode devices
|
||||
* {@link BluetoothDevice#TRANSPORT_AUTO} or
|
||||
* {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
|
||||
* @throws IllegalArgumentException if callback is null
|
||||
* @hide
|
||||
*/
|
||||
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
|
||||
BluetoothGattCallback callback, int transport) {
|
||||
// TODO(Bluetooth) check whether platform support BLE
|
||||
// Do the check here or in GattServer?
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
@ -1226,10 +1266,11 @@ public final class BluetoothDevice implements Parcelable {
|
||||
// BLE is not supported
|
||||
return null;
|
||||
}
|
||||
BluetoothGatt gatt = new BluetoothGatt(context, iGatt, this);
|
||||
BluetoothGatt gatt = new BluetoothGatt(context, iGatt, this, transport);
|
||||
gatt.connect(autoConnect, callback);
|
||||
return gatt;
|
||||
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ public final class BluetoothGatt implements BluetoothProfile {
|
||||
private int mConnState;
|
||||
private final Object mStateLock = new Object();
|
||||
private Boolean mDeviceBusy = false;
|
||||
private int mTransport;
|
||||
|
||||
private static final int CONN_STATE_IDLE = 0;
|
||||
private static final int CONN_STATE_CONNECTING = 1;
|
||||
@ -135,7 +136,7 @@ public final class BluetoothGatt implements BluetoothProfile {
|
||||
}
|
||||
try {
|
||||
mService.clientConnect(mClientIf, mDevice.getAddress(),
|
||||
!mAutoConnect); // autoConnect is inverse of "isDirect"
|
||||
!mAutoConnect, mTransport); // autoConnect is inverse of "isDirect"
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG,"",e);
|
||||
}
|
||||
@ -600,10 +601,12 @@ public final class BluetoothGatt implements BluetoothProfile {
|
||||
}
|
||||
};
|
||||
|
||||
/*package*/ BluetoothGatt(Context context, IBluetoothGatt iGatt, BluetoothDevice device) {
|
||||
/*package*/ BluetoothGatt(Context context, IBluetoothGatt iGatt, BluetoothDevice device,
|
||||
int transport) {
|
||||
mContext = context;
|
||||
mService = iGatt;
|
||||
mDevice = device;
|
||||
mTransport = transport;
|
||||
mServices = new ArrayList<BluetoothGattService>();
|
||||
|
||||
mConnState = CONN_STATE_IDLE;
|
||||
@ -759,7 +762,7 @@ public final class BluetoothGatt implements BluetoothProfile {
|
||||
public boolean connect() {
|
||||
try {
|
||||
mService.clientConnect(mClientIf, mDevice.getAddress(),
|
||||
false); // autoConnect is inverse of "isDirect"
|
||||
false, mTransport); // autoConnect is inverse of "isDirect"
|
||||
return true;
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG,"",e);
|
||||
|
@ -50,6 +50,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
|
||||
|
||||
private Object mServerIfLock = new Object();
|
||||
private int mServerIf;
|
||||
private int mTransport;
|
||||
private List<BluetoothGattService> mServices;
|
||||
|
||||
private static final int CALLBACK_REG_TIMEOUT = 10000;
|
||||
@ -269,12 +270,13 @@ public final class BluetoothGattServer implements BluetoothProfile {
|
||||
/**
|
||||
* Create a BluetoothGattServer proxy object.
|
||||
*/
|
||||
/*package*/ BluetoothGattServer(Context context, IBluetoothGatt iGatt) {
|
||||
/*package*/ BluetoothGattServer(Context context, IBluetoothGatt iGatt, int transport) {
|
||||
mContext = context;
|
||||
mService = iGatt;
|
||||
mAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mCallback = null;
|
||||
mServerIf = 0;
|
||||
mTransport = transport;
|
||||
mServices = new ArrayList<BluetoothGattService>();
|
||||
}
|
||||
|
||||
@ -401,7 +403,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
|
||||
|
||||
try {
|
||||
mService.serverConnect(mServerIf, device.getAddress(),
|
||||
autoConnect ? false : true); // autoConnect is inverse of "isDirect"
|
||||
autoConnect ? false : true,mTransport); // autoConnect is inverse of "isDirect"
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG,"",e);
|
||||
return false;
|
||||
|
@ -194,6 +194,26 @@ public final class BluetoothManager {
|
||||
*/
|
||||
public BluetoothGattServer openGattServer(Context context,
|
||||
BluetoothGattServerCallback callback) {
|
||||
|
||||
return (openGattServer (context, callback, BluetoothDevice.TRANSPORT_AUTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a GATT Server
|
||||
* The callback is used to deliver results to Caller, such as connection status as well
|
||||
* as the results of any other GATT server operations.
|
||||
* The method returns a BluetoothGattServer instance. You can use BluetoothGattServer
|
||||
* to conduct GATT server operations.
|
||||
* @param context App context
|
||||
* @param callback GATT server callback handler that will receive asynchronous callbacks.
|
||||
* @param transport preferred transport for GATT connections to remote dual-mode devices
|
||||
* {@link BluetoothDevice#TRANSPORT_AUTO} or
|
||||
* {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
|
||||
* @return BluetoothGattServer instance
|
||||
* @hide
|
||||
*/
|
||||
public BluetoothGattServer openGattServer(Context context,
|
||||
BluetoothGattServerCallback callback,int transport) {
|
||||
if (context == null || callback == null) {
|
||||
throw new IllegalArgumentException("null parameter: " + context + " " + callback);
|
||||
}
|
||||
@ -208,7 +228,7 @@ public final class BluetoothManager {
|
||||
Log.e(TAG, "Fail to get GATT Server connection");
|
||||
return null;
|
||||
}
|
||||
BluetoothGattServer mGattServer = new BluetoothGattServer(context, iGatt);
|
||||
BluetoothGattServer mGattServer = new BluetoothGattServer(context, iGatt,transport);
|
||||
Boolean regStatus = mGattServer.registerCallback(callback);
|
||||
return regStatus? mGattServer : null;
|
||||
} catch (RemoteException e) {
|
||||
|
@ -35,7 +35,7 @@ interface IBluetoothGatt {
|
||||
|
||||
void registerClient(in ParcelUuid appId, in IBluetoothGattCallback callback);
|
||||
void unregisterClient(in int clientIf);
|
||||
void clientConnect(in int clientIf, in String address, in boolean isDirect);
|
||||
void clientConnect(in int clientIf, in String address, in boolean isDirect, in int transport);
|
||||
void clientDisconnect(in int clientIf, in String address);
|
||||
void startAdvertising(in int appIf);
|
||||
void stopAdvertising();
|
||||
@ -77,7 +77,7 @@ interface IBluetoothGatt {
|
||||
|
||||
void registerServer(in ParcelUuid appId, in IBluetoothGattServerCallback callback);
|
||||
void unregisterServer(in int serverIf);
|
||||
void serverConnect(in int servertIf, in String address, in boolean isDirect);
|
||||
void serverConnect(in int servertIf, in String address, in boolean isDirect, in int transport);
|
||||
void serverDisconnect(in int serverIf, in String address);
|
||||
void beginServiceDeclaration(in int serverIf, in int srvcType,
|
||||
in int srvcInstanceId, in int minHandles,
|
||||
|
Reference in New Issue
Block a user