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

Commit a9b0bd66 authored by David Ferguson's avatar David Ferguson Committed by Gerrit Code Review
Browse files

SamsungQualcomm RILs: throttle multiple outstanding SEND_SMS requests

  * Our radio generates a GenericFailure if a SEND_SMS request is sent
    before the previous SEND_SMS has completed.
  * Add a variable to track whether a SEND_SMS is in progress.
  * In sendSMS(), wait for the previous SEND_SMS to finish. Block for
    up to 30 seconds. If this passes with no response, blindly send the
    next SEND_SMS and let normal error handling take over.
  * In responseSMS(), notify that the SEND_SMS is complete.
  * Same thing above for the CDMA RIL
  * Algorithm credit Mike Kasick

Change-Id: I7beadc809a9e35fa100e5823bdfc3e9879ab3233
parent 0c9aa577
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Message;
import android.os.Parcel;
import android.telephony.SmsMessage;
import android.os.SystemProperties;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;

@@ -50,12 +51,42 @@ import java.util.Collections;
 */
public class SamsungCDMAQualcommRIL extends QualcommSharedRIL implements
CommandsInterface {
    private Object mSMSLock = new Object();
    private boolean mIsSendingSMS = false;
    public static final long SEND_SMS_TIMEOUT_IN_MS = 30000;

    public SamsungCDMAQualcommRIL(Context context, int networkMode,
            int cdmaSubscription) {
        super(context, networkMode, cdmaSubscription);
    }

    @Override
    public void
    sendCdmaSms(byte[] pdu, Message result) {
        // Do not send a new SMS until the response for the previous SMS has been received
        //   * for the error case where the response never comes back, time out after
        //     30 seconds and just try the next CDMA_SEND_SMS
        synchronized (mSMSLock) {
            long timeoutTime  = SystemClock.elapsedRealtime() + SEND_SMS_TIMEOUT_IN_MS;
            long waitTimeLeft = SEND_SMS_TIMEOUT_IN_MS;
            while (mIsSendingSMS && (waitTimeLeft > 0)) {
                Log.d(LOG_TAG, "sendCdmaSms() waiting for response of previous CDMA_SEND_SMS");
                try {
                    mSMSLock.wait(waitTimeLeft);
                } catch (InterruptedException ex) {
                    // ignore the interrupt and rewait for the remainder
                }
                waitTimeLeft = timeoutTime - SystemClock.elapsedRealtime();
            }
            if (waitTimeLeft <= 0) {
                Log.e(LOG_TAG, "sendCdmaSms() timed out waiting for response of previous CDMA_SEND_SMS");
            }
            mIsSendingSMS = true;
        }

        super.sendCdmaSms(pdu, result);
    }

    @Override
    protected Object responseIccCardStatus(Parcel p) {
        IccCardApplication ca;
@@ -266,4 +297,16 @@ CommandsInterface {

        super.notifyRegistrantsCdmaInfoRec(infoRec);
    }

    @Override
    protected Object
    responseSMS(Parcel p) {
        // Notify that sendSMS() can send the next SMS
        synchronized (mSMSLock) {
            mIsSendingSMS = false;
            mSMSLock.notify();
        }

        return super.responseSMS(p);
    }
}
+43 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context;
import android.os.Message;
import android.os.Parcel;
import android.os.SystemProperties;
import android.os.SystemClock;
import android.os.AsyncResult;
import android.text.TextUtils;
import android.util.Log;
@@ -40,6 +41,9 @@ public class SamsungQualcommUiccRIL extends QualcommSharedRIL implements Command

    public static final int INVALID_SNR = 0x7fffffff;
    private boolean mSignalbarCount = SystemProperties.getBoolean("ro.telephony.sends_barcount", false);
    private Object mSMSLock = new Object();
    private boolean mIsSendingSMS = false;
    public static final long SEND_SMS_TIMEOUT_IN_MS = 30000;

    public SamsungQualcommUiccRIL(Context context, int networkMode, int cdmaSubscription) {
        super(context, networkMode, cdmaSubscription);
@@ -110,6 +114,33 @@ public class SamsungQualcommUiccRIL extends QualcommSharedRIL implements Command
        }
    }

    @Override
    public void
    sendSMS (String smscPDU, String pdu, Message result) {
        // Do not send a new SMS until the response for the previous SMS has been received
        //   * for the error case where the response never comes back, time out after
        //     30 seconds and just try the next SEND_SMS
        synchronized (mSMSLock) {
            long timeoutTime  = SystemClock.elapsedRealtime() + SEND_SMS_TIMEOUT_IN_MS;
            long waitTimeLeft = SEND_SMS_TIMEOUT_IN_MS;
            while (mIsSendingSMS && (waitTimeLeft > 0)) {
                Log.d(LOG_TAG, "sendSMS() waiting for response of previous SEND_SMS");
                try {
                    mSMSLock.wait(waitTimeLeft);
                } catch (InterruptedException ex) {
                    // ignore the interrupt and rewait for the remainder
                }
                waitTimeLeft = timeoutTime - SystemClock.elapsedRealtime();
            }
            if (waitTimeLeft <= 0) {
                Log.e(LOG_TAG, "sendSms() timed out waiting for response of previous CDMA_SEND_SMS");
            }
            mIsSendingSMS = true;
        }

        super.sendSMS(smscPDU, pdu, result);
    }

    @Override
    public void
    setNetworkSelectionModeManual(String operatorNumeric, Message response) {
@@ -306,4 +337,16 @@ public class SamsungQualcommUiccRIL extends QualcommSharedRIL implements Command
            " lteRssnr=" + response[10] + " lteCqi=" + response[11]);
        return response;
    }

    @Override
    protected Object
    responseSMS(Parcel p) {
        // Notify that sendSMS() can send the next SMS
        synchronized (mSMSLock) {
            mIsSendingSMS = false;
            mSMSLock.notify();
        }

        return super.responseSMS(p);
    }
}