VisualVoicemailSmsFilterSettings.java revision 67ab168b78782c4de5de3f44817961468533757c
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;
20
21import java.util.Collections;
22import java.util.List;
23
24/**
25 * Class to represent various settings for the visual voicemail SMS filter. When the filter is
26 * enabled, incoming SMS matching the generalized OMTP format:
27 *
28 * <p>[clientPrefix]:[prefix]:([key]=[value];)*
29 *
30 * <p>will be regarded as a visual voicemail SMS, and removed before reaching the SMS provider. The
31 * intent {@link android.provider.VoicemailContract#ACTION_VOICEMAIL_SMS_RECEIVED} will then be sent
32 * to the default dialer with the information extracted from the SMS.
33 *
34 * <p>Use {@link android.telephony.VisualVoicemailSmsFilterSettings.Builder} to construct this
35 * class.
36 *
37 * @see android.telephony.TelephonyManager#enableVisualVoicemailSmsFilter
38 *
39 * @hide
40 */
41public 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     * @hide
49     */
50    public static final int DESTINATION_PORT_ANY = -1;
51
52    /**
53     * The visual voicemail SMS message can be directed to any port, but must be a data SMS.
54     *
55     * @hide
56     */
57    public static final int DESTINATION_PORT_DATA_SMS = -2;
58
59    public static final String DEFAULT_CLIENT_PREFIX = "//VVM";
60    public static final List<String> DEFAULT_ORIGINATING_NUMBERS = Collections.emptyList();
61    public static final int DEFAULT_DESTINATION_PORT = DESTINATION_PORT_ANY;
62
63    /**
64     * Builder class for {@link VisualVoicemailSmsFilterSettings} objects.
65     *
66     * @hide
67     */
68    public static class Builder {
69
70        private String mClientPrefix = DEFAULT_CLIENT_PREFIX;
71        private List<String> mOriginatingNumbers = DEFAULT_ORIGINATING_NUMBERS;
72        private int mDestinationPort = DEFAULT_DESTINATION_PORT;
73
74        public VisualVoicemailSmsFilterSettings build() {
75            return new VisualVoicemailSmsFilterSettings(this);
76        }
77
78        /**
79         * Sets the client prefix for the visual voicemail SMS filter. The client prefix will appear
80         * at the start of a visual voicemail SMS message, followed by a colon(:).
81         */
82        public Builder setClientPrefix(String clientPrefix) {
83            if (clientPrefix == null) {
84                throw new IllegalArgumentException("Client prefix cannot be null");
85            }
86            mClientPrefix = clientPrefix;
87            return this;
88        }
89
90        /**
91         * Sets the originating number whitelist for the visual voicemail SMS filter. If the list is
92         * not null only the SMS messages from a number in the list can be considered as a visual
93         * voicemail SMS. Otherwise, messages from any address will be considered.
94         */
95        public Builder setOriginatingNumbers(List<String> originatingNumbers) {
96            if (originatingNumbers == null) {
97                throw new IllegalArgumentException("Originating numbers cannot be null");
98            }
99            mOriginatingNumbers = originatingNumbers;
100            return this;
101        }
102
103        /**
104         * Sets the destination port for the visual voicemail SMS filter.
105         *
106         * @param destinationPort The destination port, or {@link #DESTINATION_PORT_ANY}, or {@link
107         * #DESTINATION_PORT_DATA_SMS}
108         */
109        public Builder setDestinationPort(int destinationPort) {
110            mDestinationPort = destinationPort;
111            return this;
112        }
113
114    }
115
116    /**
117     * The client prefix for the visual voicemail SMS filter. The client prefix will appear at the
118     * start of a visual voicemail SMS message, followed by a colon(:).
119     */
120    public final String clientPrefix;
121
122    /**
123     * The originating number whitelist for the visual voicemail SMS filter of a phone account. If
124     * the list is not null only the SMS messages from a number in the list can be considered as a
125     * visual voicemail SMS. Otherwise, messages from any address will be considered.
126     */
127    public final List<String> originatingNumbers;
128
129    /**
130     * The destination port for the visual voicemail SMS filter, or {@link #DESTINATION_PORT_ANY},
131     * or {@link #DESTINATION_PORT_DATA_SMS}
132     */
133    public final int destinationPort;
134
135    /**
136     * Use {@link Builder} to construct
137     */
138    private VisualVoicemailSmsFilterSettings(Builder builder) {
139        clientPrefix = builder.mClientPrefix;
140        originatingNumbers = builder.mOriginatingNumbers;
141        destinationPort = builder.mDestinationPort;
142    }
143
144    public static final Creator<VisualVoicemailSmsFilterSettings> CREATOR =
145            new Creator<VisualVoicemailSmsFilterSettings>() {
146                @Override
147                public VisualVoicemailSmsFilterSettings createFromParcel(Parcel in) {
148                    Builder builder = new Builder();
149                    builder.setClientPrefix(in.readString());
150                    builder.setOriginatingNumbers(in.createStringArrayList());
151                    builder.setDestinationPort(in.readInt());
152
153                    return builder.build();
154                }
155
156                @Override
157                public VisualVoicemailSmsFilterSettings[] newArray(int size) {
158                    return new VisualVoicemailSmsFilterSettings[size];
159                }
160            };
161
162    @Override
163    public int describeContents() {
164        return 0;
165    }
166
167    @Override
168    public void writeToParcel(Parcel dest, int flags) {
169        dest.writeString(clientPrefix);
170        dest.writeStringList(originatingNumbers);
171        dest.writeInt(destinationPort);
172    }
173
174}
175