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