• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.telephony;
17 
18 import android.os.Parcel;
19 import android.os.Parcelable;
20 import android.telephony.VisualVoicemailService.VisualVoicemailTask;
21 
22 import java.util.Collections;
23 import java.util.List;
24 
25 /**
26  * Class to represent various settings for the visual voicemail SMS filter. When the filter is
27  * enabled, incoming SMS matching the generalized OMTP format:
28  *
29  * <p>[clientPrefix]:[prefix]:([key]=[value];)*
30  *
31  * <p>will be regarded as a visual voicemail SMS, and removed before reaching the SMS provider. The
32  * {@link VisualVoicemailService} in the current default dialer will be bound and
33  * {@link VisualVoicemailService#onSmsReceived(VisualVoicemailTask, VisualVoicemailSms)}
34  * will called with the information extracted from the SMS.
35  *
36  * <p>Use {@link android.telephony.VisualVoicemailSmsFilterSettings.Builder} to construct this
37  * class.
38  *
39  * @see TelephonyManager#setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings)
40  */
41 public final class VisualVoicemailSmsFilterSettings implements Parcelable {
42 
43 
44     /**
45      * The visual voicemail SMS message does not have to be a data SMS, and can be directed to any
46      * port.
47      */
48     public static final int DESTINATION_PORT_ANY = -1;
49 
50     /**
51      * The visual voicemail SMS message can be directed to any port, but must be a data SMS.
52      */
53     public static final int DESTINATION_PORT_DATA_SMS = -2;
54 
55     /**
56      * @hide
57      */
58     public static final String DEFAULT_CLIENT_PREFIX = "//VVM";
59     /**
60      * @hide
61      */
62     public static final List<String> DEFAULT_ORIGINATING_NUMBERS = Collections.emptyList();
63     /**
64      * @hide
65      */
66     public static final int DEFAULT_DESTINATION_PORT = DESTINATION_PORT_ANY;
67     /**
68      * @hide
69      */
70     public static final int MAX_STRING_LENGTH = 256;
71     /**
72      * @hide
73      */
74     public static final int MAX_LIST_SIZE = 100;
75 
76     /**
77      * Builder class for {@link VisualVoicemailSmsFilterSettings} objects.
78      */
79     public static class Builder {
80 
81         private String mClientPrefix = DEFAULT_CLIENT_PREFIX;
82         private List<String> mOriginatingNumbers = DEFAULT_ORIGINATING_NUMBERS;
83         private int mDestinationPort = DEFAULT_DESTINATION_PORT;
84         private String mPackageName;
85 
build()86         public VisualVoicemailSmsFilterSettings build() {
87             return new VisualVoicemailSmsFilterSettings(this);
88         }
89 
90         /**
91          * Sets the client prefix for the visual voicemail SMS filter. The client prefix will appear
92          * at the start of a visual voicemail SMS message, followed by a colon(:).
93          * @throws IllegalArgumentException if the string length is greater than 256 characters
94          */
setClientPrefix(String clientPrefix)95         public Builder setClientPrefix(String clientPrefix) {
96             if (clientPrefix == null) {
97                 throw new IllegalArgumentException("Client prefix cannot be null");
98             }
99             if (clientPrefix.length() > MAX_STRING_LENGTH) {
100                 throw new IllegalArgumentException("Client prefix cannot be greater than "
101                         + MAX_STRING_LENGTH + " characters");
102             }
103             mClientPrefix = clientPrefix;
104             return this;
105         }
106 
107         /**
108          * Sets the originating number allow list for the visual voicemail SMS filter. If the list
109          * is not null only the SMS messages from a number in the list can be considered as a visual
110          * voicemail SMS. Otherwise, messages from any address will be considered.
111          * @throws IllegalArgumentException if the size of the originatingNumbers list is greater
112          * than 100 elements
113          * @throws IllegalArgumentException if an element within the originatingNumbers list has
114          * a string length greater than 256
115          */
setOriginatingNumbers(List<String> originatingNumbers)116         public Builder setOriginatingNumbers(List<String> originatingNumbers) {
117             if (originatingNumbers == null) {
118                 throw new IllegalArgumentException("Originating numbers cannot be null");
119             }
120             if (originatingNumbers.size() > MAX_LIST_SIZE) {
121                 throw new IllegalArgumentException("The originatingNumbers list size cannot be"
122                         + " greater than " + MAX_STRING_LENGTH + " elements");
123             }
124             for (String num : originatingNumbers) {
125                 if (num != null && num.length() > MAX_STRING_LENGTH) {
126                     throw new IllegalArgumentException("Numbers within the originatingNumbers list"
127                             + " cannot be greater than" + MAX_STRING_LENGTH + " characters");
128                 }
129             }
130             mOriginatingNumbers = originatingNumbers;
131             return this;
132         }
133 
134         /**
135          * Sets the destination port for the visual voicemail SMS filter.
136          *
137          * @param destinationPort The destination port, or {@link #DESTINATION_PORT_ANY}, or {@link
138          * #DESTINATION_PORT_DATA_SMS}
139          */
setDestinationPort(int destinationPort)140         public Builder setDestinationPort(int destinationPort) {
141             mDestinationPort = destinationPort;
142             return this;
143         }
144 
145         /**
146          * The package that registered this filter.
147          *
148          * @hide
149          */
setPackageName(String packageName)150         public Builder setPackageName(String packageName) {
151             mPackageName = packageName;
152             return this;
153         }
154     }
155 
156     /**
157      * The client prefix for the visual voicemail SMS filter. The client prefix will appear at the
158      * start of a visual voicemail SMS message, followed by a colon(:).
159      */
160     public final String clientPrefix;
161 
162     /**
163      * The originating number allow list for the visual voicemail SMS filter of a phone account. If
164      * the list is not null only the SMS messages from a number in the list can be considered as a
165      * visual voicemail SMS. Otherwise, messages from any address will be considered.
166      */
167     public final List<String> originatingNumbers;
168 
169     /**
170      * The destination port for the visual voicemail SMS filter, or {@link #DESTINATION_PORT_ANY},
171      * or {@link #DESTINATION_PORT_DATA_SMS}
172      */
173     public final int destinationPort;
174 
175     /**
176      * The package that registered this filter.
177      *
178      * @hide
179      */
180     public final String packageName;
181 
182     /**
183      * Use {@link Builder} to construct
184      */
VisualVoicemailSmsFilterSettings(Builder builder)185     private VisualVoicemailSmsFilterSettings(Builder builder) {
186         clientPrefix = builder.mClientPrefix;
187         originatingNumbers = builder.mOriginatingNumbers;
188         destinationPort = builder.mDestinationPort;
189         packageName = builder.mPackageName;
190     }
191 
192     public static final @android.annotation.NonNull Creator<VisualVoicemailSmsFilterSettings> CREATOR =
193             new Creator<VisualVoicemailSmsFilterSettings>() {
194                 @Override
195                 public VisualVoicemailSmsFilterSettings createFromParcel(Parcel in) {
196                     Builder builder = new Builder();
197                     builder.setClientPrefix(in.readString());
198                     builder.setOriginatingNumbers(in.createStringArrayList());
199                     builder.setDestinationPort(in.readInt());
200                     builder.setPackageName(in.readString());
201                     return builder.build();
202                 }
203 
204                 @Override
205                 public VisualVoicemailSmsFilterSettings[] newArray(int size) {
206                     return new VisualVoicemailSmsFilterSettings[size];
207                 }
208             };
209 
210     @Override
describeContents()211     public int describeContents() {
212         return 0;
213     }
214 
215     @Override
writeToParcel(Parcel dest, int flags)216     public void writeToParcel(Parcel dest, int flags) {
217         dest.writeString(clientPrefix);
218         dest.writeStringList(originatingNumbers);
219         dest.writeInt(destinationPort);
220         dest.writeString(packageName);
221     }
222 
223     @Override
toString()224     public String toString() {
225         return "[VisualVoicemailSmsFilterSettings "
226                 + "clientPrefix=" + clientPrefix
227                 + ", originatingNumbers=" + originatingNumbers
228                 + ", destinationPort=" + destinationPort
229                 + "]";
230     }
231 
232 }
233