Client (framework) side HAL changes for RIL unsolicited responses.
Amit Mahajan [Mon, 19 Dec 2016 17:40:04 +0000 (09:40 -0800)]
Test: WIP
Bug: 32020264
Change-Id: I94300f56cd46bdad81271cb44113bcc72591394f

src/java/android/telephony/SmsMessage.java
src/java/com/android/internal/telephony/RIL.java
src/java/com/android/internal/telephony/RadioIndication.java
src/java/com/android/internal/telephony/cdma/SmsMessage.java
src/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java
src/java/com/android/internal/telephony/gsm/SmsMessage.java
src/java/com/android/internal/telephony/uicc/SIMRecords.java
tests/telephonytests/src/com/android/internal/telephony/cdma/CdmaSmsCbTest.java
tests/telephonytests/src/com/android/internal/telephony/gsm/GsmSmsDispatcherTest.java

index 73e1f1a..ba4deae 100644 (file)
@@ -19,6 +19,7 @@ package android.telephony;
 import android.os.Binder;
 import android.os.Parcel;
 import android.content.res.Resources;
+import android.hardware.radio.V1_0.CdmaSmsMessage;
 import android.text.TextUtils;
 
 import com.android.internal.telephony.GsmAlphabet;
@@ -221,10 +222,10 @@ public class SmsMessage {
      *
      * {@hide}
      */
-    public static SmsMessage newFromCMT(String[] lines) {
+    public static SmsMessage newFromCMT(byte[] pdu) {
         // received SMS in 3GPP format
         SmsMessageBase wrappedMessage =
-                com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines);
+                com.android.internal.telephony.gsm.SmsMessage.newFromCMT(pdu);
 
         if (wrappedMessage != null) {
             return new SmsMessage(wrappedMessage);
@@ -235,10 +236,10 @@ public class SmsMessage {
     }
 
     /** @hide */
-    public static SmsMessage newFromParcel(Parcel p) {
+    public static SmsMessage newCdmaSmsFromRil(CdmaSmsMessage msg) {
         // received SMS in 3GPP2 format
         SmsMessageBase wrappedMessage =
-                com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p);
+                com.android.internal.telephony.cdma.SmsMessage.newFromRil(msg);
 
         return new SmsMessage(wrappedMessage);
     }
index c00fe05..a2497f5 100644 (file)
@@ -27,6 +27,7 @@ import android.hardware.radio.V1_0.RadioError;
 import android.hardware.radio.V1_0.RadioIndicationType;
 import android.hardware.radio.V1_0.RadioResponseInfo;
 import android.hardware.radio.V1_0.RadioResponseType;
+import android.hardware.radio.V1_0.SetupDataCallResult;
 import android.hardware.radio.V1_0.UusInfo;
 import android.net.ConnectivityManager;
 import android.net.LocalSocket;
@@ -2661,7 +2662,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
     void processIndication(int indicationType) {
         if (indicationType == RadioIndicationType.UNSOLICITED_ACK_EXP) {
             sendAck();
-            if (RIL.RILJ_LOGD) riljLog("Unsol response received; Sending ack to ril.cpp");
+            if (RILJ_LOGD) riljLog("Unsol response received; Sending ack to ril.cpp");
         } else {
             // ack is not expected to be sent back. Nothing is required to be done here.
         }
@@ -2754,8 +2755,8 @@ public final class RIL extends BaseCommands implements CommandsInterface {
 
     /**
      * This is a helper function to be called at the end of all RadioResponse callbacks.
-     * It takes care of logging, decrementing wakelock if needed, and releases the request from
-     * memory pool.
+     * It takes care of sending error response, logging, decrementing wakelock if needed, and
+     * releases the request from memory pool.
      * @param rr RILRequest for which response callback was called
      * @param responseInfo RadioResponseInfo received in the callback
      * @param ret object to be returned to request sender
@@ -3399,6 +3400,14 @@ public final class RIL extends BaseCommands implements CommandsInterface {
         return s;
     }
 
+    void writeMetricsNewSms(int tech, int format) {
+        mMetrics.writeRilNewSms(mInstanceId, tech, format);
+    }
+
+    void writeMetricsCallRing(char[] response) {
+        mMetrics.writeRilCallRing(mInstanceId, response);
+    }
+
     private void
     processUnsolicited (Parcel p, int type) {
         int response;
@@ -3421,33 +3430,8 @@ public final class RIL extends BaseCommands implements CommandsInterface {
         }
 
         try {switch(response) {
-/*
- cat libs/telephony/ril_unsol_commands.h \
- | egrep "^ *{RIL_" \
- | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: \2(rr, p); break;/'
-*/
-
-            case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: ret =  responseVoid(p); break;
-            case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: ret =  responseVoid(p); break;
-            case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: ret =  responseVoid(p); break;
-            case RIL_UNSOL_RESPONSE_NEW_SMS: ret =  responseString(p); break;
-            case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: ret =  responseString(p); break;
-            case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: ret =  responseInts(p); break;
-            case RIL_UNSOL_ON_USSD: ret =  responseStrings(p); break;
-            case RIL_UNSOL_NITZ_TIME_RECEIVED: ret =  responseString(p); break;
             case RIL_UNSOL_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break;
-            case RIL_UNSOL_DATA_CALL_LIST_CHANGED: ret = responseDataCallList(p);break;
-            case RIL_UNSOL_SUPP_SVC_NOTIFICATION: ret = responseSuppServiceNotification(p); break;
-            case RIL_UNSOL_STK_SESSION_END: ret = responseVoid(p); break;
-            case RIL_UNSOL_STK_PROACTIVE_COMMAND: ret = responseString(p); break;
-            case RIL_UNSOL_STK_EVENT_NOTIFY: ret = responseString(p); break;
-            case RIL_UNSOL_STK_CALL_SETUP: ret = responseInts(p); break;
-            case RIL_UNSOL_SIM_SMS_STORAGE_FULL: ret =  responseVoid(p); break;
-            case RIL_UNSOL_SIM_REFRESH: ret =  responseSimRefresh(p); break;
-            case RIL_UNSOL_CALL_RING: ret =  responseCallRing(p); break;
             case RIL_UNSOL_RESTRICTED_STATE_CHANGED: ret = responseInts(p); break;
-            case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:  ret =  responseVoid(p); break;
-            case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:  ret =  responseCdmaSms(p); break;
             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:  ret =  responseRaw(p); break;
             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:  ret =  responseVoid(p); break;
             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
@@ -3491,103 +3475,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {
                 mImsNetworkStateChangedRegistrants
                     .notifyRegistrants(new AsyncResult(null, null, null));
             break;
-            case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
-                if (RILJ_LOGD) unsljLog(response);
-
-                mCallStateRegistrants
-                    .notifyRegistrants(new AsyncResult(null, null, null));
-            break;
-            case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
-                if (RILJ_LOGD) unsljLog(response);
-
-                mVoiceNetworkStateRegistrants
-                    .notifyRegistrants(new AsyncResult(null, null, null));
-            break;
-            case RIL_UNSOL_RESPONSE_NEW_SMS: {
-                if (RILJ_LOGD) unsljLog(response);
-
-                mMetrics.writeRilNewSms(mInstanceId, SmsSession.Event.Tech.SMS_GSM,
-                        SmsSession.Event.Format.SMS_FORMAT_3GPP);
-
-                // FIXME this should move up a layer
-                String a[] = new String[2];
-
-                a[1] = (String)ret;
-
-                SmsMessage sms;
-
-                sms = SmsMessage.newFromCMT(a);
-                if (mGsmSmsRegistrant != null) {
-                    mGsmSmsRegistrant
-                        .notifyRegistrant(new AsyncResult(null, sms, null));
-                }
-            break;
-            }
-            case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
-                if (RILJ_LOGD) unsljLogRet(response, ret);
-
-                if (mSmsStatusRegistrant != null) {
-                    mSmsStatusRegistrant.notifyRegistrant(
-                            new AsyncResult(null, ret, null));
-                }
-            break;
-            case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM:
-                if (RILJ_LOGD) unsljLogRet(response, ret);
-
-                int[] smsIndex = (int[])ret;
-
-                if(smsIndex.length == 1) {
-                    if (mSmsOnSimRegistrant != null) {
-                        mSmsOnSimRegistrant.
-                                notifyRegistrant(new AsyncResult(null, smsIndex, null));
-                    }
-                } else {
-                    if (RILJ_LOGD) riljLog(" NEW_SMS_ON_SIM ERROR with wrong length "
-                            + smsIndex.length);
-                }
-            break;
-            case RIL_UNSOL_ON_USSD:
-                String[] resp = (String[])ret;
-
-                if (resp.length < 2) {
-                    resp = new String[2];
-                    resp[0] = ((String[])ret)[0];
-                    resp[1] = null;
-                }
-                if (RILJ_LOGD) unsljLogMore(response, resp[0]);
-                if (mUSSDRegistrant != null) {
-                    mUSSDRegistrant.notifyRegistrant(
-                        new AsyncResult (null, resp, null));
-                }
-            break;
-            case RIL_UNSOL_NITZ_TIME_RECEIVED:
-                if (RILJ_LOGD) unsljLogRet(response, ret);
-
-                // has bonus long containing milliseconds since boot that the NITZ
-                // time was received
-                long nitzReceiveTime = p.readLong();
-
-                Object[] result = new Object[2];
-
-                result[0] = ret;
-                result[1] = Long.valueOf(nitzReceiveTime);
-
-                boolean ignoreNitz = SystemProperties.getBoolean(
-                        TelephonyProperties.PROPERTY_IGNORE_NITZ, false);
-
-                if (ignoreNitz) {
-                    if (RILJ_LOGD) riljLog("ignoring UNSOL_NITZ_TIME_RECEIVED");
-                } else {
-                    if (mNITZTimeRegistrant != null) {
-
-                        mNITZTimeRegistrant
-                            .notifyRegistrant(new AsyncResult (null, result, null));
-                    }
-                    // in case NITZ time registrant isn't registered yet, or a new registrant
-                    // registers later
-                    mLastNITZTimeInfo = result;
-                }
-            break;
 
             case RIL_UNSOL_SIGNAL_STRENGTH:
                 // Note this is set to "verbose" because it happens
@@ -3596,82 +3483,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {
 
                 if (mSignalStrengthRegistrant != null) {
                     mSignalStrengthRegistrant.notifyRegistrant(
-                                        new AsyncResult (null, ret, null));
-                }
-            break;
-            case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
-                if (RILJ_LOGD) unsljLogRet(response, ret);
-
-                mDataNetworkStateRegistrants.notifyRegistrants(new AsyncResult(null, ret, null));
-            break;
-
-            case RIL_UNSOL_SUPP_SVC_NOTIFICATION:
-                if (RILJ_LOGD) unsljLogRet(response, ret);
-
-                if (mSsnRegistrant != null) {
-                    mSsnRegistrant.notifyRegistrant(
-                                        new AsyncResult (null, ret, null));
-                }
-                break;
-
-            case RIL_UNSOL_STK_SESSION_END:
-                if (RILJ_LOGD) unsljLog(response);
-
-                if (mCatSessionEndRegistrant != null) {
-                    mCatSessionEndRegistrant.notifyRegistrant(
-                                        new AsyncResult (null, ret, null));
-                }
-                break;
-
-            case RIL_UNSOL_STK_PROACTIVE_COMMAND:
-                if (RILJ_LOGD) unsljLog(response);
-
-                if (mCatProCmdRegistrant != null) {
-                    mCatProCmdRegistrant.notifyRegistrant(
-                                        new AsyncResult (null, ret, null));
-                }
-                break;
-
-            case RIL_UNSOL_STK_EVENT_NOTIFY:
-                if (RILJ_LOGD) unsljLog(response);
-
-                if (mCatEventRegistrant != null) {
-                    mCatEventRegistrant.notifyRegistrant(
-                                        new AsyncResult (null, ret, null));
-                }
-                break;
-
-            case RIL_UNSOL_STK_CALL_SETUP:
-                if (RILJ_LOGD) unsljLogRet(response, ret);
-
-                if (mCatCallSetUpRegistrant != null) {
-                    mCatCallSetUpRegistrant.notifyRegistrant(
-                                        new AsyncResult (null, ret, null));
-                }
-                break;
-
-            case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
-                if (RILJ_LOGD) unsljLog(response);
-
-                if (mIccSmsFullRegistrant != null) {
-                    mIccSmsFullRegistrant.notifyRegistrant();
-                }
-                break;
-
-            case RIL_UNSOL_SIM_REFRESH:
-                if (RILJ_LOGD) unsljLogRet(response, ret);
-
-                if (mIccRefreshRegistrants != null) {
-                    mIccRefreshRegistrants.notifyRegistrants(
-                            new AsyncResult (null, ret, null));
-                }
-                break;
-
-            case RIL_UNSOL_CALL_RING:
-                if (RILJ_LOGD) unsljLogRet(response, ret);
-
-                if (mRingRegistrant != null) {
-                    mRingRegistrant.notifyRegistrant(
                             new AsyncResult (null, ret, null));
                 }
                 break;
@@ -3684,28 +3495,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {
                 }
                 break;
 
-            case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
-                if (RILJ_LOGD) unsljLog(response);
-
-                if (mIccStatusChangedRegistrants != null) {
-                    mIccStatusChangedRegistrants.notifyRegistrants();
-                }
-                break;
-
-            case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
-                if (RILJ_LOGD) unsljLog(response);
-
-                mMetrics.writeRilNewSms(mInstanceId, SmsSession.Event.Tech.SMS_CDMA,
-                        SmsSession.Event.Format.SMS_FORMAT_3GPP2);
-
-                SmsMessage sms = (SmsMessage) ret;
-
-                if (mCdmaSmsRegistrant != null) {
-                    mCdmaSmsRegistrant
-                        .notifyRegistrant(new AsyncResult(null, sms, null));
-                }
-                break;
-
             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
                 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret));
 
@@ -4002,14 +3791,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {
     }
 
     private Object
-    responseCdmaSms(Parcel p) {
-        SmsMessage sms;
-        sms = SmsMessage.newFromParcel(p);
-
-        return sms;
-    }
-
-    private Object
     responseString(Parcel p) {
         String response;
 
@@ -4393,20 +4174,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {
         return notification;
     }
 
-    private Object
-    responseCallRing(Parcel p){
-        char response[] = new char[4];
-
-        response[0] = (char) p.readInt();    // isPresent
-        response[1] = (char) p.readInt();    // signalType
-        response[2] = (char) p.readInt();    // alertPitch
-        response[3] = (char) p.readInt();    // signal
-
-        mMetrics.writeRilCallRing(mInstanceId, response);
-
-        return response;
-    }
-
     private void
     notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) {
         int response = RIL_UNSOL_CDMA_INFO_REC;
@@ -5501,4 +5268,59 @@ public final class RIL extends BaseCommands implements CommandsInterface {
     public List<ClientRequestStats> getClientRequestStats() {
         return mClientWakelockTracker.getClientRequestStats();
     }
+
+    public static byte[] arrayListToPrimitiveArray(ArrayList<Byte> bytes) {
+        byte[] ret = new byte[bytes.size()];
+        for (int i = 0; i < ret.length; i++) {
+            ret[i] = bytes.get(i);
+        }
+        return ret;
+    }
+
+    static ArrayList<DataCallResponse> convertHalDcList(ArrayList<SetupDataCallResult> dcList) {
+        ArrayList<DataCallResponse> dcResponseList;
+        int num = 0;
+        if (dcList != null) {
+            num = dcList.size();
+        }
+        dcResponseList = new ArrayList<>(num);
+        for (int i = 0; i < num; i++) {
+            DataCallResponse dcResponse = new DataCallResponse();
+            SetupDataCallResult dc = dcList.get(i);
+            // todo: get rid of this version field?
+            // todo: create a DataCallResponse constructor that takes in these fields to make sure
+            // no fields are missing
+            dcResponse.version = 11;
+            dcResponse.status = dc.status;
+            dcResponse.suggestedRetryTime = dc.suggestedRetryTime;
+            dcResponse.cid = dc.cid;
+            dcResponse.active = dc.active;
+            dcResponse.type = dc.type;
+            dcResponse.ifname = dc.ifname;
+            if ((dcResponse.status == DcFailCause.NONE.getErrorCode()) &&
+                    TextUtils.isEmpty(dcResponse.ifname)) {
+                throw new RuntimeException("getDataCallResponse, no ifname");
+            }
+            String addresses = dc.addresses;
+            if (!TextUtils.isEmpty(addresses)) {
+                dcResponse.addresses = addresses.split(" ");
+            }
+            String dnses = dc.dnses;
+            if (!TextUtils.isEmpty(dnses)) {
+                dcResponse.dnses = dnses.split(" ");
+            }
+            String gateways = dc.gateways;
+            if (!TextUtils.isEmpty(gateways)) {
+                dcResponse.gateways = gateways.split(" ");
+            }
+            String pcscf = dc.pcscf;
+            if (!TextUtils.isEmpty(pcscf)) {
+                dcResponse.pcscf = pcscf.split(" ");
+            }
+            dcResponse.mtu = dc.mtu;
+
+            dcResponseList.add(dcResponse);
+        }
+        return dcResponseList;
+    }
 }
index eb1ac64..b58ca9c 100644 (file)
@@ -26,8 +26,38 @@ import android.hardware.radio.V1_0.SetupDataCallResult;
 import android.hardware.radio.V1_0.SimRefreshResult;
 import android.hardware.radio.V1_0.StkCcUnsolSsResult;
 import android.hardware.radio.V1_0.SuppSvcNotification;
-
+import android.os.AsyncResult;
+import android.os.SystemProperties;
+import android.telephony.SignalStrength;
+import android.telephony.SmsMessage;
+import android.text.TextUtils;
+
+import com.android.internal.telephony.dataconnection.DataCallResponse;
+import com.android.internal.telephony.dataconnection.DcFailCause;
+import com.android.internal.telephony.gsm.SuppServiceNotification;
+import com.android.internal.telephony.nano.TelephonyProto.SmsSession;
+import com.android.internal.telephony.uicc.IccRefreshResponse;
+
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_CALL_RING;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_DATA_CALL_LIST_CHANGED;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_NITZ_TIME_RECEIVED;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_ON_USSD;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_CDMA_NEW_SMS;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_NEW_SMS;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT;
 import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SIGNAL_STRENGTH;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SIM_REFRESH;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SIM_SMS_STORAGE_FULL;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_CALL_SETUP;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_EVENT_NOTIFY;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_PROACTIVE_COMMAND;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_STK_SESSION_END;
+import static com.android.internal.telephony.RILConstants.RIL_UNSOL_SUPP_SVC_NOTIFICATION;
 
 import java.util.ArrayList;
 
@@ -45,106 +75,316 @@ public class RadioIndication extends IRadioIndication.Stub {
      */
     public void radioStateChanged(int indicationType, int radioState) {
         mRil.processIndication(indicationType);
+
         CommandsInterface.RadioState newState = getRadioStateFromInt(radioState);
-        mRil.unsljLogMore(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, "radioStateChanged: "
-                + newState.toString());
+        if (RIL.RILJ_LOGD) {
+            mRil.unsljLogMore(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, "radioStateChanged: " +
+                    newState);
+        }
+
         mRil.setRadioState(newState);
     }
 
-    public void callStateChanged(int var1) {}
+    public void callStateChanged(int indicationType) {
+        mRil.processIndication(indicationType);
+
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED);
+
+        mRil.mCallStateRegistrants.notifyRegistrants();
+    }
+
+    public void voiceNetworkStateChanged(int indicationType) {
+        mRil.processIndication(indicationType);
+
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED);
+
+        mRil.mVoiceNetworkStateRegistrants.notifyRegistrants();
+    }
+
+    public void newSms(int indicationType, ArrayList<Byte> pdu) {
+        mRil.processIndication(indicationType);
+
+        byte[] pduArray = RIL.arrayListToPrimitiveArray(pdu);
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_RESPONSE_NEW_SMS);
+
+        mRil.writeMetricsNewSms(SmsSession.Event.Tech.SMS_GSM,
+                SmsSession.Event.Format.SMS_FORMAT_3GPP);
+
+        SmsMessage sms = SmsMessage.newFromCMT(pduArray);
+        if (mRil.mGsmSmsRegistrant != null) {
+            mRil.mGsmSmsRegistrant.notifyRegistrant(new AsyncResult(null, sms, null));
+        }
+    }
+
+    public void newSmsStatusReport(int indicationType, ArrayList<Byte> pdu) {
+        mRil.processIndication(indicationType);
+
+        byte[] pduArray = RIL.arrayListToPrimitiveArray(pdu);
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT);
+
+        if (mRil.mSmsStatusRegistrant != null) {
+            mRil.mSmsStatusRegistrant.notifyRegistrant(new AsyncResult(null, pduArray, null));
+        }
+    }
+
+    public void newSmsOnSim(int indicationType, int recordNumber) {
+        mRil.processIndication(indicationType);
+
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM);
+
+        if (mRil.mSmsOnSimRegistrant != null) {
+            mRil.mSmsOnSimRegistrant.notifyRegistrant(new AsyncResult(null, recordNumber, null));
+        }
+    }
+
+    public void onUssd(int indicationType, int ussdModeType, String msg) {
+        mRil.processIndication(indicationType);
+
+        if (RIL.RILJ_LOGD) mRil.unsljLogMore(RIL_UNSOL_ON_USSD, "" + ussdModeType);
+
+        // todo: Clean this up with a parcelable class for better self-documentation
+        String[] resp = new String[2];
+        resp[0] = "" + ussdModeType;
+        resp[1] = msg;
+        if (mRil.mUSSDRegistrant != null) {
+            mRil.mUSSDRegistrant.notifyRegistrant(new AsyncResult (null, resp, null));
+        }
+    }
+
+    public void nitzTimeReceived(int indicationType, String nitzTime, long receivedTime) {
+        mRil.processIndication(indicationType);
+
+        if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_NITZ_TIME_RECEIVED, nitzTime);
+
+        // todo: Clean this up with a parcelable class for better self-documentation
+        Object[] result = new Object[2];
+        result[0] = nitzTime;
+        result[1] = receivedTime;
+
+        boolean ignoreNitz = SystemProperties.getBoolean(
+                TelephonyProperties.PROPERTY_IGNORE_NITZ, false);
+
+        if (ignoreNitz) {
+            if (RIL.RILJ_LOGD) mRil.riljLog("ignoring UNSOL_NITZ_TIME_RECEIVED");
+        } else {
+            if (mRil.mNITZTimeRegistrant != null) {
+                mRil.mNITZTimeRegistrant.notifyRegistrant(new AsyncResult (null, result, null));
+            }
+            // in case NITZ time registrant isn't registered yet, or a new registrant
+            // registers later
+            mRil.mLastNITZTimeInfo = result;
+        }
+    }
+
+    public void currentSignalStrength(int indicationType,
+                                      android.hardware.radio.V1_0.SignalStrength signalStrength) {
+        mRil.processIndication(indicationType);
+
+        /*
+        SignalStrength ss = SignalStrength.makeSignalStrengthFromHalObject(signalStrength);
+        // Note this is set to "verbose" because it happens frequently
+        if (RIL.RILJ_LOGV) mRil.unsljLogvRet(RIL_UNSOL_SIGNAL_STRENGTH, ss);
+
+        if (mRil.mSignalStrengthRegistrant != null) {
+            mRil.mSignalStrengthRegistrant.notifyRegistrant(new AsyncResult (null, ss, null));
+        } */
+    }
+
+    public void dataCallListChanged(int indicationType, ArrayList<SetupDataCallResult> dcList) {
+        mRil.processIndication(indicationType);
+
+        ArrayList<DataCallResponse> response = RIL.convertHalDcList(dcList);
+        if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_DATA_CALL_LIST_CHANGED, response);
+
+        mRil.mDataNetworkStateRegistrants.notifyRegistrants(new AsyncResult(null, response, null));
+    }
+
+    public void suppSvcNotify(int indicationType, SuppSvcNotification suppSvcNotification) {
+        mRil.processIndication(indicationType);
+
+        SuppServiceNotification notification = new SuppServiceNotification();
+        notification.notificationType = suppSvcNotification.isMT ? 1 : 0;
+        notification.code = suppSvcNotification.code;
+        notification.index = suppSvcNotification.index;
+        notification.type = suppSvcNotification.type;
+        notification.number = suppSvcNotification.number;
+
+        if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_SUPP_SVC_NOTIFICATION, notification);
+
+        if (mRil.mSsnRegistrant != null) {
+            mRil.mSsnRegistrant.notifyRegistrant(new AsyncResult (null, notification, null));
+        }
+    }
+
+    public void stkSessionEnd(int indicationType) {
+        mRil.processIndication(indicationType);
+
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_STK_SESSION_END);
+
+        if (mRil.mCatSessionEndRegistrant != null) {
+            mRil.mCatSessionEndRegistrant.notifyRegistrant(new AsyncResult (null, null, null));
+        }
+    }
+
+    public void stkProactiveCommand(int indicationType, String cmd) {
+        mRil.processIndication(indicationType);
+
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_STK_PROACTIVE_COMMAND);
+
+        if (mRil.mCatProCmdRegistrant != null) {
+            mRil.mCatProCmdRegistrant.notifyRegistrant(new AsyncResult (null, cmd, null));
+        }
+    }
+
+    public void stkEventNotify(int indicationType, String cmd) {
+        mRil.processIndication(indicationType);
+
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_STK_EVENT_NOTIFY);
+
+        if (mRil.mCatEventRegistrant != null) {
+            mRil.mCatEventRegistrant.notifyRegistrant(new AsyncResult (null, cmd, null));
+        }
+    }
+
+    public void stkCallSetup(int indicationType, long timeout) {
+        mRil.processIndication(indicationType);
 
-    public void voiceNetworkStateChanged(int var1) {}
+        if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_STK_CALL_SETUP, timeout);
 
