diff --git a/api/system-current.txt b/api/system-current.txt index 3a71189a46145..6ee98a7c0b9ba 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -615,6 +615,7 @@ package android.bluetooth { public final class BluetoothAdapter { method public boolean disableBLE(); method public boolean enableBLE(); + method public boolean enableNoAutoConnect(); method public boolean isBleScanAlwaysAvailable(); method public boolean isLeEnabled(); field public static final java.lang.String ACTION_BLE_STATE_CHANGED = "android.bluetooth.adapter.action.BLE_STATE_CHANGED"; @@ -622,8 +623,17 @@ package android.bluetooth { } public final class BluetoothDevice implements android.os.Parcelable { + method public boolean cancelBondProcess(); method public boolean isConnected(); method public boolean isEncrypted(); + method public boolean removeBond(); + method public boolean setPhonebookAccessPermission(int); + } + + public final class BluetoothHeadset implements android.bluetooth.BluetoothProfile { + method public boolean connect(android.bluetooth.BluetoothDevice); + method public boolean disconnect(android.bluetooth.BluetoothDevice); + method public boolean setPriority(android.bluetooth.BluetoothDevice, int); } } diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 158aebb478ac5..c7be0f36ecefc 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -2425,6 +2425,8 @@ public final class BluetoothAdapter { * * @hide */ + @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean enableNoAutoConnect() { if (isEnabled()) { if (DBG) { diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index d982bb7ffb43c..ad7a93cd6bbd4 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -1098,6 +1098,8 @@ public final class BluetoothDevice implements Parcelable { * @return true on success, false on error * @hide */ + @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean cancelBondProcess() { final IBluetooth service = sService; if (service == null) { @@ -1125,6 +1127,8 @@ public final class BluetoothDevice implements Parcelable { * @return true on success, false on error * @hide */ + @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean removeBond() { final IBluetooth service = sService; if (service == null) { @@ -1174,6 +1178,7 @@ public final class BluetoothDevice implements Parcelable { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean isConnected() { final IBluetooth service = sService; if (service == null) { @@ -1197,6 +1202,7 @@ public final class BluetoothDevice implements Parcelable { * @hide */ @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean isEncrypted() { final IBluetooth service = sService; if (service == null) { @@ -1444,6 +1450,8 @@ public final class BluetoothDevice implements Parcelable { * @return Whether the value has been successfully set. * @hide */ + @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setPhonebookAccessPermission(int value) { final IBluetooth service = sService; if (service == null) { diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java index 90ae0e6313dcd..55a6b4c6b4d4e 100644 --- a/core/java/android/bluetooth/BluetoothHeadset.java +++ b/core/java/android/bluetooth/BluetoothHeadset.java @@ -16,8 +16,11 @@ package android.bluetooth; +import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; +import android.annotation.SystemApi; import android.content.ComponentName; import android.content.Context; import android.os.Binder; @@ -91,6 +94,23 @@ public final class BluetoothHeadset implements BluetoothProfile { public static final String ACTION_AUDIO_STATE_CHANGED = "android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED"; + /** + * Intent used to broadcast the selection of a connected device as active. + * + *

This intent will have one extra: + *

+ * + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission to + * receive. + * + * @hide + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_ACTIVE_DEVICE_CHANGED = + "android.bluetooth.headset.profile.action.ACTIVE_DEVICE_CHANGED"; /** * Intent used to broadcast that the headset has posted a @@ -416,6 +436,8 @@ public final class BluetoothHeadset implements BluetoothProfile { * @return false on immediate error, true otherwise * @hide */ + @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean connect(BluetoothDevice device) { if (DBG) log("connect(" + device + ")"); final IBluetoothHeadset service = mService; @@ -456,6 +478,8 @@ public final class BluetoothHeadset implements BluetoothProfile { * @return false on immediate error, true otherwise * @hide */ + @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean disconnect(BluetoothDevice device) { if (DBG) log("disconnect(" + device + ")"); final IBluetoothHeadset service = mService; @@ -543,6 +567,8 @@ public final class BluetoothHeadset implements BluetoothProfile { * @return true if priority is set, false on error * @hide */ + @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setPriority(BluetoothDevice device, int priority) { if (DBG) log("setPriority(" + device + ", " + priority + ")"); final IBluetoothHeadset service = mService; @@ -974,6 +1000,76 @@ public final class BluetoothHeadset implements BluetoothProfile { return false; } + /** + * Select a connected device as active. + * + * The active device selection is per profile. An active device's + * purpose is profile-specific. For example, in HFP and HSP profiles, + * it is the device used for phone call audio. If a remote device is not + * connected, it cannot be selected as active. + * + *

This API returns false in scenarios like the profile on the + * device is not connected or Bluetooth is not turned on. + * When this API returns true, it is guaranteed that the + * {@link #ACTION_ACTIVE_DEVICE_CHANGED} intent will be broadcasted + * with the active device. + * + *

Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} + * permission. + * + * @param device Remote Bluetooth Device, could be null if phone call audio should not be + * streamed to a headset + * @return false on immediate error, true otherwise + * @hide + */ + @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) + public boolean setActiveDevice(@Nullable BluetoothDevice device) { + if (DBG) { + Log.d(TAG, "setActiveDevice: " + device); + } + final IBluetoothHeadset service = mService; + if (service != null && isEnabled() && (device == null || isValidDevice(device))) { + try { + return service.setActiveDevice(device); + } catch (RemoteException e) { + Log.e(TAG, Log.getStackTraceString(new Throwable())); + } + } + if (service == null) { + Log.w(TAG, "Proxy not attached to service"); + } + return false; + } + + /** + * Get the connected device that is active. + * + *

Requires {@link android.Manifest.permission#BLUETOOTH} + * permission. + * + * @return the connected device that is active or null if no device + * is active. + * @hide + */ + @RequiresPermission(android.Manifest.permission.BLUETOOTH) + public BluetoothDevice getActiveDevice() { + if (VDBG) { + Log.d(TAG, "getActiveDevice"); + } + final IBluetoothHeadset service = mService; + if (service != null && isEnabled()) { + try { + return service.getActiveDevice(); + } catch (RemoteException e) { + Log.e(TAG, Log.getStackTraceString(new Throwable())); + } + } + if (service == null) { + Log.w(TAG, "Proxy not attached to service"); + } + return null; + } + /** * check if in-band ringing is supported for this platform. * diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 390d31250c2df..323bb794eb7f5 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -158,6 +158,8 @@ android:name="android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT" /> +