aaudio: disconnect when onTearDown() called

It will be called, for example, when switching from speaker to Bluetooth.

Bug: 62883778
Test: run a long app and switch to or from Bluetooth
Change-Id: Iafb9b52d85c30fee71de46abfb99a27a1daabf59
diff --git a/services/oboeservice/AAudioServiceStreamBase.cpp b/services/oboeservice/AAudioServiceStreamBase.cpp
index c415f25..c4591b0 100644
--- a/services/oboeservice/AAudioServiceStreamBase.cpp
+++ b/services/oboeservice/AAudioServiceStreamBase.cpp
@@ -79,7 +79,7 @@
         mThreadEnabled.store(false);
         result = mAAudioThread.stop();
         if (result != AAUDIO_OK) {
-            processFatalError();
+            disconnect();
             return result;
         }
         sendServiceEvent(AAUDIO_SERVICE_EVENT_PAUSED);
@@ -96,7 +96,7 @@
         mThreadEnabled.store(false);
         result = mAAudioThread.stop();
         if (result != AAUDIO_OK) {
-            processFatalError();
+            disconnect();
             return result;
         }
         sendServiceEvent(AAUDIO_SERVICE_EVENT_STOPPED);
@@ -133,8 +133,11 @@
     ALOGD("AAudioServiceStreamBase::run() exiting ----------------");
 }
 
-void AAudioServiceStreamBase::processFatalError() {
-    sendServiceEvent(AAUDIO_SERVICE_EVENT_DISCONNECTED);
+void AAudioServiceStreamBase::disconnect() {
+    if (mState != AAUDIO_STREAM_STATE_DISCONNECTED) {
+        sendServiceEvent(AAUDIO_SERVICE_EVENT_DISCONNECTED);
+        mState = AAUDIO_STREAM_STATE_DISCONNECTED;
+    }
 }
 
 aaudio_result_t AAudioServiceStreamBase::sendServiceEvent(aaudio_service_event_t event,