-    public void newSms(int var1, ArrayList<Byte> var2) {}
+        if (mRil.mCatCallSetUpRegistrant != null) {
+            mRil.mCatCallSetUpRegistrant.notifyRegistrant(new AsyncResult (null, timeout, null));
+        }
+    }
 
-    public void newSmsStatusReport(int var1, ArrayList<Byte> var2) {}
+    public void simSmsStorageFull(int indicationType) {
+        mRil.processIndication(indicationType);
 
-    public void newSmsOnSim(int var1, int var2) {}
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_SIM_SMS_STORAGE_FULL);
 
-    public void onUssd(int var1, int var2, String var3) {}
+        if (mRil.mIccSmsFullRegistrant != null) {
+            mRil.mIccSmsFullRegistrant.notifyRegistrant();
+        }
+    }
 
-    public void nitzTimeReceived(int var1, String var2, long var3) {}
+    public void simRefresh(int indicationType, SimRefreshResult refreshResult) {
+        mRil.processIndication(indicationType);
 
-    public void currentSignalStrength(int var1,
-                                      android.hardware.radio.V1_0.SignalStrength var2) {}
+        IccRefreshResponse response = new IccRefreshResponse();
+        response.refreshResult = refreshResult.type;
+        response.efId = refreshResult.efId;
+        response.aid = refreshResult.aid;
 
-    public void dataCallListChanged(int var1, ArrayList<SetupDataCallResult> var2) {}
+        if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_SIM_REFRESH, response);
 
