Restore Parameters after audio server restart

Bug: 141724113
Test: kill audioserver during phone call
Change-Id: I9b452a69ac711499b8a465b81225a3080a24e726
(cherry picked from commit 2974124d6f0325ec5c397fba070101a6b732aa2c)
diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
index c5485f9..06c4822 100644
--- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
+++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
@@ -1198,6 +1198,21 @@
         }
     }
 
+    class MyAudioServerStateCallback extends AudioManager.AudioServerStateCallback {
+        @Override
+        public void onAudioServerDown() {
+            logi("onAudioServerDown");
+        }
+
+        @Override
+        public void onAudioServerUp() {
+            logi("onAudioServerUp restoring audio parameters");
+            setAudioParameters();
+        }
+    }
+
+    MyAudioServerStateCallback mAudioServerStateCallback = new MyAudioServerStateCallback();
+
     class AudioOn extends ConnectedBase {
         @Override
         int getAudioStateInt() {
@@ -1216,10 +1231,21 @@
                 mHeadsetService.setActiveDevice(mDevice);
             }
             setAudioParameters();
+
+            mSystemInterface.getAudioManager().setAudioServerStateCallback(
+                    mHeadsetService.getMainExecutor(), mAudioServerStateCallback);
+
             broadcastStateTransitions();
         }
 
         @Override
+        public void exit() {
+            super.exit();
+
+            mSystemInterface.getAudioManager().clearAudioServerStateCallback();
+        }
+
+        @Override
         public boolean processMessage(Message message) {
             switch (message.what) {
                 case CONNECT: {