diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothDevice.java | 27 | ||||
| -rw-r--r-- | core/java/android/bluetooth/IBluetooth.aidl | 2 | ||||
| -rw-r--r-- | core/java/android/server/BluetoothEventLoop.java | 5 | ||||
| -rw-r--r-- | core/java/android/server/BluetoothService.java | 37 |
4 files changed, 71 insertions, 0 deletions
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index 0a71961992b0..0ec3243fd68b 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -266,6 +266,33 @@ public final class BluetoothDevice implements Parcelable { return BluetoothError.ERROR_IPC; } + /** + * Get trust state of a remote device. + * @hide + */ + public boolean getTrustState() { + try { + return sService.getTrustState(mAddress); + } catch (RemoteException e) { + Log.e(TAG, "", e); + } + return false; + } + + /** + * Set trust state for a remote device. + * @param value the trust state value (true or false) + * @hide + */ + public boolean setTrust(boolean value) { + try { + return sService.setTrust(mAddress, value); + } catch (RemoteException e) { + Log.e(TAG, "", e); + } + return false; + } + /** @hide */ public int getBluetoothClass() { try { diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl index 9e05a871d418..a11ceac0983f 100644 --- a/core/java/android/bluetooth/IBluetooth.aidl +++ b/core/java/android/bluetooth/IBluetooth.aidl @@ -58,4 +58,6 @@ interface IBluetooth boolean setPairingConfirmation(in String address, boolean confirm); boolean cancelPairingUserInput(in String address); + boolean setTrust(in String address, in boolean value); + boolean getTrustState(in String address); } diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index 79a7cf850855..8cef3a20eeba 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -347,7 +347,12 @@ class BluetoothEventLoop { } else { mBluetoothService.getBondState().setBondState(address, BluetoothDevice.BOND_NOT_BONDED); + mBluetoothService.setRemoteDeviceProperty(address, "Trusted", "false"); } + } else if (name.equals("Trusted")) { + if (DBG) + log("set trust state succeded, value is " + propValues[1]); + mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); } } diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index 21104c81c604..b16885000f52 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -885,6 +885,42 @@ public class BluetoothService extends IBluetooth.Stub { } /** + * Sets the remote device trust state. + * + * @return boolean to indicate operation success or fail + */ + public synchronized boolean setTrust(String address, boolean value) { + if (!BluetoothDevice.checkBluetoothAddress(address)) { + mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + return false; + } + + return setDevicePropertyBooleanNative(getObjectPathFromAddress(address), "Trusted", + value ? 1 : 0); + } + + /** + * Gets the remote device trust state as boolean. + * Note: this value may be + * retrieved from cache if we retrieved the data before * + * + * @return boolean to indicate trust or untrust state + */ + public synchronized boolean getTrustState(String address) { + if (!BluetoothDevice.checkBluetoothAddress(address)) { + mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + return false; + } + + String val = getRemoteDeviceProperty(address, "Trusted"); + if (val == null) { + return false; + } else { + return val.equals("true") ? true : false; + } + } + + /** * Gets the remote major, minor classes encoded as a 32-bit * integer. * @@ -1220,5 +1256,6 @@ public class BluetoothService extends IBluetooth.Stub { private native boolean setPasskeyNative(String address, int passkey, int nativeData); private native boolean setPairingConfirmationNative(String address, boolean confirm, int nativeData); + private native boolean setDevicePropertyBooleanNative(String objectPath, String key, int value); } |