-    public void suppSvcNotify(int var1, SuppSvcNotification var2) {}
+        if (mRil.mIccRefreshRegistrants != null) {
+            mRil.mIccRefreshRegistrants.notifyRegistrants(new AsyncResult (null, response, null));
+        }
+    }
 
-    public void stkSessionEnd(int var1) {}
+    public void callRing(int indicationType, boolean isGsm, CdmaSignalInfoRecord record) {
+        mRil.processIndication(indicationType);
+
+        char response[] = null;
+
+        // Ignore record for gsm
+        if (!isGsm) {
+            // todo: Clean this up with a parcelable class for better self-documentation
+            response = new char[4];
+            response[0] = (char) (record.isPresent ? 1 : 0);
+            response[1] = (char) record.signalType;
+            response[2] = (char) record.alertPitch;
+            response[3] = (char) record.signal;
+            mRil.writeMetricsCallRing(response);
+        }
 
-    public void stkProactiveCommand(int var1, String var2) {}
+        if (RIL.RILJ_LOGD) mRil.unsljLogRet(RIL_UNSOL_CALL_RING, response);
+
+        if (mRil.mRingRegistrant != null) {
+            mRil.mRingRegistrant.notifyRegistrant(new AsyncResult (null, response, null));
+        }
+    }
 
