• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 package com.android.voicemail.impl.transcribe.grpc;
17 
18 import android.support.annotation.Nullable;
19 import android.support.annotation.VisibleForTesting;
20 import com.android.dialer.common.Assert;
21 import com.google.internal.communications.voicemailtranscription.v1.TranscribeVoicemailAsyncResponse;
22 import io.grpc.Status;
23 
24 /** Container for response and status objects for an asynchronous transcription upload request */
25 public class TranscriptionResponseAsync extends TranscriptionResponse {
26   @Nullable private final TranscribeVoicemailAsyncResponse response;
27 
28   @VisibleForTesting
TranscriptionResponseAsync(TranscribeVoicemailAsyncResponse response)29   public TranscriptionResponseAsync(TranscribeVoicemailAsyncResponse response) {
30     Assert.checkArgument(response != null);
31     this.response = response;
32   }
33 
34   @VisibleForTesting
TranscriptionResponseAsync(Status status)35   public TranscriptionResponseAsync(Status status) {
36     super(status);
37     this.response = null;
38   }
39 
getTranscriptionId()40   public @Nullable String getTranscriptionId() {
41     if (response != null) {
42       return response.getTranscriptionId();
43     }
44     return null;
45   }
46 
getEstimatedWaitMillis()47   public long getEstimatedWaitMillis() {
48     if (response != null) {
49       return response.getEstimatedWaitSecs() * 1_000L;
50     }
51     return 0;
52   }
53 
54   @Override
toString()55   public String toString() {
56     return super.toString() + ", response: " + response;
57   }
58 }
59