Skip to content

Commit b7945ca

Browse files
author
Jake Hamby
committed
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
1 parent a1aebdf commit b7945ca

22 files changed

+1030
-1171
lines changed

core/java/android/provider/Telephony.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ public static final class Intents {
666666
public static SmsMessage[] getMessagesFromIntent(
667667
Intent intent) {
668668
Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
669+
String format = intent.getStringExtra("format");
669670
byte[][] pduObjs = new byte[messages.length][];
670671

671672
for (int i = 0; i < messages.length; i++) {
@@ -676,7 +677,7 @@ public static SmsMessage[] getMessagesFromIntent(
676677
SmsMessage[] msgs = new SmsMessage[pduCount];
677678
for (int i = 0; i < pduCount; i++) {
678679
pdus[i] = pduObjs[i];
679-
msgs[i] = SmsMessage.createFromPdu(pdus[i]);
680+
msgs[i] = SmsMessage.createFromPdu(pdus[i], format);
680681
}
681682
return msgs;
682683
}

telephony/java/android/telephony/SmsManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public boolean updateMessageOnIcc(int messageIndex, int newStatus, byte[] pdu) {
325325
*
326326
* {@hide}
327327
*/
328-
public ArrayList<SmsMessage> getAllMessagesFromIcc() {
328+
public static ArrayList<SmsMessage> getAllMessagesFromIcc() {
329329
List<SmsRawData> records = null;
330330

331331
try {
@@ -470,7 +470,7 @@ public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) {
470470
* <code>getAllMessagesFromIcc</code>
471471
* @return <code>ArrayList</code> of <code>SmsMessage</code> objects.
472472
*/
473-
private ArrayList<SmsMessage> createMessageListFromRawRecords(List<SmsRawData> records) {
473+
private static ArrayList<SmsMessage> createMessageListFromRawRecords(List<SmsRawData> records) {
474474
ArrayList<SmsMessage> messages = new ArrayList<SmsMessage>();
475475
if (records != null) {
476476
int count = records.size();

telephony/java/android/telephony/SmsMessage.java

Lines changed: 51 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
* A Short Message Service message.
3737
*/
3838
public class SmsMessage {
39-
private static final boolean LOCAL_DEBUG = true;
4039
private static final String LOG_TAG = "SMS";
4140

4241
/**
@@ -78,6 +77,18 @@ public enum MessageClass{
7877
*/
7978
public static final int MAX_USER_DATA_SEPTETS_WITH_HEADER = 153;
8079

80+
/**
81+
* Indicates a 3GPP format SMS message.
82+
* @hide pending API council approval
83+
*/
84+
public static final String FORMAT_3GPP = "3gpp";
85+
86+
/**
87+
* Indicates a 3GPP2 format SMS message.
88+
* @hide pending API council approval
89+
*/
90+
public static final String FORMAT_3GPP2 = "3gpp2";
91+
8192
/** Contains actual SmsMessage. Only public for debugging and for framework layer.
8293
*
8394
* @hide
@@ -106,30 +117,47 @@ protected SubmitPdu(SubmitPduBase spb) {
106117

107118
}
108119

109-
/**
110-
* Constructor
111-
*
112-
* @hide
113-
*/
114-
public SmsMessage() {
115-
this(getSmsFacility());
116-
}
117-
118120
private SmsMessage(SmsMessageBase smb) {
119121
mWrappedSmsMessage = smb;
120122
}
121123

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

129-
if (PHONE_TYPE_CDMA == activePhone) {
141+
/**
142+
* Create an SmsMessage from a raw PDU with the specified message format. The
143+
* message format is passed in the {@code SMS_RECEIVED_ACTION} as the {@code format}
144+
* String extra, and will be either "3gpp" for GSM/UMTS/LTE messages in 3GPP format
145+
* or "3gpp2" for CDMA/LTE messages in 3GPP2 format.
146+
*
147+
* @param pdu the message PDU from the SMS_RECEIVED_ACTION intent
148+
* @param format the format extra from the SMS_RECEIVED_ACTION intent
149+
* @hide pending API council approval
150+
*/
151+
public static SmsMessage createFromPdu(byte[] pdu, String format) {
152+
SmsMessageBase wrappedMessage;
153+
154+
if (FORMAT_3GPP2.equals(format)) {
130155
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromPdu(pdu);
131-
} else {
156+
} else if (FORMAT_3GPP.equals(format)) {
132157
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromPdu(pdu);
158+
} else {
159+
Log.e(LOG_TAG, "createFromPdu(): unsupported message format " + format);
160+
return null;
133161
}
134162

135163
return new SmsMessage(wrappedMessage);
@@ -144,57 +172,19 @@ public static SmsMessage createFromPdu(byte[] pdu) {
144172
*
145173
* {@hide}
146174
*/
147-
public static SmsMessage newFromCMT(String[] lines){
148-
SmsMessageBase wrappedMessage;
149-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
150-
151-
if (PHONE_TYPE_CDMA == activePhone) {
152-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMT(lines);
153-
} else {
154-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines);
155-
}
156-
157-
return new SmsMessage(wrappedMessage);
158-
}
159-
160-
/** @hide */
161-
protected static SmsMessage newFromCMTI(String line) {
162-
SmsMessageBase wrappedMessage;
163-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
164-
165-
if (PHONE_TYPE_CDMA == activePhone) {
166-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMTI(line);
167-
} else {
168-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMTI(line);
169-
}
170-
171-
return new SmsMessage(wrappedMessage);
172-
}
173-
174-
/** @hide */
175-
public static SmsMessage newFromCDS(String line) {
176-
SmsMessageBase wrappedMessage;
177-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
178-
179-
if (PHONE_TYPE_CDMA == activePhone) {
180-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCDS(line);
181-
} else {
182-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCDS(line);
183-
}
175+
public static SmsMessage newFromCMT(String[] lines) {
176+
// received SMS in 3GPP format
177+
SmsMessageBase wrappedMessage =
178+
com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines);
184179

185180
return new SmsMessage(wrappedMessage);
186181
}
187182

188183
/** @hide */
189184
public static SmsMessage newFromParcel(Parcel p) {
190-
SmsMessageBase wrappedMessage;
191-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
192-
193-
if (PHONE_TYPE_CDMA == activePhone) {
194-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p);
195-
} else {
196-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromParcel(p);
197-
}
185+
// received SMS in 3GPP2 format
186+
SmsMessageBase wrappedMessage =
187+
com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p);
198188

199189
return new SmsMessage(wrappedMessage);
200190
}
@@ -227,6 +217,9 @@ public static SmsMessage createFromEfRecord(int index, byte[] data) {
227217
/**
228218
* Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the
229219
* length in bytes (not hex chars) less the SMSC header
220+
*
221+
* FIXME: This method is only used by a CTS test case that isn't run on CDMA devices.
222+
* We should probably deprecate it and remove the obsolete test case.
230223
*/
231224
public static int getTPLayerLengthForPDU(String pdu) {
232225
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
@@ -373,34 +366,6 @@ public static int[] calculateLength(String messageBody, boolean use7bitOnly) {
373366
* otherwise useful apps.
374367
*/
375368

376-
/**
377-
* Get an SMS-SUBMIT PDU for a destination address and a message.
378-
* This method will not attempt to use any GSM national language 7 bit encodings.
379-
*
380-
* @param scAddress Service Centre address. Null means use default.
381-
* @return a <code>SubmitPdu</code> containing the encoded SC
382-
* address, if applicable, and the encoded message.
383-
* Returns null on encode error.
384-
* @hide
385-
*/
386-
public static SubmitPdu getSubmitPdu(String scAddress,
387-
String destinationAddress, String message,
388-
boolean statusReportRequested, byte[] header) {
389-
SubmitPduBase spb;
390-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
391-
392-
if (PHONE_TYPE_CDMA == activePhone) {
393-
spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress,
394-
destinationAddress, message, statusReportRequested,
395-
SmsHeader.fromByteArray(header));
396-
} else {
397-
spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
398-
destinationAddress, message, statusReportRequested, header);
399-
}
400-
401-
return new SubmitPdu(spb);
402-
}
403-
404369
/**
405370
* Get an SMS-SUBMIT PDU for a destination address and a message.
406371
* This method will not attempt to use any GSM national language 7 bit encodings.
@@ -602,15 +567,6 @@ public byte[] getUserData() {
602567
return mWrappedSmsMessage.getUserData();
603568
}
604569

605-
/**
606-
* Return the user data header (UDH).
607-
*
608-
* @hide
609-
*/
610-
public SmsHeader getUserDataHeader() {
611-
return mWrappedSmsMessage.getUserDataHeader();
612-
}
613-
614570
/**
615571
* Returns the raw PDU for the message.
616572
*
@@ -646,7 +602,6 @@ public byte[] getPdu() {
646602
* SmsManager.STATUS_ON_ICC_UNSENT
647603
*/
648604
public int getStatusOnIcc() {
649-
650605
return mWrappedSmsMessage.getStatusOnIcc();
651606
}
652607

@@ -666,7 +621,6 @@ public int getStatusOnIcc() {
666621
* SmsMessage was not created from a ICC SMS EF record.
667622
*/
668623
public int getIndexOnIcc() {
669-
670624
return mWrappedSmsMessage.getIndexOnIcc();
671625
}
672626

@@ -704,19 +658,4 @@ public boolean isStatusReportMessage() {
704658
public boolean isReplyPathPresent() {
705659
return mWrappedSmsMessage.isReplyPathPresent();
706660
}
707-
708-
/** This method returns the reference to a specific
709-
* SmsMessage object, which is used for accessing its static methods.
710-
* @return Specific SmsMessage.
711-
*
712-
* @hide
713-
*/
714-
private static final SmsMessageBase getSmsFacility(){
715-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
716-
if (PHONE_TYPE_CDMA == activePhone) {
717-
return new com.android.internal.telephony.cdma.SmsMessage();
718-
} else {
719-
return new com.android.internal.telephony.gsm.SmsMessage();
720-
}
721-
}
722661
}

telephony/java/android/telephony/gsm/SmsMessage.java

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -165,104 +165,6 @@ public static SmsMessage createFromPdu(byte[] pdu) {
165165
return new SmsMessage(wrappedMessage);
166166
}
167167

168-
/**
169-
* TS 27.005 3.4.1 lines[0] and lines[1] are the two lines read from the
170-
* +CMT unsolicited response (PDU mode, of course)
171-
* +CMT: [&lt;alpha>],<length><CR><LF><pdu>
172-
*
173-
* Only public for debugging and for RIL
174-
* @deprecated Use android.telephony.SmsMessage.
175-
* {@hide}
176-
*/
177-
@Deprecated
178-
public static SmsMessage newFromCMT(String[] lines){
179-
SmsMessageBase wrappedMessage;
180-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
181-
182-
if (PHONE_TYPE_CDMA == activePhone) {
183-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMT(lines);
184-
} else {
185-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines);
186-
}
187-
188-
return new SmsMessage(wrappedMessage);
189-
}
190-
191-
/** @deprecated Use android.telephony.SmsMessage.
192-
* @hide */
193-
@Deprecated
194-
protected static SmsMessage newFromCMTI(String line) {
195-
SmsMessageBase wrappedMessage;
196-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
197-
198-
if (PHONE_TYPE_CDMA == activePhone) {
199-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMTI(line);
200-
} else {
201-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMTI(line);
202-
}
203-
204-
return new SmsMessage(wrappedMessage);
205-
}
206-
207-
/** @deprecated Use android.telephony.SmsMessage.
208-
* @hide */
209-
@Deprecated
210-
public static SmsMessage newFromCDS(String line) {
211-
SmsMessageBase wrappedMessage;
212-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
213-
214-
if (PHONE_TYPE_CDMA == activePhone) {
215-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCDS(line);
216-
} else {
217-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCDS(line);
218-
}
219-
220-
return new SmsMessage(wrappedMessage);
221-
}
222-
223-
/** @deprecated Use android.telephony.SmsMessage.
224-
* @hide */
225-
@Deprecated
226-
public static SmsMessage newFromParcel(Parcel p) {
227-
SmsMessageBase wrappedMessage;
228-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
229-
230-
if (PHONE_TYPE_CDMA == activePhone) {
231-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p);
232-
} else {
233-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromParcel(p);
234-
}
235-
236-
return new SmsMessage(wrappedMessage);
237-
}
238-
239-
/**
240-
* Create an SmsMessage from an SMS EF record.
241-
*
242-
* @param index Index of SMS record. This should be index in ArrayList
243-
* returned by SmsManager.getAllMessagesFromSim + 1.
244-
* @param data Record data.
245-
* @return An SmsMessage representing the record.
246-
*
247-
* @deprecated Use android.telephony.SmsMessage.
248-
* @hide
249-
*/
250-
@Deprecated
251-
public static SmsMessage createFromEfRecord(int index, byte[] data) {
252-
SmsMessageBase wrappedMessage;
253-
int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
254-
255-
if (PHONE_TYPE_CDMA == activePhone) {
256-
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromEfRecord(
257-
index, data);
258-
} else {
259-
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromEfRecord(
260-
index, data);
261-
}
262-
263-
return new SmsMessage(wrappedMessage);
264-
}
265-
266168
/**
267169
* Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the
268170
* length in bytes (not hex chars) less the SMSC header

0 commit comments

Comments
 (0)