-    public void stkEventNotify(int var1, String var2) {}
+    public void simStatusChanged(int indicationType) {
+        mRil.processIndication(indicationType);
 
-    public void stkCallSetup(int var1, long var2) {}
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED);
 
-    public void simSmsStorageFull(int var1) {}
+        if (mRil.mIccStatusChangedRegistrants != null) {
+            mRil.mIccStatusChangedRegistrants.notifyRegistrants();
+        }
+    }
 
-    public void simRefresh(int var1, SimRefreshResult var2) {}
+    public void cdmaNewSms(int indicationType, CdmaSmsMessage msg) {
+        mRil.processIndication(indicationType);
 
-    public void callRing(int var1, boolean var2, CdmaSignalInfoRecord var3) {}
+        if (RIL.RILJ_LOGD) mRil.unsljLog(RIL_UNSOL_RESPONSE_CDMA_NEW_SMS);
 
-    public void simStatusChanged(int var1) {}
+        mRil.writeMetricsNewSms(SmsSession.Event.Tech.SMS_CDMA,
+                SmsSession.Event.Format.SMS_FORMAT_3GPP2);
 
-    public void cdmaNewSms(int var1, CdmaSmsMessage var2) {}
+        // todo: conversion from CdmaSmsMessage to SmsMessage should be contained in this class so
+        // that usage of auto-generated HAL classes is limited to this file
+        SmsMessage sms = SmsMessage.newCdmaSmsFromRil(msg);
+        if (mRil.mCdmaSmsRegistrant != null) {
+            mRil.mCdmaSmsRegistrant.notifyRegistrant(new AsyncResult(null, sms, null));
+        }
+    }
 
