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 17 package com.android.incallui.disconnectdialog; 18 19 import android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.content.Context; 22 import android.support.annotation.NonNull; 23 import android.telecom.DisconnectCause; 24 import android.text.TextUtils; 25 import android.util.Pair; 26 import com.android.incallui.call.DialerCall; 27 28 /** Default error dialog shown to user after disconnect. */ 29 public class DefaultErrorDialog implements DisconnectDialog { 30 31 @Override shouldShow(DisconnectCause disconnectCause)32 public boolean shouldShow(DisconnectCause disconnectCause) { 33 return !TextUtils.isEmpty(disconnectCause.getDescription()) 34 && (disconnectCause.getCode() == DisconnectCause.ERROR 35 || disconnectCause.getCode() == DisconnectCause.RESTRICTED); 36 } 37 38 @Override createDialog(@onNull Context context, DialerCall call)39 public Pair<Dialog, CharSequence> createDialog(@NonNull Context context, DialerCall call) { 40 DisconnectCause disconnectCause = call.getDisconnectCause(); 41 CharSequence message = disconnectCause.getDescription(); 42 43 Dialog dialog = 44 new AlertDialog.Builder(context) 45 .setMessage(message) 46 .setPositiveButton(android.R.string.cancel, null) 47 .create(); 48 return new Pair<>(dialog, message); 49 } 50 } 51