Reduce CTS audio requirements for low memory devices

Bug: 25562752
Change-Id: I41c03cd81f97927ccff1cc2c22b2831fee968383
diff --git a/tests/tests/media/src/android/media/cts/AudioRecordTest.java b/tests/tests/media/src/android/media/cts/AudioRecordTest.java
index 1865bb2..ad6cb61 100644
--- a/tests/tests/media/src/android/media/cts/AudioRecordTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioRecordTest.java
@@ -19,6 +19,8 @@
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 
+import android.app.ActivityManager;
+import android.content.Context;
 import android.content.pm.PackageManager;
 import android.cts.util.CtsAndroidTestCase;
 import android.media.AudioFormat;
@@ -280,6 +282,9 @@
 
     // Audit modes work best with non-blocking mode
     public void testAudioRecordAuditByteBufferResamplerStereoFloat() throws Exception {
+        if (isLowRamDevice()) {
+            return; // skip. FIXME: reenable when AF memory allocation is updated.
+        }
         doTest("AuditByteBufferResamplerStereoFloat",
                 false /*localRecord*/, true /*customHandler*/,
                 2 /*periodsPerSecond*/, 0 /*markerPeriodsPerSecond*/,
@@ -299,6 +304,9 @@
     // Audit buffers can run out of space with high sample rate,
     // so keep the channels and pcm encoding low
     public void testAudioRecordAuditChannelIndex2() throws Exception {
+        if (isLowRamDevice()) {
+            return; // skip. FIXME: reenable when AF memory allocation is updated.
+        }
         doTest("AuditChannelIndex2", true /*localRecord*/, true /*customHandler*/,
                 2 /*periodsPerSecond*/, 0 /*markerPeriodsPerSecond*/,
                 false /*useByteBuffer*/, false /*blocking*/,
@@ -1070,4 +1078,9 @@
         return getContext().getPackageManager().hasSystemFeature(
                 PackageManager.FEATURE_MICROPHONE);
     }
+
+    private boolean isLowRamDevice() {
+        return ((ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE))
+                .isLowRamDevice();
+    }
 }
diff --git a/tests/tests/media/src/android/media/cts/AudioTrackTest.java b/tests/tests/media/src/android/media/cts/AudioTrackTest.java
index 9ae6b64..8c8b7f4 100644
--- a/tests/tests/media/src/android/media/cts/AudioTrackTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioTrackTest.java
@@ -16,6 +16,8 @@
 
 package android.media.cts;
 
+import android.app.ActivityManager;
+import android.content.Context;
 import android.content.pm.PackageManager;
 import android.cts.util.CtsAndroidTestCase;
 import android.media.AudioAttributes;
@@ -1564,11 +1566,17 @@
         final int TEST_MODE = AudioTrack.MODE_STREAM;
         final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
         final float TEST_SWEEP = 0; // sine wave only
+        final boolean TEST_IS_LOW_RAM_DEVICE = isLowRamDevice();
 
         for (int TEST_FORMAT : TEST_FORMAT_ARRAY) {
             double frequency = 400; // frequency changes for each test
             for (int TEST_SR : TEST_SR_ARRAY) {
                 for (int TEST_CONF : TEST_CONF_ARRAY) {
+                    final int channelCount = Integer.bitCount(TEST_CONF);
+                    if (TEST_IS_LOW_RAM_DEVICE
+                            && (TEST_SR > 96000 || channelCount > 4)) {
+                        continue; // ignore. FIXME: reenable when AF memory allocation is updated.
+                    }
                     // -------- initialization --------------
                     final int minBufferSize = AudioTrack.getMinBufferSize(TEST_SR,
                             TEST_CONF, TEST_FORMAT); // in bytes
@@ -1577,7 +1585,6 @@
                     assertTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
 
                     // compute parameters for the source signal data.
-                    final int channelCount = Integer.bitCount(TEST_CONF);
                     AudioFormat format = track.getFormat();
                     assertEquals(TEST_NAME, TEST_SR, format.getSampleRate());
                     assertEquals(TEST_NAME, TEST_CONF, format.getChannelMask());
@@ -1894,6 +1901,11 @@
             .hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT);
     }
 
+    private boolean isLowRamDevice() {
+        return ((ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE))
+                .isLowRamDevice();
+    }
+
     public void testGetTimestamp() throws Exception {
         if (!hasAudioOutput()) {
             Log.w(TAG,"AUDIO_OUTPUT feature not found. This system might not have a valid "