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