• 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 
17 package com.android.incallui.disconnectdialog;
18 
19 import android.app.Dialog;
20 import android.content.Context;
21 import android.telecom.DisconnectCause;
22 import android.util.Pair;
23 import com.android.incallui.call.DialerCall;
24 import java.util.Locale;
25 
26 /**
27  * Wrapper class around @Code{android.telecom.DisconnectCause} to provide more information to user.
28  */
29 public class DisconnectMessage {
30 
31   // Disconnect dialog catalog. Default error dialog MUST be last one.
32   private static final DisconnectDialog[] DISCONNECT_DIALOGS =
33       new DisconnectDialog[] {
34         new EnableWifiCallingPrompt(), new VideoCallNotAvailablePrompt(), new DefaultErrorDialog()
35       };
36 
37   public final Dialog dialog;
38   public final CharSequence toastMessage;
39   private final DisconnectCause cause;
40 
DisconnectMessage(Context context, DialerCall call)41   public DisconnectMessage(Context context, DialerCall call) {
42     cause = call.getDisconnectCause();
43 
44     for (DisconnectDialog disconnectDialog : DISCONNECT_DIALOGS) {
45       if (disconnectDialog.shouldShow(cause)) {
46         Pair<Dialog, CharSequence> pair = disconnectDialog.createDialog(context, call);
47         dialog = pair.first;
48         toastMessage = pair.second;
49         return;
50       }
51     }
52     dialog = null;
53     toastMessage = null;
54   }
55 
56   @Override
toString()57   public String toString() {
58     return String.format(
59         Locale.ENGLISH,
60         "DisconnectMessage {code: %d, description: %s, reason: %s, message: %s}",
61         cause.getCode(),
62         cause.getDescription(),
63         cause.getReason(),
64         toastMessage);
65   }
66 }
67