From 9fbb81d83f24d6f7ad9832bc16c3a41065eb9337 Mon Sep 17 00:00:00 2001 From: mdooley Date: Sun, 14 Jan 2018 09:31:50 -0800 Subject: Make sure that voicemail transcriptions are processed serially Since we are now using the AlarmManager to decide when to poll for voicemail transcriptions, we need to ensure that we don't start transcribing a voicemail until polling for the previous one ends. This cl postpones a voicemail transcription task if there is an alarm set to poll for a transcription result. After a transcription result is received (or we give up) the db is scanned for any pending transcriptions and the next one is started. Bug: 70242961 Test: manual and updated unit tests PiperOrigin-RevId: 181899975 Change-Id: I7b8fb696164980cf710aa58a79418c6954e2b4d2 --- .../impl/transcribe/TranscriptionTaskAsync.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java') diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java b/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java index bb7aa5f38..f6035fd2c 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java @@ -58,9 +58,24 @@ public class TranscriptionTaskAsync extends TranscriptionTask { protected Pair getTranscription() { VvmLog.i(TAG, "getTranscription"); + if (GetTranscriptReceiver.hasPendingAlarm(context)) { + // Don't start a transcription while another is still active + VvmLog.i( + TAG, + "getTranscription, pending transcription, postponing transcription of: " + voicemailUri); + return new Pair<>(null, null); + } + + TranscribeVoicemailAsyncRequest uploadRequest = getUploadRequest(); + VvmLog.i( + TAG, + "getTranscription, uploading voicemail: " + + voicemailUri + + ", id: " + + uploadRequest.getTranscriptionId()); TranscriptionResponseAsync uploadResponse = (TranscriptionResponseAsync) - sendRequest((client) -> client.sendUploadRequest(getUploadRequest())); + sendRequest((client) -> client.sendUploadRequest(uploadRequest)); if (cancelled) { VvmLog.i(TAG, "getTranscription, cancelled."); @@ -72,13 +87,14 @@ public class TranscriptionTaskAsync extends TranscriptionTask { VvmLog.i(TAG, "getTranscription, upload error: " + uploadResponse.status); return new Pair<>(null, TranscriptionStatus.FAILED_NO_RETRY); } else { - VvmLog.i(TAG, "getTranscription, begin polling for result."); + VvmLog.i(TAG, "getTranscription, begin polling for: " + uploadResponse.getTranscriptionId()); GetTranscriptReceiver.beginPolling( context, voicemailUri, uploadResponse.getTranscriptionId(), uploadResponse.getEstimatedWaitMillis(), - configProvider); + configProvider, + phoneAccountHandle); // This indicates that the result is not available yet return new Pair<>(null, null); } -- cgit v1.2.3