aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAdnan Begovic <adnan@cyngn.com>2016-06-14 18:07:55 -0700
committerAdnan Begovic <adnan@cyngn.com>2016-06-16 13:54:13 -0700
commit0b76a465155c7ce72f9e349461ad033750c6d330 (patch)
tree23ef1e574a0acef2df0f891aa70ec404f59876f9 /tests
parentafa47a7973cceaf9cffc6ad67cc728cd7d22e97b (diff)
downloadvendor_cmsdk-0b76a465155c7ce72f9e349461ad033750c6d330.zip
vendor_cmsdk-0b76a465155c7ce72f9e349461ad033750c6d330.tar.gz
vendor_cmsdk-0b76a465155c7ce72f9e349461ad033750c6d330.tar.bz2
cmsdk: Provide test coverage for remainder PartnerInterface's.
TICKET: CYNGNOS-3051 Change-Id: I1c15516dc03d3c0897cdd35f22281b25eedb84de
Diffstat (limited to 'tests')
-rw-r--r--tests/AndroidManifest.xml2
-rw-r--r--tests/src/org/cyanogenmod/tests/settings/unit/CMPartnerInterfaceTest.java53
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 3560431..fe3099a 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -8,6 +8,8 @@
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.CAPTURE_AUDIO_HOTWORD" />
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="cyanogenmod.permission.BIND_CUSTOM_TILE_LISTENER_SERVICE"/>
<uses-permission android:name="cyanogenmod.permission.PUBLISH_CUSTOM_TILE"/>
diff --git a/tests/src/org/cyanogenmod/tests/settings/unit/CMPartnerInterfaceTest.java b/tests/src/org/cyanogenmod/tests/settings/unit/CMPartnerInterfaceTest.java
index c1ac0de..8fb0ff4 100644
--- a/tests/src/org/cyanogenmod/tests/settings/unit/CMPartnerInterfaceTest.java
+++ b/tests/src/org/cyanogenmod/tests/settings/unit/CMPartnerInterfaceTest.java
@@ -18,6 +18,11 @@ package org.cyanogenmod.tests.settings.unit;
import android.app.INotificationManager;
import android.content.Context;
+import android.media.AudioAttributes;
+import android.media.AudioFormat;
+import android.media.AudioManager;
+import android.media.AudioRecord;
+import android.media.MediaRecorder;
import android.net.Uri;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -194,6 +199,54 @@ public class CMPartnerInterfaceTest extends AndroidTestCase {
assertEquals(PartnerInterface.ZEN_MODE_OFF, getZenMode());
}
+ private final static int BUFFER_ELEMENTS_TO_REC = 1024;
+ private final static int BYTES_PER_ELEMENT = 2;
+ private static final int RECORDER_SAMPLERATE = 41000;
+ private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
+ private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
+
+ private static int[] mSampleRates = new int[] { 8000, 11025, 22050, 44100 };
+ public AudioRecord findAudioRecord() {
+ for (int rate : mSampleRates) {
+ for (short audioFormat : new short[] { AudioFormat.ENCODING_PCM_8BIT,
+ AudioFormat.ENCODING_PCM_16BIT }) {
+ for (short channelConfig : new short[] { AudioFormat.CHANNEL_IN_MONO,
+ AudioFormat.CHANNEL_IN_STEREO }) {
+ try {
+ Log.d(TAG, "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: "
+ + channelConfig);
+ int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
+
+ if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
+ AudioRecord recorder = new AudioRecord(
+ cyanogenmod.media.MediaRecorder.AudioSource.HOTWORD,
+ rate, channelConfig, audioFormat, bufferSize);
+
+ if (recorder.getState() == AudioRecord.STATE_INITIALIZED)
+ return recorder;
+ }
+ } catch (Exception e) {
+ Log.e(TAG, rate + "Exception, keep trying.",e);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @SmallTest
+ public void testGetCurrentHotwordPackageName() {
+ // make sure no one is actively stealing this as we attempt to
+ assertNull(mPartnerInterface.getCurrentHotwordPackageName());
+
+ // find first viable audio record
+ final AudioRecord audioRecorder = findAudioRecord();
+
+ audioRecorder.startRecording();
+ assertEquals(mContext.getPackageName(), mPartnerInterface.getCurrentHotwordPackageName());
+ audioRecorder.stop();
+ }
+
/**
* testZenModeWithDuration: sets Zen Mode with duration and blocks
* until the duration is verified. Use with care! This does not