Fix issues with synchronous record start.

- Added a timeout in case the trigger event is never fired.
- Extend AudioRecord obtainBuffer() timeout in case of
synchronous start to avoid spurious warning.
- Make sure that the event is triggered if the track is
destroyed.
- Reject event if the triggering track is in an incompatible state.

Also fix a problem when restoring a static AudioTrack after
a mediaserver crash.

Bug 6449468.

Change-Id: Ib36e11111fb88f73caa31dcb0622792737d57a4b
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index f73a317..e2662f2 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -173,6 +173,10 @@
         SYNC_EVENT_CNT,
     };
 
+    // Timeout for synchronous record start. Prevents from blocking the record thread forever
+    // if the trigger event is not fired.
+    static const uint32_t kSyncRecordStartTimeOutMs = 30000;
+
     //
     // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
     //