/** * Called when a status report is received. This should correspond to a previously successful * SEND. * * @param ar AsyncResult passed into the message handler. ar.result should be a String * representing the status report PDU, as ASCII hex. */ private void handleStatusReport(AsyncResult ar) { String pduString = (String) ar.result; SmsMessage sms = SmsMessage.newFromCDS(pduString); if (sms != null) { int tpStatus = sms.getStatus(); int messageRef = sms.mMessageRef; for (int i = 0, count = deliveryPendingList.size(); i < count; i++) { SmsTracker tracker = deliveryPendingList.get(i); if (tracker.mMessageRef == messageRef) { // Found it. Remove from list and broadcast. if (tpStatus >= Sms.STATUS_FAILED || tpStatus < Sms.STATUS_PENDING) { deliveryPendingList.remove(i); // Update the message status (COMPLETE or FAILED) tracker.updateSentMessageStatus(mContext, tpStatus); } PendingIntent intent = tracker.mDeliveryIntent; Intent fillIn = new Intent(); fillIn.putExtra("pdu", IccUtils.hexStringToBytes(pduString)); fillIn.putExtra("format", getFormat()); try { intent.send(mContext, Activity.RESULT_OK, fillIn); } catch (CanceledException ex) { } // Only expect to see one tracker matching this messageref break; } } } mCi.acknowledgeLastIncomingGsmSms(true, Intents.RESULT_SMS_HANDLED, null); }
/** * 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. * @hide */ public static SmsMessage createFromEfRecord(int index, byte[] data) { try { SmsMessage msg = new SmsMessage(); msg.mIndexOnIcc = index; // First byte is status: RECEIVED_READ, RECEIVED_UNREAD, STORED_SENT, // or STORED_UNSENT // See TS 51.011 10.5.3 if ((data[0] & 1) == 0) { Rlog.w(LOG_TAG, "SMS parsing failed: Trying to parse a free record"); return null; } else { msg.mStatusOnIcc = data[0] & 0x07; } int size = data.length - 1; // Note: Data may include trailing FF's. That's OK; message // should still parse correctly. byte[] pdu = new byte[size]; System.arraycopy(data, 1, pdu, 0, size); msg.parsePdu(pdu); return msg; } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "SMS PDU parsing failed: ", ex); return null; } }
/** @hide */ public static SmsMessage newFromCDS(String line) { try { SmsMessage msg = new SmsMessage(); msg.parsePdu(IccUtils.hexStringToBytes(line)); return msg; } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "CDS SMS PDU parsing failed: ", ex); return null; } }
/** Create an SmsMessage from a raw PDU. */ public static SmsMessage createFromPdu(byte[] pdu) { try { SmsMessage msg = new SmsMessage(); msg.parsePdu(pdu); return msg; } catch (RuntimeException ex) { Rlog.e(LOG_TAG, "SMS PDU parsing failed: ", ex); return null; } catch (OutOfMemoryError e) { Rlog.e(LOG_TAG, "SMS PDU parsing failed with out of memory: ", e); return null; } }
public void testDataDownloadMessage5() { SmsMessage message = SmsMessage.createFromPdu(SMS_PP_MESSAGE_3_1_5); assertTrue("message is SMS-PP data download", message.isUsimDataDownload()); mCm.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_5, 0x90, 0x00, "9876543210"); mCm.expectAcknowledgeGsmSmsWithPdu(true, "00077ff6059876543210"); mHandler.startDataDownload(message); mCm.assertExpectedMethodsCalled(); mCm.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_5, 0x93, 0x00, ""); mCm.expectAcknowledgeGsmSms(false, 0xd4); // SIM toolkit busy mHandler.startDataDownload(message); mCm.assertExpectedMethodsCalled(); }
public void testDataDownloadMessage1() { SmsMessage message = SmsMessage.createFromPdu(SMS_PP_MESSAGE_3_1_1); assertTrue("message is SMS-PP data download", message.isUsimDataDownload()); mCm.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_1, 0x90, 0x00, ""); mCm.expectAcknowledgeGsmSms(true, 0); mHandler.startDataDownload(message); mCm.assertExpectedMethodsCalled(); mCm.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_1, 0x90, 0x00, "0123456789"); mCm.expectAcknowledgeGsmSmsWithPdu(true, "00077f16050123456789"); mHandler.startDataDownload(message); mCm.assertExpectedMethodsCalled(); mCm.expectSendEnvelope(SMS_PP_ENVELOPE_3_1_1, 0x62, 0xff, "0123456789abcdef"); mCm.expectAcknowledgeGsmSmsWithPdu(false, "00d5077f16080123456789abcdef"); mHandler.startDataDownload(message); mCm.assertExpectedMethodsCalled(); }
/** {@inheritDoc} */ @Override protected SmsTracker getNewSubmitPduTracker( String destinationAddress, String scAddress, String message, SmsHeader smsHeader, int encoding, PendingIntent sentIntent, PendingIntent deliveryIntent, boolean lastPart, int priority, boolean isExpectMore, int validityPeriod, AtomicInteger unsentPartCount, AtomicBoolean anyPartFailed, Uri messageUri, String fullMessageText) { SmsMessage.SubmitPdu pdu = SmsMessage.getSubmitPdu( scAddress, destinationAddress, message, deliveryIntent != null, SmsHeader.toByteArray(smsHeader), encoding, smsHeader.languageTable, smsHeader.languageShiftTable, validityPeriod); if (pdu != null) { HashMap map = getSmsTrackerMap(destinationAddress, scAddress, message, pdu); return getSmsTracker( map, sentIntent, deliveryIntent, getFormat(), unsentPartCount, anyPartFailed, messageUri, smsHeader, (!lastPart || isExpectMore), fullMessageText, true /*isText*/, validityPeriod); } else { Rlog.e(TAG, "GsmSMSDispatcher.sendNewSubmitPdu(): getSubmitPdu() returned null"); return null; } }
/** {@inheritDoc} */ @Override protected void sendText( String destAddr, String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, Uri messageUri, String callingPkg, int priority, boolean isExpectMore, int validityPeriod) { SmsMessage.SubmitPdu pdu = SmsMessage.getSubmitPdu(scAddr, destAddr, text, (deliveryIntent != null), validityPeriod); if (pdu != null) { HashMap map = getSmsTrackerMap(destAddr, scAddr, text, pdu); SmsTracker tracker = getSmsTracker( map, sentIntent, deliveryIntent, getFormat(), messageUri, isExpectMore, text /*fullMessageText*/, true /*isText*/, validityPeriod); String carrierPackage = getCarrierAppPackageName(); if (carrierPackage != null) { Rlog.d(TAG, "Found carrier package."); TextSmsSender smsSender = new TextSmsSender(tracker); smsSender.sendSmsByCarrierApp(carrierPackage, new SmsSenderCallback(smsSender)); } else { Rlog.v(TAG, "No carrier package."); sendRawPdu(tracker); } } else { Rlog.e(TAG, "GsmSMSDispatcher.sendText(): getSubmitPdu() returned null"); } }
/** {@inheritDoc} */ @Override protected void sendData( String destAddr, String scAddr, int destPort, int origPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { SmsMessage.SubmitPdu pdu = SmsMessage.getSubmitPdu( scAddr, destAddr, destPort, origPort, data, (deliveryIntent != null)); if (pdu != null) { HashMap map = getSmsTrackerMap(destAddr, scAddr, destPort, origPort, data, pdu); SmsTracker tracker = getSmsTracker( map, sentIntent, deliveryIntent, getFormat(), null /*messageUri*/, false /*isExpectMore*/, null /*fullMessageText*/, false /*isText*/); String carrierPackage = getCarrierAppPackageName(); if (carrierPackage != null) { Rlog.d(TAG, "Found carrier package."); DataSmsSender smsSender = new DataSmsSender(tracker); smsSender.sendSmsByCarrierApp(carrierPackage, new SmsSenderCallback(smsSender)); } else { Rlog.v(TAG, "No carrier package."); sendRawPdu(tracker); } } else { Rlog.e(TAG, "GsmSMSDispatcher.sendData(): getSubmitPdu() returned null"); } }
/** {@inheritDoc} */ @Override protected GsmAlphabet.TextEncodingDetails calculateLength( CharSequence messageBody, boolean use7bitOnly) { return SmsMessage.calculateLength(messageBody, use7bitOnly); }