summaryrefslogtreecommitdiff
path: root/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java')
-rw-r--r--java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java71
1 files changed, 18 insertions, 53 deletions
diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java b/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
index 808bf0f87..bb7aa5f38 100644
--- a/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
+++ b/java/com/android/voicemail/impl/transcribe/TranscriptionTaskAsync.java
@@ -19,17 +19,13 @@ import android.app.job.JobWorkItem;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.util.Pair;
-import com.android.dialer.common.Assert;
import com.android.dialer.logging.DialerImpression;
-import com.android.dialer.logging.Logger;
import com.android.voicemail.VoicemailComponent;
import com.android.voicemail.impl.VvmLog;
import com.android.voicemail.impl.transcribe.TranscriptionService.JobCallback;
-import com.android.voicemail.impl.transcribe.grpc.GetTranscriptResponseAsync;
import com.android.voicemail.impl.transcribe.grpc.TranscriptionClientFactory;
import com.android.voicemail.impl.transcribe.grpc.TranscriptionResponseAsync;
import com.google.internal.communications.voicemailtranscription.v1.DonationPreference;
-import com.google.internal.communications.voicemailtranscription.v1.GetTranscriptRequest;
import com.google.internal.communications.voicemailtranscription.v1.TranscribeVoicemailAsyncRequest;
import com.google.internal.communications.voicemailtranscription.v1.TranscriptionStatus;
@@ -72,9 +68,19 @@ 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.getTranscriptionId() == null) {
+ VvmLog.i(TAG, "getTranscription, upload error: " + uploadResponse.status);
+ return new Pair<>(null, TranscriptionStatus.FAILED_NO_RETRY);
} else {
- waitForTranscription(uploadResponse);
- return pollForTranscription(uploadResponse);
+ VvmLog.i(TAG, "getTranscription, begin polling for result.");
+ GetTranscriptReceiver.beginPolling(
+ context,
+ voicemailUri,
+ uploadResponse.getTranscriptionId(),
+ uploadResponse.getEstimatedWaitMillis(),
+ configProvider);
+ // This indicates that the result is not available yet
+ return new Pair<>(null, null);
}
}
@@ -83,45 +89,6 @@ public class TranscriptionTaskAsync extends TranscriptionTask {
return DialerImpression.Type.VVM_TRANSCRIPTION_REQUEST_SENT_ASYNC;
}
- private static void waitForTranscription(TranscriptionResponseAsync uploadResponse) {
- long millis = uploadResponse.getEstimatedWaitMillis();
- VvmLog.i(TAG, "waitForTranscription, " + millis + " millis");
- sleep(millis);
- }
-
- private Pair<String, TranscriptionStatus> pollForTranscription(
- TranscriptionResponseAsync uploadResponse) {
- VvmLog.i(TAG, "pollForTranscription");
- GetTranscriptRequest request = getGetTranscriptRequest(uploadResponse);
- for (int i = 0; i < configProvider.getMaxGetTranscriptPolls(); i++) {
- if (cancelled) {
- VvmLog.i(TAG, "pollForTranscription, cancelled.");
- return new Pair<>(null, TranscriptionStatus.FAILED_NO_RETRY);
- }
- Logger.get(context).logImpression(DialerImpression.Type.VVM_TRANSCRIPTION_POLL_REQUEST);
- GetTranscriptResponseAsync response =
- (GetTranscriptResponseAsync)
- sendRequest((client) -> client.sendGetTranscriptRequest(request));
- if (cancelled) {
- VvmLog.i(TAG, "pollForTranscription, cancelled.");
- return new Pair<>(null, TranscriptionStatus.FAILED_NO_RETRY);
- } else if (response == null) {
- VvmLog.i(TAG, "pollForTranscription, no transcription result.");
- } else if (response.isTranscribing()) {
- VvmLog.i(TAG, "pollForTranscription, poll count: " + (i + 1));
- } else if (response.hasFatalError()) {
- VvmLog.i(TAG, "pollForTranscription, fail. " + response.getErrorDescription());
- return new Pair<>(null, response.getTranscriptionStatus());
- } else {
- VvmLog.i(TAG, "pollForTranscription, got transcription");
- return new Pair<>(response.getTranscript(), TranscriptionStatus.SUCCESS);
- }
- sleep(configProvider.getGetTranscriptPollIntervalMillis());
- }
- VvmLog.i(TAG, "pollForTranscription, timed out.");
- return new Pair<>(null, TranscriptionStatus.FAILED_NO_RETRY);
- }
-
@VisibleForTesting
TranscribeVoicemailAsyncRequest getUploadRequest() {
TranscribeVoicemailAsyncRequest.Builder builder =
@@ -134,7 +101,12 @@ public class TranscriptionTaskAsync extends TranscriptionTask {
// available (because rating donating voicemails requires locally generated voicemail ids).
if (configProvider.useClientGeneratedVoicemailIds()
|| configProvider.isVoicemailDonationAvailable()) {
- builder.setTranscriptionId(TranscriptionUtils.getFingerprintFor(audioData));
+ // The server currently can't handle repeated transcription id's so if we add the Uri to the
+ // fingerprint (which contains the voicemail id) which is different each time a voicemail is
+ // downloaded. If this becomes a problem then it should be possible to change the server
+ // behavior to allow id's to be re-used, a bug
+ String salt = voicemailUri.toString();
+ builder.setTranscriptionId(TranscriptionUtils.getFingerprintFor(audioData, salt));
}
return builder.build();
}
@@ -145,11 +117,4 @@ public class TranscriptionTaskAsync extends TranscriptionTask {
.getVoicemailClient()
.isVoicemailDonationEnabled(context, phoneAccountHandle);
}
-
- private GetTranscriptRequest getGetTranscriptRequest(TranscriptionResponseAsync uploadResponse) {
- Assert.checkArgument(uploadResponse.getTranscriptionId() != null);
- return GetTranscriptRequest.newBuilder()
- .setTranscriptionId(uploadResponse.getTranscriptionId())
- .build();
- }
}