FileDocCategorySizeDatePackage
SimSmsInterfaceManager.javaAPI DocAndroid 1.5 API10941Wed May 06 22:42:02 BST 2009com.android.internal.telephony.gsm

SimSmsInterfaceManager

public class SimSmsInterfaceManager extends ISms.Stub
SimSmsInterfaceManager to provide an inter-process communication to access Sms in Sim.

Fields Summary
static final String
LOG_TAG
static final boolean
DBG
private GSMPhone
mPhone
private final Object
mLock
private boolean
mSuccess
private List
mSms
private static final int
EVENT_LOAD_DONE
private static final int
EVENT_UPDATE_DONE
android.os.Handler
mHandler
Constructors Summary
public SimSmsInterfaceManager(GSMPhone phone)


       
        this.mPhone = phone;
        ServiceManager.addService("isms", this);
    
Methods Summary
private java.util.ArrayListbuildValidRawData(java.util.ArrayList messages)
create SmsRawData lists from all sms record byte[] Use null to indicate "free" record

param
messages List of message records from EF_SMS.
return
SmsRawData list of all in-used records

        int count = messages.size();
        ArrayList<SmsRawData> ret;

        ret = new ArrayList<SmsRawData>(count);

        for (int i = 0; i < count; i++) {
            byte[] ba = messages.get(i);
            if (ba[0] == 0) {
                ret.add(null);
            } else {
                ret.add(new SmsRawData(messages.get(i)));
            }
        }

        return ret;
    
public booleancopyMessageToSimEf(int status, byte[] pdu, byte[] smsc)
Copy a raw SMS PDU to the SIM.

param
pdu the raw PDU to store
param
status message status (STATUS_ON_SIM_READ, STATUS_ON_SIM_UNREAD, STATUS_ON_SIM_SENT, STATUS_ON_SIM_UNSENT)
return
success or not

        if (DBG) log("copyMessageToSimEf: status=" + status + " ==> " +
                "pdu=("+ pdu + "), smsm=(" + smsc +")");
        enforceReceiveAndSend("Copying message to SIM");
        synchronized(mLock) {
            mSuccess = false;
            Message response = mHandler.obtainMessage(EVENT_UPDATE_DONE);

            mPhone.mCM.writeSmsToSim(status, SimUtils.bytesToHexString(smsc),
                    SimUtils.bytesToHexString(pdu), response);

            try {
                mLock.wait();
            } catch (InterruptedException e) {
                log("interrupted while trying to update by index");
            }
        }
        return mSuccess;
    
private voidenforceReceiveAndSend(java.lang.String message)

        Context context = mPhone.getContext();

        context.enforceCallingPermission(
                "android.permission.RECEIVE_SMS", message);
        context.enforceCallingPermission(
                "android.permission.SEND_SMS", message);
    
public java.util.ListgetAllMessagesFromSimEf()
Retrieves all messages currently stored on SIM.

return
list of SmsRawData of all sms on SIM

        if (DBG) log("getAllMessagesFromEF");

        Context context = mPhone.getContext();

        context.enforceCallingPermission(
                "android.permission.RECEIVE_SMS",
                "Reading messages from SIM");
        synchronized(mLock) {
            Message response = mHandler.obtainMessage(EVENT_LOAD_DONE);
            mPhone.mSIMFileHandler.loadEFLinearFixedAll(SimConstants.EF_SMS,
                    response);

            try {
                mLock.wait();
            } catch (InterruptedException e) {
                log("interrupted while trying to load from the SIM");
            }
        }
        return mSms;
    
private voidlog(java.lang.String msg)

        Log.d(LOG_TAG, "[SmsInterfaceManager] " + msg);
    
private byte[]makeSmsRecordData(int status, byte[] pdu)
Generates an EF_SMS record from status and raw PDU.

param
status Message status. See TS 51.011 10.5.3.
param
pdu Raw message PDU.
return
byte array for the record.

        byte[] data = new byte[SimConstants.SMS_RECORD_LENGTH];

        // Status bits for this record.  See TS 51.011 10.5.3
        data[0] = (byte)(status & 7);

        System.arraycopy(pdu, 0, data, 1, pdu.length);

        // Pad out with 0xFF's.
        for (int j = pdu.length+1; j < SimConstants.SMS_RECORD_LENGTH; j++) {
            data[j] = -1;
        }

        return data;
    
