Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 83215fa0 authored by Amit Mahajan's avatar Amit Mahajan Committed by Android (Google) Code Review
Browse files

Merge "Keep order for multi-part SMS when retry from CarrierMessagingService"...

Merge "Keep order for multi-part SMS when retry from CarrierMessagingService" into rvc-dev-plus-aosp
parents ca8a242f c1e103aa
Loading
Loading
Loading
Loading
+74 −16
Original line number Diff line number Diff line
@@ -518,28 +518,28 @@ public abstract class SMSDispatcher extends Handler {

        switch (result) {
            case CarrierMessagingService.SEND_STATUS_OK:
                Rlog.d(TAG, "Sending SMS by IP succeeded."
                        + " id: " + tracker.mMessageId);
                Rlog.d(TAG, "processSendSmsResponse: Sending SMS by CarrierMessagingService "
                        + "succeeded. id: " + tracker.mMessageId);
                sendMessage(obtainMessage(EVENT_SEND_SMS_COMPLETE,
                                          new AsyncResult(tracker,
                                                          smsResponse,
                                                          null /* exception*/)));
                break;
            case CarrierMessagingService.SEND_STATUS_ERROR:
                Rlog.d(TAG, "Sending SMS by IP failed."
                Rlog.d(TAG, "processSendSmsResponse: Sending SMS by CarrierMessagingService failed."
                        + " id: " + tracker.mMessageId);
                sendMessage(obtainMessage(EVENT_SEND_SMS_COMPLETE,
                        new AsyncResult(tracker, smsResponse,
                                new CommandException(CommandException.Error.GENERIC_FAILURE))));
                break;
            case CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK:
                Rlog.d(TAG, "Sending SMS by IP failed. Retry on carrier network."
                        + " id: " + tracker.mMessageId);
                Rlog.d(TAG, "processSendSmsResponse: Sending SMS by CarrierMessagingService failed."
                        + " Retry on carrier network. id: " + tracker.mMessageId);
                sendSubmitPdu(tracker);
                break;
            default:
                Rlog.d(TAG, "Unknown result " + result + " Retry on carrier network."
                        + " id: " + tracker.mMessageId);
                Rlog.d(TAG, "processSendSmsResponse: Unknown result " + result + " Retry on carrier"
                        + " network. id: " + tracker.mMessageId);
                sendSubmitPdu(tracker);
        }
    }
@@ -566,7 +566,7 @@ public abstract class SMSDispatcher extends Handler {
                Rlog.e(TAG, "bindService() for carrier messaging service failed");
                mSenderCallback.onSendMultipartSmsComplete(
                        CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK,
                        null /* smsResponse */);
                        null /* messageRefs */);
            } else {
                Rlog.d(TAG, "bindService() for carrier messaging service succeeded");
            }
@@ -595,7 +595,7 @@ public abstract class SMSDispatcher extends Handler {
                Rlog.e(TAG, "Exception sending the SMS: " + e);
                mSenderCallback.onSendMultipartSmsComplete(
                        CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK,
                        null /* smsResponse */);
                        null /* messageRefs */);
            }
        }
    }
@@ -631,13 +631,7 @@ public abstract class SMSDispatcher extends Handler {
            checkCallerIsPhoneOrCarrierApp();
            final long identity = Binder.clearCallingIdentity();
            try {
                for (int i = 0; i < mSmsSender.mTrackers.length; i++) {
                    int messageRef = 0;
                    if (messageRefs != null && messageRefs.length > i) {
                        messageRef = messageRefs[i];
                    }
                    processSendSmsResponse(mSmsSender.mTrackers[i], result, messageRef);
                }
                processSendMultipartSmsResponse(mSmsSender.mTrackers, result, messageRefs);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
@@ -659,6 +653,70 @@ public abstract class SMSDispatcher extends Handler {
        }
    }

    private void processSendMultipartSmsResponse(
            SmsTracker[] trackers, int result, int[] messageRefs) {
        if (trackers == null) {
            Rlog.e(TAG, "processSendMultipartSmsResponse: null trackers");
            return;
        }

        switch (result) {
            case CarrierMessagingService.SEND_STATUS_OK:
                Rlog.d(TAG, "processSendMultipartSmsResponse: Sending SMS by "
                        + "CarrierMessagingService succeeded. id: " + trackers[0].mMessageId);
                // Sending a multi-part SMS by CarrierMessagingService successfully completed.
                // Send EVENT_SEND_SMS_COMPLETE for all the parts one by one.
                for (int i = 0; i < trackers.length; i++) {
                    int messageRef = 0;
                    if (messageRefs != null && messageRefs.length > i) {
                        messageRef = messageRefs[i];
                    }
                    sendMessage(
                            obtainMessage(
                                    EVENT_SEND_SMS_COMPLETE,
                                    new AsyncResult(
                                            trackers[i],
                                            new SmsResponse(
                                                    messageRef, null /* ackPdu */, NO_ERROR_CODE),
                                            null /* exception */)));
                }
                break;
            case CarrierMessagingService.SEND_STATUS_ERROR:
                Rlog.d(TAG, "processSendMultipartSmsResponse: Sending SMS by "
                        + "CarrierMessagingService failed. id: " + trackers[0].mMessageId);
                // Sending a multi-part SMS by CarrierMessagingService failed.
                // Send EVENT_SEND_SMS_COMPLETE with GENERIC_FAILURE for all the parts one by one.
                for (int i = 0; i < trackers.length; i++) {
                    int messageRef = 0;
                    if (messageRefs != null && messageRefs.length > i) {
                        messageRef = messageRefs[i];
                    }
                    sendMessage(
                            obtainMessage(
                                    EVENT_SEND_SMS_COMPLETE,
                                    new AsyncResult(
                                            trackers[i],
                                            new SmsResponse(
                                                    messageRef, null /* ackPdu */, NO_ERROR_CODE),
                                            new CommandException(
                                                    CommandException.Error.GENERIC_FAILURE))));
                }
                break;
            case CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK:
                Rlog.d(TAG, "processSendMultipartSmsResponse: Sending SMS by "
                        + "CarrierMessagingService failed. Retry on carrier network. id: "
                        + trackers[0].mMessageId);
                // All the parts for a multi-part SMS are handled together for retry. It helps to
                // check user confirmation once also if needed.
                sendSubmitPdu(trackers);
                break;
            default:
                Rlog.d(TAG, "processSendMultipartSmsResponse: Unknown result " + result
                        + ". Retry on carrier network. id: " + trackers[0].mMessageId);
                sendSubmitPdu(trackers);
        }
    }

    /** Send a single SMS PDU. */
    @UnsupportedAppUsage
    private void sendSubmitPdu(SmsTracker tracker) {