Fix AudioFlinger TimeCheck

The conversion of IAudioFlinger to AIDL resulted in a regression in
its watchdog behavior. This change fixes that by allowing the
implementation to fully wrap the onTransact() call rather than just
prepend to it using onPreTransact().

Fixes: 187383878
Test: Added a long wait in createTrack, as described in the bug and
      watched to logs to confirm that the watchdog kills the process.
Change-Id: I3cceb2b37d27dbea2060ced3659e11bde363f86d
diff --git a/media/libaudioclient/IAudioFlinger.cpp b/media/libaudioclient/IAudioFlinger.cpp
index 7656307..389b73f 100644
--- a/media/libaudioclient/IAudioFlinger.cpp
+++ b/media/libaudioclient/IAudioFlinger.cpp
@@ -749,10 +749,20 @@
 AudioFlingerServerAdapter::AudioFlingerServerAdapter(
         const sp<AudioFlingerServerAdapter::Delegate>& delegate) : mDelegate(delegate) {}
 
-status_t AudioFlingerServerAdapter::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
+status_t AudioFlingerServerAdapter::onTransact(uint32_t code,
+                                               const Parcel& data,
+                                               Parcel* reply,
                                                uint32_t flags) {
-    return mDelegate->onPreTransact(static_cast<Delegate::TransactionCode>(code), data, flags)
-           ?: BnAudioFlingerService::onTransact(code, data, reply, flags);
+    return mDelegate->onTransactWrapper(static_cast<Delegate::TransactionCode>(code),
+                                        data,
+                                        flags,
+                                        [&] {
+                                            return BnAudioFlingerService::onTransact(
+                                                    code,
+                                                    data,
+                                                    reply,
+                                                    flags);
+                                        });
 }
 
 status_t AudioFlingerServerAdapter::dump(int fd, const Vector<String16>& args) {
diff --git a/media/libaudioclient/include/media/IAudioFlinger.h b/media/libaudioclient/include/media/IAudioFlinger.h
index 3a5d164..3a04569 100644
--- a/media/libaudioclient/include/media/IAudioFlinger.h
+++ b/media/libaudioclient/include/media/IAudioFlinger.h
@@ -516,18 +516,22 @@
         };
 
         /**
-         * And optional hook, called on every transaction, before unparceling the data and
-         * dispatching to the respective method. Useful for bulk operations, such as logging or
-         * permission checks.
-         * If an error status is returned, the transaction will return immediately and will not be
-         * processed.
+         * And optional hook, called on every transaction, allowing additional operations to be
+         * performed before/after the unparceling  ofthe data and dispatching to the respective
+         * method. Useful for bulk operations, such as logging or permission checks.
+         * The implementer is responsible to invoke the provided delegate function, which is the
+         * actual onTransact(), unless an error occurs.
+         * By default, this is just a pass-through to the delegate.
          */
-        virtual status_t onPreTransact(TransactionCode code, const Parcel& data, uint32_t flags) {
+        virtual status_t onTransactWrapper(TransactionCode code,
+                                           const Parcel& data,
+                                           uint32_t flags,
+                                           const std::function<status_t()>& delegate) {
             (void) code;
             (void) data;
             (void) flags;
-            return OK;
-        };
+            return delegate();
+        }
 
         /**
          * An optional hook for implementing diagnostics dumping.