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

Commit 1b2b909a authored by Sergey Volnov's avatar Sergey Volnov
Browse files

Implement preriodic trusted process restarting for hotword detectors.

Bug: 188892570
Test: 1) adb shell cmd voiceinteraction restart-detection
2) Tried locally with restarting every 30 seconds, verified everything
works
3) adb shell ps | grep <test_package_name> - shows:

u0_a221       3328  1026 14501612 69208 0                   0 R com.google.th
u0_i9002      9049  1026 14448104 53860 0                   0 S com.google.th:com.google.th.SampleHotwordDetectionService:hotword_detector_3

Change-Id: I9f08943212c20b83da35c18df56460eaedbbf8f0
parent 81980798
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -263,6 +263,7 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
    private static final int MSG_DETECTION_RESUME = 5;
    private static final int MSG_HOTWORD_REJECTED = 6;
    private static final int MSG_HOTWORD_STATUS_REPORTED = 7;
    private static final int MSG_PROCESS_RESTARTED = 8;

    private final String mText;
    private final Locale mLocale;
@@ -1212,6 +1213,12 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
            message.arg1 = status;
            message.sendToTarget();
        }

        @Override
        public void onProcessRestarted() {
            Slog.i(TAG, "onProcessRestarted");
            mHandler.sendEmptyMessage(MSG_PROCESS_RESTARTED);
        }
    }

    class MyHandler extends Handler {
@@ -1246,6 +1253,9 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
                case MSG_HOTWORD_STATUS_REPORTED:
                    mExternalCallback.onHotwordDetectionServiceInitialized(msg.arg1);
                    break;
                case MSG_PROCESS_RESTARTED:
                    mExternalCallback.onHotwordDetectionServiceRestarted();
                    break;
                default:
                    super.handleMessage(msg);
            }
+1 −3
Original line number Diff line number Diff line
@@ -291,9 +291,7 @@ public abstract class HotwordDetectionService extends Service {
            @Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory,
            @DurationMillisLong long callbackTimeoutMillis,
            @Nullable IntConsumer statusCallback) {
        // TODO: Handle the unimplemented case by throwing?
    }
            @Nullable IntConsumer statusCallback) {}

    /**
     * Called when the {@link VoiceInteractionService} requests that this service
+27 −7
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
            this.mCallback = callback;
        }

        /** TODO: onDetected */
        /** Called when the detected result is valid. */
        @Override
        public void onDetected(
                @Nullable HotwordDetectedResult hotwordDetectedResult,
@@ -150,33 +150,45 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
        public void onKeyphraseDetected(
                SoundTrigger.KeyphraseRecognitionEvent recognitionEvent,
                HotwordDetectedResult result) {

            if (DEBUG) {
                Slog.i(TAG, "Ignored #onKeyphraseDetected event");
            }
        }

        @Override
        public void onGenericSoundTriggerDetected(
                SoundTrigger.GenericRecognitionEvent recognitionEvent) throws RemoteException {

            if (DEBUG) {
                Slog.i(TAG, "Ignored #onGenericSoundTriggerDetected event");
            }
        }

        @Override
        public void onRejected(HotwordRejectedResult result) throws RemoteException {

            if (DEBUG) {
                Slog.i(TAG, "Ignored #onRejected event");
            }
        }

        @Override
        public void onError(int status) throws RemoteException {

            if (DEBUG) {
                Slog.i(TAG, "Ignored #onError (" + status + ") event");
            }
        }

        @Override
        public void onRecognitionPaused() throws RemoteException {

            if (DEBUG) {
                Slog.i(TAG, "Ignored #onRecognitionPaused event");
            }
        }

        @Override
        public void onRecognitionResumed() throws RemoteException {

            if (DEBUG) {
                Slog.i(TAG, "Ignored #onRecognitionResumed event");
            }
        }

        @Override
@@ -187,6 +199,14 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
                    mCallback,
                    status));
        }

        @Override
        public void onProcessRestarted() throws RemoteException {
            Slog.v(TAG, "onProcessRestarted()");
            mHandler.sendMessage(obtainMessage(
                    HotwordDetector.Callback::onHotwordDetectionServiceRestarted,
                    mCallback));
        }
    }

    /** @hide */
+3 −0
Original line number Diff line number Diff line
@@ -78,4 +78,7 @@ oneway interface IHotwordRecognitionStatusCallback {
     * @param status The status about the result of requesting update state action.
     */
    void onStatusReported(int status);

    /** Called when the hotword detection process is restarted */
    void onProcessRestarted();
}
+1 −1
Original line number Diff line number Diff line
@@ -228,7 +228,7 @@ public interface ServiceConnector<I extends IInterface> {
        private final int mBindingFlags;
        private final @Nullable Function<IBinder, I> mBinderAsInterface;
        private final @NonNull Handler mHandler;
        private final @NonNull Executor mExecutor;
        protected final @NonNull Executor mExecutor;

        private volatile I mService = null;
        private boolean mBinding = false;
Loading