Ensure updateState() is available for software hotword.
We accidentally missed propagating this method to the interface before the previous deadline. Otherwise the change should be trivial and backwards compatible. Bug: 168305377 CTS-Coverage-Bug: 183425641 Test: atest CtsVoiceInteractionTestCases Change-Id: Ib85f5264932aeab73ff67a3371f2304d368383ae
This commit is contained in:
@@ -10504,6 +10504,7 @@ package android.service.voice {
|
||||
method @RequiresPermission(allOf={android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.CAPTURE_AUDIO_HOTWORD}) public boolean startRecognition();
|
||||
method public boolean startRecognition(@NonNull android.os.ParcelFileDescriptor, @NonNull android.media.AudioFormat, @Nullable android.os.PersistableBundle);
|
||||
method public boolean stopRecognition();
|
||||
method public void updateState(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory);
|
||||
field public static final int CONFIDENCE_LEVEL_HIGH = 3; // 0x3
|
||||
field public static final int CONFIDENCE_LEVEL_LOW = 1; // 0x1
|
||||
field public static final int CONFIDENCE_LEVEL_MEDIUM = 2; // 0x2
|
||||
|
||||
@@ -26,8 +26,10 @@ import android.os.Looper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SharedMemory;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.internal.app.IHotwordRecognitionStatusCallback;
|
||||
import com.android.internal.app.IVoiceInteractionManagerService;
|
||||
|
||||
/** Base implementation of {@link HotwordDetector}. */
|
||||
@@ -35,6 +37,8 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
|
||||
private static final String TAG = AbstractHotwordDetector.class.getSimpleName();
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
protected final Object mLock = new Object();
|
||||
|
||||
private final IVoiceInteractionManagerService mManagerService;
|
||||
private final Handler mHandler;
|
||||
private final HotwordDetector.Callback mCallback;
|
||||
@@ -79,6 +83,43 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration and pass read-only data to hotword detection service.
|
||||
*
|
||||
* @param options Application configuration data to provide to the
|
||||
* {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or
|
||||
* other contents that can be used to communicate with other processes.
|
||||
* @param sharedMemory The unrestricted data blob to provide to the
|
||||
* {@link HotwordDetectionService}. Use this to provide the hotword models data or other
|
||||
* such data to the trusted process.
|
||||
*
|
||||
* @throws IllegalStateException if this AlwaysOnHotwordDetector wasn't specified to use a
|
||||
* {@link HotwordDetectionService} when it was created. In addition, if this
|
||||
* AlwaysOnHotwordDetector is in an invalid or error state.
|
||||
*/
|
||||
@Override
|
||||
public void updateState(@Nullable PersistableBundle options,
|
||||
@Nullable SharedMemory sharedMemory) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "updateState()");
|
||||
}
|
||||
synchronized (mLock) {
|
||||
updateStateLocked(options, sharedMemory, null /* callback */);
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateStateLocked(@Nullable PersistableBundle options,
|
||||
@Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "updateStateLocked()");
|
||||
}
|
||||
try {
|
||||
mManagerService.updateState(options, sharedMemory, callback);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
private static class BinderCallback
|
||||
extends IMicrophoneHotwordDetectionVoiceInteractionCallback.Stub {
|
||||
private final Handler mHandler;
|
||||
|
||||
@@ -276,7 +276,6 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
|
||||
private final IVoiceInteractionSoundTriggerSession mSoundTriggerSession;
|
||||
private final SoundTriggerListener mInternalCallback;
|
||||
private final Callback mExternalCallback;
|
||||
private final Object mLock = new Object();
|
||||
private final Handler mHandler;
|
||||
private final IBinder mBinder = new Binder();
|
||||
private final int mTargetSdkVersion;
|
||||
@@ -584,24 +583,15 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration and pass read-only data to hotword detection service.
|
||||
*
|
||||
* @param options Application configuration data to provide to the
|
||||
* {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or
|
||||
* other contents that can be used to communicate with other processes.
|
||||
* @param sharedMemory The unrestricted data blob to provide to the
|
||||
* {@link HotwordDetectionService}. Use this to provide the hotword models data or other
|
||||
* such data to the trusted process.
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws IllegalStateException if this AlwaysOnHotwordDetector wasn't specified to use a
|
||||
* {@link HotwordDetectionService} when it was created. In addition, if this
|
||||
* AlwaysOnHotwordDetector is in an invalid or error state.
|
||||
*/
|
||||
@Override
|
||||
public final void updateState(@Nullable PersistableBundle options,
|
||||
@Nullable SharedMemory sharedMemory) {
|
||||
if (DBG) {
|
||||
Slog.d(TAG, "updateState()");
|
||||
}
|
||||
synchronized (mLock) {
|
||||
if (!mSupportHotwordDetectionService) {
|
||||
throw new IllegalStateException(
|
||||
@@ -611,20 +601,9 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
|
||||
throw new IllegalStateException(
|
||||
"updateState called on an invalid detector or error state");
|
||||
}
|
||||
updateStateLocked(options, sharedMemory, null /* callback */);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStateLocked(@Nullable PersistableBundle options,
|
||||
@Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback) {
|
||||
if (DBG) {
|
||||
Slog.d(TAG, "updateStateLocked()");
|
||||
}
|
||||
try {
|
||||
mModelManagementService.updateState(options, sharedMemory, callback);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
super.updateState(options, sharedMemory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.annotation.SystemApi;
|
||||
import android.media.AudioFormat;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.SharedMemory;
|
||||
import android.service.voice.HotwordDetectionService.InitializationStatus;
|
||||
|
||||
/**
|
||||
@@ -105,6 +106,21 @@ public interface HotwordDetector {
|
||||
@NonNull AudioFormat audioFormat,
|
||||
@Nullable PersistableBundle options);
|
||||
|
||||
/**
|
||||
* Set configuration and pass read-only data to hotword detection service.
|
||||
*
|
||||
* @param options Application configuration data to provide to the
|
||||
* {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or
|
||||
* other contents that can be used to communicate with other processes.
|
||||
* @param sharedMemory The unrestricted data blob to provide to the
|
||||
* {@link HotwordDetectionService}. Use this to provide the hotword models data or other
|
||||
* such data to the trusted process.
|
||||
*
|
||||
* @throws IllegalStateException if this HotwordDetector wasn't specified to use a
|
||||
* {@link HotwordDetectionService} when it was created.
|
||||
*/
|
||||
void updateState(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory);
|
||||
|
||||
/**
|
||||
* The callback to notify of detection events.
|
||||
*/
|
||||
|
||||
@@ -51,7 +51,6 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
|
||||
private final HotwordDetector.Callback mCallback;
|
||||
private final AudioFormat mAudioFormat;
|
||||
private final Handler mHandler;
|
||||
private final Object mLock = new Object();
|
||||
|
||||
SoftwareHotwordDetector(
|
||||
IVoiceInteractionManagerService managerService,
|
||||
@@ -65,12 +64,7 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
|
||||
mAudioFormat = audioFormat;
|
||||
mCallback = callback;
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
try {
|
||||
mManagerService.updateState(options, sharedMemory, null /* callback */);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
updateStateLocked(options, sharedMemory, null /* callback */);
|
||||
}
|
||||
|
||||
@RequiresPermission(RECORD_AUDIO)
|
||||
|
||||
Reference in New Issue
Block a user