Loading core/java/android/bluetooth/BluetoothDevice.java +25 −2 Original line number Diff line number Diff line Loading @@ -74,6 +74,14 @@ public class BluetoothDevice { /** An existing bond was explicitly revoked */ public static final int UNBOND_REASON_REMOVED = 6; /* The user will be prompted to enter a pin */ public static final int PAIRING_VARIANT_PIN = 0; /* The user will be prompted to enter a passkey */ public static final int PAIRING_VARIANT_PASSKEY = 1; /* The user will be prompted to confirm the passkey displayed on the screen */ public static final int PAIRING_VARIANT_CONFIRMATION = 2; private static final String TAG = "BluetoothDevice"; private final IBluetoothDevice mService; Loading Loading @@ -358,9 +366,24 @@ public class BluetoothDevice { } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } public boolean cancelPin(String address) { public boolean setPasskey(String address, int passkey) { try { return mService.setPasskey(address, passkey); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } public boolean setPairingConfirmation(String address, boolean confirm) { try { return mService.setPairingConfirmation(address, confirm); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } public boolean cancelPairingUserInput(String address) { try { return mService.cancelPin(address); return mService.cancelPairingUserInput(address); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } Loading core/java/android/bluetooth/BluetoothIntent.java +4 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,10 @@ public interface BluetoothIntent { "android.bluetooth.intent.BOND_PREVIOUS_STATE"; public static final String REASON = "android.bluetooth.intent.REASON"; public static final String PAIRING_VARIANT = "android.bluetooth.intent.PAIRING_VARIANT"; public static final String PASSKEY = "android.bluetooth.intent.PASSKEY"; /** Broadcast when the local Bluetooth device state changes, for example * when Bluetooth is enabled. Will contain int extra's BLUETOOTH_STATE and Loading core/java/android/bluetooth/IBluetoothDevice.aidl +4 −1 Original line number Diff line number Diff line Loading @@ -54,5 +54,8 @@ interface IBluetoothDevice int getRemoteServiceChannel(in String address, String uuid); boolean setPin(in String address, in byte[] pin); boolean cancelPin(in String address); boolean setPasskey(in String address, int passkey); boolean setPairingConfirmation(in String address, boolean confirm); boolean cancelPairingUserInput(in String address); } core/java/android/server/BluetoothDeviceService.java +40 −6 Original line number Diff line number Diff line Loading @@ -959,21 +959,52 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub { return setPinNative(address, pinString, data.intValue()); } public synchronized boolean cancelPin(String address) { public synchronized boolean setPasskey(String address, int passkey) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); if (!BluetoothDevice.checkBluetoothAddress(address)) { if (passkey < 0 || passkey > 999999 || !BluetoothDevice.checkBluetoothAddress(address)) { return false; } address = address.toUpperCase(); Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address); if (data == null) { Log.w(TAG, "cancelPin(" + address + ") called but no native data available, " + "ignoring. Maybe the PasskeyAgent Request was already cancelled by the remote " + Log.w(TAG, "setPasskey(" + address + ") called but no native data available, " + "ignoring. Maybe the PasskeyAgent Request was cancelled by the remote device" + " or by bluez.\n"); return false; } return setPasskeyNative(address, passkey, data.intValue()); } public synchronized boolean setPairingConfirmation(String address, boolean confirm) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); address = address.toUpperCase(); Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address); if (data == null) { Log.w(TAG, "setPasskey(" + address + ") called but no native data available, " + "ignoring. Maybe the PasskeyAgent Request was cancelled by the remote device" + " or by bluez.\n"); return false; } return cancelPinNative(address, data.intValue()); return setPairingConfirmationNative(address, confirm, data.intValue()); } public synchronized boolean cancelPairingUserInput(String address) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); if (!BluetoothDevice.checkBluetoothAddress(address)) { return false; } address = address.toUpperCase(); Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address); if (data == null) { Log.w(TAG, "cancelUserInputNative(" + address + ") called but no native data " + "available, ignoring. Maybe the PasskeyAgent Request was already cancelled " + "by the remote or by bluez.\n"); return false; } return cancelPairingUserInputNative(address, data.intValue()); } private final BroadcastReceiver mReceiver = new BroadcastReceiver() { Loading Loading @@ -1160,7 +1191,10 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub { private native int getDeviceServiceChannelNative(String objectPath, String uuid, int attributeId); private native boolean cancelPinNative(String address, int nativeData); private native boolean cancelPairingUserInputNative(String address, int nativeData); private native boolean setPinNative(String address, String pin, int nativeData); private native boolean setPasskeyNative(String address, int passkey, int nativeData); private native boolean setPairingConfirmationNative(String address, boolean confirm, int nativeData); } core/java/android/server/BluetoothEventLoop.java +40 −9 Original line number Diff line number Diff line Loading @@ -317,24 +317,54 @@ class BluetoothEventLoop { } mBluetoothService.setRemoteDeviceProperty(address, name, uuid); } } private void onRequestPinCode(String objectPath, int nativeData) { private String checkPairingRequestAndGetAddress(String objectPath, int nativeData) { String address = mBluetoothService.getAddressFromObjectPath(objectPath); if (address == null) { Log.e(TAG, "Unable to get device address in onRequestPinCode, returning null"); return; Log.e(TAG, "Unable to get device address in checkPairingRequestAndGetAddress, " + "returning null"); return null; } address = address.toUpperCase(); mPasskeyAgentRequestData.put(address, new Integer(nativeData)); if (mBluetoothService.getBluetoothState() == BluetoothDevice.BLUETOOTH_STATE_TURNING_OFF) { // shutdown path mBluetoothService.cancelPin(address); mBluetoothService.cancelPairingUserInput(address); return null; } return address; } private void onRequestConfirmation(String objectPath, int passkey, int nativeData) { String address = checkPairingRequestAndGetAddress(objectPath, nativeData); if (address == null) return; Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION); intent.putExtra(BluetoothIntent.ADDRESS, address); intent.putExtra(BluetoothIntent.PASSKEY, passkey); intent.putExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_CONFIRMATION); mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); return; } private void onRequestPasskey(String objectPath, int nativeData) { String address = checkPairingRequestAndGetAddress(objectPath, nativeData); if (address == null) return; Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION); intent.putExtra(BluetoothIntent.ADDRESS, address); intent.putExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PASSKEY); mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); return; } private void onRequestPinCode(String objectPath, int nativeData) { String address = checkPairingRequestAndGetAddress(objectPath, nativeData); if (address == null) return; if (mBluetoothService.getBondState().getBondState(address) == BluetoothDevice.BOND_BONDING) { // we initiated the bonding Loading @@ -358,6 +388,7 @@ class BluetoothEventLoop { } Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION); intent.putExtra(BluetoothIntent.ADDRESS, address); intent.putExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PIN); mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); return; } Loading Loading @@ -386,9 +417,9 @@ class BluetoothEventLoop { } private void onAgentCancel() { // We immediately response to DBUS Authorize() so this should not // usually happen log("onAgentCancel"); Intent intent = new Intent(BluetoothIntent.PAIRING_CANCEL_ACTION); mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); return; } private void onRestartRequired() { Loading Loading
core/java/android/bluetooth/BluetoothDevice.java +25 −2 Original line number Diff line number Diff line Loading @@ -74,6 +74,14 @@ public class BluetoothDevice { /** An existing bond was explicitly revoked */ public static final int UNBOND_REASON_REMOVED = 6; /* The user will be prompted to enter a pin */ public static final int PAIRING_VARIANT_PIN = 0; /* The user will be prompted to enter a passkey */ public static final int PAIRING_VARIANT_PASSKEY = 1; /* The user will be prompted to confirm the passkey displayed on the screen */ public static final int PAIRING_VARIANT_CONFIRMATION = 2; private static final String TAG = "BluetoothDevice"; private final IBluetoothDevice mService; Loading Loading @@ -358,9 +366,24 @@ public class BluetoothDevice { } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } public boolean cancelPin(String address) { public boolean setPasskey(String address, int passkey) { try { return mService.setPasskey(address, passkey); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } public boolean setPairingConfirmation(String address, boolean confirm) { try { return mService.setPairingConfirmation(address, confirm); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } public boolean cancelPairingUserInput(String address) { try { return mService.cancelPin(address); return mService.cancelPairingUserInput(address); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } Loading
core/java/android/bluetooth/BluetoothIntent.java +4 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,10 @@ public interface BluetoothIntent { "android.bluetooth.intent.BOND_PREVIOUS_STATE"; public static final String REASON = "android.bluetooth.intent.REASON"; public static final String PAIRING_VARIANT = "android.bluetooth.intent.PAIRING_VARIANT"; public static final String PASSKEY = "android.bluetooth.intent.PASSKEY"; /** Broadcast when the local Bluetooth device state changes, for example * when Bluetooth is enabled. Will contain int extra's BLUETOOTH_STATE and Loading
core/java/android/bluetooth/IBluetoothDevice.aidl +4 −1 Original line number Diff line number Diff line Loading @@ -54,5 +54,8 @@ interface IBluetoothDevice int getRemoteServiceChannel(in String address, String uuid); boolean setPin(in String address, in byte[] pin); boolean cancelPin(in String address); boolean setPasskey(in String address, int passkey); boolean setPairingConfirmation(in String address, boolean confirm); boolean cancelPairingUserInput(in String address); }
core/java/android/server/BluetoothDeviceService.java +40 −6 Original line number Diff line number Diff line Loading @@ -959,21 +959,52 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub { return setPinNative(address, pinString, data.intValue()); } public synchronized boolean cancelPin(String address) { public synchronized boolean setPasskey(String address, int passkey) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); if (!BluetoothDevice.checkBluetoothAddress(address)) { if (passkey < 0 || passkey > 999999 || !BluetoothDevice.checkBluetoothAddress(address)) { return false; } address = address.toUpperCase(); Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address); if (data == null) { Log.w(TAG, "cancelPin(" + address + ") called but no native data available, " + "ignoring. Maybe the PasskeyAgent Request was already cancelled by the remote " + Log.w(TAG, "setPasskey(" + address + ") called but no native data available, " + "ignoring. Maybe the PasskeyAgent Request was cancelled by the remote device" + " or by bluez.\n"); return false; } return setPasskeyNative(address, passkey, data.intValue()); } public synchronized boolean setPairingConfirmation(String address, boolean confirm) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); address = address.toUpperCase(); Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address); if (data == null) { Log.w(TAG, "setPasskey(" + address + ") called but no native data available, " + "ignoring. Maybe the PasskeyAgent Request was cancelled by the remote device" + " or by bluez.\n"); return false; } return cancelPinNative(address, data.intValue()); return setPairingConfirmationNative(address, confirm, data.intValue()); } public synchronized boolean cancelPairingUserInput(String address) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); if (!BluetoothDevice.checkBluetoothAddress(address)) { return false; } address = address.toUpperCase(); Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address); if (data == null) { Log.w(TAG, "cancelUserInputNative(" + address + ") called but no native data " + "available, ignoring. Maybe the PasskeyAgent Request was already cancelled " + "by the remote or by bluez.\n"); return false; } return cancelPairingUserInputNative(address, data.intValue()); } private final BroadcastReceiver mReceiver = new BroadcastReceiver() { Loading Loading @@ -1160,7 +1191,10 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub { private native int getDeviceServiceChannelNative(String objectPath, String uuid, int attributeId); private native boolean cancelPinNative(String address, int nativeData); private native boolean cancelPairingUserInputNative(String address, int nativeData); private native boolean setPinNative(String address, String pin, int nativeData); private native boolean setPasskeyNative(String address, int passkey, int nativeData); private native boolean setPairingConfirmationNative(String address, boolean confirm, int nativeData); }
core/java/android/server/BluetoothEventLoop.java +40 −9 Original line number Diff line number Diff line Loading @@ -317,24 +317,54 @@ class BluetoothEventLoop { } mBluetoothService.setRemoteDeviceProperty(address, name, uuid); } } private void onRequestPinCode(String objectPath, int nativeData) { private String checkPairingRequestAndGetAddress(String objectPath, int nativeData) { String address = mBluetoothService.getAddressFromObjectPath(objectPath); if (address == null) { Log.e(TAG, "Unable to get device address in onRequestPinCode, returning null"); return; Log.e(TAG, "Unable to get device address in checkPairingRequestAndGetAddress, " + "returning null"); return null; } address = address.toUpperCase(); mPasskeyAgentRequestData.put(address, new Integer(nativeData)); if (mBluetoothService.getBluetoothState() == BluetoothDevice.BLUETOOTH_STATE_TURNING_OFF) { // shutdown path mBluetoothService.cancelPin(address); mBluetoothService.cancelPairingUserInput(address); return null; } return address; } private void onRequestConfirmation(String objectPath, int passkey, int nativeData) { String address = checkPairingRequestAndGetAddress(objectPath, nativeData); if (address == null) return; Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION); intent.putExtra(BluetoothIntent.ADDRESS, address); intent.putExtra(BluetoothIntent.PASSKEY, passkey); intent.putExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_CONFIRMATION); mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); return; } private void onRequestPasskey(String objectPath, int nativeData) { String address = checkPairingRequestAndGetAddress(objectPath, nativeData); if (address == null) return; Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION); intent.putExtra(BluetoothIntent.ADDRESS, address); intent.putExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PASSKEY); mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); return; } private void onRequestPinCode(String objectPath, int nativeData) { String address = checkPairingRequestAndGetAddress(objectPath, nativeData); if (address == null) return; if (mBluetoothService.getBondState().getBondState(address) == BluetoothDevice.BOND_BONDING) { // we initiated the bonding Loading @@ -358,6 +388,7 @@ class BluetoothEventLoop { } Intent intent = new Intent(BluetoothIntent.PAIRING_REQUEST_ACTION); intent.putExtra(BluetoothIntent.ADDRESS, address); intent.putExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PIN); mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); return; } Loading Loading @@ -386,9 +417,9 @@ class BluetoothEventLoop { } private void onAgentCancel() { // We immediately response to DBUS Authorize() so this should not // usually happen log("onAgentCancel"); Intent intent = new Intent(BluetoothIntent.PAIRING_CANCEL_ACTION); mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM); return; } private void onRestartRequired() { Loading