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

Commit 2d562bdc authored by Mike Kasick's avatar Mike Kasick
Browse files

SMSDispatcher: Add option for sending pseudo-multipart SMSes

Serves as a workaround for devices that are otherwise unable to send
concatenated SMS messages on certain carrier networks, by providing the
option (enabled by the "telephony.sms.pseudo_multipart" property) to send
multipart messages as individual (not concatenated) messages.

For example, parts of Sprint's network hang on receipt of multipart SMSes
on devices (e.g., d2spr) that use the qcom SMSLock method in sending
multiple messages.  That is, the device waits for acknowledgment of the
first PDU before sending subsequent PDUs, while the network (incompatibly)
waits for subsequent PDUs before acknowledging the first.  While sending
the messages individually is suboptimal, it both works reliably and
matches stock ROM behavior.

Change-Id: I1da9d2320780d57b7b6881edb52fb9d7413332ec
parent 00bd78db
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ public abstract class SMSDispatcher extends Handler {
    protected boolean mSmsCapable = true;
    protected boolean mSmsReceiveDisabled;
    protected boolean mSmsSendDisabled;
    private   boolean mSmsPseudoMultipart;

    protected int mRemainingMessages = -1;

@@ -225,6 +226,7 @@ public abstract class SMSDispatcher extends Handler {
                                TelephonyProperties.PROPERTY_SMS_RECEIVE, mSmsCapable);
        mSmsSendDisabled = !SystemProperties.getBoolean(
                                TelephonyProperties.PROPERTY_SMS_SEND, mSmsCapable);
        mSmsPseudoMultipart = SystemProperties.getBoolean("telephony.sms.pseudo_multipart", false);
        Log.d(TAG, "SMSDispatcher: ctor mSmsCapable=" + mSmsCapable + " format=" + getFormat()
                + " mSmsReceiveDisabled=" + mSmsReceiveDisabled
                + " mSmsSendDisabled=" + mSmsSendDisabled);
@@ -846,6 +848,12 @@ public abstract class SMSDispatcher extends Handler {
    protected void sendMultipartText(String destAddr, String scAddr,
            ArrayList<String> parts, ArrayList<PendingIntent> sentIntents,
            ArrayList<PendingIntent> deliveryIntents) {
        if (mSmsPseudoMultipart) {
            // Send as individual messages as the combination of device and
            // carrier behavior may not process concatenated messages correctly.
            sendPseudoMultipartText(destAddr, scAddr, parts, sentIntents, deliveryIntents);
            return;
        }

        int refNumber = getNextConcatenatedRef() & 0x00FF;
        int msgCount = parts.size();
@@ -901,6 +909,55 @@ public abstract class SMSDispatcher extends Handler {

    }

    /**
     * Send a multi-part text based SMS as individual messages
     * (i.e., without User Data Headers).
     *
     * @param destAddr the address to send the message to
     * @param scAddr is the service center address or null to use
     *   the current default SMSC
     * @param parts an <code>ArrayList</code> of strings that, in order,
     *   comprise the original message
     * @param sentIntents if not null, an <code>ArrayList</code> of
     *   <code>PendingIntent</code>s (one for each message part) that is
     *   broadcast when the corresponding message part has been sent.
     *   The result code will be <code>Activity.RESULT_OK<code> for success,
     *   or one of these errors:
     *   <code>RESULT_ERROR_GENERIC_FAILURE</code>
     *   <code>RESULT_ERROR_RADIO_OFF</code>
     *   <code>RESULT_ERROR_NULL_PDU</code>
     *   <code>RESULT_ERROR_NO_SERVICE</code>.
     *  The per-application based SMS control checks sentIntent. If sentIntent
     *  is NULL the caller will be checked against all unknown applications,
     *  which cause smaller number of SMS to be sent in checking period.
     * @param deliveryIntents if not null, an <code>ArrayList</code> of
     *   <code>PendingIntent</code>s (one for each message part) that is
     *   broadcast when the corresponding message part has been delivered
     *   to the recipient.  The raw pdu of the status report is in the
     *   extended data ("pdu").
     */
    private void sendPseudoMultipartText(String destAddr, String scAddr,
            ArrayList<String> parts, ArrayList<PendingIntent> sentIntents,
            ArrayList<PendingIntent> deliveryIntents) {
        int msgCount = parts.size();

        mRemainingMessages = msgCount;

        for (int i = 0; i < msgCount; i++) {
            PendingIntent sentIntent = null;
            if (sentIntents != null && sentIntents.size() > i) {
                sentIntent = sentIntents.get(i);
            }

            PendingIntent deliveryIntent = null;
            if (deliveryIntents != null && deliveryIntents.size() > i) {
                deliveryIntent = deliveryIntents.get(i);
            }

            sendText(destAddr, scAddr, parts.get(i), sentIntent, deliveryIntent);
        }
    }

    /**
     * Create a new SubmitPdu and send it.
     */