blob: e8f3f1ebb6cf3b1e1e225924793b37d3c5024571 [file] [log] [blame]
Ta-wei Yen67ab1682016-05-24 15:25:16 -07001/*
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 */
16package android.telephony;
17
18import android.os.Parcel;
19import android.os.Parcelable;
Ta-wei Yen485d6de2016-12-16 12:17:30 -080020import android.telephony.VisualVoicemailService.VisualVoicemailTask;
Ta-wei Yen2d0f4862017-12-18 11:54:06 -080021
Ta-wei Yen67ab1682016-05-24 15:25:16 -070022import java.util.Collections;
23import 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
Ta-wei Yen485d6de2016-12-16 12:17:30 -080032 * {@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.
Ta-wei Yen67ab1682016-05-24 15:25:16 -070035 *
36 * <p>Use {@link android.telephony.VisualVoicemailSmsFilterSettings.Builder} to construct this
37 * class.
38 *
Ta-wei Yen70a3e822017-04-20 12:41:17 -070039 * @see TelephonyManager#setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings)
Ta-wei Yen67ab1682016-05-24 15:25:16 -070040 */
Ta-wei Yen485d6de2016-12-16 12:17:30 -080041public final class VisualVoicemailSmsFilterSettings implements Parcelable {
Ta-wei Yen67ab1682016-05-24 15:25:16 -070042
43
44 /**
45 * The visual voicemail SMS message does not have to be a data SMS, and can be directed to any
46 * port.
Ta-wei Yen67ab1682016-05-24 15:25:16 -070047 */
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.
Ta-wei Yen67ab1682016-05-24 15:25:16 -070052 */
53 public static final int DESTINATION_PORT_DATA_SMS = -2;
54
Ta-wei Yen3f5858e2017-03-06 14:57:47 -080055 /**
56 * @hide
57 */
Ta-wei Yen67ab1682016-05-24 15:25:16 -070058 public static final String DEFAULT_CLIENT_PREFIX = "//VVM";
Ta-wei Yen3f5858e2017-03-06 14:57:47 -080059 /**
60 * @hide
61 */
Ta-wei Yen67ab1682016-05-24 15:25:16 -070062 public static final List<String> DEFAULT_ORIGINATING_NUMBERS = Collections.emptyList();
Ta-wei Yen3f5858e2017-03-06 14:57:47 -080063 /**
64 * @hide
65 */
Ta-wei Yen67ab1682016-05-24 15:25:16 -070066 public static final int DEFAULT_DESTINATION_PORT = DESTINATION_PORT_ANY;
67
68 /**
69 * Builder class for {@link VisualVoicemailSmsFilterSettings} objects.
Ta-wei Yen67ab1682016-05-24 15:25:16 -070070 */
71 public static class Builder {
72
73 private String mClientPrefix = DEFAULT_CLIENT_PREFIX;
74 private List<String> mOriginatingNumbers = DEFAULT_ORIGINATING_NUMBERS;
75 private int mDestinationPort = DEFAULT_DESTINATION_PORT;
Ta-wei Yen2d0f4862017-12-18 11:54:06 -080076 private String mPackageName;
Ta-wei Yen67ab1682016-05-24 15:25:16 -070077
78 public VisualVoicemailSmsFilterSettings build() {
79 return new VisualVoicemailSmsFilterSettings(this);
80 }
81
82 /**
83 * Sets the client prefix for the visual voicemail SMS filter. The client prefix will appear
84 * at the start of a visual voicemail SMS message, followed by a colon(:).
85 */
86 public Builder setClientPrefix(String clientPrefix) {
87 if (clientPrefix == null) {
88 throw new IllegalArgumentException("Client prefix cannot be null");
89 }
90 mClientPrefix = clientPrefix;
91 return this;
92 }
93
94 /**
95 * Sets the originating number whitelist for the visual voicemail SMS filter. If the list is
96 * not null only the SMS messages from a number in the list can be considered as a visual
97 * voicemail SMS. Otherwise, messages from any address will be considered.
98 */
99 public Builder setOriginatingNumbers(List<String> originatingNumbers) {
100 if (originatingNumbers == null) {
101 throw new IllegalArgumentException("Originating numbers cannot be null");
102 }
103 mOriginatingNumbers = originatingNumbers;
104 return this;
105 }
106
107 /**
108 * Sets the destination port for the visual voicemail SMS filter.
109 *
110 * @param destinationPort The destination port, or {@link #DESTINATION_PORT_ANY}, or {@link
111 * #DESTINATION_PORT_DATA_SMS}
112 */
113 public Builder setDestinationPort(int destinationPort) {
114 mDestinationPort = destinationPort;
115 return this;
116 }
117
Ta-wei Yen2d0f4862017-12-18 11:54:06 -0800118 /**
119 * The package that registered this filter.
120 *
121 * @hide
122 */
123 public Builder setPackageName(String packageName) {
124 mPackageName = packageName;
125 return this;
126 }
Ta-wei Yen67ab1682016-05-24 15:25:16 -0700127 }
128
129 /**
130 * The client prefix for the visual voicemail SMS filter. The client prefix will appear at the
131 * start of a visual voicemail SMS message, followed by a colon(:).
132 */
133 public final String clientPrefix;
134
135 /**
136 * The originating number whitelist for the visual voicemail SMS filter of a phone account. If
137 * the list is not null only the SMS messages from a number in the list can be considered as a
138 * visual voicemail SMS. Otherwise, messages from any address will be considered.
139 */
140 public final List<String> originatingNumbers;
141
142 /**
143 * The destination port for the visual voicemail SMS filter, or {@link #DESTINATION_PORT_ANY},
144 * or {@link #DESTINATION_PORT_DATA_SMS}
145 */
146 public final int destinationPort;
147
148 /**
Ta-wei Yen2d0f4862017-12-18 11:54:06 -0800149 * The package that registered this filter.
150 *
151 * @hide
152 */
153 public final String packageName;
154
155 /**
Ta-wei Yen67ab1682016-05-24 15:25:16 -0700156 * Use {@link Builder} to construct
157 */
158 private VisualVoicemailSmsFilterSettings(Builder builder) {
159 clientPrefix = builder.mClientPrefix;
160 originatingNumbers = builder.mOriginatingNumbers;
161 destinationPort = builder.mDestinationPort;
Ta-wei Yen2d0f4862017-12-18 11:54:06 -0800162 packageName = builder.mPackageName;
Ta-wei Yen67ab1682016-05-24 15:25:16 -0700163 }
164
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700165 public static final @android.annotation.NonNull Creator<VisualVoicemailSmsFilterSettings> CREATOR =
Ta-wei Yen67ab1682016-05-24 15:25:16 -0700166 new Creator<VisualVoicemailSmsFilterSettings>() {
167 @Override
168 public VisualVoicemailSmsFilterSettings createFromParcel(Parcel in) {
169 Builder builder = new Builder();
170 builder.setClientPrefix(in.readString());
171 builder.setOriginatingNumbers(in.createStringArrayList());
172 builder.setDestinationPort(in.readInt());
Ta-wei Yen2d0f4862017-12-18 11:54:06 -0800173 builder.setPackageName(in.readString());
Ta-wei Yen67ab1682016-05-24 15:25:16 -0700174 return builder.build();
175 }
176
177 @Override
178 public VisualVoicemailSmsFilterSettings[] newArray(int size) {
179 return new VisualVoicemailSmsFilterSettings[size];
180 }
181 };
182
183 @Override
184 public int describeContents() {
185 return 0;
186 }
187
188 @Override
189 public void writeToParcel(Parcel dest, int flags) {
190 dest.writeString(clientPrefix);
191 dest.writeStringList(originatingNumbers);
192 dest.writeInt(destinationPort);
Ta-wei Yen2d0f4862017-12-18 11:54:06 -0800193 dest.writeString(packageName);
Ta-wei Yen67ab1682016-05-24 15:25:16 -0700194 }
195
Ta-wei Yen485d6de2016-12-16 12:17:30 -0800196 @Override
Ta-wei Yen2d0f4862017-12-18 11:54:06 -0800197 public String toString() {
Ta-wei Yen485d6de2016-12-16 12:17:30 -0800198 return "[VisualVoicemailSmsFilterSettings "
199 + "clientPrefix=" + clientPrefix
200 + ", originatingNumbers=" + originatingNumbers
201 + ", destinationPort=" + destinationPort
202 + "]";
203 }
204
Ta-wei Yen67ab1682016-05-24 15:25:16 -0700205}