• 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 
17 package com.android.voicemail.impl;
18 
19 /**
20  * Wrapper class to hold relevant OMTP constants as defined in the OMTP spec.
21  *
22  * <p>In essence this is a programmatic representation of the relevant portions of OMTP spec.
23  */
24 public class OmtpConstants {
25   public static final String SMS_FIELD_SEPARATOR = ";";
26   public static final String SMS_KEY_VALUE_SEPARATOR = "=";
27   public static final String SMS_PREFIX_SEPARATOR = ":";
28 
29   public static final String SYNC_SMS_PREFIX = "SYNC";
30   public static final String STATUS_SMS_PREFIX = "STATUS";
31 
32   // This is the format designated by the OMTP spec.
33   public static final String DATE_TIME_FORMAT = "dd/MM/yyyy HH:mm Z";
34 
35   /** OMTP protocol versions. */
36   public static final String PROTOCOL_VERSION1_1 = "11";
37 
38   public static final String PROTOCOL_VERSION1_2 = "12";
39   public static final String PROTOCOL_VERSION1_3 = "13";
40 
41   ///////////////////////// Client/Mobile originated SMS //////////////////////
42 
43   /** Mobile Originated requests */
44   public static final String ACTIVATE_REQUEST = "Activate";
45 
46   public static final String DEACTIVATE_REQUEST = "Deactivate";
47   public static final String STATUS_REQUEST = "Status";
48 
49   /** fields that can be present in a Mobile Originated OMTP SMS */
50   public static final String CLIENT_TYPE = "ct";
51 
52   public static final String APPLICATION_PORT = "pt";
53   public static final String PROTOCOL_VERSION = "pv";
54 
55   //////////////////////////////// Sync SMS fields ////////////////////////////
56 
57   /**
58    * Sync SMS fields.
59    *
60    * <p>Each string constant is the field's key in the SMS body which is used by the parser to
61    * identify the field's value, if present, in the SMS body.
62    */
63 
64   /** The event that triggered this SYNC SMS. See {@link OmtpConstants#SYNC_TRIGGER_EVENT_VALUES} */
65   public static final String SYNC_TRIGGER_EVENT = "ev";
66 
67   public static final String MESSAGE_UID = "id";
68   public static final String MESSAGE_LENGTH = "l";
69   public static final String NUM_MESSAGE_COUNT = "c";
70   /** See {@link OmtpConstants#CONTENT_TYPE_VALUES} */
71   public static final String CONTENT_TYPE = "t";
72 
73   public static final String SENDER = "s";
74   public static final String TIME = "dt";
75 
76   /**
77    * SYNC message trigger events.
78    *
79    * <p>These are the possible values of {@link OmtpConstants#SYNC_TRIGGER_EVENT}.
80    */
81   public static final String NEW_MESSAGE = "NM";
82 
83   public static final String MAILBOX_UPDATE = "MBU";
84   public static final String GREETINGS_UPDATE = "GU";
85 
86   public static final String[] SYNC_TRIGGER_EVENT_VALUES = {
87     NEW_MESSAGE, MAILBOX_UPDATE, GREETINGS_UPDATE
88   };
89 
90   /**
91    * Content types supported by OMTP VVM.
92    *
93    * <p>These are the possible values of {@link OmtpConstants#CONTENT_TYPE}.
94    */
95   public static final String VOICE = "v";
96 
97   public static final String VIDEO = "o";
98   public static final String FAX = "f";
99   /** Voice message deposited by an external application */
100   public static final String INFOTAINMENT = "i";
101   /** Empty Call Capture - i.e. voicemail with no voice message. */
102   public static final String ECC = "e";
103 
104   public static final String[] CONTENT_TYPE_VALUES = {VOICE, VIDEO, FAX, INFOTAINMENT, ECC};
105 
106   ////////////////////////////// Status SMS fields ////////////////////////////
107 
108   /**
109    * Status SMS fields.
110    *
111    * <p>Each string constant is the field's key in the SMS body which is used by the parser to
112    * identify the field's value, if present, in the SMS body.
113    */
114   /** See {@link OmtpConstants#PROVISIONING_STATUS_VALUES} */
115   public static final String PROVISIONING_STATUS = "st";
116   /** See {@link OmtpConstants#RETURN_CODE_VALUES} */
117   public static final String RETURN_CODE = "rc";
118   /** URL to send users to for activation VVM */
119   public static final String SUBSCRIPTION_URL = "rs";
120   /** IMAP4/SMTP server IP address or fully qualified domain name */
121   public static final String SERVER_ADDRESS = "srv";
122   /** Phone number to access voicemails through Telephony User Interface */
123   public static final String TUI_ACCESS_NUMBER = "tui";
124 
125   public static final String TUI_PASSWORD_LENGTH = "pw_len";
126   /** Number to send client origination SMS */
127   public static final String CLIENT_SMS_DESTINATION_NUMBER = "dn";
128 
129   public static final String IMAP_PORT = "ipt";
130   public static final String IMAP_USER_NAME = "u";
131   public static final String IMAP_PASSWORD = "pw";
132   public static final String SMTP_PORT = "spt";
133   public static final String SMTP_USER_NAME = "smtp_u";
134   public static final String SMTP_PASSWORD = "smtp_pw";
135 
136   /**
137    * User provisioning status values.
138    *
139    * <p>Referred by {@link OmtpConstants#PROVISIONING_STATUS}.
140    */
141   public static final String SUBSCRIBER_NEW = "N";
142 
143   public static final String SUBSCRIBER_READY = "R";
144   public static final String SUBSCRIBER_PROVISIONED = "P";
145   public static final String SUBSCRIBER_UNKNOWN = "U";
146   public static final String SUBSCRIBER_BLOCKED = "B";
147 
148   public static final String[] PROVISIONING_STATUS_VALUES = {
149     SUBSCRIBER_NEW, SUBSCRIBER_READY, SUBSCRIBER_PROVISIONED, SUBSCRIBER_UNKNOWN, SUBSCRIBER_BLOCKED
150   };
151 
152   /**
153    * The return code included in a status message.
154    *
155    * <p>These are the possible values of {@link OmtpConstants#RETURN_CODE}.
156    */
157   public static final String SUCCESS = "0";
158 
159   public static final String SYSTEM_ERROR = "1";
160   public static final String SUBSCRIBER_ERROR = "2";
161   public static final String MAILBOX_UNKNOWN = "3";
162   public static final String VVM_NOT_ACTIVATED = "4";
163   public static final String VVM_NOT_PROVISIONED = "5";
164   public static final String VVM_CLIENT_UKNOWN = "6";
165   public static final String VVM_MAILBOX_NOT_INITIALIZED = "7";
166 
167   public static final String[] RETURN_CODE_VALUES = {
168     SUCCESS,
169     SYSTEM_ERROR,
170     SUBSCRIBER_ERROR,
171     MAILBOX_UNKNOWN,
172     VVM_NOT_ACTIVATED,
173     VVM_NOT_PROVISIONED,
174     VVM_CLIENT_UKNOWN,
175     VVM_MAILBOX_NOT_INITIALIZED,
176   };
177 
178   /** IMAP command extensions */
179 
180   /**
181    * OMTP spec v1.3 2.3.1 Change password request syntax
182    *
183    * <p>This changes the PIN to access the Telephone User Interface, the traditional voicemail
184    * system.
185    */
186   public static final String IMAP_CHANGE_TUI_PWD_FORMAT = "XCHANGE_TUI_PWD PWD=%1$s OLD_PWD=%2$s";
187 
188   /**
189    * OMTP spec v1.3 2.4.1 Change languate request syntax
190    *
191    * <p>This changes the language in the Telephone User Interface.
192    */
193   public static final String IMAP_CHANGE_VM_LANG_FORMAT = "XCHANGE_VM_LANG LANG=%1$s";
194 
195   /**
196    * OMTP spec v1.3 2.5.1 Close NUT Request syntax
197    *
198    * <p>This disables the new user tutorial, the message played to new users calling in the
199    * Telephone User Interface.
200    */
201   public static final String IMAP_CLOSE_NUT = "XCLOSE_NUT";
202 
203   /** Possible NO responses for CHANGE_TUI_PWD */
204   public static final String RESPONSE_CHANGE_PIN_TOO_SHORT = "password too short";
205 
206   public static final String RESPONSE_CHANGE_PIN_TOO_LONG = "password too long";
207   public static final String RESPONSE_CHANGE_PIN_TOO_WEAK = "password too weak";
208   public static final String RESPONSE_CHANGE_PIN_MISMATCH = "old password mismatch";
209   public static final String RESPONSE_CHANGE_PIN_INVALID_CHARACTER =
210       "password contains invalid characters";
211 
getClientType()212   public static String getClientType() {
213     String manufacturer =
214         truncate(
215             android.os.Build.MANUFACTURER
216                 .replace('=', '_')
217                 .replace(';', '_')
218                 .replace('.', '_')
219                 .replace(' ', '_'),
220             12);
221 
222     String version =
223         truncate(
224             android.os.Build.VERSION
225                 .RELEASE
226                 .replace('=', '_')
227                 .replace(';', '_')
228                 .replace('.', '_')
229                 .replace(' ', '_'),
230             8);
231 
232     String model =
233         truncate(
234             android.os.Build.MODEL
235                 .replace('=', '_')
236                 .replace(';', '_')
237                 .replace('.', '_')
238                 .replace(' ', '_'),
239             28 - manufacturer.length() - version.length());
240 
241     return String.format("%s.%s.%s", manufacturer, model, version);
242   }
243 
truncate(String string, int length)244   private static final String truncate(String string, int length) {
245     return string.substring(0, Math.min(length, string.length()));
246   }
247 
248   // Alternative form of sync message: MBOXUPDATE?m=<new_message_count>;<key>=<value>;
249 
250   public static final String ALTERNATIVE_MAILBOX_UPDATE = "MBOXUPDATE";
251   public static final String ALTERNATIVE_NUM_MESSAGE_COUNT = "m";
252 }
253