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

Commit 2081b5d0 authored by Joanne Chung's avatar Joanne Chung Committed by Automerger Merge Worker
Browse files

Merge changes from topic "presubmit-am-08bbcb587d4e47b6afcc900c23899344" into...

Merge changes from topic "presubmit-am-08bbcb587d4e47b6afcc900c23899344" into sc-v2-dev am: 0f608efd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17184230

Change-Id: I35d157de8376b43f4359cd7243d12973704bf893
parents 221b5126 0f608efd
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -44,14 +44,17 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
    private final IVoiceInteractionManagerService mManagerService;
    private final Handler mHandler;
    private final HotwordDetector.Callback mCallback;
    private final int mDetectorType;

    AbstractHotwordDetector(
            IVoiceInteractionManagerService managerService,
            HotwordDetector.Callback callback) {
            HotwordDetector.Callback callback,
            int detectorType) {
        mManagerService = managerService;
        // TODO: this needs to be supplied from above
        mHandler = new Handler(Looper.getMainLooper());
        mCallback = callback;
        mDetectorType = detectorType;
    }

    /**
@@ -104,19 +107,20 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
            Slog.d(TAG, "updateState()");
        }
        synchronized (mLock) {
            updateStateLocked(options, sharedMemory, null /* callback */);
            updateStateLocked(options, sharedMemory, null /* callback */, mDetectorType);
        }
    }

    protected void updateStateLocked(@Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback) {
            @Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback,
            int detectorType) {
        if (DEBUG) {
            Slog.d(TAG, "updateStateLocked()");
        }
        Identity identity = new Identity();
        identity.packageName = ActivityThread.currentOpPackageName();
        try {
            mManagerService.updateState(identity, options, sharedMemory, callback);
            mManagerService.updateState(identity, options, sharedMemory, callback, detectorType);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+5 −2
Original line number Diff line number Diff line
@@ -578,7 +578,9 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
            IVoiceInteractionManagerService modelManagementService, int targetSdkVersion,
            boolean supportHotwordDetectionService, @Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory) {
        super(modelManagementService, callback);
        super(modelManagementService, callback,
                supportHotwordDetectionService ? DETECTOR_TYPE_TRUSTED_HOTWORD_DSP
                        : DETECTOR_TYPE_NORMAL);

        mHandler = new MyHandler();
        mText = text;
@@ -590,7 +592,8 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
        mTargetSdkVersion = targetSdkVersion;
        mSupportHotwordDetectionService = supportHotwordDetectionService;
        if (mSupportHotwordDetectionService) {
            updateStateLocked(options, sharedMemory, mInternalCallback);
            updateStateLocked(options, sharedMemory, mInternalCallback,
                    DETECTOR_TYPE_TRUSTED_HOTWORD_DSP);
        }
        try {
            Identity identity = new Identity();
+37 −0
Original line number Diff line number Diff line
@@ -36,6 +36,27 @@ import android.os.SharedMemory;
@SystemApi
public interface HotwordDetector {

    /**
     * Indicates that it is a non-trusted hotword detector.
     *
     * @hide
     */
    int DETECTOR_TYPE_NORMAL = 0;

    /**
     * Indicates that it is a DSP trusted hotword detector.
     *
     * @hide
     */
    int DETECTOR_TYPE_TRUSTED_HOTWORD_DSP = 1;

    /**
     * Indicates that it is a software trusted hotword detector.
     *
     * @hide
     */
    int DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE = 2;

    /**
     * Starts hotword recognition.
     * <p>
@@ -97,6 +118,22 @@ public interface HotwordDetector {
     */
    void updateState(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory);

    /**
     * @hide
     */
    static String detectorTypeToString(int detectorType) {
        switch (detectorType) {
            case DETECTOR_TYPE_NORMAL:
                return "normal";
            case DETECTOR_TYPE_TRUSTED_HOTWORD_DSP:
                return "trusted_hotword_dsp";
            case DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE:
                return "trusted_hotword_software";
            default:
                return Integer.toString(detectorType);
        }
    }

    /**
     * The callback to notify of detection events.
     */
+3 −2
Original line number Diff line number Diff line
@@ -60,14 +60,15 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
            PersistableBundle options,
            SharedMemory sharedMemory,
            HotwordDetector.Callback callback) {
        super(managerService, callback);
        super(managerService, callback, DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE);

        mManagerService = managerService;
        mAudioFormat = audioFormat;
        mCallback = callback;
        mHandler = new Handler(Looper.getMainLooper());
        updateStateLocked(options, sharedMemory,
                new InitializationStateListener(mHandler, mCallback));
                new InitializationStateListener(mHandler, mCallback),
                DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE);
    }

    @RequiresPermission(RECORD_AUDIO)
+3 −1
Original line number Diff line number Diff line
@@ -242,12 +242,14 @@ interface IVoiceInteractionManagerService {
     * {@link HotwordDetectionService}. Use this to provide the hotword models data or other
     * such data to the trusted process.
     * @param callback Use this to report {@link HotwordDetectionService} status.
     * @param detectorType Indicate which detector is used.
     */
    void updateState(
            in Identity originatorIdentity,
            in PersistableBundle options,
            in SharedMemory sharedMemory,
            in IHotwordRecognitionStatusCallback callback);
            in IHotwordRecognitionStatusCallback callback,
                        int detectorType);

    /**
     * Requests to shutdown hotword detection service.
Loading