summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/jni/android_media_AudioRecord.cpp11
-rw-r--r--core/res/AndroidManifest.xml8
-rw-r--r--core/res/res/values/strings.xml6
-rw-r--r--media/java/android/media/AudioManager.java10
-rw-r--r--media/java/android/media/AudioRecord.java3
-rw-r--r--media/java/android/media/MediaRecorder.java13
6 files changed, 38 insertions, 13 deletions
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index 0cd6f4a..1c43cc5 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -190,7 +190,7 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
int frameSize = nbChannels * bytesPerSample;
size_t frameCount = buffSizeInBytes / frameSize;
- if (uint32_t(source) >= AUDIO_SOURCE_CNT) {
+ if ((uint32_t(source) >= AUDIO_SOURCE_CNT) && (uint32_t(source) != AUDIO_SOURCE_HOTWORD)) {
ALOGE("Error creating AudioRecord: unknown source.");
return AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
}
@@ -387,6 +387,9 @@ static jint android_media_AudioRecord_readInByteArray(JNIEnv *env, jobject thiz
(jint)recorderBuffSize : sizeInBytes );
env->ReleaseByteArrayElements(javaAudioData, recordBuff, 0);
+ if (readSize < 0) {
+ readSize = AUDIORECORD_ERROR_INVALID_OPERATION;
+ }
return (jint) readSize;
}
@@ -427,8 +430,12 @@ static jint android_media_AudioRecord_readInDirectBuffer(JNIEnv *env, jobject t
}
// read new data from the recorder
- return (jint) lpRecorder->read(nativeFromJavaBuf,
+ ssize_t readSize = lpRecorder->read(nativeFromJavaBuf,
capacity < sizeInBytes ? capacity : sizeInBytes);
+ if (readSize < 0) {
+ readSize = AUDIORECORD_ERROR_INVALID_OPERATION;
+ }
+ return (jint)readSize;
}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 2e47928..019295d 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2071,6 +2071,14 @@
android:description="@string/permdesc_captureAudioOutput"
android:protectionLevel="signature|system" />
+ <!-- Allows an application to capture audio for hotword detection.
+ <p>Not for use by third-party applications.</p>
+ @hide -->
+ <permission android:name="android.permission.CAPTURE_AUDIO_HOTWORD"
+ android:label="@string/permlab_captureAudioHotword"
+ android:description="@string/permdesc_captureAudioHotword"
+ android:protectionLevel="signature|system" />
+
<!-- Allows an application to capture video output.
<p>Not for use by third-party applications.</p> -->
<permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 68acd8c..bd933ca 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1405,6 +1405,12 @@
<string name="permdesc_captureAudioOutput">Allows the app to capture and redirect audio output.</string>
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+ <string name="permlab_captureAudioHotword">Hotword detection</string>
+ <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+ <string name="permdesc_captureAudioHotword">Allows the app to capture audio for Hotword detection. The capture can
+ happen in the background but does not prevent other audio capture (e.g. Camcorder).</string>
+
+ <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permlab_captureVideoOutput">capture video output</string>
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permdesc_captureVideoOutput">Allows the app to capture and redirect video output.</string>
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 1dcf0e9..9bda852f 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -1532,16 +1532,6 @@ public class AudioManager {
/**
* @hide
- * Checks whether speech recognition is active
- * @return true if a recording with source {@link MediaRecorder.AudioSource#VOICE_RECOGNITION}
- * is underway.
- */
- public boolean isSpeechRecognitionActive() {
- return AudioSystem.isSourceActive(MediaRecorder.AudioSource.VOICE_RECOGNITION);
- }
-
- /**
- * @hide
* Checks whether the current audio focus is exclusive.
* @return true if the top of the audio focus stack requested focus
* with {@link #AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index d20f5b9..f49ef2e 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -252,7 +252,8 @@ public class AudioRecord
//--------------
// audio source
if ( (audioSource < MediaRecorder.AudioSource.DEFAULT) ||
- (audioSource > MediaRecorder.getAudioSourceMax()) ) {
+ ((audioSource > MediaRecorder.getAudioSourceMax()) &&
+ (audioSource != MediaRecorder.AudioSource.HOTWORD)) ) {
throw new IllegalArgumentException("Invalid audio source.");
}
mRecordSource = audioSource;
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 1d2b889..8dcbd6b 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -200,6 +200,19 @@ public class MediaRecorder
* </p>
*/
public static final int REMOTE_SUBMIX = 8;
+
+ /**
+ * Audio source for preemptible, low-priority software hotword detection
+ * It presents the same gain and pre processing tuning as {@link #VOICE_RECOGNITION}.
+ * <p>
+ * An application should use this audio source when it wishes to do
+ * always-on software hotword detection, while gracefully giving in to any other application
+ * that might want to read from the microphone.
+ * </p>
+ * This is a hidden audio source.
+ * @hide
+ */
+ protected static final int HOTWORD = 1999;
}
/**