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 package android.telephony.ims; 17 18 import android.annotation.CheckResult; 19 import android.net.Uri; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * Pass an instance of this class to 25 * {@link RcsMessage#insertFileTransfer(RcsFileTransferCreationParams)} create an 26 * {@link RcsFileTransferPart} and save it into storage. 27 * 28 * @hide 29 */ 30 public final class RcsFileTransferCreationParams implements Parcelable { 31 private String mRcsFileTransferSessionId; 32 private Uri mContentUri; 33 private String mContentMimeType; 34 private long mFileSize; 35 private long mTransferOffset; 36 private int mWidth; 37 private int mHeight; 38 private long mMediaDuration; 39 private Uri mPreviewUri; 40 private String mPreviewMimeType; 41 private @RcsFileTransferPart.RcsFileTransferStatus int mFileTransferStatus; 42 43 /** 44 * @return Returns the globally unique RCS file transfer session ID for the 45 * {@link RcsFileTransferPart} to be created 46 */ getRcsFileTransferSessionId()47 public String getRcsFileTransferSessionId() { 48 return mRcsFileTransferSessionId; 49 } 50 51 /** 52 * @return Returns the URI for the content of the {@link RcsFileTransferPart} to be created 53 */ getContentUri()54 public Uri getContentUri() { 55 return mContentUri; 56 } 57 58 /** 59 * @return Returns the MIME type for the content of the {@link RcsFileTransferPart} to be 60 * created 61 */ getContentMimeType()62 public String getContentMimeType() { 63 return mContentMimeType; 64 } 65 66 /** 67 * @return Returns the file size in bytes for the {@link RcsFileTransferPart} to be created 68 */ getFileSize()69 public long getFileSize() { 70 return mFileSize; 71 } 72 73 /** 74 * @return Returns the transfer offset for the {@link RcsFileTransferPart} to be created. The 75 * file transfer offset is defined as how many bytes have been successfully transferred to the 76 * receiver of this file transfer. 77 */ getTransferOffset()78 public long getTransferOffset() { 79 return mTransferOffset; 80 } 81 82 /** 83 * @return Returns the width of the {@link RcsFileTransferPart} to be created. The value is in 84 * pixels. 85 */ getWidth()86 public int getWidth() { 87 return mWidth; 88 } 89 90 /** 91 * @return Returns the height of the {@link RcsFileTransferPart} to be created. The value is in 92 * pixels. 93 */ getHeight()94 public int getHeight() { 95 return mHeight; 96 } 97 98 /** 99 * @return Returns the duration of the {@link RcsFileTransferPart} to be created. 100 */ getMediaDuration()101 public long getMediaDuration() { 102 return mMediaDuration; 103 } 104 105 /** 106 * @return Returns the URI of the preview of the content of the {@link RcsFileTransferPart} to 107 * be created. This should only be used for multi-media files. 108 */ getPreviewUri()109 public Uri getPreviewUri() { 110 return mPreviewUri; 111 } 112 113 /** 114 * @return Returns the MIME type of the preview of the content of the 115 * {@link RcsFileTransferPart} to be created. This should only be used for multi-media files. 116 */ getPreviewMimeType()117 public String getPreviewMimeType() { 118 return mPreviewMimeType; 119 } 120 121 /** 122 * @return Returns the status of the {@link RcsFileTransferPart} to be created. 123 */ getFileTransferStatus()124 public @RcsFileTransferPart.RcsFileTransferStatus int getFileTransferStatus() { 125 return mFileTransferStatus; 126 } 127 128 /** 129 * @hide 130 */ RcsFileTransferCreationParams(Builder builder)131 RcsFileTransferCreationParams(Builder builder) { 132 mRcsFileTransferSessionId = builder.mRcsFileTransferSessionId; 133 mContentUri = builder.mContentUri; 134 mContentMimeType = builder.mContentMimeType; 135 mFileSize = builder.mFileSize; 136 mTransferOffset = builder.mTransferOffset; 137 mWidth = builder.mWidth; 138 mHeight = builder.mHeight; 139 mMediaDuration = builder.mLength; 140 mPreviewUri = builder.mPreviewUri; 141 mPreviewMimeType = builder.mPreviewMimeType; 142 mFileTransferStatus = builder.mFileTransferStatus; 143 } 144 145 /** 146 * A builder to create instances of {@link RcsFileTransferCreationParams} 147 */ 148 public class Builder { 149 private String mRcsFileTransferSessionId; 150 private Uri mContentUri; 151 private String mContentMimeType; 152 private long mFileSize; 153 private long mTransferOffset; 154 private int mWidth; 155 private int mHeight; 156 private long mLength; 157 private Uri mPreviewUri; 158 private String mPreviewMimeType; 159 private @RcsFileTransferPart.RcsFileTransferStatus int mFileTransferStatus; 160 161 /** 162 * Sets the globally unique RCS file transfer session ID for the {@link RcsFileTransferPart} 163 * to be created 164 * 165 * @param sessionId The RCS file transfer session ID 166 * @return The same instance of {@link Builder} to chain methods 167 */ 168 @CheckResult setFileTransferSessionId(String sessionId)169 public Builder setFileTransferSessionId(String sessionId) { 170 mRcsFileTransferSessionId = sessionId; 171 return this; 172 } 173 174 /** 175 * Sets the URI for the content of the {@link RcsFileTransferPart} to be created 176 * 177 * @param contentUri The URI for the file 178 * @return The same instance of {@link Builder} to chain methods 179 */ 180 @CheckResult setContentUri(Uri contentUri)181 public Builder setContentUri(Uri contentUri) { 182 mContentUri = contentUri; 183 return this; 184 } 185 186 /** 187 * Sets the MIME type for the content of the {@link RcsFileTransferPart} to be created 188 * 189 * @param contentType The MIME type of the file 190 * @return The same instance of {@link Builder} to chain methods 191 */ 192 @CheckResult setContentMimeType(String contentType)193 public Builder setContentMimeType(String contentType) { 194 mContentMimeType = contentType; 195 return this; 196 } 197 198 /** 199 * Sets the file size for the {@link RcsFileTransferPart} to be created 200 * 201 * @param size The size of the file in bytes 202 * @return The same instance of {@link Builder} to chain methods 203 */ 204 @CheckResult setFileSize(long size)205 public Builder setFileSize(long size) { 206 mFileSize = size; 207 return this; 208 } 209 210 /** 211 * Sets the transfer offset for the {@link RcsFileTransferPart} to be created. The file 212 * transfer offset is defined as how many bytes have been successfully transferred to the 213 * receiver of this file transfer. 214 * 215 * @param offset The transfer offset in bytes 216 * @return The same instance of {@link Builder} to chain methods 217 */ 218 @CheckResult setTransferOffset(long offset)219 public Builder setTransferOffset(long offset) { 220 mTransferOffset = offset; 221 return this; 222 } 223 224 /** 225 * Sets the width of the {@link RcsFileTransferPart} to be created. This should only be used 226 * for multi-media files. 227 * 228 * @param width The width of the multi-media file in pixels. 229 * @return The same instance of {@link Builder} to chain methods 230 */ 231 @CheckResult setWidth(int width)232 public Builder setWidth(int width) { 233 mWidth = width; 234 return this; 235 } 236 237 /** 238 * Sets the height of the {@link RcsFileTransferPart} to be created. This should only be 239 * used for multi-media files. 240 * 241 * @param height The height of the multi-media file in pixels. 242 * @return The same instance of {@link Builder} to chain methods 243 */ 244 @CheckResult setHeight(int height)245 public Builder setHeight(int height) { 246 mHeight = height; 247 return this; 248 } 249 250 /** 251 * Sets the length of the {@link RcsFileTransferPart} to be created. This should only be 252 * used for multi-media files such as audio or video. 253 * 254 * @param length The length of the multi-media file in milliseconds 255 * @return The same instance of {@link Builder} to chain methods 256 */ 257 @CheckResult setMediaDuration(long length)258 public Builder setMediaDuration(long length) { 259 mLength = length; 260 return this; 261 } 262 263 /** 264 * Sets the URI of the preview of the content of the {@link RcsFileTransferPart} to be 265 * created. This should only be used for multi-media files. 266 * 267 * @param previewUri The URI of the preview of the file transfer 268 * @return The same instance of {@link Builder} to chain methods 269 */ 270 @CheckResult setPreviewUri(Uri previewUri)271 public Builder setPreviewUri(Uri previewUri) { 272 mPreviewUri = previewUri; 273 return this; 274 } 275 276 /** 277 * Sets the MIME type of the preview of the content of the {@link RcsFileTransferPart} to 278 * be created. This should only be used for multi-media files. 279 * 280 * @param previewType The MIME type of the preview of the file transfer 281 * @return The same instance of {@link Builder} to chain methods 282 */ 283 @CheckResult setPreviewMimeType(String previewType)284 public Builder setPreviewMimeType(String previewType) { 285 mPreviewMimeType = previewType; 286 return this; 287 } 288 289 /** 290 * Sets the status of the {@link RcsFileTransferPart} to be created. 291 * 292 * @param status The status of the file transfer 293 * @return The same instance of {@link Builder} to chain methods 294 */ 295 @CheckResult setFileTransferStatus( @csFileTransferPart.RcsFileTransferStatus int status)296 public Builder setFileTransferStatus( 297 @RcsFileTransferPart.RcsFileTransferStatus int status) { 298 mFileTransferStatus = status; 299 return this; 300 } 301 302 /** 303 * Creates an instance of {@link RcsFileTransferCreationParams} with the given 304 * parameters. 305 * 306 * @return The same instance of {@link Builder} to chain methods 307 * @see RcsMessage#insertFileTransfer(RcsFileTransferCreationParams) 308 */ build()309 public RcsFileTransferCreationParams build() { 310 return new RcsFileTransferCreationParams(this); 311 } 312 } 313 RcsFileTransferCreationParams(Parcel in)314 private RcsFileTransferCreationParams(Parcel in) { 315 mRcsFileTransferSessionId = in.readString(); 316 mContentUri = in.readParcelable(Uri.class.getClassLoader()); 317 mContentMimeType = in.readString(); 318 mFileSize = in.readLong(); 319 mTransferOffset = in.readLong(); 320 mWidth = in.readInt(); 321 mHeight = in.readInt(); 322 mMediaDuration = in.readLong(); 323 mPreviewUri = in.readParcelable(Uri.class.getClassLoader()); 324 mPreviewMimeType = in.readString(); 325 mFileTransferStatus = in.readInt(); 326 } 327 328 public static final @android.annotation.NonNull Creator<RcsFileTransferCreationParams> CREATOR = 329 new Creator<RcsFileTransferCreationParams>() { 330 @Override 331 public RcsFileTransferCreationParams createFromParcel(Parcel in) { 332 return new RcsFileTransferCreationParams(in); 333 } 334 335 @Override 336 public RcsFileTransferCreationParams[] newArray(int size) { 337 return new RcsFileTransferCreationParams[size]; 338 } 339 }; 340 341 @Override describeContents()342 public int describeContents() { 343 return 0; 344 } 345 346 @Override writeToParcel(Parcel dest, int flags)347 public void writeToParcel(Parcel dest, int flags) { 348 dest.writeString(mRcsFileTransferSessionId); 349 dest.writeParcelable(mContentUri, flags); 350 dest.writeString(mContentMimeType); 351 dest.writeLong(mFileSize); 352 dest.writeLong(mTransferOffset); 353 dest.writeInt(mWidth); 354 dest.writeInt(mHeight); 355 dest.writeLong(mMediaDuration); 356 dest.writeParcelable(mPreviewUri, flags); 357 dest.writeString(mPreviewMimeType); 358 dest.writeInt(mFileTransferStatus); 359 } 360 } 361