summaryrefslogtreecommitdiff
path: root/java/com/android/voicemail
diff options
context:
space:
mode:
authoruabdullah <uabdullah@google.com>2018-03-29 18:03:47 -0700
committerCopybara-Service <copybara-piper@google.com>2018-03-29 18:05:51 -0700
commit410bf3115122e7298d27b7f5b4daeb6b80edc5d9 (patch)
tree2bb34854a35722e852b6e9700a0d2db348425006 /java/com/android/voicemail
parent0afd6bab1c6d1111a23802ff7381e3b4694c92e3 (diff)
Use existing transcription from transcription server if available
Repeated requests from the server responds in an ALREADY_EXISTS error and does not transcribe the voicemails. In that case we should ask the server if the request is present already on the server, and if so retrieve it. Bug: 77236260 Test: N/A PiperOrigin-RevId: 191016332 Change-Id: I605c546a3bec3599c7b162853463ca7e46f63886
Diffstat (limited to 'java/com/android/voicemail')
-rw-r--r--java/com/android/voicemail/impl/transcribe/GetTranscriptReceiver.java2
-rw-r--r--java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java10
-rw-r--r--java/com/android/voicemail/impl/transcribe/grpc/TranscriptionResponse.java9
3 files changed, 20 insertions, 1 deletions
diff --git a/java/com/android/voicemail/impl/transcribe/GetTranscriptReceiver.java b/java/com/android/voicemail/impl/transcribe/GetTranscriptReceiver.java
index cbf165753..5c5bae547 100644
--- a/java/com/android/voicemail/impl/transcribe/GetTranscriptReceiver.java
+++ b/java/com/android/voicemail/impl/transcribe/GetTranscriptReceiver.java
@@ -295,7 +295,7 @@ public class GetTranscriptReceiver extends BroadcastReceiver {
transcriptionClientFactoryForTesting = factory;
}
- private static TranscriptionClientFactory getTranscriptionClientFactory(Context context) {
+ static TranscriptionClientFactory getTranscriptionClientFactory(Context context) {
if (transcriptionClientFactoryForTesting != null) {
return transcriptionClientFactoryForTesting;
}
diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java b/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
index 60a6811ac..034af6bfc 100644
--- a/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
+++ b/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
@@ -83,6 +83,16 @@ public class TranscriptionTaskAsync extends TranscriptionTask {
} else if (uploadResponse == null) {
VvmLog.i(TAG, "getTranscription, failed to upload voicemail.");
return new Pair<>(null, TranscriptionStatus.FAILED_NO_RETRY);
+ } else if (uploadResponse.isStatusAlreadyExists()) {
+ VvmLog.i(TAG, "getTranscription, transcription already exists.");
+ GetTranscriptReceiver.beginPolling(
+ context,
+ voicemailUri,
+ uploadRequest.getTranscriptionId(),
+ 0,
+ configProvider,
+ phoneAccountHandle);
+ return new Pair<>(null, null);
} else if (uploadResponse.getTranscriptionId() == null) {
VvmLog.i(TAG, "getTranscription, upload error: " + uploadResponse.status);
return new Pair<>(null, TranscriptionStatus.FAILED_NO_RETRY);
diff --git a/java/com/android/voicemail/impl/transcribe/grpc/TranscriptionResponse.java b/java/com/android/voicemail/impl/transcribe/grpc/TranscriptionResponse.java
index ae4796dea..bd65abe84 100644
--- a/java/com/android/voicemail/impl/transcribe/grpc/TranscriptionResponse.java
+++ b/java/com/android/voicemail/impl/transcribe/grpc/TranscriptionResponse.java
@@ -18,6 +18,7 @@ package com.android.voicemail.impl.transcribe.grpc;
import android.support.annotation.Nullable;
import com.android.dialer.common.Assert;
import io.grpc.Status;
+import io.grpc.Status.Code;
/**
* Base class for encapulating a voicemail transcription server response. This handles the Grpc
@@ -43,6 +44,14 @@ public abstract class TranscriptionResponse {
return false;
}
+ public boolean isStatusAlreadyExists() {
+ if (status != null) {
+ return status.getCode() == Code.ALREADY_EXISTS;
+ }
+
+ return false;
+ }
+
public boolean hasFatalError() {
if (status != null) {
return status.getCode() != Status.Code.OK && status.getCode() != Status.Code.UNAVAILABLE;