From 718cbd32cee6e2fc43c98f50b951cd1b04210331 Mon Sep 17 00:00:00 2001 From: Nate Myren Date: Wed, 8 Feb 2023 15:41:36 -0800 Subject: [PATCH] Add sessions to RecognitionService before starting In order for the handleAttributionContextCreation method to work properly, sessions must be added to the map before calling onStartListening. If the permission checks fail, then they can be removed afterwards Bug: 255108991 Test: manual Change-Id: I2380600d6b9ee88c78ceb8a839563da5fefe1919 --- core/java/android/speech/RecognitionService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/java/android/speech/RecognitionService.java b/core/java/android/speech/RecognitionService.java index 1cc772ac44559..a5dbdd7ce89a9 100644 --- a/core/java/android/speech/RecognitionService.java +++ b/core/java/android/speech/RecognitionService.java @@ -142,6 +142,10 @@ public abstract class RecognitionService extends Service { if (preflightPermissionCheckPassed) { currentCallback = new Callback(listener, attributionSource); sessionState = new SessionState(currentCallback); + mSessions.put(listener.asBinder(), sessionState); + if (DBG) { + Log.d(TAG, "Added a new session to the map, pending permission checks"); + } RecognitionService.this.onStartListening(intent, currentCallback); } @@ -151,16 +155,12 @@ public abstract class RecognitionService extends Service { if (preflightPermissionCheckPassed) { // If start listening was attempted, cancel the callback. RecognitionService.this.onCancel(currentCallback); + mSessions.remove(listener.asBinder()); finishDataDelivery(sessionState); sessionState.reset(); } Log.i(TAG, "#startListening received from a caller " + "without permission " + Manifest.permission.RECORD_AUDIO + "."); - } else { - if (DBG) { - Log.d(TAG, "Added a new session to the map."); - } - mSessions.put(listener.asBinder(), sessionState); } } else { listener.onError(SpeechRecognizer.ERROR_CLIENT);