1 /* 2 * Copyright (C) 2019 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.ims; 18 19 import static android.telephony.ims.RcsMessage.LOCATION_NOT_SET; 20 21 import android.annotation.CheckResult; 22 import android.annotation.Nullable; 23 import android.os.Parcel; 24 25 /** 26 * The collection of parameters to be passed into 27 * {@link RcsThread#addIncomingMessage(RcsIncomingMessageCreationParams)} and 28 * {@link RcsThread#addOutgoingMessage(RcsOutgoingMessageCreationParams)} to create and persist 29 * {@link RcsMessage}s on an {@link RcsThread} 30 * 31 * @hide 32 */ 33 public class RcsMessageCreationParams { 34 // The globally unique id of the RcsMessage to be created. 35 private final String mRcsMessageGlobalId; 36 37 // The subscription that this message was/will be received/sent from. 38 private final int mSubId; 39 // The sending/receiving status of the message 40 private final @RcsMessage.RcsMessageStatus int mMessageStatus; 41 // The timestamp of message creation 42 private final long mOriginationTimestamp; 43 // The user visible content of the message 44 private final String mText; 45 // The latitude of the message if this is a location message 46 private final double mLatitude; 47 // The longitude of the message if this is a location message 48 private final double mLongitude; 49 50 /** 51 * @return Returns the globally unique RCS Message ID for the {@link RcsMessage} to be created. 52 * Please see 4.4.5.2 - GSMA RCC.53 (RCS Device API 1.6 Specification 53 */ 54 @Nullable getRcsMessageGlobalId()55 public String getRcsMessageGlobalId() { 56 return mRcsMessageGlobalId; 57 } 58 59 /** 60 * @return Returns the subscription ID that was used to send or receive the {@link RcsMessage} 61 * to be created. 62 */ getSubId()63 public int getSubId() { 64 return mSubId; 65 } 66 67 /** 68 * @return Returns the status for the {@link RcsMessage} to be created. 69 * @see RcsMessage.RcsMessageStatus 70 */ getMessageStatus()71 public int getMessageStatus() { 72 return mMessageStatus; 73 } 74 75 /** 76 * @return Returns the origination timestamp of the {@link RcsMessage} to be created in 77 * milliseconds passed after midnight, January 1, 1970 UTC. Origination is defined as when 78 * the sender tapped the send button. 79 */ getOriginationTimestamp()80 public long getOriginationTimestamp() { 81 return mOriginationTimestamp; 82 } 83 84 /** 85 * @return Returns the user visible text contained in the {@link RcsMessage} to be created 86 */ 87 @Nullable getText()88 public String getText() { 89 return mText; 90 } 91 92 /** 93 * @return Returns the latitude of the {@link RcsMessage} to be created, or 94 * {@link RcsMessage#LOCATION_NOT_SET} if the message does not contain a location. 95 */ getLatitude()96 public double getLatitude() { 97 return mLatitude; 98 } 99 100 /** 101 * @return Returns the longitude of the {@link RcsMessage} to be created, or 102 * {@link RcsMessage#LOCATION_NOT_SET} if the message does not contain a location. 103 */ getLongitude()104 public double getLongitude() { 105 return mLongitude; 106 } 107 108 /** 109 * The base builder for creating {@link RcsMessage}s on {@link RcsThread}s. 110 * 111 * @see RcsIncomingMessageCreationParams 112 */ 113 public static class Builder { 114 private String mRcsMessageGlobalId; 115 private int mSubId; 116 private @RcsMessage.RcsMessageStatus int mMessageStatus; 117 private long mOriginationTimestamp; 118 private String mText; 119 private double mLatitude = LOCATION_NOT_SET; 120 private double mLongitude = LOCATION_NOT_SET; 121 122 /** 123 * @hide 124 */ Builder(long originationTimestamp, int subscriptionId)125 public Builder(long originationTimestamp, int subscriptionId) { 126 mOriginationTimestamp = originationTimestamp; 127 mSubId = subscriptionId; 128 } 129 130 /** 131 * Sets the status of the {@link RcsMessage} to be built. 132 * 133 * @param rcsMessageStatus The status to be set 134 * @return The same instance of {@link Builder} to chain methods 135 * @see RcsMessage#setStatus(int) 136 */ 137 @CheckResult setStatus(@csMessage.RcsMessageStatus int rcsMessageStatus)138 public Builder setStatus(@RcsMessage.RcsMessageStatus int rcsMessageStatus) { 139 mMessageStatus = rcsMessageStatus; 140 return this; 141 } 142 143 /** 144 * Sets the globally unique RCS message identifier for the {@link RcsMessage} to be built. 145 * This function does not confirm that this message id is unique. Please see 4.4.5.2 - GSMA 146 * RCC.53 (RCS Device API 1.6 Specification) 147 * 148 * @param rcsMessageId The ID to be set 149 * @return The same instance of {@link Builder} to chain methods 150 * @see RcsMessage#setRcsMessageId(String) 151 */ 152 @CheckResult setRcsMessageId(String rcsMessageId)153 public Builder setRcsMessageId(String rcsMessageId) { 154 mRcsMessageGlobalId = rcsMessageId; 155 return this; 156 } 157 158 /** 159 * Sets the text of the {@link RcsMessage} to be built. 160 * 161 * @param text The user visible text of the message 162 * @return The same instance of {@link Builder} to chain methods 163 * @see RcsMessage#setText(String) 164 */ 165 @CheckResult setText(String text)166 public Builder setText(String text) { 167 mText = text; 168 return this; 169 } 170 171 /** 172 * Sets the latitude of the {@link RcsMessage} to be built. Please see US5-24 - GSMA RCC.71 173 * (RCS Universal Profile Service Definition Document) 174 * 175 * @param latitude The latitude of the location information associated with this message. 176 * @return The same instance of {@link Builder} to chain methods 177 * @see RcsMessage#setLatitude(double) 178 */ 179 @CheckResult setLatitude(double latitude)180 public Builder setLatitude(double latitude) { 181 mLatitude = latitude; 182 return this; 183 } 184 185 /** 186 * Sets the longitude of the {@link RcsMessage} to be built. Please see US5-24 - GSMA RCC.71 187 * (RCS Universal Profile Service Definition Document) 188 * 189 * @param longitude The longitude of the location information associated with this message. 190 * @return The same instance of {@link Builder} to chain methods 191 * @see RcsMessage#setLongitude(double) 192 */ 193 @CheckResult setLongitude(double longitude)194 public Builder setLongitude(double longitude) { 195 mLongitude = longitude; 196 return this; 197 } 198 199 /** 200 * @return Builds and returns a newly created {@link RcsMessageCreationParams} 201 */ build()202 public RcsMessageCreationParams build() { 203 return new RcsMessageCreationParams(this); 204 } 205 } 206 RcsMessageCreationParams(Builder builder)207 protected RcsMessageCreationParams(Builder builder) { 208 mRcsMessageGlobalId = builder.mRcsMessageGlobalId; 209 mSubId = builder.mSubId; 210 mMessageStatus = builder.mMessageStatus; 211 mOriginationTimestamp = builder.mOriginationTimestamp; 212 mText = builder.mText; 213 mLatitude = builder.mLatitude; 214 mLongitude = builder.mLongitude; 215 } 216 217 /** 218 * @hide 219 */ RcsMessageCreationParams(Parcel in)220 RcsMessageCreationParams(Parcel in) { 221 mRcsMessageGlobalId = in.readString(); 222 mSubId = in.readInt(); 223 mMessageStatus = in.readInt(); 224 mOriginationTimestamp = in.readLong(); 225 mText = in.readString(); 226 mLatitude = in.readDouble(); 227 mLongitude = in.readDouble(); 228 } 229 230 /** 231 * @hide 232 */ writeToParcel(Parcel dest)233 public void writeToParcel(Parcel dest) { 234 dest.writeString(mRcsMessageGlobalId); 235 dest.writeInt(mSubId); 236 dest.writeInt(mMessageStatus); 237 dest.writeLong(mOriginationTimestamp); 238 dest.writeString(mText); 239 dest.writeDouble(mLatitude); 240 dest.writeDouble(mLongitude); 241 } 242 } 243