• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.dialer.voicemail.listui.error;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.os.Build.VERSION_CODES;
23 import android.provider.VoicemailContract.Status;
24 import android.support.annotation.NonNull;
25 import android.support.annotation.Nullable;
26 import android.support.annotation.RequiresApi;
27 import android.view.View;
28 import android.view.View.OnClickListener;
29 import com.android.contacts.common.util.ContactDisplayUtils;
30 import com.android.dialer.logging.DialerImpression;
31 import com.android.dialer.logging.Logger;
32 import com.android.dialer.voicemail.listui.error.VoicemailErrorMessage.Action;
33 
34 /**
35  * Create error message from {@link VoicemailStatus} for VVM3 visual voicemail. VVM3 is used only by
36  * Verizon Wireless.
37  */
38 @RequiresApi(VERSION_CODES.N_MR1)
39 public class Vvm3VoicemailMessageCreator {
40 
41   // Copied from com.android.phone.vvm.omtp.protocol.Vvm3EventHandler
42   // TODO(a bug): unbundle VVM client so we can access these values directly
43   public static final int VMS_DNS_FAILURE = -9001;
44   public static final int VMG_DNS_FAILURE = -9002;
45   public static final int SPG_DNS_FAILURE = -9003;
46   public static final int VMS_NO_CELLULAR = -9004;
47   public static final int VMG_NO_CELLULAR = -9005;
48   public static final int SPG_NO_CELLULAR = -9006;
49   public static final int VMS_TIMEOUT = -9007;
50   public static final int VMG_TIMEOUT = -9008;
51   public static final int STATUS_SMS_TIMEOUT = -9009;
52 
53   public static final int SUBSCRIBER_BLOCKED = -9990;
54   public static final int UNKNOWN_USER = -9991;
55   public static final int UNKNOWN_DEVICE = -9992;
56   public static final int INVALID_PASSWORD = -9993;
57   public static final int MAILBOX_NOT_INITIALIZED = -9994;
58   public static final int SERVICE_NOT_PROVISIONED = -9995;
59   public static final int SERVICE_NOT_ACTIVATED = -9996;
60   public static final int USER_BLOCKED = -9998;
61   public static final int IMAP_GETQUOTA_ERROR = -9997;
62   public static final int IMAP_SELECT_ERROR = -9989;
63   public static final int IMAP_ERROR = -9999;
64 
65   public static final int VMG_INTERNAL_ERROR = -101;
66   public static final int VMG_DB_ERROR = -102;
67   public static final int VMG_COMMUNICATION_ERROR = -103;
68   public static final int SPG_URL_NOT_FOUND = -301;
69 
70   // Non VVM3 codes:
71   public static final int VMG_UNKNOWN_ERROR = -1;
72   public static final int PIN_NOT_SET = -100;
73   public static final int SUBSCRIBER_UNKNOWN = -99;
74 
75   @Nullable
create( final Context context, final VoicemailStatus status, final VoicemailStatusReader statusReader)76   public static VoicemailErrorMessage create(
77       final Context context,
78       final VoicemailStatus status,
79       final VoicemailStatusReader statusReader) {
80     VoicemailErrorMessage tosMessage =
81         new VoicemailTosMessageCreator(context, status, statusReader).maybeCreateTosMessage();
82     if (tosMessage != null) {
83       return tosMessage;
84     }
85 
86     if (VMS_DNS_FAILURE == status.dataChannelState) {
87       return new VoicemailErrorMessage(
88           context.getString(R.string.vvm3_error_vms_dns_failure_title),
89           getCustomerSupportString(context, R.string.vvm3_error_vms_dns_failure_message),
90           VoicemailErrorMessage.createRetryAction(context, status),
91           createCallCustomerSupportAction(context));
92     }
93 
94     if (VMG_DNS_FAILURE == status.configurationState) {
95       return new VoicemailErrorMessage(
96           context.getString(R.string.vvm3_error_vmg_dns_failure_title),
97           getCustomerSupportString(context, R.string.vvm3_error_vmg_dns_failure_message),
98           VoicemailErrorMessage.createRetryAction(context, status),
99           createCallCustomerSupportAction(context));
100     }
101 
102     if (SPG_DNS_FAILURE == status.configurationState) {
103       return new VoicemailErrorMessage(
104           context.getString(R.string.vvm3_error_spg_dns_failure_title),
105           getCustomerSupportString(context, R.string.vvm3_error_spg_dns_failure_message),
106           VoicemailErrorMessage.createRetryAction(context, status),
107           createCallCustomerSupportAction(context));
108     }
109 
110     if (VMS_NO_CELLULAR == status.dataChannelState) {
111       return new VoicemailErrorMessage(
112           context.getString(R.string.vvm3_error_vms_no_cellular_title),
113           getCustomerSupportString(context, R.string.vvm3_error_vms_no_cellular_message),
114           VoicemailErrorMessage.createRetryAction(context, status),
115           createCallCustomerSupportAction(context));
116     }
117 
118     if (VMG_NO_CELLULAR == status.configurationState) {
119       return new VoicemailErrorMessage(
120           context.getString(R.string.vvm3_error_vmg_no_cellular_title),
121           getCustomerSupportString(context, R.string.vvm3_error_vmg_no_cellular_message),
122           VoicemailErrorMessage.createRetryAction(context, status),
123           createCallCustomerSupportAction(context));
124     }
125 
126     if (SPG_NO_CELLULAR == status.configurationState) {
127       return new VoicemailErrorMessage(
128           context.getString(R.string.vvm3_error_spg_no_cellular_title),
129           getCustomerSupportString(context, R.string.vvm3_error_spg_no_cellular_message),
130           VoicemailErrorMessage.createRetryAction(context, status),
131           createCallCustomerSupportAction(context));
132     }
133 
134     if (VMS_TIMEOUT == status.dataChannelState) {
135       return new VoicemailErrorMessage(
136           context.getString(R.string.vvm3_error_vms_timeout_title),
137           getCustomerSupportString(context, R.string.vvm3_error_vms_timeout_message),
138           VoicemailErrorMessage.createRetryAction(context, status),
139           createCallCustomerSupportAction(context));
140     }
141 
142     if (VMG_TIMEOUT == status.configurationState) {
143       return new VoicemailErrorMessage(
144           context.getString(R.string.vvm3_error_vmg_timeout_title),
145           getCustomerSupportString(context, R.string.vvm3_error_vmg_timeout_message),
146           VoicemailErrorMessage.createRetryAction(context, status),
147           createCallCustomerSupportAction(context));
148     }
149 
150     if (STATUS_SMS_TIMEOUT == status.notificationChannelState) {
151       return new VoicemailErrorMessage(
152           context.getString(R.string.vvm3_error_status_sms_timeout_title),
153           getCustomerSupportString(context, R.string.vvm3_error_status_sms_timeout_message),
154           VoicemailErrorMessage.createRetryAction(context, status),
155           createCallCustomerSupportAction(context));
156     }
157 
158     if (SUBSCRIBER_BLOCKED == status.configurationState) {
159       return new VoicemailErrorMessage(
160           context.getString(R.string.vvm3_error_subscriber_blocked_title),
161           getCustomerSupportString(context, R.string.vvm3_error_subscriber_blocked_message),
162           VoicemailErrorMessage.createRetryAction(context, status),
163           createCallCustomerSupportAction(context));
164     }
165 
166     if (UNKNOWN_USER == status.configurationState) {
167       return new VoicemailErrorMessage(
168           context.getString(R.string.vvm3_error_unknown_user_title),
169           getCustomerSupportString(context, R.string.vvm3_error_unknown_user_message),
170           VoicemailErrorMessage.createCallVoicemailAction(context, status.getPhoneAccountHandle()),
171           createCallCustomerSupportAction(context));
172     }
173 
174     if (UNKNOWN_DEVICE == status.configurationState) {
175       return new VoicemailErrorMessage(
176           context.getString(R.string.vvm3_error_unknown_device_title),
177           getCustomerSupportString(context, R.string.vvm3_error_unknown_device_message),
178           VoicemailErrorMessage.createCallVoicemailAction(context, status.getPhoneAccountHandle()),
179           createCallCustomerSupportAction(context));
180     }
181 
182     if (INVALID_PASSWORD == status.configurationState) {
183       return new VoicemailErrorMessage(
184           context.getString(R.string.vvm3_error_invalid_password_title),
185           getCustomerSupportString(context, R.string.vvm3_error_invalid_password_message),
186           VoicemailErrorMessage.createCallVoicemailAction(context, status.getPhoneAccountHandle()),
187           createCallCustomerSupportAction(context));
188     }
189 
190     if (MAILBOX_NOT_INITIALIZED == status.configurationState) {
191       return new VoicemailErrorMessage(
192           context.getString(R.string.vvm3_error_mailbox_not_initialized_title),
193           getCustomerSupportString(context, R.string.vvm3_error_mailbox_not_initialized_message),
194           createCallCustomerSupportAction(context));
195     }
196 
197     if (SERVICE_NOT_PROVISIONED == status.configurationState) {
198       return new VoicemailErrorMessage(
199           context.getString(R.string.vvm3_error_service_not_provisioned_title),
200           getCustomerSupportString(context, R.string.vvm3_error_service_not_provisioned_message),
201           createCallCustomerSupportAction(context));
202     }
203 
204     if (SERVICE_NOT_ACTIVATED == status.configurationState) {
205       return new VoicemailErrorMessage(
206           context.getString(R.string.vvm3_error_service_not_activated_title),
207           getCustomerSupportString(context, R.string.vvm3_error_service_not_activated_message),
208           createCallCustomerSupportAction(context));
209     }
210 
211     if (USER_BLOCKED == status.configurationState) {
212       return new VoicemailErrorMessage(
213           context.getString(R.string.vvm3_error_user_blocked_title),
214           getCustomerSupportString(context, R.string.vvm3_error_user_blocked_message),
215           createCallCustomerSupportAction(context));
216     }
217 
218     if (SUBSCRIBER_UNKNOWN == status.configurationState) {
219       return new VoicemailErrorMessage(
220           context.getString(R.string.vvm3_error_subscriber_unknown_title),
221           getCustomerSupportString(context, R.string.vvm3_error_subscriber_unknown_message),
222           VoicemailErrorMessage.createCallVoicemailAction(context, status.getPhoneAccountHandle()),
223           createCallCustomerSupportAction(context));
224     }
225 
226     if (IMAP_GETQUOTA_ERROR == status.dataChannelState) {
227       return new VoicemailErrorMessage(
228           context.getString(R.string.vvm3_error_imap_getquota_error_title),
229           getCustomerSupportString(context, R.string.vvm3_error_imap_getquota_error_message),
230           VoicemailErrorMessage.createCallVoicemailAction(context, status.getPhoneAccountHandle()),
231           createCallCustomerSupportAction(context));
232     }
233 
234     if (IMAP_SELECT_ERROR == status.dataChannelState) {
235       return new VoicemailErrorMessage(
236           context.getString(R.string.vvm3_error_imap_select_error_title),
237           getCustomerSupportString(context, R.string.vvm3_error_imap_select_error_message),
238           VoicemailErrorMessage.createCallVoicemailAction(context, status.getPhoneAccountHandle()),
239           createCallCustomerSupportAction(context));
240     }
241 
242     if (IMAP_ERROR == status.dataChannelState) {
243       return new VoicemailErrorMessage(
244           context.getString(R.string.vvm3_error_imap_error_title),
245           getCustomerSupportString(context, R.string.vvm3_error_imap_error_message),
246           VoicemailErrorMessage.createCallVoicemailAction(context, status.getPhoneAccountHandle()),
247           createCallCustomerSupportAction(context));
248     }
249 
250     if (PIN_NOT_SET == status.configurationState) {
251       Logger.get(context).logImpression(DialerImpression.Type.VOICEMAIL_ALERT_SET_PIN_SHOWN);
252       return new VoicemailErrorMessage(
253           context.getString(R.string.voicemail_error_pin_not_set_title),
254           getCustomerSupportString(context, R.string.voicemail_error_pin_not_set_message),
255           VoicemailErrorMessage.createSetPinAction(context, status.getPhoneAccountHandle()));
256     }
257 
258     return OmtpVoicemailMessageCreator.create(context, status, statusReader);
259   }
260 
isSyncBlockingError(VoicemailStatus status)261   public static boolean isSyncBlockingError(VoicemailStatus status) {
262     if (status.notificationChannelState != Status.NOTIFICATION_CHANNEL_STATE_OK) {
263       return true;
264     }
265 
266     if (status.dataChannelState != Status.DATA_CHANNEL_STATE_OK) {
267       return true;
268     }
269 
270     switch (status.configurationState) {
271       case PIN_NOT_SET:
272       case Status.CONFIGURATION_STATE_OK:
273         // allow activation to be queued again in case it is interrupted
274       case Status.CONFIGURATION_STATE_CONFIGURING:
275         return false;
276       default:
277         return true;
278     }
279   }
280 
281   @NonNull
getCustomerSupportString(Context context, int id)282   private static CharSequence getCustomerSupportString(Context context, int id) {
283     // TODO(twyen): get number based on the country the user is currently in.
284     return ContactDisplayUtils.getTtsSpannedPhoneNumber(
285         context.getResources(),
286         id,
287         context.getString(R.string.verizon_domestic_customer_support_display_number));
288   }
289 
290   @NonNull
createCallCustomerSupportAction(final Context context)291   private static Action createCallCustomerSupportAction(final Context context) {
292     return new Action(
293         context.getString(R.string.voicemail_action_call_customer_support),
294         new OnClickListener() {
295           @Override
296           public void onClick(View v) {
297             Intent intent =
298                 new Intent(
299                     Intent.ACTION_CALL,
300                     Uri.parse(
301                         "tel:"
302                             + context.getString(
303                                 R.string.verizon_domestic_customer_support_number)));
304             context.startActivity(intent);
305           }
306         });
307   }
308 }
309