From ead9d0a229e3ea2372a1ea55249925a19a71f9bb Mon Sep 17 00:00:00 2001 From: Nicholas Ambur Date: Fri, 3 Mar 2023 21:41:02 +0000 Subject: [PATCH] remove instances of IllegalDetectorStateException Test: build VoiceInteraction test app only Bug: 260387702 Change-Id: Ia967f461a44cae28cc00337b14b35641264bce1b --- .../android/voiceinteractor/MainActivity.java | 6 +-- .../SampleVoiceInteractionService.java | 50 +++---------------- 2 files changed, 9 insertions(+), 47 deletions(-) diff --git a/samples/VoiceInteractionService/src/com/example/android/voiceinteractor/MainActivity.java b/samples/VoiceInteractionService/src/com/example/android/voiceinteractor/MainActivity.java index 7272531ef..483a36e11 100644 --- a/samples/VoiceInteractionService/src/com/example/android/voiceinteractor/MainActivity.java +++ b/samples/VoiceInteractionService/src/com/example/android/voiceinteractor/MainActivity.java @@ -53,11 +53,7 @@ public class MainActivity extends Activity { Log.e(TAG, "No service"); return; } - try { - mService.mHotwordDetector.startRecognition(); - } catch (HotwordDetector.IllegalDetectorStateException e) { - e.printStackTrace(); - } + mService.mHotwordDetector.startRecognition(); } }); button = (Button) findViewById(R.id.directRecord); diff --git a/samples/VoiceInteractionService/src/com/example/android/voiceinteractor/SampleVoiceInteractionService.java b/samples/VoiceInteractionService/src/com/example/android/voiceinteractor/SampleVoiceInteractionService.java index 84729c181..165a2613b 100644 --- a/samples/VoiceInteractionService/src/com/example/android/voiceinteractor/SampleVoiceInteractionService.java +++ b/samples/VoiceInteractionService/src/com/example/android/voiceinteractor/SampleVoiceInteractionService.java @@ -34,7 +34,6 @@ import android.service.voice.AlwaysOnHotwordDetector; import android.service.voice.AlwaysOnHotwordDetector.EventPayload; import android.service.voice.DetectorFailure; import android.service.voice.HotwordDetector; -import android.service.voice.HotwordDetector.IllegalDetectorStateException; import android.service.voice.HotwordRejectedResult; import android.service.voice.SandboxedDetectionInitializer; import android.service.voice.VisualQueryDetector; @@ -140,22 +139,14 @@ public class SampleVoiceInteractionService extends VoiceInteractionService { public void onVisualQueryDetectionServiceInitialized(int status) { Log.i(TAG, "VQD init: "+ status); if (status == SandboxedDetectionInitializer.INITIALIZATION_STATUS_SUCCESS) { - try { - mVisualQueryDetector.startRecognition(); - } catch (IllegalDetectorStateException e) { - e.printStackTrace(); - } + mVisualQueryDetector.startRecognition(); } } @Override public void onVisualQueryDetectionServiceRestarted() { Log.i(TAG, "VQD restarted"); - try { - mVisualQueryDetector.startRecognition(); - } catch (IllegalDetectorStateException e) { - e.printStackTrace(); - } + mVisualQueryDetector.startRecognition(); } @Override @@ -182,11 +173,7 @@ public class SampleVoiceInteractionService extends VoiceInteractionService { } if (status == STATE_KEYPHRASE_UNENROLLED) { Intent enrollIntent = null; - try { - enrollIntent = ((AlwaysOnHotwordDetector) mHotwordDetector).createEnrollIntent(); - } catch (IllegalDetectorStateException e) { - e.printStackTrace(); - } + enrollIntent = ((AlwaysOnHotwordDetector) mHotwordDetector).createEnrollIntent(); if (enrollIntent == null) { Log.w(TAG, "No enroll intent found. Try enrolling the keyphrase using the" + " device's default assistant."); @@ -203,11 +190,7 @@ public class SampleVoiceInteractionService extends VoiceInteractionService { @Override public void onRejected(@NonNull HotwordRejectedResult result) { - try { - mHotwordDetector.startRecognition(); - } catch (IllegalDetectorStateException e) { - e.printStackTrace(); - } + mHotwordDetector.startRecognition(); } @Override @@ -249,11 +232,7 @@ public class SampleVoiceInteractionService extends VoiceInteractionService { Trace.setCounter("VIS AudioRecord.getState", record.getState()); Log.e(TAG, "Failed to init first AudioRecord."); - try { - mHotwordDetector.startRecognition(); - } catch (IllegalDetectorStateException e) { - e.printStackTrace(); - } + mHotwordDetector.startRecognition(); return; } @@ -281,22 +260,13 @@ public class SampleVoiceInteractionService extends VoiceInteractionService { mData.putByteArray("1", buffer); mAudioFormat = eventPayload.getCaptureAudioFormat(); mLastPayload = eventPayload; - - try { - mHotwordDetector.startRecognition(); - } catch (IllegalDetectorStateException e) { - e.printStackTrace(); - } + mHotwordDetector.startRecognition(); } @Override public void onError() { Log.i(TAG, "onError"); - try { - mHotwordDetector.startRecognition(); - } catch (IllegalDetectorStateException e) { - e.printStackTrace(); - } + mHotwordDetector.startRecognition(); } @Override @@ -314,11 +284,7 @@ public class SampleVoiceInteractionService extends VoiceInteractionService { Log.i(TAG, "onHotwordDetectionServiceInitialized: " + status + ". mAvailable=" + mAvailable); if (mAvailable) { - try { - mHotwordDetector.startRecognition(); - } catch (IllegalDetectorStateException e) { - e.printStackTrace(); - } + mHotwordDetector.startRecognition(); } //TODO(b/265535257): Provide two services independent lifecycle. mVisualQueryDetector = createVisualQueryDetector(null, null,