Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65aed0d0 authored by Sergey Volnov's avatar Sergey Volnov Committed by Android (Google) Code Review
Browse files

Merge "Ensure updateState() is available for software hotword." into sc-dev

parents ca0506fc 307f51a1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10550,6 +10550,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
+41 −0
Original line number Diff line number Diff line
@@ -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;
+3 −24
Original line number Diff line number Diff line
@@ -278,7 +278,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;
@@ -586,24 +585,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(
@@ -613,20 +603,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);
    }

    /**
+16 −0
Original line number Diff line number Diff line
@@ -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.
     */
+1 −7
Original line number Diff line number Diff line
@@ -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)