-    public void newBroadcastSms(int var1, ArrayList<Byte> var2) {}
+    public void newBroadcastSms(int indicationType, ArrayList<Byte> var2) {}
 
-    public void cdmaRuimSmsStorageFull(int var1) {}
+    public void cdmaRuimSmsStorageFull(int indicationType) {}
 
-    public void restrictedStateChanged(int var1, int var2) {}
+    public void restrictedStateChanged(int indicationType, int var2) {}
 
-    public void enterEmergencyCallbackMode(int var1) {}
+    public void enterEmergencyCallbackMode(int indicationType) {}
 
-    public void cdmaCallWaiting(int var1, CdmaCallWaiting var2) {}
+    public void cdmaCallWaiting(int indicationType, CdmaCallWaiting var2) {}
 
-    public void cdmaOtaProvisionStatus(int var1, int var2) {}
+    public void cdmaOtaProvisionStatus(int indicationType, int var2) {}
 
-    public void cdmaInfoRec(int var1,
+    public void cdmaInfoRec(int indicationType,
                             android.hardware.radio.V1_0.CdmaInformationRecords var2) {}
 
-    public void oemHookRaw(int var1, ArrayList<Byte> var2) {}
+    public void oemHookRaw(int indicationType, ArrayList<Byte> var2) {}
 
-    public void indicateRingbackTone(int var1, boolean var2) {}
+    public void indicateRingbackTone(int indicationType, boolean var2) {}
 
-    public void resendIncallMute(int var1) {}
+    public void resendIncallMute(int indicationType) {}
 
-    public void cdmaSubscriptionSourceChanged(int var1, int var2) {}
+    public void cdmaSubscriptionSourceChanged(int indicationType, int var2) {}
 
-    public void cdmaPrlChanged(int var1, int var2) {}
+    public void cdmaPrlChanged(int indicationType, int var2) {}
 
-    public void exitEmergencyCallbackMode(int var1) {}
+    public void exitEmergencyCallbackMode(int indicationType) {}
 
-    public void rilConnected(int var1) {}
+    public void rilConnected(int indicationType) {}
 
-    public void voiceRadioTechChanged(int var1, int var2) {}
+    public void voiceRadioTechChanged(int indicationType, int var2) {}
 
-    public void cellInfoList(int var1, ArrayList<android.hardware.radio.V1_0.CellInfo> var2) {}
+    public void cellInfoList(int indicationType, ArrayList<android.hardware.radio.V1_0.CellInfo> var2) {}
 
-    public void imsNetworkStateChanged(int var1) {}
+    public void imsNetworkStateChanged(int indicationType) {}
 
-    public void subscriptionStatusChanged(int var1, boolean var2) {}
+    public void subscriptionStatusChanged(int indicationType, boolean var2) {}
 
-    public void srvccStateNotify(int var1, int var2) {}
+    public void srvccStateNotify(int indicationType, int var2) {}
 
     public void hardwareConfigChanged(
-            int var1,
+            int indicationType,
             ArrayList<android.hardware.radio.V1_0.HardwareConfig> var2) {}
 
-    public void radioCapabilityIndication(int var1,
+    public void radioCapabilityIndication(int indicationType,
                                           android.hardware.radio.V1_0.RadioCapability var2) {}
 
-    public void onSupplementaryServiceIndication(int var1, StkCcUnsolSsResult var2) {}
+    public void onSupplementaryServiceIndication(int indicationType, StkCcUnsolSsResult var2) {}
 
-    public void stkCallControlAlphaNotify(int var1, String var2) {}
+    public void stkCallControlAlphaNotify(int indicationType, String var2) {}
 
-    public void lceData(int var1, LceDataInfo var2) {}
+    public void lceData(int indicationType, LceDataInfo var2) {}
 
-    public void pcoData(int var1, PcoDataInfo var2) {}
+    public void pcoData(int indicationType, PcoDataInfo var2) {}
 
-    public void modemReset(int var1, String var2) {}
+    public void modemReset(int indicationType, String var2) {}
 
     private CommandsInterface.RadioState getRadioStateFromInt(int stateInt) {
         CommandsInterface.RadioState state;
index 0b75fa5..729062b 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.internal.telephony.cdma;
 
+import android.hardware.radio.V1_0.CdmaSmsMessage;
 import android.os.Parcel;
 import android.os.SystemProperties;
 import android.telephony.PhoneNumberUtils;
@@ -127,7 +128,7 @@ public class SmsMessage extends SmsMessageBase {
      *  Create a "raw" CDMA SmsMessage from a Parcel that was forged in ril.cpp.
      *  Note: Only primitive fields are set.
      */
-    public static SmsMessage newFromParcel(Parcel p) {
+    public static SmsMessage newFromRil(CdmaSmsMessage cdmaSmsMessage) {
         // Note: Parcel.readByte actually reads one Int and masks to byte
         SmsMessage msg = new SmsMessage();
         SmsEnvelope env = new SmsEnvelope();
@@ -139,9 +140,9 @@ public class SmsMessage extends SmsMessageBase {
         int addressDigitMode;
 
         //currently not supported by the modem-lib: env.mMessageType
-        env.teleService = p.readInt(); //p_cur->uTeleserviceID
+        env.teleService = cdmaSmsMessage.teleserviceId;
 
-        if (0 != p.readByte()) { //p_cur->bIsServicePresent
+        if (cdmaSmsMessage.isServicePresent) {
             env.messageType = SmsEnvelope.MESSAGE_TYPE_BROADCAST;
         }
         else {
@@ -152,20 +153,19 @@ public class SmsMessage extends SmsMessageBase {
                 env.messageType = SmsEnvelope.MESSAGE_TYPE_POINT_TO_POINT;
             }
         }
-        env.serviceCategory = p.readInt(); //p_cur->uServicecategory
+        env.serviceCategory = cdmaSmsMessage.serviceCategory;
 
         // address
-        addressDigitMode = p.readInt();
-        addr.digitMode = (byte) (0xFF & addressDigitMode); //p_cur->sAddress.digit_mode
-        addr.numberMode = (byte) (0xFF & p.readInt()); //p_cur->sAddress.number_mode
-        addr.ton = p.readInt(); //p_cur->sAddress.number_type
-        addr.numberPlan = (byte) (0xFF & p.readInt()); //p_cur->sAddress.number_plan
-        count = p.readByte(); //p_cur->sAddress.number_of_digits
+        addressDigitMode = cdmaSmsMessage.address.digitMode;
+        addr.digitMode = (byte) (0xFF & addressDigitMode);
+        addr.numberMode = (byte) (0xFF & cdmaSmsMessage.address.numberMode);
+        addr.ton = cdmaSmsMessage.address.numberType;
+        addr.numberPlan = (byte) (0xFF & cdmaSmsMessage.address.numberPlan);
+        count = (byte) cdmaSmsMessage.address.digits.size();
         addr.numberOfDigits = count;
         data = new byte[count];
-        //p_cur->sAddress.digits[digitCount]
         for (int index=0; index < count; index++) {
-            data[index] = p.readByte();
+            data[index] = cdmaSmsMessage.address.digits.get(index);
 
             // convert the value if it is 4-bit DTMF to 8 bit
             if (addressDigitMode == CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF) {
@@ -175,9 +175,9 @@ public class SmsMessage extends SmsMessageBase {
 
         addr.origBytes = data;
 
-        subaddr.type = p.readInt(); // p_cur->sSubAddress.subaddressType
-        subaddr.odd = p.readByte();     // p_cur->sSubAddress.odd
-        count = p.readByte();           // p_cur->sSubAddress.number_of_digits
+        subaddr.type = cdmaSmsMessage.subAddress.subaddressType;
+        subaddr.odd = (byte) (cdmaSmsMessage.subAddress.odd ? 1 : 0);
+        count = (byte) cdmaSmsMessage.subAddress.digits.size();
 
         if (count < 0) {
             count = 0;
@@ -188,7 +188,7 @@ public class SmsMessage extends SmsMessageBase {
         data = new byte[count];
 
         for (int index = 0; index < count; ++index) {
-            data[index] = p.readByte();
+            data[index] = cdmaSmsMessage.subAddress.digits.get(index);
         }
 
         subaddr.origBytes = data;
@@ -201,14 +201,14 @@ public class SmsMessage extends SmsMessageBase {
         */
 
         // bearer data
-        countInt = p.readInt(); //p_cur->uBearerDataLen
+        countInt = cdmaSmsMessage.bearerData.size();
         if (countInt < 0) {
             countInt = 0;
         }
 
         data = new byte[countInt];
         for (int index=0; index < countInt; index++) {
-            data[index] = p.readByte();
+            data[index] = cdmaSmsMessage.bearerData.get(index);
         }
         // BD gets further decoded when accessed in SMSDispatcher
         env.bearerData = data;
index 15981aa..8f18c61 100644 (file)
@@ -117,8 +117,8 @@ public final class GsmSMSDispatcher extends SMSDispatcher {
      *           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);
+        byte[] pdu = (byte[]) ar.result;
+        SmsMessage sms = SmsMessage.newFromCDS(pdu);
 
         if (sms != null) {
             int tpStatus = sms.getStatus();
@@ -134,7 +134,7 @@ public final class GsmSMSDispatcher extends SMSDispatcher {
                     }
                     PendingIntent intent = tracker.mDeliveryIntent;
                     Intent fillIn = new Intent();
-                    fillIn.putExtra("pdu", IccUtils.hexStringToBytes(pduString));
+                    fillIn.putExtra("pdu", pdu);
                     fillIn.putExtra("format", getFormat());
                     try {
                         intent.send(mContext, Activity.RESULT_OK, fillIn);
index 0d9bed4..582506a 100644 (file)
@@ -126,10 +126,10 @@ public class SmsMessage extends SmsMessageBase {
      *
      * {@hide}
      */
-    public static SmsMessage newFromCMT(String[] lines) {
+    public static SmsMessage newFromCMT(byte[] pdu) {
         try {
             SmsMessage msg = new SmsMessage();
-            msg.parsePdu(IccUtils.hexStringToBytes(lines[1]));
+            msg.parsePdu(pdu);
             return msg;
         } catch (RuntimeException ex) {
             Rlog.e(LOG_TAG, "SMS PDU parsing failed: ", ex);
@@ -138,10 +138,10 @@ public class SmsMessage extends SmsMessageBase {
     }
 
     /** @hide */
-    public static SmsMessage newFromCDS(String line) {
+    public static SmsMessage newFromCDS(byte[] pdu) {
         try {
             SmsMessage msg = new SmsMessage();
-            msg.parsePdu(IccUtils.hexStringToBytes(line));
+            msg.parsePdu(pdu);
             return msg;
         } catch (RuntimeException ex) {
             Rlog.e(LOG_TAG, "CDS SMS PDU parsing failed: ", ex);
index 42d2a74..95e3b3f 100644 (file)
@@ -1070,15 +1070,14 @@ public class SIMRecords extends IccRecords {
 
                 ar = (AsyncResult)msg.obj;
 
-                int[] index = (int[])ar.result;
+                Integer index = (Integer)ar.result;
 
-                if (ar.exception != null || index.length != 1) {
+                if (ar.exception != null || index == null) {
                     loge("Error on SMS_ON_SIM with exp "
-                            + ar.exception + " length " + index.length);
+                            + ar.exception + " index " + index);
                 } else {
-                    log("READ EF_SMS RECORD index=" + index[0]);
-                    mFh.loadEFLinearFixed(EF_SMS,index[0],
-                            obtainMessage(EVENT_GET_SMS_DONE));
+                    log("READ EF_SMS RECORD index=" + index);
+                    mFh.loadEFLinearFixed(EF_SMS, index, obtainMessage(EVENT_GET_SMS_DONE));
                 }
                 break;
 
index 3460599..db091f5 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.internal.telephony.cdma;
 
+import android.hardware.radio.V1_0.CdmaSmsMessage;
 import android.os.Parcel;
 import android.platform.test.annotations.Postsubmit;
 import android.telephony.SmsCbCmasInfo;
@@ -35,6 +36,7 @@ import com.android.internal.util.BitwiseOutputStream;
 
 import org.junit.Test;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Random;
@@ -57,23 +59,21 @@ public class CdmaSmsCbTest extends AndroidTestCase {
      * @param serviceCategory the CDMA service category
      * @return the initialized Parcel
      */
-    private static Parcel createBroadcastParcel(int serviceCategory) {
-        Parcel p = Parcel.obtain();
+    private static CdmaSmsMessage createBroadcastParcel(int serviceCategory) {
+        CdmaSmsMessage msg = new CdmaSmsMessage();
 
-        p.writeInt(SmsEnvelope.TELESERVICE_NOT_SET);
-        p.writeByte((byte) 1);  // non-zero for MESSAGE_TYPE_BROADCAST
-        p.writeInt(serviceCategory);
+        msg.teleserviceId = SmsEnvelope.TELESERVICE_NOT_SET;
+        msg.isServicePresent = true;
+        msg.serviceCategory = serviceCategory;
 
         // dummy address (RIL may generate a different dummy address for broadcasts)
-        p.writeInt(CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF);            // sAddress.digit_mode
-        p.writeInt(CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK);    // sAddress.number_mode
-        p.writeInt(CdmaSmsAddress.TON_UNKNOWN);                     // sAddress.number_type
-        p.writeInt(CdmaSmsAddress.NUMBERING_PLAN_ISDN_TELEPHONY);   // sAddress.number_plan
-        p.writeByte((byte) 0);      // sAddress.number_of_digits
-        p.writeInt((byte) 0);       // sSubAddress.subaddressType
-        p.writeByte((byte) 0);      // sSubAddress.odd
-        p.writeByte((byte) 0);      // sSubAddress.number_of_digits
-        return p;
+        msg.address.digitMode = CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF;
+        msg.address.numberMode = CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK;
+        msg.address.numberType = CdmaSmsAddress.TON_UNKNOWN;
+        msg.address.numberPlan = CdmaSmsAddress.NUMBERING_PLAN_ISDN_TELEPHONY;
+        msg.subAddress.subaddressType = 0;
+        msg.subAddress.odd = false;
+        return msg;
     }
 
     /**
@@ -113,18 +113,15 @@ public class CdmaSmsCbTest extends AndroidTestCase {
 
     /**
      * Write the bearer data array to the parcel, then return a new SmsMessage from the parcel.
-     * @param p the parcel containing the CDMA SMS headers
+     * @param msg CdmaSmsMessage containing the CDMA SMS headers
      * @param bearerData the bearer data byte array to append to the parcel
      * @return the new SmsMessage created from the parcel
      */
-    private static SmsMessage createMessageFromParcel(Parcel p, byte[] bearerData) {
-        p.writeInt(bearerData.length);
+    private static SmsMessage createMessageFromParcel(CdmaSmsMessage msg, byte[] bearerData) {
         for (byte b : bearerData) {
-            p.writeByte(b);
+            msg.bearerData.add(b);
         }
-        p.setDataPosition(0);   // reset position for reading
-        SmsMessage message = SmsMessage.newFromParcel(p);
-        p.recycle();
+        SmsMessage message = SmsMessage.newFromRil(msg);
         return message;
     }
 
@@ -167,7 +164,7 @@ public class CdmaSmsCbTest extends AndroidTestCase {
 
         byte[] cmasUserData = cmasBos.toByteArray();
 
-        Parcel p = createBroadcastParcel(serviceCategory);
+        CdmaSmsMessage msg = createBroadcastParcel(serviceCategory);
         BitwiseOutputStream bos = createBearerDataStream(messageId, priority, language);
 
         bos.write(8, SUBPARAM_USER_DATA);
@@ -177,7 +174,7 @@ public class CdmaSmsCbTest extends AndroidTestCase {
         bos.writeByteArray(cmasUserData.length * 8, cmasUserData);
         bos.write(3, 0);    // pad to byte boundary
 
-        return createMessageFromParcel(p, bos.toByteArray());
+        return createMessageFromParcel(msg, bos.toByteArray());
     }
 
     /**
@@ -193,13 +190,13 @@ public class CdmaSmsCbTest extends AndroidTestCase {
      */
     private static SmsMessage createBroadcastSmsMessage(int serviceCategory, int messageId,
             int priority, int language, int encoding, String body) throws Exception {
-        Parcel p = createBroadcastParcel(serviceCategory);
+        CdmaSmsMessage msg = createBroadcastParcel(serviceCategory);
         BitwiseOutputStream bos = createBearerDataStream(messageId, priority, language);
 
         bos.write(8, SUBPARAM_USER_DATA);
         encodeBody(encoding, body, false, bos);
 
-        return createMessageFromParcel(p, bos.toByteArray());
+        return createMessageFromParcel(msg, bos.toByteArray());
     }
 
     /**
@@ -546,8 +543,8 @@ public class CdmaSmsCbTest extends AndroidTestCase {
             // Rlog.d("CdmaSmsCbTest", "trying random bearer data run " + run + " length " + len);
             try {
                 int category = 0x0ff0 + r.nextInt(32);  // half CMAS, half non-CMAS
-                Parcel p = createBroadcastParcel(category);
-                SmsMessage msg = createMessageFromParcel(p, data);
+                CdmaSmsMessage cdmaSmsMessage = createBroadcastParcel(category);
+                SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, data);
                 SmsCbMessage cbMessage = msg.parseBroadcastSms();
                 // with random input, cbMessage will almost always be null (log when it isn't)
                 if (cbMessage != null) {
@@ -566,7 +563,7 @@ public class CdmaSmsCbTest extends AndroidTestCase {
         Random r = new Random(94040);
         for (int run = 0; run < 1000; run++) {
             int category = 0x0ff0 + r.nextInt(32);  // half CMAS, half non-CMAS
-            Parcel p = createBroadcastParcel(category);
+            CdmaSmsMessage cdmaSmsMessage = createBroadcastParcel(category);
             int len = r.nextInt(140);
             // Rlog.d("CdmaSmsCbTest", "trying random user data run " + run + " length " + len);
 
@@ -581,7 +578,7 @@ public class CdmaSmsCbTest extends AndroidTestCase {
                     bos.write(8, r.nextInt(256));
                 }
 
-                SmsMessage msg = createMessageFromParcel(p, bos.toByteArray());
+                SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, bos.toByteArray());
                 SmsCbMessage cbMessage = msg.parseBroadcastSms();
             } catch (Exception e) {
                 Rlog.d("CdmaSmsCbTest", "exception thrown", e);
@@ -595,23 +592,21 @@ public class CdmaSmsCbTest extends AndroidTestCase {
      * write the bearer data and then convert it to an SmsMessage.
      * @return the initialized Parcel
      */
-    private static Parcel createServiceCategoryProgramDataParcel() {
-        Parcel p = Parcel.obtain();
+    private static CdmaSmsMessage createServiceCategoryProgramDataParcel() {
+        CdmaSmsMessage msg = new CdmaSmsMessage();
 
-        p.writeInt(SmsEnvelope.TELESERVICE_SCPT);
-        p.writeByte((byte) 0);  // non-zero for MESSAGE_TYPE_BROADCAST
-        p.writeInt(0);
+        msg.teleserviceId = SmsEnvelope.TELESERVICE_SCPT;
+        msg.isServicePresent = false;
+        msg.serviceCategory = 0;
 
         // dummy address (RIL may generate a different dummy address for broadcasts)
-        p.writeInt(CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF);            // sAddress.digit_mode
-        p.writeInt(CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK);    // sAddress.number_mode
-        p.writeInt(CdmaSmsAddress.TON_UNKNOWN);                     // sAddress.number_type
-        p.writeInt(CdmaSmsAddress.NUMBERING_PLAN_ISDN_TELEPHONY);   // sAddress.number_plan
-        p.writeByte((byte) 0);      // sAddress.number_of_digits
-        p.writeInt((byte) 0);       // sSubAddress.subaddressType
-        p.writeByte((byte) 0);      // sSubAddress.odd
-        p.writeByte((byte) 0);      // sSubAddress.number_of_digits
-        return p;
+        msg.address.digitMode = CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF;
+        msg.address.numberMode = CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK;
+        msg.address.numberType = CdmaSmsAddress.TON_UNKNOWN;
+        msg.address.numberPlan = CdmaSmsAddress.NUMBERING_PLAN_ISDN_TELEPHONY;
+        msg.subAddress.subaddressType = 0;
+        msg.subAddress.odd = false;
+        return msg;
     }
 
     private static final String CAT_EXTREME_THREAT = "Extreme Threat to Life and Property";
@@ -620,7 +615,7 @@ public class CdmaSmsCbTest extends AndroidTestCase {
 
     @Test @SmallTest
     public void testServiceCategoryProgramDataAddCategory() throws Exception {
-        Parcel p = createServiceCategoryProgramDataParcel();
+        CdmaSmsMessage cdmaSmsMessage = createServiceCategoryProgramDataParcel();
         BitwiseOutputStream bos = createBearerDataStream(123, -1, -1);
 
         int categoryNameLength = CAT_EXTREME_THREAT.length();
@@ -645,7 +640,7 @@ public class CdmaSmsCbTest extends AndroidTestCase {
         }
         bos.write(subparamPadBits, 0);
 
-        SmsMessage msg = createMessageFromParcel(p, bos.toByteArray());
+        SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, bos.toByteArray());
         assertNotNull(msg);
         msg.parseSms();
         List<CdmaSmsCbProgramData> programDataList = msg.getSmsCbProgramData();
@@ -662,7 +657,7 @@ public class CdmaSmsCbTest extends AndroidTestCase {
 
     @Test @SmallTest
     public void testServiceCategoryProgramDataDeleteTwoCategories() throws Exception {
-        Parcel p = createServiceCategoryProgramDataParcel();
+        CdmaSmsMessage cdmaSmsMessage = createServiceCategoryProgramDataParcel();
         BitwiseOutputStream bos = createBearerDataStream(456, -1, -1);
 
         int category1NameLength = CAT_SEVERE_THREAT.length();
@@ -702,7 +697,7 @@ public class CdmaSmsCbTest extends AndroidTestCase {
 
         bos.write(subparamPadBits, 0);
 
-        SmsMessage msg = createMessageFromParcel(p, bos.toByteArray());
+        SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, bos.toByteArray());
         assertNotNull(msg);
         msg.parseSms();
         List<CdmaSmsCbProgramData> programDataList = msg.getSmsCbProgramData();
@@ -744,8 +739,8 @@ public class CdmaSmsCbTest extends AndroidTestCase {
     // Test case for CMAS test message received on the Sprint network.
     @Test @SmallTest
     public void testDecodeRawBearerData() throws Exception {
-        Parcel p = createBroadcastParcel(SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE);
-        SmsMessage msg = createMessageFromParcel(p, CMAS_TEST_BEARER_DATA);
+        CdmaSmsMessage cdmaSmsMessage = createBroadcastParcel(SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE);
+        SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, CMAS_TEST_BEARER_DATA);
 
         SmsCbMessage cbMessage = msg.parseBroadcastSms();
         assertNotNull("expected non-null for bearer data", cbMessage);
index 7766bae..e513644 100644 (file)
@@ -97,7 +97,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
 
     @Test @SmallTest
     public void testSmsStatus() {
-        mSimulatedCommands.notifySmsStatus("0123056789ABCDEF");
+        mSimulatedCommands.notifySmsStatus("0123056789ABCDEF"); //change parameter to byte[] pdu
         TelephonyTestUtils.waitForMs(50);
         verify(mSimulatedCommandsVerifier).acknowledgeLastIncomingGsmSms(true,
                 Telephony.Sms.Intents.RESULT_SMS_HANDLED, null);