aaudio: fix command thread busy loop.

When a shared stream is idle, it'll be busy retring entering standby.
The reason is that there is no need to enter standby mode for shared
stream. In that case, set standbyTime to max() if standby_l is not
implemented. For mmap stream, the standby_l can return error if there is
something wrong with the HAL. In that case, wait some more time to retry
entering standby for mmap stream.

Test: atest AAudioTests
Test: Play Netflix video and check `top -H`
Bug: 260165213
Bug: 260246526
Change-Id: I041d1b146afdffa0ba62b604a8fe6c0f59e1ddd9
Merged-In: I041d1b146afdffa0ba62b604a8fe6c0f59e1ddd9
(cherry picked from commit 20d04e3bb3968eeee1b7f60a6a64ca95763024cc)
diff --git a/services/oboeservice/AAudioServiceStreamBase.cpp b/services/oboeservice/AAudioServiceStreamBase.cpp
index 9f48f80..f4ee84f 100644
--- a/services/oboeservice/AAudioServiceStreamBase.cpp
+++ b/services/oboeservice/AAudioServiceStreamBase.cpp
@@ -435,7 +435,15 @@
             }
         }
         if (isIdle_l() && AudioClock::getNanoseconds() >= standbyTime) {
-            standby_l();
+            aaudio_result_t result = standby_l();
+            if (result != AAUDIO_OK) {
+                // If standby failed because of the function is not implemented, there is no
+                // need to retry. Otherwise, retry standby later.
+                ALOGW("Failed to enter standby, error=%d", result);
+                standbyTime = result == AAUDIO_ERROR_UNIMPLEMENTED
+                        ? std::numeric_limits<int64_t>::max()
+                        : AudioClock::getNanoseconds() + IDLE_TIMEOUT_NANOS;
+            }
         }
 
         if (command != nullptr) {
diff --git a/services/oboeservice/AAudioServiceStreamBase.h b/services/oboeservice/AAudioServiceStreamBase.h
index b2ba725..b5f8b90 100644
--- a/services/oboeservice/AAudioServiceStreamBase.h
+++ b/services/oboeservice/AAudioServiceStreamBase.h
@@ -320,7 +320,7 @@
     }
 
     virtual aaudio_result_t standby_l() REQUIRES(mLock) {
-        return AAUDIO_ERROR_UNAVAILABLE;
+        return AAUDIO_ERROR_UNIMPLEMENTED;
     }
     class ExitStandbyParam : public AAudioCommandParam {
     public: