/** * 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; } }