Fix tethering using BT.

1. Since Input device runs in Bluetooth Service, avoid the proxy call.
2. Accept or reject incoming tethering connections.

This broke because of incoming connection request change for phonebook, HID,
A2DP.
Change-Id: Ia8c537bb79e4dbc66cfb6b23dcad4f99dbf950b3
This commit is contained in:
Jaikumar Ganesh
2011-08-01 19:11:18 -07:00
parent 9a6c7383b3
commit bbd8675057
5 changed files with 31 additions and 45 deletions

View File

@@ -1048,12 +1048,12 @@ public final class BluetoothDeviceProfileState extends StateMachine {
break;
case CONNECT_HID_INCOMING:
if (!accept) {
ret = mService.allowIncomingHidConnect(mDevice, false);
ret = mService.allowIncomingProfileConnect(mDevice, false);
sendMessage(TRANSITION_TO_STABLE);
updateIncomingAllowedTimer();
} else {
writeTimerValue(0);
ret = mService.allowIncomingHidConnect(mDevice, true);
ret = mService.allowIncomingProfileConnect(mDevice, true);
}
break;
default:

View File

@@ -308,28 +308,6 @@ public final class BluetoothInputDevice implements BluetoothProfile {
return BluetoothProfile.PRIORITY_OFF;
}
/**
* Allow or disallow incoming connection
* @param device Input device
* @param allow true / false
* @return Success or Failure of the operation
* @hide
*/
public boolean allowIncomingConnect(BluetoothDevice device, boolean allow) {
if (DBG) log("allowIncomingConnect(" + device + ", " + allow + ")");
if (mService == null || !isEnabled() || !isValidDevice(device)) {
return false;
}
try {
mService.allowIncomingHidConnect(device, allow);
} catch (RemoteException e) {
Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
return false;
}
return true;
}
private boolean isEnabled() {
if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
return false;

View File

@@ -85,6 +85,7 @@ interface IBluetooth
int addRfcommServiceRecord(in String serviceName, in ParcelUuid uuid, int channel, IBinder b);
void removeServiceRecord(int handle);
boolean allowIncomingProfileConnect(in BluetoothDevice device, boolean value);
boolean connectHeadset(String address);
boolean disconnectHeadset(String address);
@@ -98,7 +99,6 @@ interface IBluetooth
int getInputDeviceConnectionState(in BluetoothDevice device);
boolean setInputDevicePriority(in BluetoothDevice device, int priority);
int getInputDevicePriority(in BluetoothDevice device);
boolean allowIncomingHidConnect(in BluetoothDevice device, boolean value);
boolean isTetheringOn();
void setBluetoothTethering(boolean value);

View File

@@ -54,7 +54,6 @@ class BluetoothEventLoop {
private final BluetoothAdapter mAdapter;
private final BluetoothAdapterStateMachine mBluetoothState;
private BluetoothA2dp mA2dp;
private BluetoothInputDevice mInputDevice;
private final Context mContext;
// The WakeLock is used for bringing up the LCD during a pairing request
// from remote device when Android is in Suspend state.
@@ -134,15 +133,11 @@ class BluetoothEventLoop {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.A2DP) {
mA2dp = (BluetoothA2dp) proxy;
} else if (profile == BluetoothProfile.INPUT_DEVICE) {
mInputDevice = (BluetoothInputDevice) proxy;
}
}
public void onServiceDisconnected(int profile) {
if (profile == BluetoothProfile.A2DP) {
mA2dp = null;
} else if (profile == BluetoothProfile.INPUT_DEVICE) {
mInputDevice = null;
}
}
};
@@ -803,21 +798,25 @@ class BluetoothEventLoop {
"Incoming A2DP / AVRCP connection from " + address);
mA2dp.allowIncomingConnect(device, authorized);
}
} else if (mInputDevice != null && BluetoothUuid.isInputDevice(uuid)) {
} else if (BluetoothUuid.isInputDevice(uuid)) {
// We can have more than 1 input device connected.
authorized = mInputDevice.getPriority(device) > BluetoothInputDevice.PRIORITY_OFF;
if (authorized) {
Log.i(TAG, "First check pass for incoming HID connection from " + address);
// notify profile state change
mBluetoothService.notifyIncomingHidConnection(address);
} else {
Log.i(TAG, "Rejecting incoming HID connection from " + address);
mBluetoothService.allowIncomingHidConnect(device, authorized);
}
} else if (BluetoothUuid.isBnep(uuid) && mBluetoothService.allowIncomingTethering()){
authorized = true;
authorized = mBluetoothService.getInputDevicePriority(device) >
BluetoothInputDevice.PRIORITY_OFF;
if (authorized) {
Log.i(TAG, "First check pass for incoming HID connection from " + address);
// notify profile state change
mBluetoothService.notifyIncomingHidConnection(address);
} else {
Log.i(TAG, "Rejecting incoming HID connection from " + address);
mBluetoothService.allowIncomingProfileConnect(device, authorized);
}
} else if (BluetoothUuid.isBnep(uuid)) {
// PAN doesn't go to the state machine, accept or reject from here
authorized = mBluetoothService.allowIncomingTethering();
mBluetoothService.allowIncomingProfileConnect(device, authorized);
} else {
Log.i(TAG, "Rejecting incoming " + deviceUuid + " connection from " + address);
mBluetoothService.allowIncomingProfileConnect(device, authorized);
}
log("onAgentAuthorize(" + objectPath + ", " + deviceUuid + ") = " + authorized);
}

View File

@@ -2113,7 +2113,16 @@ public class BluetoothService extends IBluetooth.Stub {
}
}
public boolean allowIncomingHidConnect(BluetoothDevice device, boolean allow) {
/**
* Handle incoming profile acceptance for profiles handled by Bluetooth Service,
* currently PAN and HID. This also is the catch all for all rejections for profiles
* that is not supported.
*
* @param device - Bluetooth Device
* @param allow - true / false
* @return
*/
public boolean allowIncomingProfileConnect(BluetoothDevice device, boolean allow) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
String address = device.getAddress();
@@ -2123,11 +2132,11 @@ public class BluetoothService extends IBluetooth.Stub {
Integer data = getAuthorizationAgentRequestData(address);
if (data == null) {
Log.w(TAG, "allowIncomingHidConnect(" + device +
Log.w(TAG, "allowIncomingProfileConnect(" + device +
") called but no native data available");
return false;
}
if (DBG) log("allowIncomingHidConnect: " + device + " : " + allow + " : " + data);
if (DBG) log("allowIncomingProfileConnect: " + device + " : " + allow + " : " + data);
return setAuthorizationNative(address, allow, data.intValue());
}