Perform checking for restarting SandboxedDetectionProcesses

SandboxedDetectionServices should not be started unexpectedly if the
service is not specified. This change adds a checking to fix this.

Bug: 265535257
Test: atest CtsVoiceInteractionTestCases
Change-Id: I6143079bbf3288039246ce5f9af27164a84b0958
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
index 665d5e7..dfa6f86 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java
@@ -432,9 +432,15 @@
         mLastRestartInstant = Instant.now();
         // Recreate connection to reset the cache.
 
-        mRemoteHotwordDetectionService = mHotwordDetectionServiceConnectionFactory.createLocked();
-        mRemoteVisualQueryDetectionService =
-                mVisualQueryDetectionServiceConnectionFactory.createLocked();
+        if (oldHotwordConnection != null) {
+            mRemoteHotwordDetectionService =
+                    mHotwordDetectionServiceConnectionFactory.createLocked();
+        }
+
+        if (oldVisualQueryDetectionConnection != null) {
+            mRemoteVisualQueryDetectionService =
+                    mVisualQueryDetectionServiceConnectionFactory.createLocked();
+        }
 
         Slog.v(TAG, "Started the new process, dispatching processRestarted to detector");
         runForEachDetectorSessionLocked((session) -> {