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

Commit b6e44763 authored by Joanne Chung's avatar Joanne Chung
Browse files

Allow to update restart period dynamically.

We use a flag to control the restart period time, the value is static
and set in class level that means if we update the device config, we
should reboot the device to get the updated value.

This change reads the value in the constructor, so the value will be
updated when the voice interaction app updates no need to reboot.
Ideally it's good to listen the value change dynamically but it
increases the complexity here, we provide a workable and safe change
now.

Bug: 224618257
Test: update the package and the value is expected by command:
adb shell dumpsys voiceinteraction | grep RESTART_PERIOD_SECONDS

Change-Id: Id7d5f2d4f17de1f36baf6509598a82d6d73c5b53
parent a84dc9b8
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -119,13 +119,6 @@ final class HotwordDetectionConnection {
    private static final Duration MAX_UPDATE_TIMEOUT_DURATION =
            Duration.ofMillis(MAX_UPDATE_TIMEOUT_MILLIS);
    private static final long RESET_DEBUG_HOTWORD_LOGGING_TIMEOUT_MILLIS = 60 * 60 * 1000; // 1 hour
    /**
     * Time after which each HotwordDetectionService process is stopped and replaced by a new one.
     * 0 indicates no restarts.
     */
    private static final int RESTART_PERIOD_SECONDS =
            DeviceConfig.getInt(DeviceConfig.NAMESPACE_VOICE_INTERACTION,
                    KEY_RESTART_PERIOD_IN_SECONDS, 0);
    private static final int MAX_ISOLATED_PROCESS_NUMBER = 10;

    // Hotword metrics
@@ -150,6 +143,11 @@ final class HotwordDetectionConnection {
    private final @NonNull ServiceConnectionFactory mServiceConnectionFactory;
    private final IHotwordRecognitionStatusCallback mCallback;
    private final int mDetectorType;
    /**
     * Time after which each HotwordDetectionService process is stopped and replaced by a new one.
     * 0 indicates no restarts.
     */
    private final int mReStartPeriodSeconds;

    final Object mLock;
    final int mVoiceInteractionServiceUid;
@@ -195,6 +193,8 @@ final class HotwordDetectionConnection {
        mUser = userId;
        mCallback = callback;
        mDetectorType = detectorType;
        mReStartPeriodSeconds = DeviceConfig.getInt(DeviceConfig.NAMESPACE_VOICE_INTERACTION,
                KEY_RESTART_PERIOD_IN_SECONDS, 0);
        final Intent intent = new Intent(HotwordDetectionService.SERVICE_INTERFACE);
        intent.setComponent(mDetectionComponentName);
        initAudioFlingerLocked();
@@ -206,11 +206,11 @@ final class HotwordDetectionConnection {
        mLastRestartInstant = Instant.now();
        updateStateAfterProcessStart(options, sharedMemory);

        if (RESTART_PERIOD_SECONDS <= 0) {
        if (mReStartPeriodSeconds <= 0) {
            mCancellationTaskFuture = null;
        } else {
            // TODO(volnov): we need to be smarter here, e.g. schedule it a bit more often, but wait
            // until the current session is closed.
            // TODO: we need to be smarter here, e.g. schedule it a bit more often,
            //  but wait until the current session is closed.
            mCancellationTaskFuture = mScheduledExecutorService.scheduleAtFixedRate(() -> {
                Slog.v(TAG, "Time to restart the process, TTL has passed");
                synchronized (mLock) {
@@ -218,7 +218,7 @@ final class HotwordDetectionConnection {
                    HotwordMetricsLogger.writeServiceRestartEvent(mDetectorType,
                            HOTWORD_DETECTION_SERVICE_RESTARTED__REASON__SCHEDULE);
                }
            }, RESTART_PERIOD_SECONDS, RESTART_PERIOD_SECONDS, TimeUnit.SECONDS);
            }, mReStartPeriodSeconds, mReStartPeriodSeconds, TimeUnit.SECONDS);
        }
    }

@@ -785,7 +785,7 @@ final class HotwordDetectionConnection {
    }

    public void dump(String prefix, PrintWriter pw) {
        pw.print(prefix); pw.print("RESTART_PERIOD_SECONDS="); pw.println(RESTART_PERIOD_SECONDS);
        pw.print(prefix); pw.print("mReStartPeriodSeconds="); pw.println(mReStartPeriodSeconds);
        pw.print(prefix);
        pw.print("mBound=" + mRemoteHotwordDetectionService.isBound());
        pw.print(", mValidatingDspTrigger=" + mValidatingDspTrigger);