Merge "Add setConnectionPolicy to HidDevice and Pan. Clean up documentation for the method in Pbap." am: 06410db097 am: 20acd0b7a7
Change-Id: I3ea4fa8fa743c159c1aef5d7f80bc42ebc8d7d70
This commit is contained in:
@@ -1413,6 +1413,10 @@ package android.bluetooth {
|
||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
|
||||
}
|
||||
|
||||
public final class BluetoothHidDevice implements android.bluetooth.BluetoothProfile {
|
||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
|
||||
}
|
||||
|
||||
public final class BluetoothHidHost implements android.bluetooth.BluetoothProfile {
|
||||
method @NonNull public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
|
||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice);
|
||||
@@ -1427,6 +1431,7 @@ package android.bluetooth {
|
||||
method public int getConnectionState(@Nullable android.bluetooth.BluetoothDevice);
|
||||
method public boolean isTetheringOn();
|
||||
method public void setBluetoothTethering(boolean);
|
||||
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.pan.profile.action.CONNECTION_STATE_CHANGED";
|
||||
field public static final String EXTRA_LOCAL_ROLE = "android.bluetooth.pan.extra.LOCAL_ROLE";
|
||||
field public static final int LOCAL_NAP_ROLE = 1; // 0x1
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
|
||||
package android.bluetooth;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.annotation.SystemApi;
|
||||
import android.content.Context;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
@@ -36,6 +40,7 @@ import java.util.concurrent.Executor;
|
||||
*/
|
||||
public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
private static final String TAG = BluetoothHidDevice.class.getSimpleName();
|
||||
private static final boolean DBG = false;
|
||||
|
||||
/**
|
||||
* Intent used to broadcast the change in connection state of the Input Host profile.
|
||||
@@ -682,4 +687,62 @@ public final class BluetoothHidDevice implements BluetoothProfile {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects Hid Device if connectionPolicy is {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED}
|
||||
* and disconnects Hid device if connectionPolicy is
|
||||
* {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN}.
|
||||
*
|
||||
* <p> The device should already be paired.
|
||||
* Connection policy can be one of:
|
||||
* {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED},
|
||||
* {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN},
|
||||
* {@link BluetoothProfile#CONNECTION_POLICY_UNKNOWN}
|
||||
*
|
||||
* @param device Paired bluetooth device
|
||||
* @param connectionPolicy determines whether hid device should be connected or disconnected
|
||||
* @return true if hid device is connected or disconnected, false otherwise
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
|
||||
@ConnectionPolicy int connectionPolicy) {
|
||||
log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
|
||||
try {
|
||||
final IBluetoothHidDevice service = getService();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEnabled() {
|
||||
if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isValidDevice(BluetoothDevice device) {
|
||||
if (device == null) return false;
|
||||
|
||||
if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void log(String msg) {
|
||||
if (DBG) {
|
||||
Log.d(TAG, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
|
||||
package android.bluetooth;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -255,6 +257,41 @@ public final class BluetoothPan implements BluetoothProfile {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set connection policy of the profile
|
||||
*
|
||||
* <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 connectionPolicy is set, false on error
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
|
||||
@ConnectionPolicy int connectionPolicy) {
|
||||
if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
|
||||
try {
|
||||
final IBluetoothPan service = getService();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -274,15 +274,15 @@ public class BluetoothPbap implements BluetoothProfile {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pbap does not store connection policy, so this function only disconnects Pbap if
|
||||
* connectionPolicy is CONNECTION_POLICY_FORBIDDEN.
|
||||
* Pbap does not store connection policy, so this function only disconnects pbap if
|
||||
* connectionPolicy is {@link #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
|
||||
* @param connectionPolicy determines whether to disconnect the device
|
||||
* @return true if pbap is successfully disconnected, false otherwise
|
||||
* @hide
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user