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.phone.vvm.omtp; 18 19 import android.content.Context; 20 import android.provider.VoicemailContract; 21 import android.provider.VoicemailContract.Status; 22 23 import com.android.phone.VoicemailStatus; 24 import com.android.phone.vvm.omtp.OmtpEvents.Type; 25 26 public class DefaultOmtpEventHandler { 27 28 private static final String TAG = "DefErrorCodeHandler"; 29 handleEvent(Context context, OmtpVvmCarrierConfigHelper config, VoicemailStatus.Editor status, OmtpEvents event)30 public static void handleEvent(Context context, OmtpVvmCarrierConfigHelper config, 31 VoicemailStatus.Editor status, OmtpEvents event) { 32 switch (event.getType()) { 33 case Type.CONFIGURATION: 34 handleConfigurationEvent(context, status, event); 35 break; 36 case Type.DATA_CHANNEL: 37 handleDataChannelEvent(context, status, event); 38 break; 39 case Type.NOTIFICATION_CHANNEL: 40 handleNotificationChannelEvent(context, config, status, event); 41 break; 42 case Type.OTHER: 43 handleOtherEvent(context, status, event); 44 break; 45 default: 46 VvmLog.wtf(TAG, "invalid event type " + event.getType() + " for " + event); 47 } 48 } 49 handleConfigurationEvent(Context context, VoicemailStatus.Editor status, OmtpEvents event)50 private static void handleConfigurationEvent(Context context, VoicemailStatus.Editor status, 51 OmtpEvents event) { 52 switch (event) { 53 case CONFIG_DEFAULT_PIN_REPLACED: 54 case CONFIG_REQUEST_STATUS_SUCCESS: 55 case CONFIG_PIN_SET: 56 status 57 .setConfigurationState(VoicemailContract.Status.CONFIGURATION_STATE_OK) 58 .setNotificationChannelState(Status.NOTIFICATION_CHANNEL_STATE_OK) 59 .apply(); 60 break; 61 case CONFIG_ACTIVATING: 62 // Wipe all errors from the last activation. All errors shown should be new errors 63 // for this activation. 64 status 65 .setConfigurationState(Status.CONFIGURATION_STATE_CONFIGURING) 66 .setNotificationChannelState(Status.NOTIFICATION_CHANNEL_STATE_OK) 67 .setDataChannelState(Status.DATA_CHANNEL_STATE_OK).apply(); 68 break; 69 case CONFIG_ACTIVATING_SUBSEQUENT: 70 status 71 .setConfigurationState(Status.CONFIGURATION_STATE_OK) 72 .setNotificationChannelState(Status.NOTIFICATION_CHANNEL_STATE_OK) 73 .setDataChannelState(Status.DATA_CHANNEL_STATE_OK).apply(); 74 break; 75 case CONFIG_SERVICE_NOT_AVAILABLE: 76 status 77 .setConfigurationState(Status.CONFIGURATION_STATE_FAILED) 78 .apply(); 79 break; 80 case CONFIG_STATUS_SMS_TIME_OUT: 81 status 82 .setConfigurationState(Status.CONFIGURATION_STATE_FAILED) 83 .apply(); 84 break; 85 default: 86 VvmLog.wtf(TAG, "invalid configuration event " + event); 87 } 88 } 89 handleDataChannelEvent(Context context, VoicemailStatus.Editor status, OmtpEvents event)90 private static void handleDataChannelEvent(Context context, VoicemailStatus.Editor status, 91 OmtpEvents event) { 92 switch (event) { 93 case DATA_IMAP_OPERATION_STARTED: 94 case DATA_IMAP_OPERATION_COMPLETED: 95 status 96 .setDataChannelState(Status.DATA_CHANNEL_STATE_OK) 97 .apply(); 98 break; 99 100 case DATA_NO_CONNECTION: 101 status 102 .setDataChannelState(Status.DATA_CHANNEL_STATE_NO_CONNECTION) 103 .apply(); 104 break; 105 106 case DATA_NO_CONNECTION_CELLULAR_REQUIRED: 107 status 108 .setDataChannelState( 109 Status.DATA_CHANNEL_STATE_NO_CONNECTION_CELLULAR_REQUIRED) 110 .apply(); 111 break; 112 case DATA_INVALID_PORT: 113 status 114 .setDataChannelState( 115 VoicemailContract.Status.DATA_CHANNEL_STATE_BAD_CONFIGURATION) 116 .apply(); 117 break; 118 case DATA_CANNOT_RESOLVE_HOST_ON_NETWORK: 119 status 120 .setDataChannelState( 121 VoicemailContract.Status.DATA_CHANNEL_STATE_SERVER_CONNECTION_ERROR) 122 .apply(); 123 break; 124 case DATA_SSL_INVALID_HOST_NAME: 125 case DATA_CANNOT_ESTABLISH_SSL_SESSION: 126 case DATA_IOE_ON_OPEN: 127 case DATA_GENERIC_IMAP_IOE: 128 status 129 .setDataChannelState( 130 VoicemailContract.Status.DATA_CHANNEL_STATE_COMMUNICATION_ERROR) 131 .apply(); 132 break; 133 case DATA_BAD_IMAP_CREDENTIAL: 134 case DATA_AUTH_UNKNOWN_USER: 135 case DATA_AUTH_UNKNOWN_DEVICE: 136 case DATA_AUTH_INVALID_PASSWORD: 137 case DATA_AUTH_MAILBOX_NOT_INITIALIZED: 138 case DATA_AUTH_SERVICE_NOT_PROVISIONED: 139 case DATA_AUTH_SERVICE_NOT_ACTIVATED: 140 case DATA_AUTH_USER_IS_BLOCKED: 141 status 142 .setDataChannelState( 143 VoicemailContract.Status.DATA_CHANNEL_STATE_BAD_CONFIGURATION) 144 .apply(); 145 break; 146 147 case DATA_REJECTED_SERVER_RESPONSE: 148 case DATA_INVALID_INITIAL_SERVER_RESPONSE: 149 case DATA_MAILBOX_OPEN_FAILED: 150 case DATA_SSL_EXCEPTION: 151 case DATA_ALL_SOCKET_CONNECTION_FAILED: 152 status 153 .setDataChannelState( 154 VoicemailContract.Status.DATA_CHANNEL_STATE_SERVER_ERROR) 155 .apply(); 156 break; 157 158 default: 159 VvmLog.wtf(TAG, "invalid data channel event " + event); 160 } 161 } 162 handleNotificationChannelEvent(Context context, OmtpVvmCarrierConfigHelper config, VoicemailStatus.Editor status, OmtpEvents event)163 private static void handleNotificationChannelEvent(Context context, 164 OmtpVvmCarrierConfigHelper config, VoicemailStatus.Editor status, OmtpEvents event) { 165 switch (event) { 166 case NOTIFICATION_IN_SERVICE: 167 status 168 .setNotificationChannelState(Status.NOTIFICATION_CHANNEL_STATE_OK) 169 // Clear the error state. A sync should follow signal return so any error 170 // will be reposted. 171 .setDataChannelState(Status.DATA_CHANNEL_STATE_OK) 172 .apply(); 173 break; 174 case NOTIFICATION_SERVICE_LOST: 175 status.setNotificationChannelState(Status.NOTIFICATION_CHANNEL_STATE_NO_CONNECTION); 176 if (config.isCellularDataRequired()) { 177 status.setDataChannelState( 178 Status.DATA_CHANNEL_STATE_NO_CONNECTION_CELLULAR_REQUIRED); 179 } 180 status.apply(); 181 break; 182 default: 183 VvmLog.wtf(TAG, "invalid notification channel event " + event); 184 } 185 } 186 handleOtherEvent(Context context, VoicemailStatus.Editor status, OmtpEvents event)187 private static void handleOtherEvent(Context context, VoicemailStatus.Editor status, 188 OmtpEvents event) { 189 switch (event) { 190 case OTHER_SOURCE_REMOVED: 191 status 192 .setConfigurationState(Status.CONFIGURATION_STATE_NOT_CONFIGURED) 193 .setNotificationChannelState( 194 Status.NOTIFICATION_CHANNEL_STATE_NO_CONNECTION) 195 .setDataChannelState(Status.DATA_CHANNEL_STATE_NO_CONNECTION) 196 .apply(); 197 break; 198 default: 199 VvmLog.wtf(TAG, "invalid other event " + event); 200 } 201 } 202 } 203