MicIndicatorTest recognition service config fix

The selected recognition service in
testNonTrustedRecognitionServiceCanBlameCallingApp is now changed back
at the end of the test execution. Previously, this value would
propagate to the other test cases and make
testTrustedRecognitionServiceCanBlameCallingApp fail.

Bug: 288339499
Test: atest
Change-Id: I149a57a9c6f38b9eb6179b980e07ee72ee44541a
diff --git a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/RecognitionServiceMicIndicatorTest.java b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/RecognitionServiceMicIndicatorTest.java
index 1de78f2..056004a 100644
--- a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/RecognitionServiceMicIndicatorTest.java
+++ b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/RecognitionServiceMicIndicatorTest.java
@@ -44,6 +44,7 @@
 import androidx.test.rule.ActivityTestRule;
 import androidx.test.runner.AndroidJUnit4;
 
+import com.android.compatibility.common.util.CddTest;
 import com.android.compatibility.common.util.SettingsStateChangerRule;
 import com.android.compatibility.common.util.SystemUtil;
 
@@ -159,6 +160,10 @@
         mUiDevice.waitForIdle();
     }
 
+    private String getCurrentRecognizer() {
+        return Settings.Secure.getString(mContext.getContentResolver(), VOICE_RECOGNITION_SERVICE);
+    }
+
     private void setIndicatorsEnabledState(String enabled) {
         runWithShellPermissionIdentity(
                 () -> DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY, INDICATORS_FLAG,
@@ -183,16 +188,26 @@
     }
 
     @Test
+    @CddTest(requirements = {"9.8.2/H-4-1"})
     public void testNonTrustedRecognitionServiceCanBlameCallingApp() throws Throwable {
-        // We treat trusted if the current voice recognizer is also a preinstalled app. This is a
-        // untrusted case.
+        // Save currently selected recognition service.
+        String previousRecognizer = getCurrentRecognizer();
+
+        // We treat trusted if the current voice recognizer is also a preinstalled app.
+        // This is an untrusted case.
         setCurrentRecognizer(CTS_VOICE_RECOGNITION_SERVICE);
 
-        // verify that the untrusted app cannot blame the calling app mic access
-        testVoiceRecognitionServiceBlameCallingApp(/* trustVoiceService */ false);
+        try {
+            // Verify that the untrusted app cannot blame the calling app mic access.
+            testVoiceRecognitionServiceBlameCallingApp(/* trustVoiceService */ false);
+        } finally {
+            // Reinstate previously selected recognition service.
+            setCurrentRecognizer(previousRecognizer);
+        }
     }
 
     @Test
+    @CddTest(requirements = {"9.8.2/H-4-1"})
     public void testTrustedRecognitionServiceCanBlameCallingApp() throws Throwable {
         // We treat trusted if the current voice recognizer is also a preinstalled app. This is a
         // trusted case.