From 8c08a3f41975cb18ce017fd15aa230836ee047ea Mon Sep 17 00:00:00 2001 From: Taesu Lee Date: Wed, 30 Sep 2020 19:00:30 +0900 Subject: [PATCH] Mark messages as failed if SIM is inactive If a SIM is inactive, Mark messages corresponding to the SIM as failed instead of updating selfId as default selfId. The failed messages could be sent through the SIM manually if the SIM is re-activated. Test: Manual Change-Id: I1eee7c12aaedebe8aa3e0c41b4b057758a3b17a2 Signed-off-by: Taesu Lee --- .../action/ProcessPendingMessagesAction.java | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/com/android/messaging/datamodel/action/ProcessPendingMessagesAction.java b/src/com/android/messaging/datamodel/action/ProcessPendingMessagesAction.java index 1a3eb63..a897ce0 100644 --- a/src/com/android/messaging/datamodel/action/ProcessPendingMessagesAction.java +++ b/src/com/android/messaging/datamodel/action/ProcessPendingMessagesAction.java @@ -335,7 +335,7 @@ public class ProcessPendingMessagesAction extends Action implements Parcelable { selfId} ); - // Look for messages we cound send + // Look for messages we could send cursor = db.query(DatabaseHelper.MESSAGES_TABLE, MessageData.getProjection(), DatabaseHelper.MessageColumns.STATUS + " IN (?, ?) AND " @@ -354,43 +354,34 @@ public class ProcessPendingMessagesAction extends Action implements Parcelable { values.put(DatabaseHelper.MessageColumns.STATUS, MessageData.BUGLE_STATUS_OUTGOING_FAILED); + // Prior to L_MR1, isActiveSubscription is true always + boolean isActiveSubscription = true; + if (OsUtil.isAtLeastL_MR1()) { + final ParticipantData messageSelf = + BugleDatabaseOperations.getExistingParticipant(db, selfId); + if (messageSelf == null || !messageSelf.isActiveSubscription()) { + isActiveSubscription = false; + } + } while (cursor.moveToNext()) { final MessageData message = new MessageData(); message.bind(cursor); - if (message.getInResendWindow(now)) { - // If no messages currently sending - if (sendingCnt == 0) { - // Resend this message - toSendMessageId = message.getMessageId(); - // Before queuing the message for resending, check if the message's self is - // active. If not, switch back to the system's default subscription. - if (OsUtil.isAtLeastL_MR1()) { - final ParticipantData messageSelf = BugleDatabaseOperations - .getExistingParticipant(db, selfId); - if (messageSelf == null || !messageSelf.isActiveSubscription()) { - final ParticipantData defaultSelf = BugleDatabaseOperations - .getOrCreateSelf(db, PhoneUtils.getDefault() - .getDefaultSmsSubscriptionId()); - if (defaultSelf != null) { - message.bindSelfId(defaultSelf.getId()); - final ContentValues selfValues = new ContentValues(); - selfValues.put(MessageColumns.SELF_PARTICIPANT_ID, - defaultSelf.getId()); - BugleDatabaseOperations.updateMessageRow(db, - message.getMessageId(), selfValues); - MessagingContentProvider.notifyMessagesChanged( - message.getConversationId()); - } - } - } - } - break; - } else { + + // Mark this message as failed if the message's self is inactive or the message is + // outside of resend window + if (!isActiveSubscription || !message.getInResendWindow(now)) { failedCnt++; // Mark message as failed BugleDatabaseOperations.updateMessageRow(db, message.getMessageId(), values); MessagingContentProvider.notifyMessagesChanged(message.getConversationId()); + } else { + // If no messages currently sending + if (sendingCnt == 0) { + // Send this message + toSendMessageId = message.getMessageId(); + } + break; } } db.setTransactionSuccessful();