Merge "Add a header for string.h for strerror and memset" into honeycomb-mr1
diff --git a/tests/tests/media/src/android/media/cts/AudioRecordTest.java b/tests/tests/media/src/android/media/cts/AudioRecordTest.java
index 74b0952..1ddcdd5 100644
--- a/tests/tests/media/src/android/media/cts/AudioRecordTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioRecordTest.java
@@ -139,6 +139,9 @@
         )
     })
     public void testAudioRecordProperties() throws Exception {
+        if (!hasMicrophone()) {
+            return;
+        }
         assertEquals(AudioFormat.ENCODING_PCM_16BIT, mAudioRecord.getAudioFormat());
         assertEquals(MediaRecorder.AudioSource.DEFAULT, mAudioRecord.getAudioSource());
         assertEquals(1, mAudioRecord.getChannelCount());
@@ -226,6 +229,9 @@
         )
     })
     public void testAudioRecordOP() throws Exception {
+        if (!hasMicrophone()) {
+            return;
+        }
         final int SLEEP_TIME = 10;
         final int RECORD_TIME = 10000;
         assertEquals(AudioRecord.STATE_INITIALIZED, mAudioRecord.getState());
@@ -330,4 +336,8 @@
         mAudioRecord.release();
         assertEquals(AudioRecord.STATE_UNINITIALIZED, mAudioRecord.getState());
     }
+
+    private boolean hasMicrophone() {
+        return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE);
+    }
 }
diff --git a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
index 70b108e..aea88af 100644
--- a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
@@ -20,6 +20,7 @@
 import dalvik.annotation.TestTargetNew;
 import dalvik.annotation.TestTargets;
 
+import android.content.pm.PackageManager;
 import android.hardware.Camera;
 import android.media.MediaRecorder;
 import android.media.MediaRecorder.OnErrorListener;
@@ -150,6 +151,9 @@
         )
     })
     public void testRecorderCamera() throws Exception {
+        if (!hasCamera()) {
+            return;
+        }
         mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
         mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
@@ -262,6 +266,9 @@
         )
     })
     public void testRecorderVideo() throws Exception {
+        if (!hasCamera()) {
+            return;
+        }
         mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
         mMediaRecorder.setOutputFile(OUTPUT_PATH2);
@@ -329,6 +336,9 @@
         )
     })
     public void testRecorderAudio() throws Exception {
+        if (!hasMicrophone()) {
+            return;
+        }
         mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
         assertEquals(0, mMediaRecorder.getMaxAmplitude());
         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
@@ -385,6 +395,9 @@
         )
     })
     public void testOnInfoListener() throws Exception {
+        if (!hasMicrophone()) {
+            return;
+        }
         mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
         mMediaRecorder.setMaxDuration(MAX_DURATION_MSEC);
@@ -443,6 +456,9 @@
         )
     })
     public void testOnErrorListener() throws Exception {
+        if (!hasMicrophone()) {
+            return;
+        }
         mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
         mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
@@ -464,4 +480,13 @@
         assertTrue(outFile.length() < 1.1 * maxFileSize);
         assertTrue(outFile.length() > 0);
     }
+
+    private boolean hasCamera() {
+        return getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
+    }
+
+    private boolean hasMicrophone() {
+        return getActivity().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_MICROPHONE);
+    }
 }