1 /* 2 * Copyright (C) 2015 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 package com.android.voicemail.impl.sms; 17 18 import android.os.Bundle; 19 import com.android.voicemail.impl.NeededForTesting; 20 import com.android.voicemail.impl.OmtpConstants; 21 import com.android.voicemail.impl.VisualVoicemailPreferences; 22 import com.android.voicemail.impl.VvmLog; 23 24 /** 25 * Structured data representation of OMTP STATUS message. 26 * 27 * <p>The getters will return null if the field was not set in the message body or it could not be 28 * parsed. 29 */ 30 public class StatusMessage { 31 // NOTE: Following Status SMS fields are not yet parsed, as they do not seem 32 // to be useful for initial omtp source implementation. 33 // lang, g_len, vs_len, pw_len, pm, gm, vtc, vt 34 35 private final String provisioningStatus; 36 private final String statusReturnCode; 37 private final String subscriptionUrl; 38 private final String serverAddress; 39 private final String tuiAccessNumber; 40 private final String clientSmsDestinationNumber; 41 private final String imapPort; 42 private final String imapUserName; 43 private final String imapPassword; 44 private final String smtpPort; 45 private final String smtpUserName; 46 private final String smtpPassword; 47 private final String tuiPasswordLength; 48 49 @Override toString()50 public String toString() { 51 return "StatusMessage [mProvisioningStatus=" 52 + provisioningStatus 53 + ", mStatusReturnCode=" 54 + statusReturnCode 55 + ", mSubscriptionUrl=" 56 + subscriptionUrl 57 + ", mServerAddress=" 58 + serverAddress 59 + ", mTuiAccessNumber=" 60 + tuiAccessNumber 61 + ", mClientSmsDestinationNumber=" 62 + clientSmsDestinationNumber 63 + ", mImapPort=" 64 + imapPort 65 + ", mImapUserName=" 66 + imapUserName 67 + ", mImapPassword=" 68 + VvmLog.pii(imapPassword) 69 + ", mSmtpPort=" 70 + smtpPort 71 + ", mSmtpUserName=" 72 + smtpUserName 73 + ", mSmtpPassword=" 74 + VvmLog.pii(smtpPassword) 75 + ", mTuiPasswordLength=" 76 + tuiPasswordLength 77 + "]"; 78 } 79 StatusMessage(Bundle wrappedData)80 public StatusMessage(Bundle wrappedData) { 81 provisioningStatus = unquote(getString(wrappedData, OmtpConstants.PROVISIONING_STATUS)); 82 statusReturnCode = getString(wrappedData, OmtpConstants.RETURN_CODE); 83 subscriptionUrl = getString(wrappedData, OmtpConstants.SUBSCRIPTION_URL); 84 serverAddress = getString(wrappedData, OmtpConstants.SERVER_ADDRESS); 85 tuiAccessNumber = getString(wrappedData, OmtpConstants.TUI_ACCESS_NUMBER); 86 clientSmsDestinationNumber = 87 getString(wrappedData, OmtpConstants.CLIENT_SMS_DESTINATION_NUMBER); 88 imapPort = getString(wrappedData, OmtpConstants.IMAP_PORT); 89 imapUserName = getString(wrappedData, OmtpConstants.IMAP_USER_NAME); 90 imapPassword = getString(wrappedData, OmtpConstants.IMAP_PASSWORD); 91 smtpPort = getString(wrappedData, OmtpConstants.SMTP_PORT); 92 smtpUserName = getString(wrappedData, OmtpConstants.SMTP_USER_NAME); 93 smtpPassword = getString(wrappedData, OmtpConstants.SMTP_PASSWORD); 94 tuiPasswordLength = getString(wrappedData, OmtpConstants.TUI_PASSWORD_LENGTH); 95 } 96 unquote(String string)97 private static String unquote(String string) { 98 if (string.length() < 2) { 99 return string; 100 } 101 if (string.startsWith("\"") && string.endsWith("\"")) { 102 return string.substring(1, string.length() - 1); 103 } 104 return string; 105 } 106 107 /** @return the subscriber's VVM provisioning status. */ getProvisioningStatus()108 public String getProvisioningStatus() { 109 return provisioningStatus; 110 } 111 112 /** @return the return-code of the status SMS. */ getReturnCode()113 public String getReturnCode() { 114 return statusReturnCode; 115 } 116 117 /** 118 * @return the URL of the voicemail server. This is the URL to send the users to for subscribing 119 * to the visual voicemail service. 120 */ 121 @NeededForTesting getSubscriptionUrl()122 public String getSubscriptionUrl() { 123 return subscriptionUrl; 124 } 125 126 /** 127 * @return the voicemail server address. Either server IP address or fully qualified domain name. 128 */ getServerAddress()129 public String getServerAddress() { 130 return serverAddress; 131 } 132 133 /** 134 * @return the Telephony User Interface number to call to access voicemails directly from the IVR. 135 */ 136 @NeededForTesting getTuiAccessNumber()137 public String getTuiAccessNumber() { 138 return tuiAccessNumber; 139 } 140 141 /** @return the number to which client originated SMSes should be sent to. */ 142 @NeededForTesting getClientSmsDestinationNumber()143 public String getClientSmsDestinationNumber() { 144 return clientSmsDestinationNumber; 145 } 146 147 /** @return the IMAP server port to talk to. */ getImapPort()148 public String getImapPort() { 149 return imapPort; 150 } 151 152 /** @return the IMAP user name to be used for authentication. */ getImapUserName()153 public String getImapUserName() { 154 return imapUserName; 155 } 156 157 /** @return the IMAP password to be used for authentication. */ getImapPassword()158 public String getImapPassword() { 159 return imapPassword; 160 } 161 162 /** @return the SMTP server port to talk to. */ 163 @NeededForTesting getSmtpPort()164 public String getSmtpPort() { 165 return smtpPort; 166 } 167 168 /** @return the SMTP user name to be used for SMTP authentication. */ 169 @NeededForTesting getSmtpUserName()170 public String getSmtpUserName() { 171 return smtpUserName; 172 } 173 174 /** @return the SMTP password to be used for SMTP authentication. */ 175 @NeededForTesting getSmtpPassword()176 public String getSmtpPassword() { 177 return smtpPassword; 178 } 179 getTuiPasswordLength()180 public String getTuiPasswordLength() { 181 return tuiPasswordLength; 182 } 183 getString(Bundle bundle, String key)184 private static String getString(Bundle bundle, String key) { 185 String value = bundle.getString(key); 186 if (value == null) { 187 return ""; 188 } 189 return value; 190 } 191 192 /** Saves a StatusMessage to the {@link VisualVoicemailPreferences}. Not all fields are saved. */ putStatus(VisualVoicemailPreferences.Editor editor)193 public VisualVoicemailPreferences.Editor putStatus(VisualVoicemailPreferences.Editor editor) { 194 return editor 195 .putString(OmtpConstants.IMAP_PORT, getImapPort()) 196 .putString(OmtpConstants.SERVER_ADDRESS, getServerAddress()) 197 .putString(OmtpConstants.IMAP_USER_NAME, getImapUserName()) 198 .putString(OmtpConstants.IMAP_PASSWORD, getImapPassword()) 199 .putString(OmtpConstants.TUI_PASSWORD_LENGTH, getTuiPasswordLength()); 200 } 201 } 202