From 31bcaf44ae6ddd977d475d14509bb3e92fd2daa2 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Thu, 9 Dec 2021 20:00:08 +0000 Subject: [PATCH] Revert "Complete hard removal of BluetoothHeadset#setPriority system API that" This reverts commit 7407887e0005af63add9aec07242094da5515bd2. Bug: 209335798 Test: Manual Reason for revert: Failing signature test that will be updated by paulduffin@ Change-Id: I9de1b07f2d0f4d01d9e3b57a6ddf8a4232db29b6 --- core/api/system-removed.txt | 8 ++++ .../android/bluetooth/BluetoothHeadset.java | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/core/api/system-removed.txt b/core/api/system-removed.txt index 2c5acf182d51f..9cb9ddcc6280a 100644 --- a/core/api/system-removed.txt +++ b/core/api/system-removed.txt @@ -60,6 +60,14 @@ package android.app.search { } +package android.bluetooth { + + public final class BluetoothHeadset implements android.bluetooth.BluetoothProfile { + method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean setPriority(android.bluetooth.BluetoothDevice, int); + } + +} + package android.content { public class Intent implements java.lang.Cloneable android.os.Parcelable { diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java index 8212eaa4e47aa..c0463243f41d5 100644 --- a/core/java/android/bluetooth/BluetoothHeadset.java +++ b/core/java/android/bluetooth/BluetoothHeadset.java @@ -600,6 +600,49 @@ public final class BluetoothHeadset implements BluetoothProfile { return BluetoothProfile.STATE_DISCONNECTED; } + /** + * Set priority of the profile + * + *

The device should already be paired. + * Priority can be one of {@link BluetoothProfile#PRIORITY_ON} or + * {@link BluetoothProfile#PRIORITY_OFF} + * + * @param device Paired bluetooth device + * @param priority + * @return true if priority is set, false on error + * @hide + * @deprecated Replaced with {@link #setConnectionPolicy(BluetoothDevice, int)} + * @removed + */ + @Deprecated + @SystemApi + @RequiresLegacyBluetoothAdminPermission + @RequiresBluetoothConnectPermission + @RequiresPermission(allOf = { + android.Manifest.permission.BLUETOOTH_CONNECT, + android.Manifest.permission.MODIFY_PHONE_STATE, + }) + public boolean setPriority(BluetoothDevice device, int priority) { + if (DBG) log("setPriority(" + device + ", " + priority + ")"); + final IBluetoothHeadset service = mService; + if (service != null && isEnabled() && isValidDevice(device)) { + if (priority != BluetoothProfile.PRIORITY_OFF + && priority != BluetoothProfile.PRIORITY_ON) { + return false; + } + try { + return service.setPriority( + device, BluetoothAdapter.priorityToConnectionPolicy(priority), + mAttributionSource); + } catch (RemoteException e) { + Log.e(TAG, Log.getStackTraceString(new Throwable())); + return false; + } + } + if (service == null) Log.w(TAG, "Proxy not attached to service"); + return false; + } + /** * Set connection policy of the profile *