diff options
author | Rahul Sabnis <rahulsabnis@google.com> | 2020-01-07 12:56:19 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2020-01-07 12:56:19 -0800 |
commit | 53c8e6cbc0dcdeac787b707728922ccfd1c0f482 (patch) | |
tree | fe98a54b02e1505a5f27b436c7cd11d6ca9c71f6 | |
parent | 6aca95071a3646df15648462020b1ce988906405 (diff) | |
parent | c0c8c00976aa69a2739b354ce406061f04ed0f3c (diff) | |
download | base-tmp_b_147314974.tar.gz |
Merge "Add setConnectionPolicy to BluetoothPbap"tmp_b_147314974
am: c0c8c00976
Change-Id: I96a64f6a86392f1140884fc03f8059b5590e8736
-rwxr-xr-x | api/system-current.txt | 1 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothPbap.java | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index 4a9154ee9875..e62360ef393b 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -1429,6 +1429,7 @@ package android.bluetooth { public class BluetoothPbap implements android.bluetooth.BluetoothProfile { method public int getConnectionState(@Nullable android.bluetooth.BluetoothDevice); + method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int); field public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.pbap.profile.action.CONNECTION_STATE_CHANGED"; } diff --git a/core/java/android/bluetooth/BluetoothPbap.java b/core/java/android/bluetooth/BluetoothPbap.java index df0289643ee0..291015070385 100644 --- a/core/java/android/bluetooth/BluetoothPbap.java +++ b/core/java/android/bluetooth/BluetoothPbap.java @@ -16,7 +16,10 @@ package android.bluetooth; +import android.Manifest; +import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SuppressLint; import android.annotation.SystemApi; @@ -271,6 +274,42 @@ public class BluetoothPbap implements BluetoothProfile { } /** + * Pbap does not store connection policy, so this function only disconnects Pbap if + * connectionPolicy is CONNECTION_POLICY_FORBIDDEN. + * + * <p> The device should already be paired. + * Connection policy can be one of {@link #CONNECTION_POLICY_ALLOWED}, + * {@link #CONNECTION_POLICY_FORBIDDEN}, {@link #CONNECTION_POLICY_UNKNOWN} + * + * @param device Paired bluetooth device + * @param connectionPolicy is the connection policy to set to for this profile + * @return true if pbap is successfully disconnected, false otherwise + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) + public boolean setConnectionPolicy(@NonNull BluetoothDevice device, + @ConnectionPolicy int connectionPolicy) { + if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); + try { + final IBluetoothPbap service = mService; + if (service != null && isEnabled() + && isValidDevice(device)) { + if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN + && connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) { + return false; + } + return service.setConnectionPolicy(device, connectionPolicy); + } + if (service == null) Log.w(TAG, "Proxy not attached to service"); + return false; + } catch (RemoteException e) { + Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); + return false; + } + } + + /** * Disconnects the current Pbap client (PCE). Currently this call blocks, * it may soon be made asynchronous. Returns false if this proxy object is * not currently connected to the Pbap service. |