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
17package com.android.incallui.disconnectdialog;
18
19import android.app.AlertDialog;
20import android.app.Dialog;
21import android.content.Context;
22import android.support.annotation.NonNull;
23import android.telecom.DisconnectCause;
24import android.text.TextUtils;
25import android.util.Pair;
26import com.android.incallui.call.DialerCall;
27
28/** Default error dialog shown to user after disconnect. */
29public class DefaultErrorDialog implements DisconnectDialog {
30
31  @Override
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
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