Revert "Revert "Make close part of the BluetoothProfile interface""

This reverts commit fbbbc47bd1982d6a796ec217e65f823070e5fc30.

Reason for revert: Fixed the failing test in the re-revert's topic.
Test: atest CtsBluetoothTestCases FrameworkBluetoothTests SignatureMultiLibsTest
Change-Id: I8096625c93b2c101dabf3b368418d36d92416477
diff --git a/framework/java/android/bluetooth/BluetoothA2dp.java b/framework/java/android/bluetooth/BluetoothA2dp.java
index 8977e9e..c74c1fb 100644
--- a/framework/java/android/bluetooth/BluetoothA2dp.java
+++ b/framework/java/android/bluetooth/BluetoothA2dp.java
@@ -47,7 +47,6 @@
 import java.util.List;
 import java.util.concurrent.TimeoutException;
 
-
 /**
  * This class provides the public APIs to control the Bluetooth A2DP
  * profile.
@@ -290,8 +289,12 @@
         mProfileConnector.connect(context, listener);
     }
 
+    /**
+     * @hide
+     */
     @UnsupportedAppUsage
-    /*package*/ void close() {
+    @Override
+    public void close() {
         mProfileConnector.disconnect();
     }
 
diff --git a/framework/java/android/bluetooth/BluetoothA2dpSink.java b/framework/java/android/bluetooth/BluetoothA2dpSink.java
index 67042de..c299b17 100755
--- a/framework/java/android/bluetooth/BluetoothA2dpSink.java
+++ b/framework/java/android/bluetooth/BluetoothA2dpSink.java
@@ -105,7 +105,9 @@
         mProfileConnector.connect(context, listener);
     }
 
