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