public voidsendMultipartText(java.lang.String destinationAddress, java.lang.String scAddress, java.util.List parts, java.util.List sentIntents, java.util.List deliveryIntents)
Send a multi-part text based SMS.

param
destinationAddress the address to send the message to
param
scAddress is the service center address or null to use the current default SMSC
param
parts an ArrayList of strings that, in order, comprise the original message
param
sentIntents if not null, an ArrayList of PendingIntents (one for each message part) that is broadcast when the corresponding message part has been sent. The result code will be Activity.RESULT_OK for success, or one of these errors: RESULT_ERROR_GENERIC_FAILURE RESULT_ERROR_RADIO_OFF RESULT_ERROR_NULL_PDU.
param
deliveryIntents if not null, an ArrayList of PendingIntents (one for each message part) that is broadcast when the corresponding message part has been delivered to the recipient. The raw pdu of the status report is in the extended data ("pdu").

        Context context = mPhone.getContext();

        context.enforceCallingPermission(
                "android.permission.SEND_SMS",
                "Sending SMS message");
        if (DBG) log("sendMultipartText");
        mPhone.mSMS.sendMultipartText(destinationAddress, scAddress, (ArrayList<String>) parts,
                (ArrayList<PendingIntent>) sentIntents, (ArrayList<PendingIntent>) deliveryIntents);
    
public voidsendRawPdu(byte[] smsc, byte[] pdu, android.app.PendingIntent sentIntent, android.app.PendingIntent deliveryIntent)
Send a Raw PDU SMS

param
smsc the SMSC to send the message through, or NULL for the defatult SMSC
param
pdu the raw PDU to send
param
sentIntent if not NULL this Intent is broadcast when the message is sucessfully sent, or failed. The result code will be Activity.RESULT_OK for success, or one of these errors: RESULT_ERROR_GENERIC_FAILURE RESULT_ERROR_RADIO_OFF RESULT_ERROR_NULL_PDU.
param
deliveryIntent if not NULL this Intent is broadcast when the message is delivered to the recipient. The raw pdu of the status report is in the extended data ("pdu").

        Context context = mPhone.getContext();

        context.enforceCallingPermission(
                "android.permission.SEND_SMS",
                "Sending SMS message");
        if (DBG) log("sendRawPdu: smsc=" + smsc +
                " pdu="+ pdu + " sentIntent" + sentIntent +
                " deliveryIntent" + deliveryIntent);
        mPhone.mSMS.sendRawPdu(smsc, pdu, sentIntent, deliveryIntent);
    
public booleanupdateMessageOnSimEf(int index, int status, byte[] pdu)
Update the specified message on the SIM.

param
index record index of message to update
param
status new message status (STATUS_ON_SIM_READ, STATUS_ON_SIM_UNREAD, STATUS_ON_SIM_SENT, STATUS_ON_SIM_UNSENT, STATUS_ON_SIM_FREE)
param
pdu the raw PDU to store
return
success or not

        if (DBG) log("updateMessageOnSimEf: index=" + index +
                " status=" + status + " ==> " +
                "("+ pdu + ")");
        enforceReceiveAndSend("Updating message on SIM");
        synchronized(mLock) {
            mSuccess = false;
            Message response = mHandler.obtainMessage(EVENT_UPDATE_DONE);

            if (status == SmsManager.STATUS_ON_SIM_FREE) {
                // Special case FREE: call deleteSmsOnSim instead of
                // manipulating the SIM record
                mPhone.mCM.deleteSmsOnSim(index, response);
            } else {
                byte[] record = makeSmsRecordData(status, pdu);
                mPhone.mSIMFileHandler.updateEFLinearFixed( SimConstants.EF_SMS,
                        index, record, null, response);
            }
            try {
                mLock.wait();
            } catch (InterruptedException e) {
                log("interrupted while trying to update by index");
            }
        }
        return mSuccess;