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.IntDef; 19 import android.annotation.Nullable; 20 import android.annotation.WorkerThread; 21 import android.net.Uri; 22 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 26 /** 27 * A part of a composite {@link RcsMessage} that holds a file transfer. Please see Section 7 28 * (File Transfer) - GSMA RCC.71 (RCS Universal Profile Service Definition Document) 29 * 30 * @hide 31 */ 32 public class RcsFileTransferPart { 33 /** 34 * The status to indicate that this {@link RcsFileTransferPart} is not set yet. 35 */ 36 public static final int NOT_SET = 0; 37 38 /** 39 * The status to indicate that this {@link RcsFileTransferPart} is a draft and is not in the 40 * process of sending yet. 41 */ 42 public static final int DRAFT = 1; 43 44 /** 45 * The status to indicate that this {@link RcsFileTransferPart} is actively being sent right 46 * now. 47 */ 48 public static final int SENDING = 2; 49 50 /** 51 * The status to indicate that this {@link RcsFileTransferPart} was being sent, but the user has 52 * paused the sending process. 53 */ 54 public static final int SENDING_PAUSED = 3; 55 56 /** 57 * The status to indicate that this {@link RcsFileTransferPart} was attempted, but failed to 58 * send. 59 */ 60 public static final int SENDING_FAILED = 4; 61 62 /** 63 * The status to indicate that this {@link RcsFileTransferPart} is permanently cancelled to 64 * send. 65 */ 66 public static final int SENDING_CANCELLED = 5; 67 68 /** 69 * The status to indicate that this {@link RcsFileTransferPart} is actively being downloaded 70 * right now. 71 */ 72 public static final int DOWNLOADING = 6; 73 74 /** 75 * The status to indicate that this {@link RcsFileTransferPart} was being downloaded, but the 76 * user paused the downloading process. 77 */ 78 public static final int DOWNLOADING_PAUSED = 7; 79 80 /** 81 * The status to indicate that this {@link RcsFileTransferPart} was attempted, but failed to 82 * download. 83 */ 84 public static final int DOWNLOADING_FAILED = 8; 85 86 /** 87 * The status to indicate that this {@link RcsFileTransferPart} is permanently cancelled to 88 * download. 89 */ 90 public static final int DOWNLOADING_CANCELLED = 9; 91 92 /** 93 * The status to indicate that this {@link RcsFileTransferPart} was successfully sent or 94 * received. 95 */ 96 public static final int SUCCEEDED = 10; 97 98 @IntDef({ 99 DRAFT, SENDING, SENDING_PAUSED, SENDING_FAILED, SENDING_CANCELLED, DOWNLOADING, 100 DOWNLOADING_PAUSED, DOWNLOADING_FAILED, DOWNLOADING_CANCELLED, SUCCEEDED 101 }) 102 @Retention(RetentionPolicy.SOURCE) 103 public @interface RcsFileTransferStatus { 104 } 105 106 private final RcsControllerCall mRcsControllerCall; 107 108 private int mId; 109 110 /** 111 * @hide 112 */ RcsFileTransferPart(RcsControllerCall rcsControllerCall, int id)113 RcsFileTransferPart(RcsControllerCall rcsControllerCall, int id) { 114 mRcsControllerCall = rcsControllerCall; 115 mId = id; 116 } 117 118 /** 119 * @hide 120 */ setId(int id)121 public void setId(int id) { 122 mId = id; 123 } 124 125 /** 126 * @hide 127 */ getId()128 public int getId() { 129 return mId; 130 } 131 132 /** 133 * Sets the RCS file transfer session ID for this file transfer and persists into storage. 134 * 135 * @param sessionId The session ID to be used for this file transfer. 136 * @throws RcsMessageStoreException if the value could not be persisted into storage 137 */ 138 @WorkerThread setFileTransferSessionId(String sessionId)139 public void setFileTransferSessionId(String sessionId) throws RcsMessageStoreException { 140 mRcsControllerCall.callWithNoReturn( 141 (iRcs, callingPackage) -> iRcs.setFileTransferSessionId(mId, sessionId, 142 callingPackage)); 143 } 144 145 /** 146 * @return Returns the file transfer session ID. 147 * @throws RcsMessageStoreException if the value could not be read from the storage 148 */ 149 @WorkerThread getFileTransferSessionId()150 public String getFileTransferSessionId() throws RcsMessageStoreException { 151 return mRcsControllerCall.call( 152 (iRcs, callingPackage) -> iRcs.getFileTransferSessionId(mId, callingPackage)); 153 } 154 155 /** 156 * Sets the content URI for this file transfer and persists into storage. The file transfer 157 * should be reachable using this URI. 158 * 159 * @param contentUri The URI for this file transfer. 160 * @throws RcsMessageStoreException if the value could not be persisted into storage 161 */ 162 @WorkerThread setContentUri(Uri contentUri)163 public void setContentUri(Uri contentUri) throws RcsMessageStoreException { 164 mRcsControllerCall.callWithNoReturn( 165 (iRcs, callingPackage) -> iRcs.setFileTransferContentUri(mId, contentUri, 166 callingPackage)); 167 } 168 169 /** 170 * @return Returns the URI for this file transfer 171 * @throws RcsMessageStoreException if the value could not be read from the storage 172 */ 173 @Nullable 174 @WorkerThread getContentUri()175 public Uri getContentUri() throws RcsMessageStoreException { 176 return mRcsControllerCall.call( 177 (iRcs, callingPackage) -> iRcs.getFileTransferContentUri(mId, callingPackage)); 178 } 179 180 /** 181 * Sets the MIME type of this file transfer and persists into storage. Whether this type 182 * actually matches any known or supported types is not checked. 183 * 184 * @param contentMimeType The type of this file transfer. 185 * @throws RcsMessageStoreException if the value could not be persisted into storage 186 */ 187 @WorkerThread setContentMimeType(String contentMimeType)188 public void setContentMimeType(String contentMimeType) throws RcsMessageStoreException { 189 mRcsControllerCall.callWithNoReturn( 190 (iRcs, callingPackage) -> iRcs.setFileTransferContentType(mId, contentMimeType, 191 callingPackage)); 192 } 193 194 /** 195 * @return Returns the content type of this file transfer 196 * @throws RcsMessageStoreException if the value could not be read from the storage 197 */ 198 @WorkerThread 199 @Nullable getContentMimeType()200 public String getContentMimeType() throws RcsMessageStoreException { 201 return mRcsControllerCall.call( 202 (iRcs, callingPackage) -> iRcs.getFileTransferContentType(mId, callingPackage)); 203 } 204 205 /** 206 * Sets the content length (i.e. file size) for this file transfer and persists into storage. 207 * 208 * @param contentLength The content length of this file transfer 209 * @throws RcsMessageStoreException if the value could not be persisted into storage 210 */ 211 @WorkerThread setFileSize(long contentLength)212 public void setFileSize(long contentLength) throws RcsMessageStoreException { 213 mRcsControllerCall.callWithNoReturn( 214 (iRcs, callingPackage) -> iRcs.setFileTransferFileSize(mId, contentLength, 215 callingPackage)); 216 } 217 218 /** 219 * @return Returns the content length (i.e. file size) for this file transfer. 220 * @throws RcsMessageStoreException if the value could not be read from the storage 221 */ 222 @WorkerThread getFileSize()223 public long getFileSize() throws RcsMessageStoreException { 224 return mRcsControllerCall.call( 225 (iRcs, callingPackage) -> iRcs.getFileTransferFileSize(mId, callingPackage)); 226 } 227 228 /** 229 * Sets the transfer offset for this file transfer and persists into storage. The file transfer 230 * offset is defined as how many bytes have been successfully transferred to the receiver of 231 * this file transfer. 232 * 233 * @param transferOffset The transfer offset for this file transfer. 234 * @throws RcsMessageStoreException if the value could not be persisted into storage 235 */ 236 @WorkerThread setTransferOffset(long transferOffset)237 public void setTransferOffset(long transferOffset) throws RcsMessageStoreException { 238 mRcsControllerCall.callWithNoReturn( 239 (iRcs, callingPackage) -> iRcs.setFileTransferTransferOffset(mId, transferOffset, 240 callingPackage)); 241 } 242 243 /** 244 * @return Returns the number of bytes that have successfully transferred. 245 * @throws RcsMessageStoreException if the value could not be read from the storage 246 */ 247 @WorkerThread getTransferOffset()248 public long getTransferOffset() throws RcsMessageStoreException { 249 return mRcsControllerCall.call( 250 (iRcs, callingPackage) -> iRcs.getFileTransferTransferOffset(mId, callingPackage)); 251 } 252 253 /** 254 * Sets the status for this file transfer and persists into storage. 255 * 256 * @param status The status of this file transfer. 257 * @throws RcsMessageStoreException if the value could not be persisted into storage 258 */ 259 @WorkerThread setFileTransferStatus(@csFileTransferStatus int status)260 public void setFileTransferStatus(@RcsFileTransferStatus int status) 261 throws RcsMessageStoreException { 262 mRcsControllerCall.callWithNoReturn( 263 (iRcs, callingPackage) -> iRcs.setFileTransferStatus(mId, status, callingPackage)); 264 } 265 266 /** 267 * @return Returns the status of this file transfer. 268 * @throws RcsMessageStoreException if the value could not be read from the storage 269 */ 270 @WorkerThread getFileTransferStatus()271 public @RcsFileTransferStatus int getFileTransferStatus() throws RcsMessageStoreException { 272 return mRcsControllerCall.call( 273 (iRcs, callingPackage) -> iRcs.getFileTransferStatus(mId, callingPackage)); 274 } 275 276 /** 277 * @return Returns the width of this multi-media message part in pixels. 278 * @throws RcsMessageStoreException if the value could not be read from the storage 279 */ 280 @WorkerThread getWidth()281 public int getWidth() throws RcsMessageStoreException { 282 return mRcsControllerCall.call( 283 (iRcs, callingPackage) -> iRcs.getFileTransferWidth(mId, callingPackage)); 284 } 285 286 /** 287 * Sets the width of this RCS multi-media message part and persists into storage. 288 * 289 * @param width The width value in pixels 290 * @throws RcsMessageStoreException if the value could not be persisted into storage 291 */ 292 @WorkerThread setWidth(int width)293 public void setWidth(int width) throws RcsMessageStoreException { 294 mRcsControllerCall.callWithNoReturn( 295 (iRcs, callingPackage) -> iRcs.setFileTransferWidth(mId, width, callingPackage)); 296 } 297 298 /** 299 * @return Returns the height of this multi-media message part in pixels. 300 * @throws RcsMessageStoreException if the value could not be read from the storage 301 */ 302 @WorkerThread getHeight()303 public int getHeight() throws RcsMessageStoreException { 304 return mRcsControllerCall.call( 305 (iRcs, callingPackage) -> iRcs.getFileTransferHeight(mId, callingPackage)); 306 } 307 308 /** 309 * Sets the height of this RCS multi-media message part and persists into storage. 310 * 311 * @param height The height value in pixels 312 * @throws RcsMessageStoreException if the value could not be persisted into storage 313 */ 314 @WorkerThread setHeight(int height)315 public void setHeight(int height) throws RcsMessageStoreException { 316 mRcsControllerCall.callWithNoReturn( 317 (iRcs, callingPackage) -> iRcs.setFileTransferHeight(mId, height, callingPackage)); 318 } 319 320 /** 321 * @return Returns the length of this multi-media file (e.g. video or audio) in milliseconds. 322 * @throws RcsMessageStoreException if the value could not be read from the storage 323 */ 324 @WorkerThread getLength()325 public long getLength() throws RcsMessageStoreException { 326 return mRcsControllerCall.call( 327 (iRcs, callingPackage) -> iRcs.getFileTransferLength(mId, callingPackage)); 328 } 329 330 /** 331 * Sets the length of this multi-media file (e.g. video or audio) and persists into storage. 332 * 333 * @param length The length of the file in milliseconds. 334 * @throws RcsMessageStoreException if the value could not be persisted into storage 335 */ 336 @WorkerThread setLength(long length)337 public void setLength(long length) throws RcsMessageStoreException { 338 mRcsControllerCall.callWithNoReturn( 339 (iRcs, callingPackage) -> iRcs.setFileTransferLength(mId, length, callingPackage)); 340 } 341 342 /** 343 * @return Returns the URI for the preview of this multi-media file (e.g. an image thumbnail for 344 * a video) 345 * @throws RcsMessageStoreException if the value could not be read from the storage 346 */ 347 @WorkerThread getPreviewUri()348 public Uri getPreviewUri() throws RcsMessageStoreException { 349 return mRcsControllerCall.call( 350 (iRcs, callingPackage) -> iRcs.getFileTransferPreviewUri(mId, callingPackage)); 351 } 352 353 /** 354 * Sets the URI for the preview of this multi-media file and persists into storage. 355 * 356 * @param previewUri The URI to access to the preview file. 357 * @throws RcsMessageStoreException if the value could not be persisted into storage 358 */ 359 @WorkerThread setPreviewUri(Uri previewUri)360 public void setPreviewUri(Uri previewUri) throws RcsMessageStoreException { 361 mRcsControllerCall.callWithNoReturn( 362 (iRcs, callingPackage) -> iRcs.setFileTransferPreviewUri(mId, previewUri, 363 callingPackage)); 364 } 365 366 /** 367 * @return Returns the MIME type of this multi-media file's preview. 368 * @throws RcsMessageStoreException if the value could not be read from the storage 369 */ 370 @WorkerThread getPreviewMimeType()371 public String getPreviewMimeType() throws RcsMessageStoreException { 372 return mRcsControllerCall.call( 373 (iRcs, callingPackage) -> iRcs.getFileTransferPreviewType(mId, callingPackage)); 374 } 375 376 /** 377 * Sets the MIME type for this multi-media file's preview and persists into storage. 378 * 379 * @param previewMimeType The MIME type for the preview 380 * @throws RcsMessageStoreException if the value could not be persisted into storage 381 */ 382 @WorkerThread setPreviewMimeType(String previewMimeType)383 public void setPreviewMimeType(String previewMimeType) throws RcsMessageStoreException { 384 mRcsControllerCall.callWithNoReturn( 385 (iRcs, callingPackage) -> iRcs.setFileTransferPreviewType(mId, previewMimeType, 386 callingPackage)); 387 } 388 } 389