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 17 package android.telephony; 18 19 import android.annotation.Nullable; 20 import android.os.Bundle; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.telecom.PhoneAccountHandle; 24 import android.telephony.VisualVoicemailService.VisualVoicemailTask; 25 26 /** 27 * Represents the content of a visual voicemail SMS. If a incoming SMS matches the {@link 28 * VisualVoicemailSmsFilterSettings} set by the default dialer, {@link 29 * VisualVoicemailService#onSmsReceived(VisualVoicemailTask, VisualVoicemailSms)} will be called. 30 */ 31 public final class VisualVoicemailSms implements Parcelable { 32 33 private final PhoneAccountHandle mPhoneAccountHandle; 34 @Nullable 35 private final String mPrefix; 36 37 @Nullable 38 private final Bundle mFields; 39 40 private final String mMessageBody; 41 VisualVoicemailSms(Builder builder)42 VisualVoicemailSms(Builder builder) { 43 mPhoneAccountHandle = builder.mPhoneAccountHandle; 44 mPrefix = builder.mPrefix; 45 mFields = builder.mFields; 46 mMessageBody = builder.mMessageBody; 47 } 48 49 /** 50 * The {@link PhoneAccountHandle} that received the SMS. 51 */ getPhoneAccountHandle()52 public PhoneAccountHandle getPhoneAccountHandle() { 53 return mPhoneAccountHandle; 54 } 55 56 /** 57 * The event type of the SMS or {@code null} if the framework cannot parse the SMS as voicemail 58 * but the carrier pattern indicates it is. Common values are "SYNC" or "STATUS". 59 */ getPrefix()60 public String getPrefix() { 61 return mPrefix; 62 } 63 64 /** 65 * The key-value pairs sent by the SMS, or {@code null} if the framework cannot parse the SMS as 66 * voicemail but the carrier pattern indicates it is. The interpretation of the fields is 67 * carrier dependent. 68 */ getFields()69 public Bundle getFields() { 70 return mFields; 71 } 72 73 /** 74 * Raw message body of the received SMS. 75 */ getMessageBody()76 public String getMessageBody() { 77 return mMessageBody; 78 } 79 80 /** 81 * Builder for the {@link VisualVoicemailSms}. Internal use only. 82 * 83 * @hide 84 */ 85 public static class Builder { 86 87 private PhoneAccountHandle mPhoneAccountHandle; 88 private String mPrefix; 89 private Bundle mFields; 90 private String mMessageBody; 91 build()92 public VisualVoicemailSms build() { 93 return new VisualVoicemailSms(this); 94 } 95 setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle)96 public Builder setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 97 this.mPhoneAccountHandle = phoneAccountHandle; 98 return this; 99 } 100 setPrefix(String prefix)101 public Builder setPrefix(String prefix) { 102 this.mPrefix = prefix; 103 return this; 104 } 105 setFields(Bundle fields)106 public Builder setFields(Bundle fields) { 107 this.mFields = fields; 108 return this; 109 } 110 setMessageBody(String messageBody)111 public Builder setMessageBody(String messageBody) { 112 this.mMessageBody = messageBody; 113 return this; 114 } 115 116 } 117 118 119 public static final @android.annotation.NonNull Creator<VisualVoicemailSms> CREATOR = 120 new Creator<VisualVoicemailSms>() { 121 @Override 122 public VisualVoicemailSms createFromParcel(Parcel in) { 123 return new Builder() 124 .setPhoneAccountHandle((PhoneAccountHandle) in.readParcelable(null, android.telecom.PhoneAccountHandle.class)) 125 .setPrefix(in.readString()) 126 .setFields(in.readBundle()) 127 .setMessageBody(in.readString()) 128 .build(); 129 } 130 131 @Override 132 public VisualVoicemailSms[] newArray(int size) { 133 return new VisualVoicemailSms[size]; 134 } 135 }; 136 137 @Override describeContents()138 public int describeContents() { 139 return 0; 140 } 141 142 @Override writeToParcel(Parcel dest, int flags)143 public void writeToParcel(Parcel dest, int flags) { 144 dest.writeParcelable(getPhoneAccountHandle(), flags); 145 dest.writeString(getPrefix()); 146 dest.writeBundle(getFields()); 147 dest.writeString(getMessageBody()); 148 } 149 } 150