-    /*package*/ void close() {
+    /** @hide */
+    @Override
+    public void close() {
         mProfileConnector.disconnect();
     }
 
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index 8746367..fb1b4d7 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -3750,118 +3750,19 @@
     /**
      * Close the connection of the profile proxy to the Service.
      *
-     * <p> Clients should call this when they are no longer using
-     * the proxy obtained from {@link #getProfileProxy}.
-     * Profile can be one of  {@link BluetoothProfile#HEADSET} or {@link BluetoothProfile#A2DP}
+     * <p>Clients should call this when they are no longer using the proxy obtained from {@link
+     * #getProfileProxy}. Profile can be one of {@link BluetoothProfile#HEADSET} or {@link
+     * BluetoothProfile#A2DP}
      *
-     * @param profile
+     * @param unusedProfile
      * @param proxy Profile proxy object
      */
-    @SuppressLint({
-            "AndroidFrameworkRequiresPermission",
-            "AndroidFrameworkBluetoothPermission"
-    })
-    public void closeProfileProxy(int profile, BluetoothProfile proxy) {
+    @SuppressLint({"AndroidFrameworkRequiresPermission", "AndroidFrameworkBluetoothPermission"})
+    public void closeProfileProxy(int unusedProfile, BluetoothProfile proxy) {
         if (proxy == null) {
             return;
         }
-
-        switch (profile) {
-            case BluetoothProfile.HEADSET:
-                BluetoothHeadset headset = (BluetoothHeadset) proxy;
-                headset.close();
-                break;
-            case BluetoothProfile.A2DP:
-                BluetoothA2dp a2dp = (BluetoothA2dp) proxy;
-                a2dp.close();
-                break;
-            case BluetoothProfile.A2DP_SINK:
-                BluetoothA2dpSink a2dpSink = (BluetoothA2dpSink) proxy;
-                a2dpSink.close();
-                break;
-            case BluetoothProfile.AVRCP_CONTROLLER:
-                BluetoothAvrcpController avrcp = (BluetoothAvrcpController) proxy;
-                avrcp.close();
-                break;
-            case BluetoothProfile.HID_HOST:
-                BluetoothHidHost iDev = (BluetoothHidHost) proxy;
-                iDev.close();
-                break;
-            case BluetoothProfile.PAN:
-                BluetoothPan pan = (BluetoothPan) proxy;
-                pan.close();
-                break;
-            case BluetoothProfile.PBAP:
-                BluetoothPbap pbap = (BluetoothPbap) proxy;
-                pbap.close();
-                break;
-            case BluetoothProfile.GATT:
-                BluetoothGatt gatt = (BluetoothGatt) proxy;
-                gatt.close();
-                break;
-            case BluetoothProfile.GATT_SERVER:
-                BluetoothGattServer gattServer = (BluetoothGattServer) proxy;
-                gattServer.close();
-                break;
-            case BluetoothProfile.MAP:
-                BluetoothMap map = (BluetoothMap) proxy;
-                map.close();
-                break;
-            case BluetoothProfile.HEADSET_CLIENT:
-                BluetoothHeadsetClient headsetClient = (BluetoothHeadsetClient) proxy;
-                headsetClient.close();
-                break;
-            case BluetoothProfile.SAP:
-                BluetoothSap sap = (BluetoothSap) proxy;
-                sap.close();
-                break;
-            case BluetoothProfile.PBAP_CLIENT:
-                BluetoothPbapClient pbapClient = (BluetoothPbapClient) proxy;
-                pbapClient.close();
-                break;
-            case BluetoothProfile.MAP_CLIENT:
-                BluetoothMapClient mapClient = (BluetoothMapClient) proxy;
-                mapClient.close();
-                break;
-            case BluetoothProfile.HID_DEVICE:
-                BluetoothHidDevice hidDevice = (BluetoothHidDevice) proxy;
-                hidDevice.close();
-                break;
-            case BluetoothProfile.HAP_CLIENT:
-                BluetoothHapClient HapClient = (BluetoothHapClient) proxy;
-                HapClient.close();
-                break;
-            case BluetoothProfile.HEARING_AID:
-                BluetoothHearingAid hearingAid = (BluetoothHearingAid) proxy;
-                hearingAid.close();
-                break;
-            case BluetoothProfile.LE_AUDIO:
-                BluetoothLeAudio leAudio = (BluetoothLeAudio) proxy;
-                leAudio.close();
-                break;
-            case BluetoothProfile.LE_AUDIO_BROADCAST:
-                BluetoothLeBroadcast leAudioBroadcast = (BluetoothLeBroadcast) proxy;
-                leAudioBroadcast.close();
-                break;
-            case BluetoothProfile.VOLUME_CONTROL:
-                BluetoothVolumeControl vcs = (BluetoothVolumeControl) proxy;
-                vcs.close();
-                break;
-            case BluetoothProfile.CSIP_SET_COORDINATOR:
-                BluetoothCsipSetCoordinator csipSetCoordinator =
-                        (BluetoothCsipSetCoordinator) proxy;
-                csipSetCoordinator.close();
-                break;
-            case BluetoothProfile.LE_CALL_CONTROL:
-                BluetoothLeCallControl tbs = (BluetoothLeCallControl) proxy;
-                tbs.close();
-                break;
-            case BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT:
-                BluetoothLeBroadcastAssistant leAudioBroadcastAssistant =
-                        (BluetoothLeBroadcastAssistant) proxy;
-                leAudioBroadcastAssistant.close();
-                break;
-        }
+        proxy.close();
     }
 
     private static final IBluetoothManagerCallback sManagerCallback =
diff --git a/framework/java/android/bluetooth/BluetoothAvrcpController.java b/framework/java/android/bluetooth/BluetoothAvrcpController.java
index 81ad3c6..e442faf 100644
--- a/framework/java/android/bluetooth/BluetoothAvrcpController.java
+++ b/framework/java/android/bluetooth/BluetoothAvrcpController.java
@@ -112,7 +112,9 @@
         mProfileConnector.connect(context, listener);
     }
 
-    /*package*/ void close() {
+    /** @hide */
+    @Override
+    public void close() {
         mProfileConnector.disconnect();
     }
 
diff --git a/framework/java/android/bluetooth/BluetoothCsipSetCoordinator.java b/framework/java/android/bluetooth/BluetoothCsipSetCoordinator.java
index 5f30a98..b9e3bf7 100644
--- a/framework/java/android/bluetooth/BluetoothCsipSetCoordinator.java
+++ b/framework/java/android/bluetooth/BluetoothCsipSetCoordinator.java
@@ -239,9 +239,8 @@
         close();
     }
 
-    /**
-     * @hide
-     */
+    /** @hide */
+    @Override
     public void close() {
         mProfileConnector.disconnect();
     }
diff --git a/framework/java/android/bluetooth/BluetoothGatt.java b/framework/java/android/bluetooth/BluetoothGatt.java
index d7eea45..702d45a 100644
--- a/framework/java/android/bluetooth/BluetoothGatt.java
+++ b/framework/java/android/bluetooth/BluetoothGatt.java
@@ -850,11 +850,12 @@
     /**
      * Close this Bluetooth GATT client.
      *
-     * Application should call this method as early as possible after it is done with
-     * this GATT client.
+     * <p>Application should call this method as early as possible after it is done with this GATT
+     * client.
      */
     @RequiresBluetoothConnectPermission
     @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
+    @Override
     public void close() {
         if (DBG) Log.d(TAG, "close()");
 
diff --git a/framework/java/android/bluetooth/BluetoothGattServer.java b/framework/java/android/bluetooth/BluetoothGattServer.java
index a2e7801..d42d0c4 100644
--- a/framework/java/android/bluetooth/BluetoothGattServer.java
+++ b/framework/java/android/bluetooth/BluetoothGattServer.java
@@ -469,11 +469,12 @@
     /**
      * Close this GATT server instance.
      *
-     * Application should call this method as early as possible after it is done with
-     * this GATT server.
+     * <p>Application should call this method as early as possible after it is done with this GATT
+     * server.
      */
     @RequiresBluetoothConnectPermission
     @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
+    @Override
     public void close() {
         if (DBG) Log.d(TAG, "close()");
         unregisterCallback();
diff --git a/framework/java/android/bluetooth/BluetoothHapClient.java b/framework/java/android/bluetooth/BluetoothHapClient.java
index a5946fc..2188104 100644
--- a/framework/java/android/bluetooth/BluetoothHapClient.java
+++ b/framework/java/android/bluetooth/BluetoothHapClient.java
@@ -47,7 +47,6 @@
 import java.util.concurrent.Executor;
 import java.util.concurrent.TimeoutException;
 
-
 /**
  * This class provides a public APIs to control the Bluetooth Hearing Access Profile client service.
  *
@@ -532,9 +531,8 @@
         close();
     }
 
-    /**
-     * @hide
-     */
+    /** @hide */
+    @Override
     public void close() {
         if (VDBG) log("close()");
 
diff --git a/framework/java/android/bluetooth/BluetoothHeadset.java b/framework/java/android/bluetooth/BluetoothHeadset.java
index 18964fd..4241fff 100644
--- a/framework/java/android/bluetooth/BluetoothHeadset.java
+++ b/framework/java/android/bluetooth/BluetoothHeadset.java
@@ -360,13 +360,14 @@
     }
 
     /**
-     * Close the connection to the backing service.
-     * Other public functions of BluetoothHeadset will return default error
-     * results once close() has been called. Multiple invocations of close()
+     * Close the connection to the backing service. Other public functions of BluetoothHeadset will
+     * return default error results once close() has been called. Multiple invocations of close()
      * are ok.
+     *
+     * @hide
      */
     @UnsupportedAppUsage
-    /*package*/ void close() {
+    public void close() {
         mProfileConnector.disconnect();
     }
 
diff --git a/framework/java/android/bluetooth/BluetoothHeadsetClient.java b/framework/java/android/bluetooth/BluetoothHeadsetClient.java
index 89b42d9..2f11cbf 100644
--- a/framework/java/android/bluetooth/BluetoothHeadsetClient.java
+++ b/framework/java/android/bluetooth/BluetoothHeadsetClient.java
@@ -752,13 +752,13 @@
     }
 
     /**
-     * Close the connection to the backing service.
-     * Other public functions of BluetoothHeadsetClient will return default error
-     * results once close() has been called. Multiple invocations of close()
-     * are ok.
+     * Close the connection to the backing service. Other public functions of BluetoothHeadsetClient
+     * will return default error results once close() has been called. Multiple invocations of
+     * close() are ok.
      *
      * @hide
      */
+    @Override
     public void close() {
         if (VDBG) log("close()");
         mProfileConnector.disconnect();
diff --git a/framework/java/android/bluetooth/BluetoothHealth.java b/framework/java/android/bluetooth/BluetoothHealth.java
index 65f68a9..a155e4f 100644
--- a/framework/java/android/bluetooth/BluetoothHealth.java
+++ b/framework/java/android/bluetooth/BluetoothHealth.java
@@ -262,6 +262,12 @@
         return STATE_DISCONNECTED;
     }
 
+    /** @hide */
+    @Override
+    public void close() {
+        // Do nothing.
+    }
+
     /**
      * Get connected devices for the health profile.
      *
diff --git a/framework/java/android/bluetooth/BluetoothHearingAid.java b/framework/java/android/bluetooth/BluetoothHearingAid.java
index ff358cc..cff41e1 100644
--- a/framework/java/android/bluetooth/BluetoothHearingAid.java
+++ b/framework/java/android/bluetooth/BluetoothHearingAid.java
@@ -199,7 +199,9 @@
         mProfileConnector.connect(context, listener);
     }
 
-    /*package*/ void close() {
+    /** @hide */
+    @Override
+    public void close() {
         mProfileConnector.disconnect();
     }
 
diff --git a/framework/java/android/bluetooth/BluetoothHidDevice.java b/framework/java/android/bluetooth/BluetoothHidDevice.java
index 72c5d15..0e39b3e 100644
--- a/framework/java/android/bluetooth/BluetoothHidDevice.java
+++ b/framework/java/android/bluetooth/BluetoothHidDevice.java
@@ -445,7 +445,9 @@
         mProfileConnector.connect(context, listener);
     }
 
-    void close() {
+    /** @hide */
+    @Override
+    public void close() {
         mProfileConnector.disconnect();
     }
 
diff --git a/framework/java/android/bluetooth/BluetoothHidHost.java b/framework/java/android/bluetooth/BluetoothHidHost.java
index 73c3ca8..957ffdd 100644
--- a/framework/java/android/bluetooth/BluetoothHidHost.java
+++ b/framework/java/android/bluetooth/BluetoothHidHost.java
@@ -40,7 +40,6 @@
 import java.util.List;
 import java.util.concurrent.TimeoutException;
 
-
 /**
  * This class provides the public APIs to control the Bluetooth Input
  * Device Profile.
@@ -263,7 +262,9 @@
         mProfileConnector.connect(context, listener);
     }
 
-    /*package*/ void close() {
+    /** @hide */
+    @Override
+    public void close() {
         if (VDBG) log("close()");
         mProfileConnector.disconnect();
     }
diff --git a/framework/java/android/bluetooth/BluetoothLeAudio.java b/framework/java/android/bluetooth/BluetoothLeAudio.java
index 36b8f1b..5485d20 100644
--- a/framework/java/android/bluetooth/BluetoothLeAudio.java
+++ b/framework/java/android/bluetooth/BluetoothLeAudio.java
@@ -688,9 +688,8 @@
         mCloseGuard.open("close");
     }
 
-    /**
-     * @hide
-     */
+    /** @hide */
+    @Override
     public void close() {
         IBluetoothManager mgr = mAdapter.getBluetoothManager();
         if (mgr != null) {
diff --git a/framework/java/android/bluetooth/BluetoothLeBroadcastAssistant.java b/framework/java/android/bluetooth/BluetoothLeBroadcastAssistant.java
index 04abf3a..5aebad8 100755
--- a/framework/java/android/bluetooth/BluetoothLeBroadcastAssistant.java
+++ b/framework/java/android/bluetooth/BluetoothLeBroadcastAssistant.java
@@ -339,9 +339,8 @@
         close();
     }
 
-    /**
-     * @hide
-     */
+    /** @hide */
+    @Override
     public void close() {
         mProfileConnector.disconnect();
     }
diff --git a/framework/java/android/bluetooth/BluetoothLeCallControl.java b/framework/java/android/bluetooth/BluetoothLeCallControl.java
index be13d9f..3e1a6a9 100644
--- a/framework/java/android/bluetooth/BluetoothLeCallControl.java
+++ b/framework/java/android/bluetooth/BluetoothLeCallControl.java
@@ -399,7 +399,9 @@
         mProfileConnector.connect(context, listener);
     }
 
-    /* package */ void close() {
+    /** @hide */
+    @Override
+    public void close() {
         if (VDBG) log("close()");
 
         unregisterBearer();
diff --git a/framework/java/android/bluetooth/BluetoothMap.java b/framework/java/android/bluetooth/BluetoothMap.java
index 9e606f9..f47a3a9 100644
--- a/framework/java/android/bluetooth/BluetoothMap.java
+++ b/framework/java/android/bluetooth/BluetoothMap.java
@@ -118,14 +118,14 @@
     }
 
     /**
-     * Close the connection to the backing service.
-     * Other public functions of BluetoothMap will return default error
-     * results once close() has been called. Multiple invocations of close()
+     * Close the connection to the backing service. Other public functions of BluetoothMap will
+     * return default error results once close() has been called. Multiple invocations of close()
      * are ok.
      *
      * @hide
      */
     @SystemApi
+    @Override
     public void close() {
         if (VDBG) log("close()");
         mProfileConnector.disconnect();
diff --git a/framework/java/android/bluetooth/BluetoothMapClient.java b/framework/java/android/bluetooth/BluetoothMapClient.java
index 41dac11..f4f1301 100644
--- a/framework/java/android/bluetooth/BluetoothMapClient.java
+++ b/framework/java/android/bluetooth/BluetoothMapClient.java
@@ -234,12 +234,13 @@
     }
 
     /**
-     * Close the connection to the backing service.
-     * Other public functions of BluetoothMap will return default error
-     * results once close() has been called. Multiple invocations of close()
+     * Close the connection to the backing service. Other public functions of BluetoothMap will
+     * return default error results once close() has been called. Multiple invocations of close()
      * are ok.
+     *
      * @hide
      */
+    @Override
     public void close() {
         mProfileConnector.disconnect();
         if (mCloseGuard != null) {
diff --git a/framework/java/android/bluetooth/BluetoothPan.java b/framework/java/android/bluetooth/BluetoothPan.java
index 2f6fe4e..e970b7b 100644
--- a/framework/java/android/bluetooth/BluetoothPan.java
+++ b/framework/java/android/bluetooth/BluetoothPan.java
@@ -264,9 +264,12 @@
 
     /**
      * Closes the connection to the service and unregisters callbacks
+     *
+     * @hide
      */
     @UnsupportedAppUsage
-    void close() {
+    @Override
+    public void close() {
         if (VDBG) log("close()");
         mProfileConnector.disconnect();
     }
diff --git a/framework/java/android/bluetooth/BluetoothPbap.java b/framework/java/android/bluetooth/BluetoothPbap.java
index de2db9c..f0580e0 100644
--- a/framework/java/android/bluetooth/BluetoothPbap.java
+++ b/framework/java/android/bluetooth/BluetoothPbap.java
@@ -135,13 +135,13 @@
     }
 
     /**
-     * Close the connection to the backing service.
-     * Other public functions of BluetoothPbap will return default error
-     * results once close() has been called. Multiple invocations of close()
+     * Close the connection to the backing service. Other public functions of BluetoothPbap will
+     * return default error results once close() has been called. Multiple invocations of close()
      * are ok.
      *
      * @hide
      */
+    @Override
     public synchronized void close() {
         mProfileConnector.disconnect();
     }
diff --git a/framework/java/android/bluetooth/BluetoothPbapClient.java b/framework/java/android/bluetooth/BluetoothPbapClient.java
index 35c9629..cdec02f 100644
--- a/framework/java/android/bluetooth/BluetoothPbapClient.java
+++ b/framework/java/android/bluetooth/BluetoothPbapClient.java
@@ -127,13 +127,13 @@
     }
 
     /**
-     * Close the connection to the backing service.
-     * Other public functions of BluetoothPbapClient will return default error
-     * results once close() has been called. Multiple invocations of close()
-     * are ok.
+     * Close the connection to the backing service. Other public functions of BluetoothPbapClient
+     * will return default error results once close() has been called. Multiple invocations of
+     * close() are ok.
      *
      * @hide
      */
+    @Override
     public synchronized void close() {
         mProfileConnector.disconnect();
         if (mCloseGuard != null) {
diff --git a/framework/java/android/bluetooth/BluetoothProfile.java b/framework/java/android/bluetooth/BluetoothProfile.java
index 24444fb..728dbaf 100644
--- a/framework/java/android/bluetooth/BluetoothProfile.java
+++ b/framework/java/android/bluetooth/BluetoothProfile.java
@@ -384,6 +384,13 @@
     @BtProfileState int getConnectionState(BluetoothDevice device);
 
     /**
+     * Releases any held resources.
+     *
+     * @hide
+     */
+    void close();
+
+    /**
      * An interface for notifying BluetoothProfile IPC clients when they have
      * been connected or disconnected to the service.
      */
diff --git a/framework/java/android/bluetooth/BluetoothSap.java b/framework/java/android/bluetooth/BluetoothSap.java
index 774df33..2aada0d 100644
--- a/framework/java/android/bluetooth/BluetoothSap.java
+++ b/framework/java/android/bluetooth/BluetoothSap.java
@@ -149,13 +149,13 @@
     }
 
     /**
-     * Close the connection to the backing service.
-     * Other public functions of BluetoothSap will return default error
-     * results once close() has been called. Multiple invocations of close()
+     * Close the connection to the backing service. Other public functions of BluetoothSap will
+     * return default error results once close() has been called. Multiple invocations of close()
      * are ok.
      *
      * @hide
      */
+    @Override
     public synchronized void close() {
         mProfileConnector.disconnect();
     }
diff --git a/framework/java/android/bluetooth/BluetoothVolumeControl.java b/framework/java/android/bluetooth/BluetoothVolumeControl.java
index a4e04dd..8f16ae3 100644
--- a/framework/java/android/bluetooth/BluetoothVolumeControl.java
+++ b/framework/java/android/bluetooth/BluetoothVolumeControl.java
@@ -208,10 +208,11 @@
     /**
      * Close this VolumeControl server instance.
      *
-     * Application should call this method as early as possible after it is done with
-     * this VolumeControl server.
+     * <p>Application should call this method as early as possible after it is done with this
+     * VolumeControl server.
      */
     @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
+    @Override
     public void close() {
         if (VDBG) log("close()");