From 410bf3115122e7298d27b7f5b4daeb6b80edc5d9 Mon Sep 17 00:00:00 2001 From: uabdullah Date: Thu, 29 Mar 2018 18:03:47 -0700 Subject: 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 --- .../voicemail/impl/transcribe/GetTranscriptReceiver.java | 2 +- .../voicemail/impl/transcribe/TranscriptionTaskAsync.java | 10 ++++++++++ .../voicemail/impl/transcribe/grpc/TranscriptionResponse.java | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3