• 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 com.android.dialer.common.Assert;
20 import io.grpc.Status;
21 import io.grpc.Status.Code;
22 
23 /**
24  * Base class for encapulating a voicemail transcription server response. This handles the Grpc
25  * status response, subclasses will handle request specific responses.
26  */
27 public abstract class TranscriptionResponse {
28   @Nullable public final Status status;
29 
TranscriptionResponse()30   TranscriptionResponse() {
31     this.status = null;
32   }
33 
TranscriptionResponse(Status status)34   TranscriptionResponse(Status status) {
35     Assert.checkArgument(status != null);
36     this.status = status;
37   }
38 
hasRecoverableError()39   public boolean hasRecoverableError() {
40     if (status != null) {
41       return status.getCode() == Status.Code.UNAVAILABLE;
42     }
43 
44     return false;
45   }
46 
isStatusAlreadyExists()47   public boolean isStatusAlreadyExists() {
48     if (status != null) {
49       return status.getCode() == Code.ALREADY_EXISTS;
50     }
51 
52     return false;
53   }
54 
hasFatalError()55   public boolean hasFatalError() {
56     if (status != null) {
57       return status.getCode() != Status.Code.OK && status.getCode() != Status.Code.UNAVAILABLE;
58     }
59 
60     return false;
61   }
62 
63   @Override
toString()64   public String toString() {
65     return "status: " + status;
66   }
67 }
68