2525import android .os .SystemProperties ;
2626import android .provider .Telephony .Sms ;
2727import android .provider .Telephony .Sms .Intents ;
28- import android .telephony .ServiceState ;
28+ import android .telephony .PhoneNumberUtils ;
2929import android .telephony .SmsCbMessage ;
30+ import android .telephony .SmsManager ;
3031import android .telephony .gsm .GsmCellLocation ;
3132import android .util .Log ;
3233
4142import com .android .internal .telephony .SmsUsageMonitor ;
4243import com .android .internal .telephony .TelephonyProperties ;
4344
44- import java .util .ArrayList ;
4545import java .util .HashMap ;
4646import java .util .Iterator ;
4747
@@ -56,9 +56,16 @@ public final class GsmSMSDispatcher extends SMSDispatcher {
5656 /** New broadcast SMS */
5757 private static final int EVENT_NEW_BROADCAST_SMS = 101 ;
5858
59+ /** Result of writing SM to UICC (when SMS-PP service is not available). */
60+ private static final int EVENT_WRITE_SMS_COMPLETE = 102 ;
61+
62+ /** Handler for SMS-PP data download messages to UICC. */
63+ private final UsimDataDownloadHandler mDataDownloadHandler ;
64+
5965 public GsmSMSDispatcher (PhoneBase phone , SmsStorageMonitor storageMonitor ,
6066 SmsUsageMonitor usageMonitor ) {
6167 super (phone , storageMonitor , usageMonitor );
68+ mDataDownloadHandler = new UsimDataDownloadHandler (mCm );
6269 mCm .setOnNewGsmSms (this , EVENT_NEW_SMS , null );
6370 mCm .setOnSmsStatus (this , EVENT_NEW_SMS_STATUS_REPORT , null );
6471 mCm .setOnNewGsmBroadcastSms (this , EVENT_NEW_BROADCAST_SMS , null );
@@ -93,6 +100,18 @@ public void handleMessage(Message msg) {
93100 handleBroadcastSms ((AsyncResult )msg .obj );
94101 break ;
95102
103+ case EVENT_WRITE_SMS_COMPLETE :
104+ AsyncResult ar = (AsyncResult ) msg .obj ;
105+ if (ar .exception == null ) {
106+ Log .d (TAG , "Successfully wrote SMS-PP message to UICC" );
107+ mCm .acknowledgeLastIncomingGsmSms (true , 0 , null );
108+ } else {
109+ Log .d (TAG , "Failed to write SMS-PP message to UICC" , ar .exception );
110+ mCm .acknowledgeLastIncomingGsmSms (false ,
111+ CommandsInterface .GSM_SMS_FAIL_CAUSE_UNSPECIFIED_ERROR , null );
112+ }
113+ break ;
114+
96115 default :
97116 super .handleMessage (msg );
98117 }
@@ -154,6 +173,29 @@ public int dispatchMessage(SmsMessageBase smsb) {
154173 return Intents .RESULT_SMS_HANDLED ;
155174 }
156175
176+ // Send SMS-PP data download messages to UICC. See 3GPP TS 31.111 section 7.1.1.
177+ if (sms .isUsimDataDownload ()) {
178+ UsimServiceTable ust = mPhone .getUsimServiceTable ();
179+ // If we receive an SMS-PP message before the UsimServiceTable has been loaded,
180+ // assume that the data download service is not present. This is very unlikely to
181+ // happen because the IMS connection will not be established until after the ISIM
182+ // records have been loaded, after the USIM service table has been loaded.
183+ if (ust != null && ust .isAvailable (
184+ UsimServiceTable .UsimService .DATA_DL_VIA_SMS_PP )) {
185+ Log .d (TAG , "Received SMS-PP data download, sending to UICC." );
186+ return mDataDownloadHandler .startDataDownload (sms );
187+ } else {
188+ Log .d (TAG , "DATA_DL_VIA_SMS_PP service not available, storing message to UICC." );
189+ String smsc = IccUtils .bytesToHexString (
190+ PhoneNumberUtils .networkPortionToCalledPartyBCDWithLength (
191+ sms .getServiceCenterAddress ()));
192+ mCm .writeSmsToSim (SmsManager .STATUS_ON_ICC_UNREAD , smsc ,
193+ IccUtils .bytesToHexString (sms .getPdu ()),
194+ obtainMessage (EVENT_WRITE_SMS_COMPLETE ));
195+ return Activity .RESULT_OK ; // acknowledge after response from write to USIM
196+ }
197+ }
198+
157199 if (mSmsReceiveDisabled ) {
158200 // Device doesn't support SMS service,
159201 Log .d (TAG , "Received short message on device which doesn't support "
0 commit comments