summaryrefslogtreecommitdiff
path: root/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
diff options
context:
space:
mode:
authormdooley <mdooley@google.com>2018-01-14 09:31:50 -0800
committerCopybara-Service <copybara-piper@google.com>2018-01-14 09:34:53 -0800
commit9fbb81d83f24d6f7ad9832bc16c3a41065eb9337 (patch)
treee50dd75250358ee2cf1a86eecbbbef2e40daab79 /java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
parent25f24a79a24334e23706c2a8d69903820c622edb (diff)
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
Diffstat (limited to 'java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java')
-rw-r--r--java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java22
1 files changed, 19 insertions, 3 deletions
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<String, TranscriptionStatus> 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);
}