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
This commit is contained in:
Nate Myren
2023-02-08 15:41:36 -08:00
parent e93dca15c8
commit 718cbd32ce

View File

@@ -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);