• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 mProvisioningStatus;
36   private final String mStatusReturnCode;
37   private final String mSubscriptionUrl;
38   private final String mServerAddress;
39   private final String mTuiAccessNumber;
40   private final String mClientSmsDestinationNumber;
41   private final String mImapPort;
42   private final String mImapUserName;
43   private final String mImapPassword;
44   private final String mSmtpPort;
45   private final String mSmtpUserName;
46   private final String mSmtpPassword;
47   private final String mTuiPasswordLength;
48 
49   @Override
toString()50   public String toString() {
51     return "StatusMessage [mProvisioningStatus="
52         + mProvisioningStatus
53         + ", mStatusReturnCode="
54         + mStatusReturnCode
55         + ", mSubscriptionUrl="
56         + mSubscriptionUrl
57         + ", mServerAddress="
58         + mServerAddress
59         + ", mTuiAccessNumber="
60         + mTuiAccessNumber
61         + ", mClientSmsDestinationNumber="
62         + mClientSmsDestinationNumber
63         + ", mImapPort="
64         + mImapPort
65         + ", mImapUserName="
66         + mImapUserName
67         + ", mImapPassword="
68         + VvmLog.pii(mImapPassword)
69         + ", mSmtpPort="
70         + mSmtpPort
71         + ", mSmtpUserName="
72         + mSmtpUserName
73         + ", mSmtpPassword="
74         + VvmLog.pii(mSmtpPassword)
75         + ", mTuiPasswordLength="
76         + mTuiPasswordLength
77         + "]";
78   }
79 
StatusMessage(Bundle wrappedData)80   public StatusMessage(Bundle wrappedData) {
81     mProvisioningStatus = unquote(getString(wrappedData, OmtpConstants.PROVISIONING_STATUS));
82     mStatusReturnCode = getString(wrappedData, OmtpConstants.RETURN_CODE);
83     mSubscriptionUrl = getString(wrappedData, OmtpConstants.SUBSCRIPTION_URL);
84     mServerAddress = getString(wrappedData, OmtpConstants.SERVER_ADDRESS);
85     mTuiAccessNumber = getString(wrappedData, OmtpConstants.TUI_ACCESS_NUMBER);
86     mClientSmsDestinationNumber =
87         getString(wrappedData, OmtpConstants.CLIENT_SMS_DESTINATION_NUMBER);
88     mImapPort = getString(wrappedData, OmtpConstants.IMAP_PORT);
89     mImapUserName = getString(wrappedData, OmtpConstants.IMAP_USER_NAME);
90     mImapPassword = getString(wrappedData, OmtpConstants.IMAP_PASSWORD);
91     mSmtpPort = getString(wrappedData, OmtpConstants.SMTP_PORT);
92     mSmtpUserName = getString(wrappedData, OmtpConstants.SMTP_USER_NAME);
93     mSmtpPassword = getString(wrappedData, OmtpConstants.SMTP_PASSWORD);
94     mTuiPasswordLength = 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 mProvisioningStatus;
110   }
111 
112   /** @return the return-code of the status SMS. */
getReturnCode()113   public String getReturnCode() {
114     return mStatusReturnCode;
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 mSubscriptionUrl;
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 mServerAddress;
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 mTuiAccessNumber;
139   }
140 
141   /** @return the number to which client originated SMSes should be sent to. */
142   @NeededForTesting
getClientSmsDestinationNumber()143   public String getClientSmsDestinationNumber() {
144     return mClientSmsDestinationNumber;
145   }
146 
147   /** @return the IMAP server port to talk to. */
getImapPort()148   public String getImapPort() {
149     return mImapPort;
150   }
151 
152   /** @return the IMAP user name to be used for authentication. */
getImapUserName()153   public String getImapUserName() {
154     return mImapUserName;
155   }
156 
157   /** @return the IMAP password to be used for authentication. */
getImapPassword()158   public String getImapPassword() {
159     return mImapPassword;
160   }
161 
162   /** @return the SMTP server port to talk to. */
163   @NeededForTesting
getSmtpPort()164   public String getSmtpPort() {
165     return mSmtpPort;
166   }
167 
168   /** @return the SMTP user name to be used for SMTP authentication. */
169   @NeededForTesting
getSmtpUserName()170   public String getSmtpUserName() {
171     return mSmtpUserName;
172   }
173 
174   /** @return the SMTP password to be used for SMTP authentication. */
175   @NeededForTesting
getSmtpPassword()176   public String getSmtpPassword() {
177     return mSmtpPassword;
178   }
179 
getTuiPasswordLength()180   public String getTuiPasswordLength() {
181     return mTuiPasswordLength;
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