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

Commit b7945cae authored by Jake Hamby's avatar Jake Hamby
Browse files

Enable support for multiple SMSDispatchers in CDMALTEPhone.

Refactor framework to support multiple SMSDispatcher objects on
dual-mode devices that require support for both 3GPP and 3GPP2
format SMS messages. Each dispatcher registers to receive events for
the appropriate message format.

Note: All applications which handle incoming SMS messages by processing the
SMS_RECEIVED_ACTION broadcast intent MUST pass the "format" extra from the intent
into the new createPdu() method in android.telephony.SmsMessage that takes an
extra format parameter. This is required in order to correctly decode the PDU on
devices which require support for both 3GPP and 3GPP2 formats at the same time,
such as CDMA/LTE devices and GSM/CDMA world phones.

 - moved code to manage device storage events from SMSDispatcher to a
   new class, SmsStorageMonitor, which is shared among all dispatchers.

 - moved code to monitor per-application outgoing SMS usage from
   SMSDispatcher.SmsCounter to a new class, SmsUsageMonitor, which
   is shared among all dispatchers.

 - fixed a bug that prevented CDMALTEPhone from setting the MCC/MNC
   operator numeric value in the telephony provider from the UICC,
   as GSMPhone does, when the SIM records have loaded.

Change-Id: I2789ac07b6ca2948138bca7f75481f9b31514f20
parent a1aebdf7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -666,6 +666,7 @@ public final class Telephony {
            public static SmsMessage[] getMessagesFromIntent(
                    Intent intent) {
                Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
                String format = intent.getStringExtra("format");
                byte[][] pduObjs = new byte[messages.length][];

                for (int i = 0; i < messages.length; i++) {
@@ -676,7 +677,7 @@ public final class Telephony {
                SmsMessage[] msgs = new SmsMessage[pduCount];
                for (int i = 0; i < pduCount; i++) {
                    pdus[i] = pduObjs[i];
                    msgs[i] = SmsMessage.createFromPdu(pdus[i]);
                    msgs[i] = SmsMessage.createFromPdu(pdus[i], format);
                }
                return msgs;
            }
+2 −2
Original line number Diff line number Diff line
@@ -325,7 +325,7 @@ public final class SmsManager {
     *
     * {@hide}
     */
    public ArrayList<SmsMessage> getAllMessagesFromIcc() {
    public static ArrayList<SmsMessage> getAllMessagesFromIcc() {
        List<SmsRawData> records = null;

        try {
@@ -470,7 +470,7 @@ public final class SmsManager {
     *   <code>getAllMessagesFromIcc</code>
     * @return <code>ArrayList</code> of <code>SmsMessage</code> objects.
     */
    private ArrayList<SmsMessage> createMessageListFromRawRecords(List<SmsRawData> records) {
    private static ArrayList<SmsMessage> createMessageListFromRawRecords(List<SmsRawData> records) {
        ArrayList<SmsMessage> messages = new ArrayList<SmsMessage>();
        if (records != null) {
            int count = records.size();
+51 −112
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;
 * A Short Message Service message.
 */
public class SmsMessage {
    private static final boolean LOCAL_DEBUG = true;
    private static final String LOG_TAG = "SMS";

    /**
@@ -78,6 +77,18 @@ public class SmsMessage {
     */
    public static final int MAX_USER_DATA_SEPTETS_WITH_HEADER = 153;

    /**
     * Indicates a 3GPP format SMS message.
     * @hide pending API council approval
     */
    public static final String FORMAT_3GPP = "3gpp";

    /**
     * Indicates a 3GPP2 format SMS message.
     * @hide pending API council approval
     */
    public static final String FORMAT_3GPP2 = "3gpp2";

    /** Contains actual SmsMessage. Only public for debugging and for framework layer.
     *
     * @hide
@@ -106,30 +117,47 @@ public class SmsMessage {

    }

    /**
     * Constructor
     *
     * @hide
     */
    public SmsMessage() {
        this(getSmsFacility());
    }

    private SmsMessage(SmsMessageBase smb) {
        mWrappedSmsMessage = smb;
    }

    /**
     * Create an SmsMessage from a raw PDU.
     *
     * <p><b>This method will soon be deprecated</b> and all applications which handle
     * incoming SMS messages by processing the {@code SMS_RECEIVED_ACTION} broadcast
     * intent <b>must</b> now pass the new {@code format} String extra from the intent
     * into the new method {@code createFromPdu(byte[], String)} which takes an
     * extra format parameter. This is required in order to correctly decode the PDU on
     * devices that require support for both 3GPP and 3GPP2 formats at the same time,
     * such as dual-mode GSM/CDMA and CDMA/LTE phones.
     */
    public static SmsMessage createFromPdu(byte[] pdu) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
        String format = (PHONE_TYPE_CDMA == activePhone) ? FORMAT_3GPP2 : FORMAT_3GPP;
        return createFromPdu(pdu, format);
    }

        if (PHONE_TYPE_CDMA == activePhone) {
    /**
     * Create an SmsMessage from a raw PDU with the specified message format. The
     * message format is passed in the {@code SMS_RECEIVED_ACTION} as the {@code format}
     * String extra, and will be either "3gpp" for GSM/UMTS/LTE messages in 3GPP format
     * or "3gpp2" for CDMA/LTE messages in 3GPP2 format.
     *
     * @param pdu the message PDU from the SMS_RECEIVED_ACTION intent
     * @param format the format extra from the SMS_RECEIVED_ACTION intent
     * @hide pending API council approval
     */
    public static SmsMessage createFromPdu(byte[] pdu, String format) {
        SmsMessageBase wrappedMessage;

        if (FORMAT_3GPP2.equals(format)) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromPdu(pdu);
        } else {
        } else if (FORMAT_3GPP.equals(format)) {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromPdu(pdu);
        } else {
            Log.e(LOG_TAG, "createFromPdu(): unsupported message format " + format);
            return null;
        }

        return new SmsMessage(wrappedMessage);
@@ -145,56 +173,18 @@ public class SmsMessage {
     * {@hide}
     */
    public static SmsMessage newFromCMT(String[] lines) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMT(lines);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines);
        }

        return new SmsMessage(wrappedMessage);
    }

    /** @hide */
    protected static SmsMessage newFromCMTI(String line) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMTI(line);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMTI(line);
        }

        return new SmsMessage(wrappedMessage);
    }

    /** @hide */
    public static SmsMessage newFromCDS(String line) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCDS(line);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCDS(line);
        }
        // received SMS in 3GPP format
        SmsMessageBase wrappedMessage =
                com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines);

        return new SmsMessage(wrappedMessage);
    }

    /** @hide */
    public static SmsMessage newFromParcel(Parcel p) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromParcel(p);
        }
        // received SMS in 3GPP2 format
        SmsMessageBase wrappedMessage =
                com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p);

        return new SmsMessage(wrappedMessage);
    }
@@ -227,6 +217,9 @@ public class SmsMessage {
    /**
     * Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the
     * length in bytes (not hex chars) less the SMSC header
     *
     * FIXME: This method is only used by a CTS test case that isn't run on CDMA devices.
     * We should probably deprecate it and remove the obsolete test case.
     */
    public static int getTPLayerLengthForPDU(String pdu) {
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
@@ -373,34 +366,6 @@ public class SmsMessage {
     * otherwise useful apps.
     */

    /**
     * Get an SMS-SUBMIT PDU for a destination address and a message.
     * This method will not attempt to use any GSM national language 7 bit encodings.
     *
     * @param scAddress Service Centre address.  Null means use default.
     * @return a <code>SubmitPdu</code> containing the encoded SC
     *         address, if applicable, and the encoded message.
     *         Returns null on encode error.
     * @hide
     */
    public static SubmitPdu getSubmitPdu(String scAddress,
            String destinationAddress, String message,
            boolean statusReportRequested, byte[] header) {
        SubmitPduBase spb;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress,
                    destinationAddress, message, statusReportRequested,
                    SmsHeader.fromByteArray(header));
        } else {
            spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
                    destinationAddress, message, statusReportRequested, header);
        }

        return new SubmitPdu(spb);
    }

    /**
     * Get an SMS-SUBMIT PDU for a destination address and a message.
     * This method will not attempt to use any GSM national language 7 bit encodings.
@@ -602,15 +567,6 @@ public class SmsMessage {
        return mWrappedSmsMessage.getUserData();
    }

    /**
     * Return the user data header (UDH).
     *
     * @hide
     */
    public SmsHeader getUserDataHeader() {
        return mWrappedSmsMessage.getUserDataHeader();
    }

    /**
     * Returns the raw PDU for the message.
     *
@@ -646,7 +602,6 @@ public class SmsMessage {
     *         SmsManager.STATUS_ON_ICC_UNSENT
     */
    public int getStatusOnIcc() {

        return mWrappedSmsMessage.getStatusOnIcc();
    }

@@ -666,7 +621,6 @@ public class SmsMessage {
     *         SmsMessage was not created from a ICC SMS EF record.
     */
    public int getIndexOnIcc() {

        return mWrappedSmsMessage.getIndexOnIcc();
    }

@@ -704,19 +658,4 @@ public class SmsMessage {
    public boolean isReplyPathPresent() {
        return mWrappedSmsMessage.isReplyPathPresent();
    }

    /** This method returns the reference to a specific
     *  SmsMessage object, which is used for accessing its static methods.
     * @return Specific SmsMessage.
     *
     * @hide
     */
    private static final SmsMessageBase getSmsFacility(){
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
        if (PHONE_TYPE_CDMA == activePhone) {
            return new com.android.internal.telephony.cdma.SmsMessage();
        } else {
            return new com.android.internal.telephony.gsm.SmsMessage();
        }
    }
}
+0 −98
Original line number Diff line number Diff line
@@ -165,104 +165,6 @@ public class SmsMessage {
        return new SmsMessage(wrappedMessage);
    }

    /**
     * TS 27.005 3.4.1 lines[0] and lines[1] are the two lines read from the
     * +CMT unsolicited response (PDU mode, of course)
     *  +CMT: [&lt;alpha>],<length><CR><LF><pdu>
     *
     * Only public for debugging and for RIL
     * @deprecated Use android.telephony.SmsMessage.
     * {@hide}
     */
    @Deprecated
    public static SmsMessage newFromCMT(String[] lines){
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMT(lines);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines);
        }

        return new SmsMessage(wrappedMessage);
    }

    /** @deprecated Use android.telephony.SmsMessage.
     *  @hide */
    @Deprecated
    protected static SmsMessage newFromCMTI(String line) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMTI(line);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMTI(line);
        }

        return new SmsMessage(wrappedMessage);
    }

    /** @deprecated Use android.telephony.SmsMessage.
     *  @hide */
    @Deprecated
    public static SmsMessage newFromCDS(String line) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCDS(line);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCDS(line);
        }

        return new SmsMessage(wrappedMessage);
    }

    /** @deprecated Use android.telephony.SmsMessage.
     *  @hide */
    @Deprecated
    public static SmsMessage newFromParcel(Parcel p) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromParcel(p);
        }

        return new SmsMessage(wrappedMessage);
    }

    /**
     * Create an SmsMessage from an SMS EF record.
     *
     * @param index Index of SMS record. This should be index in ArrayList
     *              returned by SmsManager.getAllMessagesFromSim + 1.
     * @param data Record data.
     * @return An SmsMessage representing the record.
     *
     * @deprecated Use android.telephony.SmsMessage.
     * @hide
     */
    @Deprecated
    public static SmsMessage createFromEfRecord(int index, byte[] data) {
        SmsMessageBase wrappedMessage;
        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();

        if (PHONE_TYPE_CDMA == activePhone) {
            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromEfRecord(
                    index, data);
        } else {
            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromEfRecord(
                    index, data);
        }

        return new SmsMessage(wrappedMessage);
    }

    /**
     * Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the
     * length in bytes (not hex chars) less the SMSC header
+14 −5
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ public abstract class BaseCommands implements CommandsInterface {
    protected RegistrantList mRilConnectedRegistrants = new RegistrantList();
    protected RegistrantList mIccRefreshRegistrants = new RegistrantList();

    protected Registrant mSMSRegistrant;
    protected Registrant mGsmSmsRegistrant;
    protected Registrant mCdmaSmsRegistrant;
    protected Registrant mNITZTimeRegistrant;
    protected Registrant mSignalStrengthRegistrant;
    protected Registrant mUSSDRegistrant;
@@ -358,12 +359,20 @@ public abstract class BaseCommands implements CommandsInterface {
        mIccStatusChangedRegistrants.remove(h);
    }

    public void setOnNewSMS(Handler h, int what, Object obj) {
        mSMSRegistrant = new Registrant (h, what, obj);
    public void setOnNewGsmSms(Handler h, int what, Object obj) {
        mGsmSmsRegistrant = new Registrant (h, what, obj);
    }

    public void unSetOnNewSMS(Handler h) {
        mSMSRegistrant.clear();
    public void unSetOnNewGsmSms(Handler h) {
        mGsmSmsRegistrant.clear();
    }

    public void setOnNewCdmaSms(Handler h, int what, Object obj) {
        mCdmaSmsRegistrant = new Registrant (h, what, obj);
    }

    public void unSetOnNewCdmaSms(Handler h) {
        mCdmaSmsRegistrant.clear();
    }

    public void setOnNewGsmBroadcastSms(Handler h, int what, Object obj) {
Loading