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

Commit 6cdb680b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

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

parents 17b05cb6 32c6c8ff
Loading
Loading
Loading
Loading
+74 −14
Original line number Original line Diff line number Diff line
@@ -516,24 +516,27 @@ public abstract class SMSDispatcher extends Handler {


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

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