diff options
| author | Ytai Ben-Tsvi <ytai@google.com> | 2020-05-27 13:58:59 -0700 |
|---|---|---|
| committer | Ytai Ben-Tsvi <ytai@google.com> | 2020-09-10 13:27:08 -0700 |
| commit | 10c9b09f257e5c1ea06ce73101e859598b288f6f (patch) | |
| tree | c32098518524515ebb6912ef3b9470108e6d4ff6 /core/java | |
| parent | 75580173017c243fc4c059b3eefcc1314a4e1d1d (diff) | |
Sessionize VoiceInteractionManagerService
This change associates an identity with every
VoiceInteractionManagerService session.
Change-Id: I6c87c2976a4409b8dda4480234d794db91cee374
Bug: 163865561
Diffstat (limited to 'core/java')
3 files changed, 124 insertions, 75 deletions
diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index 6f941121771e..b25053a049b7 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -19,6 +19,7 @@ package android.service.voice; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.app.ActivityThread; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.Intent; @@ -32,6 +33,7 @@ import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra; import android.hardware.soundtrigger.SoundTrigger.ModuleProperties; import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig; import android.media.AudioFormat; +import android.media.permission.Identity; import android.os.AsyncTask; import android.os.Handler; import android.os.Message; @@ -39,6 +41,7 @@ import android.os.RemoteException; import android.util.Slog; import com.android.internal.app.IVoiceInteractionManagerService; +import com.android.internal.app.IVoiceInteractionSoundTriggerSession; import java.io.PrintWriter; import java.lang.annotation.Retention; @@ -228,6 +231,7 @@ public class AlwaysOnHotwordDetector { private KeyphraseMetadata mKeyphraseMetadata; private final KeyphraseEnrollmentInfo mKeyphraseEnrollmentInfo; private final IVoiceInteractionManagerService mModelManagementService; + private final IVoiceInteractionSoundTriggerSession mSoundTriggerSession; private final SoundTriggerListener mInternalCallback; private final Callback mExternalCallback; private final Object mLock = new Object(); @@ -425,6 +429,14 @@ public class AlwaysOnHotwordDetector { mHandler = new MyHandler(); mInternalCallback = new SoundTriggerListener(mHandler); mModelManagementService = modelManagementService; + try { + Identity identity = new Identity(); + identity.packageName = ActivityThread.currentOpPackageName(); + mSoundTriggerSession = mModelManagementService.createSoundTriggerSessionAsOriginator( + identity); + } catch (RemoteException e) { + throw e.rethrowAsRuntimeException(); + } new RefreshAvailabiltyTask().execute(); } @@ -485,7 +497,7 @@ public class AlwaysOnHotwordDetector { private int getSupportedAudioCapabilitiesLocked() { try { ModuleProperties properties = - mModelManagementService.getDspModuleProperties(); + mSoundTriggerSession.getDspModuleProperties(); if (properties != null) { return properties.getAudioCapabilities(); } @@ -782,7 +794,7 @@ public class AlwaysOnHotwordDetector { int code; try { - code = mModelManagementService.startRecognition( + code = mSoundTriggerSession.startRecognition( mKeyphraseMetadata.getId(), mLocale.toLanguageTag(), mInternalCallback, new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers, recognitionExtra, null /* additional data */, audioCapabilities)); @@ -799,7 +811,7 @@ public class AlwaysOnHotwordDetector { private int stopRecognitionLocked() { int code; try { - code = mModelManagementService.stopRecognition(mKeyphraseMetadata.getId(), + code = mSoundTriggerSession.stopRecognition(mKeyphraseMetadata.getId(), mInternalCallback); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); @@ -813,7 +825,7 @@ public class AlwaysOnHotwordDetector { private int setParameterLocked(@ModelParams int modelParam, int value) { try { - int code = mModelManagementService.setParameter(mKeyphraseMetadata.getId(), modelParam, + int code = mSoundTriggerSession.setParameter(mKeyphraseMetadata.getId(), modelParam, value); if (code != STATUS_OK) { @@ -828,7 +840,7 @@ public class AlwaysOnHotwordDetector { private int getParameterLocked(@ModelParams int modelParam) { try { - return mModelManagementService.getParameter(mKeyphraseMetadata.getId(), modelParam); + return mSoundTriggerSession.getParameter(mKeyphraseMetadata.getId(), modelParam); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -838,7 +850,7 @@ public class AlwaysOnHotwordDetector { private ModelParamRange queryParameterLocked(@ModelParams int modelParam) { try { SoundTrigger.ModelParamRange modelParamRange = - mModelManagementService.queryParameter(mKeyphraseMetadata.getId(), modelParam); + mSoundTriggerSession.queryParameter(mKeyphraseMetadata.getId(), modelParam); if (modelParamRange == null) { return null; @@ -972,7 +984,7 @@ public class AlwaysOnHotwordDetector { ModuleProperties dspModuleProperties; try { dspModuleProperties = - mModelManagementService.getDspModuleProperties(); + mSoundTriggerSession.getDspModuleProperties(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl index 15ba8e8c11f7..49b4cd1e6a73 100644 --- a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl +++ b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl @@ -18,6 +18,7 @@ package com.android.internal.app; import android.content.ComponentName; import android.content.Intent; +import android.media.permission.Identity; import android.os.Bundle; import android.os.RemoteCallback; @@ -25,9 +26,8 @@ import com.android.internal.app.IVoiceActionCheckCallback; import com.android.internal.app.IVoiceInteractionSessionShowCallback; import com.android.internal.app.IVoiceInteractor; import com.android.internal.app.IVoiceInteractionSessionListener; -import android.hardware.soundtrigger.IRecognitionStatusCallback; +import com.android.internal.app.IVoiceInteractionSoundTriggerSession; import android.hardware.soundtrigger.KeyphraseMetadata; -import android.hardware.soundtrigger.ModelParams; import android.hardware.soundtrigger.SoundTrigger; import android.service.voice.IVoiceInteractionService; import android.service.voice.IVoiceInteractionSession; @@ -86,13 +86,6 @@ interface IVoiceInteractionManagerService { * @RequiresPermission Manifest.permission.MANAGE_VOICE_KEYPHRASES */ int deleteKeyphraseSoundModel(int keyphraseId, in String bcp47Locale); - - /** - * Gets the properties of the DSP hardware on this device, null if not present. - * Caller must be the active voice interaction service via - * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. - */ - SoundTrigger.ModuleProperties getDspModuleProperties(); /** * Indicates if there's a keyphrase sound model available for the given keyphrase ID and the * user ID of the caller. @@ -116,65 +109,6 @@ interface IVoiceInteractionManagerService { */ KeyphraseMetadata getEnrolledKeyphraseMetadata(String keyphrase, String bcp47Locale); /** - * Starts a recognition for the given keyphrase. - * Caller must be the active voice interaction service via - * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. - */ - int startRecognition(int keyphraseId, in String bcp47Locale, - in IRecognitionStatusCallback callback, - in SoundTrigger.RecognitionConfig recognitionConfig); - /** - * Stops a recognition for the given keyphrase. - * Caller must be the active voice interaction service via - * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. - */ - int stopRecognition(int keyphraseId, in IRecognitionStatusCallback callback); - /** - * Set a model specific ModelParams with the given value. This - * parameter will keep its value for the duration the model is loaded regardless of starting and - * stopping recognition. Once the model is unloaded, the value will be lost. - * queryParameter should be checked first before calling this method. - * Caller must be the active voice interaction service via - * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. - * - * @param keyphraseId The unique identifier for the keyphrase. - * @param modelParam ModelParams - * @param value Value to set - * @return - {@link SoundTrigger#STATUS_OK} in case of success - * - {@link SoundTrigger#STATUS_NO_INIT} if the native service cannot be reached - * - {@link SoundTrigger#STATUS_BAD_VALUE} invalid input parameter - * - {@link SoundTrigger#STATUS_INVALID_OPERATION} if the call is out of sequence or - * if API is not supported by HAL - */ - int setParameter(int keyphraseId, in ModelParams modelParam, int value); - /** - * Get a model specific ModelParams. This parameter will keep its value - * for the duration the model is loaded regardless of starting and stopping recognition. - * Once the model is unloaded, the value will be lost. If the value is not set, a default - * value is returned. See ModelParams for parameter default values. - * queryParameter should be checked first before calling this method. - * Caller must be the active voice interaction service via - * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. - * - * @param keyphraseId The unique identifier for the keyphrase. - * @param modelParam ModelParams - * @return value of parameter - */ - int getParameter(int keyphraseId, in ModelParams modelParam); - /** - * Determine if parameter control is supported for the given model handle. - * This method should be checked prior to calling setParameter or getParameter. - * Caller must be the active voice interaction service via - * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. - * - * @param keyphraseId The unique identifier for the keyphrase. - * @param modelParam ModelParams - * @return supported range of parameter, null if not supported - */ - @nullable SoundTrigger.ModelParamRange queryParameter(int keyphraseId, - in ModelParams modelParam); - - /** * @return the component name for the currently active voice interaction service * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE */ @@ -277,4 +211,12 @@ interface IVoiceInteractionManagerService { */ void setDisabled(boolean disabled); + /** + * Creates a session, allowing controlling running sound models on detection hardware. + * Caller must provide an identity, used for permission tracking purposes. + * The uid/pid elements of the identity will be ignored by the server and replaced with the ones + * provided by binder. + */ + IVoiceInteractionSoundTriggerSession createSoundTriggerSessionAsOriginator( + in Identity originatorIdentity); } diff --git a/core/java/com/android/internal/app/IVoiceInteractionSoundTriggerSession.aidl b/core/java/com/android/internal/app/IVoiceInteractionSoundTriggerSession.aidl new file mode 100644 index 000000000000..33aab4132150 --- /dev/null +++ b/core/java/com/android/internal/app/IVoiceInteractionSoundTriggerSession.aidl @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.app; + +import android.hardware.soundtrigger.IRecognitionStatusCallback; +import android.hardware.soundtrigger.ModelParams; +import android.hardware.soundtrigger.SoundTrigger; + +/** + * This interface allows performing sound-trigger related operations with the actual sound trigger + * hardware. + * + * Every instance of this interface is associated with a client identity ("originator"), established + * upon the creation of the instance and used for permission accounting. + */ +interface IVoiceInteractionSoundTriggerSession { + /** + * Gets the properties of the DSP hardware on this device, null if not present. + * Caller must be the active voice interaction service via + * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. + */ + SoundTrigger.ModuleProperties getDspModuleProperties(); + /** + * Starts a recognition for the given keyphrase. + * Caller must be the active voice interaction service via + * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. + */ + int startRecognition(int keyphraseId, in String bcp47Locale, + in IRecognitionStatusCallback callback, + in SoundTrigger.RecognitionConfig recognitionConfig); + /** + * Stops a recognition for the given keyphrase. + * Caller must be the active voice interaction service via + * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. + */ + int stopRecognition(int keyphraseId, in IRecognitionStatusCallback callback); + /** + * Set a model specific ModelParams with the given value. This + * parameter will keep its value for the duration the model is loaded regardless of starting and + * stopping recognition. Once the model is unloaded, the value will be lost. + * queryParameter should be checked first before calling this method. + * Caller must be the active voice interaction service via + * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. + * + * @param keyphraseId The unique identifier for the keyphrase. + * @param modelParam ModelParams + * @param value Value to set + * @return - {@link SoundTrigger#STATUS_OK} in case of success + * - {@link SoundTrigger#STATUS_NO_INIT} if the native service cannot be reached + * - {@link SoundTrigger#STATUS_BAD_VALUE} invalid input parameter + * - {@link SoundTrigger#STATUS_INVALID_OPERATION} if the call is out of sequence or + * if API is not supported by HAL + */ + int setParameter(int keyphraseId, in ModelParams modelParam, int value); + /** + * Get a model specific ModelParams. This parameter will keep its value + * for the duration the model is loaded regardless of starting and stopping recognition. + * Once the model is unloaded, the value will be lost. If the value is not set, a default + * value is returned. See ModelParams for parameter default values. + * queryParameter should be checked first before calling this method. + * Caller must be the active voice interaction service via + * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. + * + * @param keyphraseId The unique identifier for the keyphrase. + * @param modelParam ModelParams + * @return value of parameter + */ + int getParameter(int keyphraseId, in ModelParams modelParam); + /** + * Determine if parameter control is supported for the given model handle. + * This method should be checked prior to calling setParameter or getParameter. + * Caller must be the active voice interaction service via + * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. + * + * @param keyphraseId The unique identifier for the keyphrase. + * @param modelParam ModelParams + * @return supported range of parameter, null if not supported + */ + @nullable SoundTrigger.ModelParamRange queryParameter(int keyphraseId, + in ModelParams modelParam); +} |
