audioserver: impose memory restrictions

Impose restrictions to limit effect of excessive memory
allocation.

adb shell setprop audio.maxmem SOME_VALUE_GREATER_THAN_60MB_IN_BYTES
adb shell pkill audioserver

and see what happens when AudioTracks / AudioRecords are created

Test: as above
Bug: 69927864
Change-Id: I0a6a90db3321f066a25fb2fcd01e9f834d199979
diff --git a/media/audioserver/main_audioserver.cpp b/media/audioserver/main_audioserver.cpp
index 5a9d1bb..db57248 100644
--- a/media/audioserver/main_audioserver.cpp
+++ b/media/audioserver/main_audioserver.cpp
@@ -35,12 +35,19 @@
 #include "AAudioService.h"
 #include "utility/AAudioUtilities.h"
 #include "MediaLogService.h"
+#include "MediaUtils.h"
 #include "SoundTriggerHwService.h"
 
 using namespace android;
 
 int main(int argc __unused, char **argv)
 {
+    // TODO: update with refined parameters
+    limitProcessMemory(
+        "audio.maxmem", /* "ro.audio.maxmem", property that defines limit */
+        (size_t)512 * (1 << 20), /* SIZE_MAX, upper limit in bytes */
+        20 /* upper limit as percentage of physical RAM */);
+
     signal(SIGPIPE, SIG_IGN);
 
     bool doLog = (bool) property_get_bool("ro.test_harness", 0);