diff options
| author | Ytai Ben-Tsvi <ytai@google.com> | 2020-08-18 14:53:41 -0700 |
|---|---|---|
| committer | Ytai Ben-Tsvi <ytai@google.com> | 2020-09-16 15:14:17 -0700 |
| commit | c4d23a482d9e0d65ef146c2d68ff2ab416a5e47d (patch) | |
| tree | a5319ab4a277feae3ca7c412ac2ec10adaa126fe /core/java/android | |
| parent | 10c9b09f257e5c1ea06ce73101e859598b288f6f (diff) | |
Demote AlwaysOnHotwordDetector to SystemApi
AlwaysOnHotwordDetector gets demoted from public to SystemApi and
new permissions are enforced on its methods that imply usage of the
microphone via sound trigger.
Bug: 163865561
Change-Id: I113d69e569962b20d9d7dd1c6815daa6fb0650c5
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/service/voice/AlwaysOnHotwordDetector.java | 18 | ||||
| -rw-r--r-- | core/java/android/service/voice/VoiceInteractionService.java | 14 |
2 files changed, 28 insertions, 4 deletions
diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index b25053a049b7..8f8e6cc3d84a 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -16,10 +16,15 @@ package android.service.voice; +import static android.Manifest.permission.CAPTURE_AUDIO_HOTWORD; +import static android.Manifest.permission.RECORD_AUDIO; + import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityThread; +import android.annotation.RequiresPermission; +import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.Intent; @@ -51,7 +56,12 @@ import java.util.Locale; /** * A class that lets a VoiceInteractionService implementation interact with * always-on keyphrase detection APIs. + * + * @hide + * TODO(b/168605867): Once Metalava supports expressing a removed public, but current system API, + * mark and track it as such. */ +@SystemApi public class AlwaysOnHotwordDetector { //---- States of Keyphrase availability. Return codes for onAvailabilityChanged() ----// /** @@ -525,6 +535,7 @@ public class AlwaysOnHotwordDetector { * This may happen if another detector has been instantiated or the * {@link VoiceInteractionService} hosting this detector has been shut down. */ + @RequiresPermission(allOf = {RECORD_AUDIO, CAPTURE_AUDIO_HOTWORD}) public boolean startRecognition(@RecognitionFlags int recognitionFlags) { if (DBG) Slog.d(TAG, "startRecognition(" + recognitionFlags + ")"); synchronized (mLock) { @@ -555,6 +566,7 @@ public class AlwaysOnHotwordDetector { * This may happen if another detector has been instantiated or the * {@link VoiceInteractionService} hosting this detector has been shut down. */ + @RequiresPermission(allOf = {RECORD_AUDIO, CAPTURE_AUDIO_HOTWORD}) public boolean stopRecognition() { if (DBG) Slog.d(TAG, "stopRecognition()"); synchronized (mLock) { @@ -589,6 +601,7 @@ public class AlwaysOnHotwordDetector { * - {@link SoundTrigger#STATUS_INVALID_OPERATION} if the call is out of sequence or * if API is not supported by HAL */ + @RequiresPermission(allOf = {RECORD_AUDIO, CAPTURE_AUDIO_HOTWORD}) public int setParameter(@ModelParams int modelParam, int value) { if (DBG) { Slog.d(TAG, "setParameter(" + modelParam + ", " + value + ")"); @@ -616,6 +629,7 @@ public class AlwaysOnHotwordDetector { * @param modelParam {@link ModelParams} * @return value of parameter */ + @RequiresPermission(allOf = {RECORD_AUDIO, CAPTURE_AUDIO_HOTWORD}) public int getParameter(@ModelParams int modelParam) { if (DBG) { Slog.d(TAG, "getParameter(" + modelParam + ")"); @@ -640,6 +654,7 @@ public class AlwaysOnHotwordDetector { * @param modelParam {@link ModelParams} * @return supported range of parameter, null if not supported */ + @RequiresPermission(allOf = {RECORD_AUDIO, CAPTURE_AUDIO_HOTWORD}) @Nullable public ModelParamRange queryParameter(@ModelParams int modelParam) { if (DBG) { @@ -670,6 +685,7 @@ public class AlwaysOnHotwordDetector { * This may happen if another detector has been instantiated or the * {@link VoiceInteractionService} hosting this detector has been shut down. */ + @Nullable public Intent createEnrollIntent() { if (DBG) Slog.d(TAG, "createEnrollIntent"); synchronized (mLock) { @@ -691,6 +707,7 @@ public class AlwaysOnHotwordDetector { * This may happen if another detector has been instantiated or the * {@link VoiceInteractionService} hosting this detector has been shut down. */ + @Nullable public Intent createUnEnrollIntent() { if (DBG) Slog.d(TAG, "createUnEnrollIntent"); synchronized (mLock) { @@ -712,6 +729,7 @@ public class AlwaysOnHotwordDetector { * This may happen if another detector has been instantiated or the * {@link VoiceInteractionService} hosting this detector has been shut down. */ + @Nullable public Intent createReEnrollIntent() { if (DBG) Slog.d(TAG, "createReEnrollIntent"); synchronized (mLock) { diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index 45d3465fdae8..fb03ed45113e 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -20,6 +20,7 @@ import android.Manifest; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; +import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.app.Service; import android.compat.annotation.UnsupportedAppUsage; @@ -237,9 +238,8 @@ public class VoiceInteractionService extends Service { /** * Called during service initialization to tell you when the system is ready * to receive interaction from it. You should generally do initialization here - * rather than in {@link #onCreate}. Methods such as {@link #showSession} and - * {@link #createAlwaysOnHotwordDetector} - * will not be operational until this point. + * rather than in {@link #onCreate}. Methods such as {@link #showSession} will + * not be operational until this point. */ public void onReady() { mSystemService = IVoiceInteractionManagerService.Stub.asInterface( @@ -309,9 +309,15 @@ public class VoiceInteractionService extends Service { * @param locale The locale for which the enrollment needs to be performed. * @param callback The callback to notify of detection events. * @return An always-on hotword detector for the given keyphrase and locale. + * + * @hide */ + @SystemApi + @NonNull public final AlwaysOnHotwordDetector createAlwaysOnHotwordDetector( - String keyphrase, Locale locale, AlwaysOnHotwordDetector.Callback callback) { + @SuppressLint("MissingNullability") String keyphrase, // TODO: annotate nullability properly + @SuppressLint({"MissingNullability", "UseIcu"}) Locale locale, + @SuppressLint("MissingNullability") AlwaysOnHotwordDetector.Callback callback) { if (mSystemService == null) { throw new IllegalStateException("Not available until onReady() is called"); } |
