Merge "Add EXTRA_LOCAL_ROLE to Pan State change intent."
This commit is contained in:
@@ -34,21 +34,31 @@ public final class BluetoothPan {
|
||||
private static final String TAG = "BluetoothPan";
|
||||
private static final boolean DBG = false;
|
||||
|
||||
//TODO: This needs to inherit from BluetoothProfile like other profiles.
|
||||
|
||||
/** int extra for ACTION_PAN_STATE_CHANGED */
|
||||
public static final String EXTRA_PAN_STATE =
|
||||
"android.bluetooth.pan.extra.STATE";
|
||||
public static final String EXTRA_PAN_STATE = "android.bluetooth.pan.extra.STATE";
|
||||
|
||||
/** int extra for ACTION_PAN_STATE_CHANGED */
|
||||
public static final String EXTRA_PREVIOUS_PAN_STATE =
|
||||
"android.bluetooth.pan.extra.PREVIOUS_STATE";
|
||||
|
||||
/** Indicates the state of an PAN device has changed.
|
||||
/** int extra for ACTION_PAN_STATE_CHANGED */
|
||||
public static final String EXTRA_LOCAL_ROLE = "android.bluetooth.pan.extra.LOCAL_ROLE";
|
||||
|
||||
public static final int LOCAL_NAP_ROLE = 1;
|
||||
public static final int LOCAL_PANU_ROLE = 2;
|
||||
|
||||
/**
|
||||
* Indicates the state of an PAN device has changed.
|
||||
* This intent will always contain EXTRA_DEVICE_STATE,
|
||||
* EXTRA_PREVIOUS_DEVICE_STATE and BluetoothDevice.EXTRA_DEVICE
|
||||
* EXTRA_PREVIOUS_DEVICE_STATE, BluetoothDevice.EXTRA_DEVICE
|
||||
* and EXTRA_LOCAL_ROLE.
|
||||
* extras.
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||
public static final String ACTION_PAN_STATE_CHANGED =
|
||||
"android.bluetooth.pan.action.STATE_CHANGED";
|
||||
"android.bluetooth.pan.action.STATE_CHANGED";
|
||||
|
||||
public static final String NAP_ROLE = "nap";
|
||||
public static final String NAP_BRIDGE = "pan1";
|
||||
@@ -130,40 +140,42 @@ public final class BluetoothPan {
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the state of a PAN Device.
|
||||
*
|
||||
* This function returns an int representing the state of the PAN connection
|
||||
*
|
||||
* @param device Remote BT device.
|
||||
* @return The current state of the PAN Device
|
||||
* @hide
|
||||
*/
|
||||
public int getPanDeviceState(BluetoothDevice device) {
|
||||
if (DBG) log("getPanDeviceState(" + device + ")");
|
||||
/**
|
||||
* Get the state of a PAN Device.
|
||||
*
|
||||
* This function returns an int representing the state of the PAN connection
|
||||
*
|
||||
* @param device Remote BT device.
|
||||
* @return The current state of the PAN Device
|
||||
* @hide
|
||||
*/
|
||||
public int getPanDeviceState(BluetoothDevice device) {
|
||||
if (DBG) log("getPanDeviceState(" + device + ")");
|
||||
try {
|
||||
return mService.getPanDeviceState(device);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "", e);
|
||||
return STATE_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of all the connected PAN Devices
|
||||
*
|
||||
* Does not include devices that are currently connecting or disconnecting
|
||||
*
|
||||
* @return List of PAN devices or empty on Error
|
||||
* @hide
|
||||
*/
|
||||
public List<BluetoothDevice> getConnectedDevices() {
|
||||
if (DBG) log("getConnectedDevices");
|
||||
try {
|
||||
return mService.getPanDeviceState(device);
|
||||
return mService.getConnectedPanDevices();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "", e);
|
||||
return STATE_DISCONNECTED;
|
||||
return new ArrayList<BluetoothDevice>();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns a set of all the connected PAN Devices
|
||||
*
|
||||
* Does not include devices that are currently connecting or disconnecting
|
||||
*
|
||||
* @return List of PAN devices or empty on Error
|
||||
* @hide
|
||||
*/
|
||||
public List<BluetoothDevice> getConnectedDevices() {
|
||||
if (DBG) log("getConnectedDevices");
|
||||
try {
|
||||
return mService.getConnectedPanDevices();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "", e);
|
||||
return new ArrayList<BluetoothDevice>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void log(String msg) {
|
||||
Log.d(TAG, msg);
|
||||
|
||||
@@ -420,12 +420,14 @@ class BluetoothEventLoop {
|
||||
if (name.equals("Connected")) {
|
||||
if (propValues[1].equals("false")) {
|
||||
mBluetoothService.handlePanDeviceStateChange(device,
|
||||
BluetoothInputDevice.STATE_DISCONNECTED);
|
||||
BluetoothPan.STATE_DISCONNECTED,
|
||||
BluetoothPan.LOCAL_PANU_ROLE);
|
||||
}
|
||||
} else if (name.equals("Interface")) {
|
||||
String iface = propValues[1];
|
||||
mBluetoothService.handlePanDeviceStateChange(device, iface,
|
||||
BluetoothInputDevice.STATE_CONNECTED);
|
||||
BluetoothPan.STATE_CONNECTED,
|
||||
BluetoothPan.LOCAL_PANU_ROLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,18 +753,21 @@ class BluetoothEventLoop {
|
||||
}
|
||||
int newState = connected? BluetoothPan.STATE_CONNECTED :
|
||||
BluetoothPan.STATE_DISCONNECTED;
|
||||
mBluetoothService.handlePanDeviceStateChange(device, newState);
|
||||
mBluetoothService.handlePanDeviceStateChange(device, newState,
|
||||
BluetoothPan.LOCAL_PANU_ROLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void onNetworkDeviceDisconnected(String address) {
|
||||
BluetoothDevice device = mAdapter.getRemoteDevice(address);
|
||||
mBluetoothService.handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED);
|
||||
mBluetoothService.handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED,
|
||||
BluetoothPan.LOCAL_NAP_ROLE);
|
||||
}
|
||||
|
||||
private void onNetworkDeviceConnected(String address, String iface, int destUuid) {
|
||||
BluetoothDevice device = mAdapter.getRemoteDevice(address);
|
||||
mBluetoothService.handlePanDeviceStateChange(device, iface, BluetoothPan.STATE_CONNECTED);
|
||||
mBluetoothService.handlePanDeviceStateChange(device, iface, BluetoothPan.STATE_CONNECTED,
|
||||
BluetoothPan.LOCAL_NAP_ROLE);
|
||||
}
|
||||
|
||||
private void onRestartRequired() {
|
||||
|
||||
@@ -1513,12 +1513,14 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
return false;
|
||||
}
|
||||
|
||||
handlePanDeviceStateChange(device, BluetoothPan.STATE_CONNECTING);
|
||||
if (connectPanDeviceNative(objectPath, "nap")) {
|
||||
handlePanDeviceStateChange(device, BluetoothPan.STATE_CONNECTING,
|
||||
BluetoothPan.LOCAL_PANU_ROLE);
|
||||
if (connectPanDeviceNative(objectPath, "nap", "panu")) {
|
||||
log ("connecting to PAN");
|
||||
return true;
|
||||
} else {
|
||||
handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED);
|
||||
handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED,
|
||||
BluetoothPan.LOCAL_PANU_ROLE);
|
||||
log ("could not connect to PAN");
|
||||
return false;
|
||||
}
|
||||
@@ -1560,13 +1562,15 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
if (getPanDeviceState(device) != BluetoothPan.STATE_CONNECTED) {
|
||||
log (device + " already disconnected from PAN");
|
||||
}
|
||||
handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTING);
|
||||
handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTING,
|
||||
BluetoothPan.LOCAL_PANU_ROLE);
|
||||
return disconnectPanDeviceNative(objectPath);
|
||||
}
|
||||
|
||||
/*package*/ synchronized void handlePanDeviceStateChange(BluetoothDevice device,
|
||||
String iface,
|
||||
int state) {
|
||||
int state,
|
||||
int role) {
|
||||
int prevState;
|
||||
String ifaceAddr = null;
|
||||
|
||||
@@ -1578,13 +1582,16 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
}
|
||||
if (prevState == state) return;
|
||||
|
||||
if (state == BluetoothPan.STATE_CONNECTED) {
|
||||
ifaceAddr = enableTethering(iface);
|
||||
if (ifaceAddr == null) Log.e(TAG, "Error seting up tether interface");
|
||||
} else if (state == BluetoothPan.STATE_DISCONNECTED) {
|
||||
if (ifaceAddr != null) {
|
||||
mBluetoothIfaceAddresses.remove(ifaceAddr);
|
||||
ifaceAddr = null;
|
||||
// TODO: We might need this for PANU role too.
|
||||
if (role == BluetoothPan.LOCAL_NAP_ROLE) {
|
||||
if (state == BluetoothPan.STATE_CONNECTED) {
|
||||
ifaceAddr = enableTethering(iface);
|
||||
if (ifaceAddr == null) Log.e(TAG, "Error seting up tether interface");
|
||||
} else if (state == BluetoothPan.STATE_DISCONNECTED) {
|
||||
if (ifaceAddr != null) {
|
||||
mBluetoothIfaceAddresses.remove(ifaceAddr);
|
||||
ifaceAddr = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1595,6 +1602,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
|
||||
intent.putExtra(BluetoothPan.EXTRA_PREVIOUS_PAN_STATE, prevState);
|
||||
intent.putExtra(BluetoothPan.EXTRA_PAN_STATE, state);
|
||||
intent.putExtra(BluetoothPan.EXTRA_LOCAL_ROLE, role);
|
||||
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
|
||||
|
||||
if (DBG) log("Pan Device state : device: " + device + " State:" + prevState + "->" + state);
|
||||
@@ -1602,8 +1610,8 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
}
|
||||
|
||||
/*package*/ synchronized void handlePanDeviceStateChange(BluetoothDevice device,
|
||||
int state) {
|
||||
handlePanDeviceStateChange(device, null, state);
|
||||
int state, int role) {
|
||||
handlePanDeviceStateChange(device, null, state, role);
|
||||
}
|
||||
|
||||
private String createNewTetheringAddressLocked() {
|
||||
|
||||
Reference in New Issue
Block a user