VisualVoicemailSmsFilterSettings.java revision 2d0f48606e8b9da193c693743dad0b432f9364d2
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 */
16package android.telephony;
17
18import android.os.Parcel;
19import android.os.Parcelable;
20import android.telephony.VisualVoicemailService.VisualVoicemailTask;
21
22import 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
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 */
41public 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    /**
69     * Builder class for {@link VisualVoicemailSmsFilterSettings} objects.
70     */
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;
76        private String mPackageName;
77
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
118        /**
119         * The package that registered this filter.
120         *
121         * @hide
122         */
123        public Builder setPackageName(String packageName) {
124            mPackageName = packageName;
125            return this;
126        }
127    }
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    /**
149     * The package that registered this filter.
150     *
151     * @hide
152     */
153    public final String packageName;
154
155    /**
156     * Use {@link Builder} to construct
157     */
158    private VisualVoicemailSmsFilterSettings(Builder builder) {
159        clientPrefix = builder.mClientPrefix;
160        originatingNumbers = builder.mOriginatingNumbers;
161        destinationPort = builder.mDestinationPort;
162        packageName = builder.mPackageName;
163    }
164
165    public static final Creator<VisualVoicemailSmsFilterSettings> CREATOR =
166            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());
173                    builder.setPackageName(in.readString());
174                    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);
193        dest.writeString(packageName);
194    }
195
196    @Override
197    public String toString() {
198        return "[VisualVoicemailSmsFilterSettings "
199                + "clientPrefix=" + clientPrefix
200                + ", originatingNumbers=" + originatingNumbers
201                + ", destinationPort=" + destinationPort
202                + "]";
203    }
204
205}
206