Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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; |
Ta-wei Yen | 485d6de | 2016-12-16 12:17:30 -0800 | [diff] [blame] | 20 | import android.telephony.VisualVoicemailService.VisualVoicemailTask; |
Ta-wei Yen | 2d0f486 | 2017-12-18 11:54:06 -0800 | [diff] [blame] | 21 | |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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 |
Ta-wei Yen | 485d6de | 2016-12-16 12:17:30 -0800 | [diff] [blame] | 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. |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 35 | * |
| 36 | * <p>Use {@link android.telephony.VisualVoicemailSmsFilterSettings.Builder} to construct this |
| 37 | * class. |
| 38 | * |
Ta-wei Yen | 70a3e82 | 2017-04-20 12:41:17 -0700 | [diff] [blame] | 39 | * @see TelephonyManager#setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings) |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 40 | */ |
Ta-wei Yen | 485d6de | 2016-12-16 12:17:30 -0800 | [diff] [blame] | 41 | public final class VisualVoicemailSmsFilterSettings implements Parcelable { |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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. |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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. |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 52 | */ |
| 53 | public static final int DESTINATION_PORT_DATA_SMS = -2; |
| 54 | |
Ta-wei Yen | 3f5858e | 2017-03-06 14:57:47 -0800 | [diff] [blame] | 55 | /** |
| 56 | * @hide |
| 57 | */ |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 58 | public static final String DEFAULT_CLIENT_PREFIX = "//VVM"; |
Ta-wei Yen | 3f5858e | 2017-03-06 14:57:47 -0800 | [diff] [blame] | 59 | /** |
| 60 | * @hide |
| 61 | */ |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 62 | public static final List<String> DEFAULT_ORIGINATING_NUMBERS = Collections.emptyList(); |
Ta-wei Yen | 3f5858e | 2017-03-06 14:57:47 -0800 | [diff] [blame] | 63 | /** |
| 64 | * @hide |
| 65 | */ |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 66 | public static final int DEFAULT_DESTINATION_PORT = DESTINATION_PORT_ANY; |
| 67 | |
| 68 | /** |
| 69 | * Builder class for {@link VisualVoicemailSmsFilterSettings} objects. |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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; |
Ta-wei Yen | 2d0f486 | 2017-12-18 11:54:06 -0800 | [diff] [blame] | 76 | private String mPackageName; |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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 | |
Ta-wei Yen | 2d0f486 | 2017-12-18 11:54:06 -0800 | [diff] [blame] | 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 | } |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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 | /** |
Ta-wei Yen | 2d0f486 | 2017-12-18 11:54:06 -0800 | [diff] [blame] | 149 | * The package that registered this filter. |
| 150 | * |
| 151 | * @hide |
| 152 | */ |
| 153 | public final String packageName; |
| 154 | |
| 155 | /** |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 156 | * 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 Yen | 2d0f486 | 2017-12-18 11:54:06 -0800 | [diff] [blame] | 162 | packageName = builder.mPackageName; |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 165 | public static final @android.annotation.NonNull Creator<VisualVoicemailSmsFilterSettings> CREATOR = |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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()); |
Ta-wei Yen | 2d0f486 | 2017-12-18 11:54:06 -0800 | [diff] [blame] | 173 | builder.setPackageName(in.readString()); |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 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); |
Ta-wei Yen | 2d0f486 | 2017-12-18 11:54:06 -0800 | [diff] [blame] | 193 | dest.writeString(packageName); |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Ta-wei Yen | 485d6de | 2016-12-16 12:17:30 -0800 | [diff] [blame] | 196 | @Override |
Ta-wei Yen | 2d0f486 | 2017-12-18 11:54:06 -0800 | [diff] [blame] | 197 | public String toString() { |
Ta-wei Yen | 485d6de | 2016-12-16 12:17:30 -0800 | [diff] [blame] | 198 | return "[VisualVoicemailSmsFilterSettings " |
| 199 | + "clientPrefix=" + clientPrefix |
| 200 | + ", originatingNumbers=" + originatingNumbers |
| 201 | + ", destinationPort=" + destinationPort |
| 202 | + "]"; |
| 203 | } |
| 204 | |
Ta-wei Yen | 67ab168 | 2016-05-24 15:25:16 -0700 | [diff] [blame] | 205 | } |