From b6e44763bd888f12142a3ac797848a36ef31e339 Mon Sep 17 00:00:00 2001 From: Joanne Chung Date: Wed, 30 Mar 2022 20:39:10 +0800 Subject: [PATCH] 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 --- .../HotwordDetectionConnection.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index c86f38d4264de..8d4a0176e3be2 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -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);