Loading core/java/android/bluetooth/BluetoothPan.java +47 −35 Original line number Diff line number Diff line Loading @@ -34,16 +34,26 @@ 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) Loading Loading @@ -130,7 +140,8 @@ public final class BluetoothPan { } } /** Get the state of a PAN Device. /** * Get the state of a PAN Device. * * This function returns an int representing the state of the PAN connection * Loading @@ -148,7 +159,8 @@ public final class BluetoothPan { } } /** Returns a set of all the connected PAN Devices /** * Returns a set of all the connected PAN Devices * * Does not include devices that are currently connecting or disconnecting * Loading core/java/android/server/BluetoothEventLoop.java +10 −5 Original line number Diff line number Diff line Loading @@ -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); } } Loading Loading @@ -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() { Loading core/java/android/server/BluetoothService.java +22 −14 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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; Loading @@ -1578,6 +1582,8 @@ public class BluetoothService extends IBluetooth.Stub { } if (prevState == state) return; // 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"); Loading @@ -1587,6 +1593,7 @@ public class BluetoothService extends IBluetooth.Stub { ifaceAddr = null; } } } Pair<Integer, String> value = new Pair<Integer, String>(state, ifaceAddr); mPanDevices.put(device, value); Loading @@ -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); Loading @@ -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() { Loading Loading
core/java/android/bluetooth/BluetoothPan.java +47 −35 Original line number Diff line number Diff line Loading @@ -34,16 +34,26 @@ 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) Loading Loading @@ -130,7 +140,8 @@ public final class BluetoothPan { } } /** Get the state of a PAN Device. /** * Get the state of a PAN Device. * * This function returns an int representing the state of the PAN connection * Loading @@ -148,7 +159,8 @@ public final class BluetoothPan { } } /** Returns a set of all the connected PAN Devices /** * Returns a set of all the connected PAN Devices * * Does not include devices that are currently connecting or disconnecting * Loading
core/java/android/server/BluetoothEventLoop.java +10 −5 Original line number Diff line number Diff line Loading @@ -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); } } Loading Loading @@ -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() { Loading
core/java/android/server/BluetoothService.java +22 −14 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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; Loading @@ -1578,6 +1582,8 @@ public class BluetoothService extends IBluetooth.Stub { } if (prevState == state) return; // 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"); Loading @@ -1587,6 +1593,7 @@ public class BluetoothService extends IBluetooth.Stub { ifaceAddr = null; } } } Pair<Integer, String> value = new Pair<Integer, String>(state, ifaceAddr); mPanDevices.put(device, value); Loading @@ -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); Loading @@ -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() { Loading