1 /* 2 * Copyright (C) 2018 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.NonNull; 19 import android.annotation.WorkerThread; 20 21 /** 22 * This class holds the delivery information of an {@link RcsOutgoingMessage} for each 23 * {@link RcsParticipant} that the message was intended for. 24 * 25 * @hide 26 */ 27 public class RcsOutgoingMessageDelivery { 28 private final RcsControllerCall mRcsControllerCall; 29 // The participant that this delivery is intended for 30 private final int mRecipientId; 31 // The message this delivery is associated with 32 private final int mRcsOutgoingMessageId; 33 34 /** 35 * Constructor to be used with RcsOutgoingMessage.getDelivery() 36 * 37 * @hide 38 */ RcsOutgoingMessageDelivery( RcsControllerCall rcsControllerCall, int recipientId, int messageId)39 RcsOutgoingMessageDelivery( 40 RcsControllerCall rcsControllerCall, int recipientId, int messageId) { 41 mRcsControllerCall = rcsControllerCall; 42 mRecipientId = recipientId; 43 mRcsOutgoingMessageId = messageId; 44 } 45 46 /** 47 * Sets the delivery time of this outgoing delivery and persists into storage. 48 * 49 * @param deliveredTimestamp The timestamp to set to delivery. It is defined as milliseconds 50 * passed after midnight, January 1, 1970 UTC 51 * @throws RcsMessageStoreException if the value could not be persisted into storage 52 */ 53 @WorkerThread setDeliveredTimestamp(long deliveredTimestamp)54 public void setDeliveredTimestamp(long deliveredTimestamp) throws RcsMessageStoreException { 55 mRcsControllerCall.callWithNoReturn( 56 (iRcs, callingPackage) -> iRcs.setOutgoingDeliveryDeliveredTimestamp( 57 mRcsOutgoingMessageId, mRecipientId, deliveredTimestamp, callingPackage)); 58 } 59 60 /** 61 * @return Returns the delivered timestamp of the associated message to the associated 62 * participant. Timestamp is defined as milliseconds passed after midnight, January 1, 1970 UTC. 63 * Returns 0 if the {@link RcsOutgoingMessage} is not delivered yet. 64 * @throws RcsMessageStoreException if the value could not be read from the storage 65 */ 66 @WorkerThread getDeliveredTimestamp()67 public long getDeliveredTimestamp() throws RcsMessageStoreException { 68 return mRcsControllerCall.call( 69 (iRcs, callingPackage) -> iRcs.getOutgoingDeliveryDeliveredTimestamp( 70 mRcsOutgoingMessageId, mRecipientId, callingPackage)); 71 } 72 73 /** 74 * Sets the seen time of this outgoing delivery and persists into storage. 75 * 76 * @param seenTimestamp The timestamp to set to delivery. It is defined as milliseconds 77 * passed after midnight, January 1, 1970 UTC 78 * @throws RcsMessageStoreException if the value could not be persisted into storage 79 */ 80 @WorkerThread setSeenTimestamp(long seenTimestamp)81 public void setSeenTimestamp(long seenTimestamp) throws RcsMessageStoreException { 82 mRcsControllerCall.callWithNoReturn( 83 (iRcs, callingPackage) -> iRcs.setOutgoingDeliverySeenTimestamp( 84 mRcsOutgoingMessageId, mRecipientId, seenTimestamp, callingPackage)); 85 } 86 87 /** 88 * @return Returns the seen timestamp of the associated message by the associated 89 * participant. Timestamp is defined as milliseconds passed after midnight, January 1, 1970 UTC. 90 * Returns 0 if the {@link RcsOutgoingMessage} is not seen yet. 91 * @throws RcsMessageStoreException if the value could not be read from the storage 92 */ 93 @WorkerThread getSeenTimestamp()94 public long getSeenTimestamp() throws RcsMessageStoreException { 95 return mRcsControllerCall.call( 96 (iRcs, callingPackage) -> iRcs.getOutgoingDeliverySeenTimestamp( 97 mRcsOutgoingMessageId, mRecipientId, callingPackage)); 98 } 99 100 /** 101 * Sets the status of this outgoing delivery and persists into storage. 102 * 103 * @param status The status of the associated {@link RcsMessage}s delivery to the associated 104 * {@link RcsParticipant} 105 * @throws RcsMessageStoreException if the value could not be persisted into storage 106 */ 107 @WorkerThread setStatus(@csMessage.RcsMessageStatus int status)108 public void setStatus(@RcsMessage.RcsMessageStatus int status) throws RcsMessageStoreException { 109 mRcsControllerCall.callWithNoReturn( 110 (iRcs, callingPackage) -> iRcs.setOutgoingDeliveryStatus( 111 mRcsOutgoingMessageId, mRecipientId, status, callingPackage)); 112 } 113 114 /** 115 * @return Returns the status of this outgoing delivery. 116 * @throws RcsMessageStoreException if the value could not be read from the storage 117 */ 118 @WorkerThread getStatus()119 public @RcsMessage.RcsMessageStatus int getStatus() throws RcsMessageStoreException { 120 return mRcsControllerCall.call( 121 (iRcs, callingPackage) -> iRcs.getOutgoingDeliveryStatus(mRcsOutgoingMessageId, 122 mRecipientId, callingPackage)); 123 } 124 125 /** 126 * @return Returns the recipient associated with this delivery. 127 */ 128 @NonNull getRecipient()129 public RcsParticipant getRecipient() { 130 return new RcsParticipant(mRcsControllerCall, mRecipientId); 131 } 132 133 /** 134 * @return Returns the {@link RcsOutgoingMessage} associated with this delivery. 135 */ 136 @NonNull getMessage()137 public RcsOutgoingMessage getMessage() { 138 return new RcsOutgoingMessage(mRcsControllerCall, mRcsOutgoingMessageId); 139 } 140 } 141