Merge "Connect to CellularNetworkService in SST."
diff --git a/src/java/com/android/internal/telephony/CellularNetworkService.java b/src/java/com/android/internal/telephony/CellularNetworkService.java
index d40bccb..55d5f25 100644
--- a/src/java/com/android/internal/telephony/CellularNetworkService.java
+++ b/src/java/com/android/internal/telephony/CellularNetworkService.java
@@ -167,8 +167,7 @@
             }
         }
 
-        private int[] getAvailableServices(int regState, int domain,
-                boolean emergencyOnly) {
+        private int[] getAvailableServices(int regState, int domain, boolean emergencyOnly) {
             int[] availableServices = null;
 
             // In emergency only states, only SERVICE_TYPE_EMERGENCY is available.
@@ -177,7 +176,7 @@
             if (emergencyOnly) {
                 availableServices = new int[] {NetworkRegistrationState.SERVICE_TYPE_EMERGENCY};
             } else if (regState == NetworkRegistrationState.REG_STATE_ROAMING
-                    || regState != NetworkRegistrationState.REG_STATE_HOME) {
+                    || regState == NetworkRegistrationState.REG_STATE_HOME) {
                 if (domain == NetworkRegistrationState.DOMAIN_PS) {
                     availableServices = new int[] {NetworkRegistrationState.SERVICE_TYPE_DATA};
                 } else if (domain == NetworkRegistrationState.DOMAIN_CS) {
@@ -243,6 +242,10 @@
 
         private CellIdentity convertHalCellIdentityToCellIdentity(
                 android.hardware.radio.V1_0.CellIdentity cellIdentity) {
+            if (cellIdentity == null) {
+                return null;
+            }
+
             CellIdentity result = null;
             switch(cellIdentity.cellInfoType) {
                 case CellInfoType.GSM: {
diff --git a/src/java/com/android/internal/telephony/ServiceStateTracker.java b/src/java/com/android/internal/telephony/ServiceStateTracker.java
index 7c5842f..2b6acdb 100644
--- a/src/java/com/android/internal/telephony/ServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/ServiceStateTracker.java
@@ -33,9 +33,6 @@
 import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.hardware.radio.V1_0.CellInfoType;
-import android.hardware.radio.V1_0.DataRegStateResult;
-import android.hardware.radio.V1_0.RegState;
-import android.hardware.radio.V1_0.VoiceRegStateResult;
 import android.os.AsyncResult;
 import android.os.BaseBundle;
 import android.os.Build;
@@ -50,33 +47,42 @@
 import android.os.WorkSource;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
+import android.telephony.AccessNetworkConstants;
 import android.telephony.CarrierConfigManager;
+import android.telephony.CellIdentity;
+import android.telephony.CellIdentityCdma;
 import android.telephony.CellIdentityGsm;
 import android.telephony.CellIdentityLte;
+import android.telephony.CellIdentityTdscdma;
 import android.telephony.CellIdentityWcdma;
 import android.telephony.CellInfo;
 import android.telephony.CellInfoGsm;
 import android.telephony.CellInfoLte;
 import android.telephony.CellInfoWcdma;
 import android.telephony.CellLocation;
+import android.telephony.DataSpecificRegistrationStates;
+import android.telephony.NetworkRegistrationState;
 import android.telephony.Rlog;
 import android.telephony.ServiceState;
 import android.telephony.SignalStrength;
 import android.telephony.SubscriptionManager;
 import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
 import android.telephony.TelephonyManager;
+import android.telephony.VoiceSpecificRegistrationStates;
 import android.telephony.cdma.CdmaCellLocation;
 import android.telephony.gsm.GsmCellLocation;
 import android.text.TextUtils;
 import android.util.EventLog;
 import android.util.LocalLog;
 import android.util.Pair;
+import android.util.SparseArray;
 import android.util.TimeUtils;
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
 import com.android.internal.telephony.cdma.EriInfo;
 import com.android.internal.telephony.dataconnection.DcTracker;
+import com.android.internal.telephony.dataconnection.TransportManager;
 import com.android.internal.telephony.metrics.TelephonyMetrics;
 import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState;
 import com.android.internal.telephony.uicc.IccRecords;
@@ -452,6 +458,9 @@
     private String mRegistrationDeniedReason;
     private String mCurrentCarrier = null;
 
+    private final TransportManager mTransportManager;
+    private final SparseArray<NetworkRegistrationManager> mRegStateManagers = new SparseArray<>();
+
     /* list of LTE EARFCNs (E-UTRA Absolute Radio Frequency Channel Number,
      * Reference: 3GPP TS 36.104 5.4.3)
      * inclusive ranges for which the lte rsrp boost is applied */
@@ -482,9 +491,17 @@
                 .addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
         mRestrictedState = new RestrictedState();
 
+        mTransportManager = new TransportManager();
+
+        for (int transportType : mTransportManager.getAvailableTransports()) {
+            mRegStateManagers.append(transportType, new NetworkRegistrationManager(
+                    transportType, phone));
+            mRegStateManagers.get(transportType).registerForNetworkRegistrationStateChanged(
+                    this, EVENT_NETWORK_STATE_CHANGED, null);
+        }
+
         mCi.registerForImsNetworkStateChanged(this, EVENT_IMS_STATE_CHANGED, null);
         mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
-        mCi.registerForNetworkStateChanged(this, EVENT_NETWORK_STATE_CHANGED, null);
         mCi.setOnNITZTime(this, EVENT_NITZ_TIME, null);
 
         mCr = phone.getContext().getContentResolver();
@@ -854,55 +871,37 @@
         }
     }
 
-    private void processCellLocationInfo(CellLocation cellLocation,
-                                         VoiceRegStateResult voiceRegStateResult) {
+    private void processCellLocationInfo(CellLocation cellLocation, CellIdentity cellIdentity) {
         if (mPhone.isPhoneTypeGsm()) {
             int psc = -1;
             int cid = -1;
             int lac = -1;
-            switch(voiceRegStateResult.cellIdentity.cellInfoType) {
-                case CellInfoType.GSM: {
-                    if (voiceRegStateResult.cellIdentity.cellIdentityGsm.size() == 1) {
-                        android.hardware.radio.V1_0.CellIdentityGsm cellIdentityGsm =
-                                voiceRegStateResult.cellIdentity.cellIdentityGsm.get(0);
-                        cid = cellIdentityGsm.cid;
-                        lac = cellIdentityGsm.lac;
+            if (cellIdentity != null) {
+                switch (cellIdentity.getType()) {
+                    case CellInfoType.GSM: {
+                        cid = ((CellIdentityGsm) cellIdentity).getCid();
+                        lac = ((CellIdentityGsm) cellIdentity).getLac();
+                        break;
                     }
-                    break;
-                }
-                case CellInfoType.WCDMA: {
-                    if (voiceRegStateResult.cellIdentity.cellIdentityWcdma.size() == 1) {
-                        android.hardware.radio.V1_0.CellIdentityWcdma cellIdentityWcdma =
-                                voiceRegStateResult.cellIdentity.cellIdentityWcdma.get(0);
-                        cid = cellIdentityWcdma.cid;
-                        lac = cellIdentityWcdma.lac;
-                        psc = cellIdentityWcdma.psc;
+                    case CellInfoType.WCDMA: {
+                        cid = ((CellIdentityWcdma) cellIdentity).getCid();
+                        lac = ((CellIdentityWcdma) cellIdentity).getLac();
+                        psc = ((CellIdentityWcdma) cellIdentity).getPsc();
+                        break;
                     }
-                    break;
-                }
-                case CellInfoType.TD_SCDMA: {
-                    if (voiceRegStateResult.cellIdentity.cellIdentityTdscdma.size() == 1) {
-                        android.hardware.radio.V1_0.CellIdentityTdscdma
-                                cellIdentityTdscdma =
-                                voiceRegStateResult.cellIdentity.cellIdentityTdscdma.get(0);
-                        cid = cellIdentityTdscdma.cid;
-                        lac = cellIdentityTdscdma.lac;
+                    case CellInfoType.TD_SCDMA: {
+                        cid = ((CellIdentityTdscdma) cellIdentity).getCid();
+                        lac = ((CellIdentityTdscdma) cellIdentity).getLac();
+                        break;
                     }
-                    break;
-                }
-                case CellInfoType.LTE: {
-                    if (voiceRegStateResult.cellIdentity.cellIdentityLte.size() == 1) {
-                        android.hardware.radio.V1_0.CellIdentityLte cellIdentityLte =
-                                voiceRegStateResult.cellIdentity.cellIdentityLte.get(0);
-                        cid = cellIdentityLte.ci;
-
-                        /* Continuing the historical behaviour of using tac as lac. */
-                        lac = cellIdentityLte.tac;
+                    case CellInfoType.LTE: {
+                        cid = ((CellIdentityLte) cellIdentity).getCi();
+                        lac = ((CellIdentityLte) cellIdentity).getTac();
+                        break;
                     }
-                    break;
-                }
-                default: {
-                    break;
+                    default: {
+                        break;
+                    }
                 }
             }
             // LAC and CID are -1 if not avail
@@ -915,21 +914,19 @@
             int systemId = 0;
             int networkId = 0;
 
-            switch(voiceRegStateResult.cellIdentity.cellInfoType) {
-                case CellInfoType.CDMA: {
-                    if (voiceRegStateResult.cellIdentity.cellIdentityCdma.size() == 1) {
-                        android.hardware.radio.V1_0.CellIdentityCdma cellIdentityCdma =
-                                voiceRegStateResult.cellIdentity.cellIdentityCdma.get(0);
-                        baseStationId = cellIdentityCdma.baseStationId;
-                        baseStationLatitude = cellIdentityCdma.latitude;
-                        baseStationLongitude = cellIdentityCdma.longitude;
-                        systemId = cellIdentityCdma.systemId;
-                        networkId = cellIdentityCdma.networkId;
+            if (cellIdentity != null) {
+                switch (cellIdentity.getType()) {
+                    case CellInfoType.CDMA: {
+                        baseStationId = ((CellIdentityCdma) cellIdentity).getBasestationId();
+                        baseStationLatitude = ((CellIdentityCdma) cellIdentity).getLatitude();
+                        baseStationLongitude = ((CellIdentityCdma) cellIdentity).getLongitude();
+                        systemId = ((CellIdentityCdma) cellIdentity).getSystemId();
+                        networkId = ((CellIdentityCdma) cellIdentity).getNetworkId();
+                        break;
                     }
-                    break;
-                }
-                default: {
-                    break;
+                    default: {
+                        break;
+                    }
                 }
             }
 
@@ -945,19 +942,17 @@
         }
     }
 
-    private int getLteEarfcn(DataRegStateResult dataRegStateResult) {
+    private int getLteEarfcn(CellIdentity cellIdentity) {
         int lteEarfcn = INVALID_LTE_EARFCN;
-        switch(dataRegStateResult.cellIdentity.cellInfoType) {
-            case CellInfoType.LTE: {
-                if (dataRegStateResult.cellIdentity.cellIdentityLte.size() == 1) {
-                    android.hardware.radio.V1_0.CellIdentityLte cellIdentityLte =
-                            dataRegStateResult.cellIdentity.cellIdentityLte.get(0);
-                    lteEarfcn = cellIdentityLte.earfcn;
+        if (cellIdentity != null) {
+            switch (cellIdentity.getType()) {
+                case CellInfoType.LTE: {
+                    lteEarfcn = ((CellIdentityLte) cellIdentity).getEarfcn();
+                    break;
                 }
-                break;
-            }
-            default: {
-                break;
+                default: {
+                    break;
+                }
             }
         }
 
@@ -1103,7 +1098,9 @@
             case EVENT_GET_LOC_DONE:
                 ar = (AsyncResult) msg.obj;
                 if (ar.exception == null) {
-                    processCellLocationInfo(mCellLoc, (VoiceRegStateResult) ar.result);
+                    CellIdentity cellIdentity = ((NetworkRegistrationState) ar.result)
+                            .getCellIdentity();
+                    processCellLocationInfo(mCellLoc, cellIdentity);
                     mPhone.notifyLocationChanged();
                 }
 
@@ -1176,7 +1173,9 @@
                 ar = (AsyncResult) msg.obj;
 
                 if (ar.exception == null) {
-                    mCi.getVoiceRegistrationState(obtainMessage(EVENT_GET_LOC_DONE, null));
+                    mRegStateManagers.get(AccessNetworkConstants.TransportType.WWAN)
+                            .getNetworkRegistrationState(NetworkRegistrationState.DOMAIN_CS,
+                            obtainMessage(EVENT_GET_LOC_DONE, null));
                 }
                 break;
 
@@ -1721,47 +1720,25 @@
         return cdmaRoaming && !isSameOperatorNameFromSimAndSS(s);
     }
 
-    private int getRegStateFromHalRegState(int regState) {
-        switch (regState) {
-            case RegState.NOT_REG_MT_NOT_SEARCHING_OP:
-                return ServiceState.RIL_REG_STATE_NOT_REG;
-            case RegState.REG_HOME:
-                return ServiceState.RIL_REG_STATE_HOME;
-            case RegState.NOT_REG_MT_SEARCHING_OP:
-                return ServiceState.RIL_REG_STATE_SEARCHING;
-            case RegState.REG_DENIED:
-                return ServiceState.RIL_REG_STATE_DENIED;
-            case RegState.UNKNOWN:
-                return ServiceState.RIL_REG_STATE_UNKNOWN;
-            case RegState.REG_ROAMING:
-                return ServiceState.RIL_REG_STATE_ROAMING;
-            case RegState.NOT_REG_MT_NOT_SEARCHING_OP_EM:
-                return ServiceState.RIL_REG_STATE_NOT_REG_EMERGENCY_CALL_ENABLED;
-            case RegState.NOT_REG_MT_SEARCHING_OP_EM:
-                return ServiceState.RIL_REG_STATE_SEARCHING_EMERGENCY_CALL_ENABLED;
-            case RegState.REG_DENIED_EM:
-                return ServiceState.RIL_REG_STATE_DENIED_EMERGENCY_CALL_ENABLED;
-            case RegState.UNKNOWN_EM:
-                return ServiceState.RIL_REG_STATE_UNKNOWN_EMERGENCY_CALL_ENABLED;
-            default:
-                return ServiceState.REGISTRATION_STATE_NOT_REGISTERED_AND_NOT_SEARCHING;
-        }
-    }
-
     void handlePollStateResultMessage(int what, AsyncResult ar) {
         int ints[];
         switch (what) {
             case EVENT_POLL_STATE_REGISTRATION: {
-                VoiceRegStateResult voiceRegStateResult = (VoiceRegStateResult) ar.result;
-                int registrationState = getRegStateFromHalRegState(voiceRegStateResult.regState);
-                int cssIndicator = voiceRegStateResult.cssSupported ? 1 : 0;
+                NetworkRegistrationState regStates = (NetworkRegistrationState) ar.result;
+                VoiceSpecificRegistrationStates voiceSpecificStates =
+                        regStates.getVoiceSpecificStates();
+
+                int registrationState = regStates.getRegState();
+                int cssIndicator = voiceSpecificStates.cssSupported ? 1 : 0;
+                int newVoiceRat = ServiceState.networkTypeToRilRadioTechnology(
+                        regStates.getAccessNetworkTechnology());
 
                 mNewSS.setVoiceRegState(regCodeToServiceState(registrationState));
                 mNewSS.setCssIndicator(cssIndicator);
-                mNewSS.setRilVoiceRadioTechnology(voiceRegStateResult.rat);
+                mNewSS.setRilVoiceRadioTechnology(newVoiceRat);
 
                 //Denial reason if registrationState = 3
-                int reasonForDenial = voiceRegStateResult.reasonForDenial;
+                int reasonForDenial = regStates.getReasonForDenial();
                 if (mPhone.isPhoneTypeGsm()) {
 
                     mGsmRoaming = regCodeIsRoaming(registrationState);
@@ -1769,27 +1746,15 @@
 
                     boolean isVoiceCapable = mPhone.getContext().getResources()
                             .getBoolean(com.android.internal.R.bool.config_voice_capable);
-                    if (((registrationState
-                            == ServiceState.RIL_REG_STATE_DENIED_EMERGENCY_CALL_ENABLED)
-                            || (registrationState
-                            == ServiceState.RIL_REG_STATE_NOT_REG_EMERGENCY_CALL_ENABLED)
-                            || (registrationState
-                            == ServiceState.RIL_REG_STATE_SEARCHING_EMERGENCY_CALL_ENABLED)
-                            || (registrationState
-                            == ServiceState.RIL_REG_STATE_UNKNOWN_EMERGENCY_CALL_ENABLED))
-                            && isVoiceCapable) {
-                        mEmergencyOnly = true;
-                    } else {
-                        mEmergencyOnly = false;
-                    }
+                    mEmergencyOnly = regStates.isEmergencyEnabled();
                 } else {
-                    int roamingIndicator = voiceRegStateResult.roamingIndicator;
+                    int roamingIndicator = voiceSpecificStates.roamingIndicator;
 
                     //Indicates if current system is in PR
-                    int systemIsInPrl = voiceRegStateResult.systemIsInPrl;
+                    int systemIsInPrl = voiceSpecificStates.systemIsInPrl;
 
                     //Is default roaming indicator from PRL
-                    int defaultRoamingIndicator = voiceRegStateResult.defaultRoamingIndicator;
+                    int defaultRoamingIndicator = voiceSpecificStates.defaultRoamingIndicator;
 
                     mRegistrationState = registrationState;
                     // When registration state is roaming and TSB58
@@ -1806,12 +1771,10 @@
 
                     int systemId = 0;
                     int networkId = 0;
-                    if (voiceRegStateResult.cellIdentity.cellInfoType == CellInfoType.CDMA
-                            && voiceRegStateResult.cellIdentity.cellIdentityCdma.size() == 1) {
-                        android.hardware.radio.V1_0.CellIdentityCdma cellIdentityCdma =
-                                voiceRegStateResult.cellIdentity.cellIdentityCdma.get(0);
-                        systemId = cellIdentityCdma.systemId;
-                        networkId = cellIdentityCdma.networkId;
+                    CellIdentity cellIdentity = regStates.getCellIdentity();
+                    if (cellIdentity != null && cellIdentity.getType() == CellInfoType.CDMA) {
+                        systemId = ((CellIdentityCdma) cellIdentity).getSystemId();
+                        networkId = ((CellIdentityCdma) cellIdentity).getNetworkId();
                     }
                     mNewSS.setSystemAndNetworkId(systemId, networkId);
 
@@ -1828,34 +1791,37 @@
                     }
                 }
 
-                processCellLocationInfo(mNewCellLoc, voiceRegStateResult);
+                processCellLocationInfo(mNewCellLoc, regStates.getCellIdentity());
 
                 if (DBG) {
                     log("handlPollVoiceRegResultMessage: regState=" + registrationState
-                            + " radioTechnology=" + voiceRegStateResult.rat);
+                            + " radioTechnology=" + newVoiceRat);
                 }
                 break;
             }
 
             case EVENT_POLL_STATE_GPRS: {
-                DataRegStateResult dataRegStateResult = (DataRegStateResult) ar.result;
-                int regState = getRegStateFromHalRegState(dataRegStateResult.regState);
-                int dataRegState = regCodeToServiceState(regState);
-                int newDataRat = dataRegStateResult.rat;
-                mNewSS.setDataRegState(dataRegState);
+                NetworkRegistrationState regStates = (NetworkRegistrationState) ar.result;
+                DataSpecificRegistrationStates dataSpecificStates =
+                        regStates.getDataSpecificStates();
+                int regState = regStates.getRegState();
+                int serviceState = regCodeToServiceState(regState);
+                int newDataRat = ServiceState.networkTypeToRilRadioTechnology(
+                        regStates.getAccessNetworkTechnology());
+                mNewSS.setDataRegState(serviceState);
                 mNewSS.setRilDataRadioTechnology(newDataRat);
 
                 if (mPhone.isPhoneTypeGsm()) {
 
-                    mNewReasonDataDenied = dataRegStateResult.reasonDataDenied;
-                    mNewMaxDataCalls = dataRegStateResult.maxDataCalls;
+                    mNewReasonDataDenied = regStates.getReasonForDenial();
+                    mNewMaxDataCalls = dataSpecificStates.maxDataCalls;
                     mDataRoaming = regCodeIsRoaming(regState);
                     // Save the data roaming state reported by modem registration before resource
                     // overlay or carrier config possibly overrides it.
                     mNewSS.setDataRoamingFromRegistration(mDataRoaming);
 
                     if (DBG) {
-                        log("handlPollStateResultMessage: GsmSST setDataRegState=" + dataRegState
+                        log("handlPollStateResultMessage: GsmSST dataServiceState=" + serviceState
                                 + " regState=" + regState
                                 + " dataRadioTechnology=" + newDataRat);
                     }
@@ -1868,7 +1834,7 @@
                     mNewSS.setDataRoamingFromRegistration(isDataRoaming);
 
                     if (DBG) {
-                        log("handlPollStateResultMessage: cdma setDataRegState=" + dataRegState
+                        log("handlPollStateResultMessage: cdma dataServiceState=" + serviceState
                                 + " regState=" + regState
                                 + " dataRadioTechnology=" + newDataRat);
                     }
@@ -1896,13 +1862,13 @@
                     // overlay or carrier config possibly overrides it.
                     mNewSS.setDataRoamingFromRegistration(isDataRoaming);
                     if (DBG) {
-                        log("handlPollStateResultMessage: CdmaLteSST setDataRegState="
-                                + dataRegState + " regState=" + regState + " dataRadioTechnology="
+                        log("handlPollStateResultMessage: CdmaLteSST dataServiceState="
+                                + serviceState + " regState=" + regState + " dataRadioTechnology="
                                 + newDataRat);
                     }
                 }
 
-                updateServiceStateLteEarfcnBoost(mNewSS, getLteEarfcn(dataRegStateResult));
+                updateServiceStateLteEarfcnBoost(mNewSS, getLteEarfcn(regStates.getCellIdentity()));
                 break;
             }
 
@@ -2567,15 +2533,19 @@
             default:
                 // Issue all poll-related commands at once then count down the responses, which
                 // are allowed to arrive out-of-order
+                // TODO: Add WLAN support.
                 mPollingContext[0]++;
                 mCi.getOperator(obtainMessage(EVENT_POLL_STATE_OPERATOR, mPollingContext));
 
                 mPollingContext[0]++;
-                mCi.getDataRegistrationState(obtainMessage(EVENT_POLL_STATE_GPRS, mPollingContext));
+                mRegStateManagers.get(AccessNetworkConstants.TransportType.WWAN)
+                        .getNetworkRegistrationState(NetworkRegistrationState.DOMAIN_PS,
+                        obtainMessage(EVENT_POLL_STATE_GPRS, mPollingContext));
 
                 mPollingContext[0]++;
-                mCi.getVoiceRegistrationState(obtainMessage(EVENT_POLL_STATE_REGISTRATION,
-                        mPollingContext));
+                mRegStateManagers.get(AccessNetworkConstants.TransportType.WWAN)
+                        .getNetworkRegistrationState(NetworkRegistrationState.DOMAIN_CS,
+                        obtainMessage(EVENT_POLL_STATE_REGISTRATION, mPollingContext));
 
                 if (mPhone.isPhoneTypeGsm()) {
                     mPollingContext[0]++;
@@ -3122,8 +3092,8 @@
      * to service state */
     private int regCodeToServiceState(int code) {
         switch (code) {
-            case ServiceState.RIL_REG_STATE_HOME:
-            case ServiceState.RIL_REG_STATE_ROAMING:
+            case NetworkRegistrationState.REG_STATE_HOME:
+            case NetworkRegistrationState.REG_STATE_ROAMING:
                 return ServiceState.STATE_IN_SERVICE;
             default:
                 return ServiceState.STATE_OUT_OF_SERVICE;
@@ -3135,7 +3105,7 @@
      * returns true if registered roam, false otherwise
      */
     private boolean regCodeIsRoaming (int code) {
-        return ServiceState.RIL_REG_STATE_ROAMING == code;
+        return NetworkRegistrationState.REG_STATE_ROAMING == code;
     }
 
     private boolean isSameOperatorNameFromSimAndSS(ServiceState s) {
diff --git a/src/java/com/android/internal/telephony/TelephonyTester.java b/src/java/com/android/internal/telephony/TelephonyTester.java
index 8c5880d..16fac4d 100644
--- a/src/java/com/android/internal/telephony/TelephonyTester.java
+++ b/src/java/com/android/internal/telephony/TelephonyTester.java
@@ -23,14 +23,15 @@
 import android.net.Uri;
 import android.os.BadParcelableException;
 import android.os.Build;
+import android.telephony.NetworkRegistrationState;
 import android.telephony.Rlog;
 import android.telephony.ServiceState;
-
-import com.android.ims.ImsCall;
 import android.telephony.ims.ImsCallProfile;
 import android.telephony.ims.ImsConferenceState;
 import android.telephony.ims.ImsExternalCallState;
 import android.telephony.ims.ImsReasonInfo;
+
+import com.android.ims.ImsCall;
 import com.android.internal.telephony.gsm.SuppServiceNotification;
 import com.android.internal.telephony.imsphone.ImsExternalCallTracker;
 import com.android.internal.telephony.imsphone.ImsPhone;
@@ -338,12 +339,12 @@
         }
         if (mServiceStateTestIntent.hasExtra(EXTRA_VOICE_REG_STATE)) {
             ss.setVoiceRegState(mServiceStateTestIntent.getIntExtra(EXTRA_VOICE_REG_STATE,
-                    ServiceState.RIL_REG_STATE_UNKNOWN));
+                    NetworkRegistrationState.REG_STATE_UNKNOWN));
             log("Override voice reg state with " + ss.getVoiceRegState());
         }
         if (mServiceStateTestIntent.hasExtra(EXTRA_DATA_REG_STATE)) {
             ss.setDataRegState(mServiceStateTestIntent.getIntExtra(EXTRA_DATA_REG_STATE,
-                    ServiceState.RIL_REG_STATE_UNKNOWN));
+                    NetworkRegistrationState.REG_STATE_UNKNOWN));
             log("Override data reg state with " + ss.getDataRegState());
         }
         if (mServiceStateTestIntent.hasExtra(EXTRA_VOICE_RAT)) {
diff --git a/src/java/com/android/internal/telephony/test/SimulatedCommands.java b/src/java/com/android/internal/telephony/test/SimulatedCommands.java
index ce85587..cc9886f 100644
--- a/src/java/com/android/internal/telephony/test/SimulatedCommands.java
+++ b/src/java/com/android/internal/telephony/test/SimulatedCommands.java
@@ -34,6 +34,7 @@
 import android.telephony.CellInfoGsm;
 import android.telephony.IccOpenLogicalChannelResponse;
 import android.telephony.ImsiEncryptionInfo;
+import android.telephony.NetworkRegistrationState;
 import android.telephony.NetworkScanRequest;
 import android.telephony.Rlog;
 import android.telephony.ServiceState;
@@ -118,10 +119,17 @@
     int mNetworkType;
     String mPin2Code;
     boolean mSsnNotifyOn = false;
-    private int mVoiceRegState = ServiceState.RIL_REG_STATE_HOME;
+    private int mVoiceRegState = NetworkRegistrationState.REG_STATE_HOME;
     private int mVoiceRadioTech = ServiceState.RIL_RADIO_TECHNOLOGY_UMTS;
-    private int mDataRegState = ServiceState.RIL_REG_STATE_HOME;
+    private int mDataRegState = NetworkRegistrationState.REG_STATE_HOME;
     private int mDataRadioTech = ServiceState.RIL_RADIO_TECHNOLOGY_UMTS;
+    public boolean mCssSupported;
+    public int mRoamingIndicator;
+    public int mSystemIsInPrl;
+    public int mDefaultRoamingIndicator;
+    public int mReasonForDenial;
+    public int mMaxDataCalls;
+
     private SignalStrength mSignalStrength;
     private List<CellInfo> mCellInfoList;
     private int[] mImsRegState;
@@ -956,6 +964,11 @@
         VoiceRegStateResult ret = new VoiceRegStateResult();
         ret.regState = mVoiceRegState;
         ret.rat = mVoiceRadioTech;
+        ret.cssSupported = mCssSupported;
+        ret.roamingIndicator = mRoamingIndicator;
+        ret.systemIsInPrl = mSystemIsInPrl;
+        ret.defaultRoamingIndicator = mDefaultRoamingIndicator;
+        ret.reasonForDenial = mReasonForDenial;
 
         resultSuccess(result, ret);
     }
@@ -982,6 +995,8 @@
         DataRegStateResult ret = new DataRegStateResult();
         ret.regState = mDataRegState;
         ret.rat = mDataRadioTech;
+        ret.maxDataCalls = mMaxDataCalls;
+        ret.reasonDataDenied = mReasonForDenial;
 
         resultSuccess(result, ret);
     }
diff --git a/tests/telephonytests/src/com/android/internal/telephony/CellularNetworkServiceTest.java b/tests/telephonytests/src/com/android/internal/telephony/CellularNetworkServiceTest.java
new file mode 100644
index 0000000..16bc535
--- /dev/null
+++ b/tests/telephonytests/src/com/android/internal/telephony/CellularNetworkServiceTest.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony;
+
+import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.content.IntentFilter;
+import android.content.pm.ServiceInfo;
+import android.os.RemoteException;
+import android.telephony.AccessNetworkConstants;
+import android.telephony.INetworkService;
+import android.telephony.INetworkServiceCallback;
+import android.telephony.NetworkRegistrationState;
+import android.telephony.NetworkService;
+import android.telephony.NetworkServiceCallback;
+import android.telephony.ServiceState;
+import android.telephony.SubscriptionManager;
+import android.test.suitebuilder.annotation.MediumTest;
+
+import com.android.internal.R;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class CellularNetworkServiceTest extends TelephonyTest {
+    CellularNetworkService mCellularNetworkService;
+
+    @Mock
+    private INetworkServiceCallback mCallback;
+
+    private void addNetworkService() {
+        mCellularNetworkService = new CellularNetworkService();
+        ServiceInfo serviceInfo =  new ServiceInfo();
+        serviceInfo.packageName = "com.android.phone";
+        serviceInfo.permission = "android.permission.BIND_NETWORK_SERVICE";
+        IntentFilter filter = new IntentFilter();
+        mContextFixture.addService(
+                NetworkService.NETWORK_SERVICE_INTERFACE,
+                null,
+                "com.android.phone",
+                mCellularNetworkService.mBinder,
+                serviceInfo,
+                filter);
+    }
+    INetworkService.Stub mBinder;
+
+    @Before
+    public void setUp() throws Exception {
+
+        logd("CellularNetworkServiceTest +Setup!");
+        super.setUp("CellularNetworkServiceTest");
+
+        mContextFixture.putResource(R.string.config_wwan_network_service_package,
+                "com.android.phone");
+        addNetworkService();
+        mBinder = mCellularNetworkService.mBinder;
+        mBinder.createNetworkServiceProvider(0);
+
+        int dds = SubscriptionManager.getDefaultDataSubscriptionId();
+        doReturn(dds).when(mPhone).getSubId();
+
+        logd("CellularNetworkServiceTest -Setup!");
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    @Test
+    @MediumTest
+    public void testGetNetworkRegistrationState() {
+        int voiceRegState = NetworkRegistrationState.REG_STATE_HOME;
+        int dataRegState = NetworkRegistrationState.REG_STATE_HOME;
+        int voiceRadioTech = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
+        int dataRadioTech = ServiceState.RIL_RADIO_TECHNOLOGY_HSPA;
+        int domain = NetworkRegistrationState.DOMAIN_CS;
+
+        boolean cssSupported = true;
+        int roamingIndicator = 1;
+        int systemIsInPrl = 2;
+        int defaultRoamingIndicator = 3;
+        int reasonForDenial = 0;
+        int maxDataCalls = 4;
+        int[] availableServices = new int[] {
+                NetworkRegistrationState.SERVICE_TYPE_VOICE,
+                NetworkRegistrationState.SERVICE_TYPE_SMS,
+                NetworkRegistrationState.SERVICE_TYPE_VIDEO
+        };
+
+        mSimulatedCommands.setVoiceRegState(voiceRegState);
+        mSimulatedCommands.setVoiceRadioTech(voiceRadioTech);
+        mSimulatedCommands.setDataRegState(dataRegState);
+        mSimulatedCommands.setDataRadioTech(dataRadioTech);
+        mSimulatedCommands.mCssSupported = cssSupported;
+        mSimulatedCommands.mRoamingIndicator = roamingIndicator;
+        mSimulatedCommands.mSystemIsInPrl = systemIsInPrl;
+        mSimulatedCommands.mDefaultRoamingIndicator = defaultRoamingIndicator;
+        mSimulatedCommands.mReasonForDenial = reasonForDenial;
+        mSimulatedCommands.mMaxDataCalls = maxDataCalls;
+
+        mSimulatedCommands.notifyNetworkStateChanged();
+
+        try {
+            mBinder.getNetworkRegistrationState(0, domain, mCallback);
+        } catch (RemoteException e) {
+            assertTrue(false);
+        }
+
+        waitForMs(1000);
+
+        NetworkRegistrationState expectedState = new NetworkRegistrationState(
+                AccessNetworkConstants.TransportType.WWAN, domain, voiceRegState,
+                ServiceState.rilRadioTechnologyToNetworkType(voiceRadioTech), reasonForDenial,
+                false, availableServices, null, cssSupported,
+                roamingIndicator, systemIsInPrl, defaultRoamingIndicator);
+
+        try {
+            verify(mCallback, times(1)).onGetNetworkRegistrationStateComplete(
+                    eq(NetworkServiceCallback.RESULT_SUCCESS), eq(expectedState));
+        } catch (RemoteException e) {
+            assertTrue(false);
+        }
+
+        domain = NetworkRegistrationState.DOMAIN_PS;
+        availableServices = new int[] {NetworkRegistrationState.SERVICE_TYPE_DATA};
+        try {
+            mBinder.getNetworkRegistrationState(0, domain, mCallback);
+        } catch (RemoteException e) {
+            assertTrue(false);
+        }
+
+        waitForMs(1000);
+
+        expectedState = new NetworkRegistrationState(
+                AccessNetworkConstants.TransportType.WWAN, domain, voiceRegState,
+                ServiceState.rilRadioTechnologyToNetworkType(voiceRadioTech), reasonForDenial,
+                false, availableServices, null, maxDataCalls);
+
+        try {
+            verify(mCallback, times(1)).onGetNetworkRegistrationStateComplete(
+                    eq(NetworkServiceCallback.RESULT_SUCCESS), eq(expectedState));
+        } catch (RemoteException e) {
+            assertTrue(false);
+        }
+    }
+}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java
index 5c1c900..d14e1a9 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java
@@ -34,9 +34,8 @@
 
 import android.app.IAlarmManager;
 import android.content.Intent;
-import android.hardware.radio.V1_0.CellIdentityGsm;
-import android.hardware.radio.V1_0.CellInfoType;
-import android.hardware.radio.V1_0.VoiceRegStateResult;
+import android.content.IntentFilter;
+import android.content.pm.ServiceInfo;
 import android.os.AsyncResult;
 import android.os.Bundle;
 import android.os.Handler;
@@ -50,8 +49,11 @@
 import android.os.WorkSource;
 import android.support.test.filters.FlakyTest;
 import android.telephony.CarrierConfigManager;
+import android.telephony.CellIdentityGsm;
 import android.telephony.CellInfo;
 import android.telephony.CellInfoGsm;
+import android.telephony.NetworkRegistrationState;
+import android.telephony.NetworkService;
 import android.telephony.ServiceState;
 import android.telephony.SignalStrength;
 import android.telephony.SubscriptionManager;
@@ -60,6 +62,7 @@
 import android.test.suitebuilder.annotation.SmallTest;
 import android.util.Pair;
 
+import com.android.internal.R;
 import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
 import com.android.internal.telephony.dataconnection.DcTracker;
 import com.android.internal.telephony.test.SimulatedCommands;
@@ -88,6 +91,8 @@
     @Mock
     protected IAlarmManager mAlarmManager;
 
+    CellularNetworkService mCellularNetworkService;
+
     private ServiceStateTracker sst;
     private ServiceStateTrackerTestHandler mSSTTestHandler;
     private PersistableBundle mBundle;
@@ -117,12 +122,31 @@
         }
     }
 
+    private void addNetworkService() {
+        mCellularNetworkService = new CellularNetworkService();
+        ServiceInfo serviceInfo =  new ServiceInfo();
+        serviceInfo.packageName = "com.android.phone";
+        serviceInfo.permission = "android.permission.BIND_NETWORK_SERVICE";
+        IntentFilter filter = new IntentFilter();
+        mContextFixture.addService(
+                NetworkService.NETWORK_SERVICE_INTERFACE,
+                null,
+                "com.android.phone",
+                mCellularNetworkService.mBinder,
+                serviceInfo,
+                filter);
+    }
+
     @Before
     public void setUp() throws Exception {
 
         logd("ServiceStateTrackerTest +Setup!");
         super.setUp("ServiceStateTrackerTest");
 
+        mContextFixture.putResource(R.string.config_wwan_network_service_package,
+                "com.android.phone");
+        addNetworkService();
+
         doReturn(true).when(mDct).isDisconnected();
         mPhone.mDcTracker = mDct;
 
@@ -134,9 +158,9 @@
         mBundle.putStringArray(
                 CarrierConfigManager.KEY_NON_ROAMING_OPERATOR_STRING_ARRAY, new String[]{"123456"});
 
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_HOME);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_HOME);
         mSimulatedCommands.setVoiceRadioTech(ServiceState.RIL_RADIO_TECHNOLOGY_HSPA);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_HOME);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_HOME);
         mSimulatedCommands.setDataRadioTech(ServiceState.RIL_RADIO_TECHNOLOGY_HSPA);
 
         int dds = SubscriptionManager.getDefaultDataSubscriptionId();
@@ -406,12 +430,9 @@
     @Test
     @MediumTest
     public void testGsmCellLocation() {
-
-        VoiceRegStateResult result = new VoiceRegStateResult();
-        result.cellIdentity.cellInfoType = CellInfoType.GSM;
-        result.cellIdentity.cellIdentityGsm.add(new CellIdentityGsm());
-        result.cellIdentity.cellIdentityGsm.get(0).lac = 2;
-        result.cellIdentity.cellIdentityGsm.get(0).cid = 3;
+        CellIdentityGsm cellIdentityGsm = new CellIdentityGsm(0, 0, 2, 3);
+        NetworkRegistrationState result = new NetworkRegistrationState(
+                0, 0, 0, 0, 0, false, null, cellIdentityGsm);
 
         sst.sendMessage(sst.obtainMessage(ServiceStateTracker.EVENT_GET_LOC_DONE,
                 new AsyncResult(null, result, null)));
@@ -474,8 +495,8 @@
 
         // Enable roaming and trigger events to notify handler registered
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);
@@ -486,8 +507,8 @@
         assertEquals(EVENT_DATA_ROAMING_ON, messageArgumentCaptor.getValue().what);
 
         // Disable roaming
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_HOME);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_HOME);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_HOME);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_HOME);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -496,8 +517,8 @@
         sst.unregisterForVoiceRoamingOn(mTestHandler);
 
         // Enable roaming
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);
@@ -511,8 +532,8 @@
     public void testRegAndUnregForVoiceRoamingOff() throws Exception {
         // Enable roaming
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -521,8 +542,8 @@
 
         // Disable roaming
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_HOME);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_HOME);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_HOME);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_HOME);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);
@@ -533,8 +554,8 @@
         assertEquals(EVENT_DATA_ROAMING_OFF, messageArgumentCaptor.getValue().what);
 
         // Enable roaming
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -543,8 +564,8 @@
         sst.unregisterForVoiceRoamingOff(mTestHandler);
 
         // Disable roaming
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_HOME);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_HOME);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_HOME);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_HOME);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -560,8 +581,8 @@
 
         // Enable roaming and trigger events to notify handler registered
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);
@@ -572,8 +593,8 @@
         assertEquals(EVENT_DATA_ROAMING_ON, messageArgumentCaptor.getValue().what);
 
         // Disable roaming
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_HOME);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_HOME);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_HOME);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_HOME);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -582,8 +603,8 @@
         sst.unregisterForDataRoamingOn(mTestHandler);
 
         // Enable roaming
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);
@@ -597,8 +618,8 @@
     public void testRegAndUnregForDataRoamingOff() throws Exception {
         // Enable roaming
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -607,8 +628,8 @@
 
         // Disable roaming
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_HOME);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_HOME);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_HOME);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_HOME);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -619,8 +640,8 @@
         assertEquals(EVENT_DATA_ROAMING_OFF, messageArgumentCaptor.getValue().what);
 
         // Enable roaming
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -629,8 +650,8 @@
         sst.unregisterForDataRoamingOff(mTestHandler);
 
         // Disable roaming
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_HOME);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_HOME);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_HOME);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_HOME);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -653,8 +674,8 @@
         sst.registerForDataConnectionAttached(mTestHandler, EVENT_DATA_CONNECTION_ATTACHED, null);
 
         // set service state in service and trigger events to post message on handler
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);
@@ -675,8 +696,8 @@
         sst.unregisterForDataConnectionAttached(mTestHandler);
 
         // set service state in service
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -690,8 +711,8 @@
     public void testRegAndUnregForDataConnAttach() throws Exception {
         // Initially set service state out of service
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -699,8 +720,8 @@
         sst.registerForDataConnectionAttached(mTestHandler, EVENT_DATA_CONNECTION_ATTACHED, null);
 
         // set service state in service and trigger events to post message on handler
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);
@@ -711,8 +732,8 @@
         assertEquals(EVENT_DATA_CONNECTION_ATTACHED, messageArgumentCaptor.getValue().what);
 
         // set service state out of service
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -721,8 +742,8 @@
         sst.unregisterForDataConnectionAttached(mTestHandler);
 
         // set service state in service
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -736,15 +757,15 @@
     public void testRegAndUnregForDataConnDetach() throws Exception {
         // Initially set service state in service
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         sst.registerForDataConnectionDetached(mTestHandler, EVENT_DATA_CONNECTION_DETACHED, null);
 
         // set service state out of service and trigger events to post message on handler
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);
@@ -755,8 +776,8 @@
         assertEquals(EVENT_DATA_CONNECTION_DETACHED, messageArgumentCaptor.getValue().what);
 
         // set service state in service
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -765,8 +786,8 @@
         sst.unregisterForDataConnectionDetached(mTestHandler);
 
         // set service state out of service
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -778,7 +799,7 @@
     @Test
     @MediumTest
     public void testRegisterForDataRegStateOrRatChange() {
-        int drs = sst.mSS.RIL_REG_STATE_HOME;
+        int drs = NetworkRegistrationState.REG_STATE_HOME;
         int rat = sst.mSS.RIL_RADIO_TECHNOLOGY_LTE;
         sst.mSS.setRilDataRadioTechnology(rat);
         sst.mSS.setDataRegState(drs);
@@ -799,8 +820,8 @@
     public void testRegAndUnregForNetworkAttached() throws Exception {
         // Initially set service state out of service
         doReturn(true).when(mPhone).isPhoneTypeGsm();
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -808,8 +829,8 @@
         sst.registerForNetworkAttached(mTestHandler, EVENT_REGISTERED_TO_NETWORK, null);
 
         // set service state in service and trigger events to post message on handler
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -820,8 +841,8 @@
         assertEquals(EVENT_REGISTERED_TO_NETWORK, messageArgumentCaptor.getValue().what);
 
         // set service state out of service
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_UNKNOWN);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_UNKNOWN);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -830,8 +851,8 @@
         sst.unregisterForNetworkAttached(mTestHandler);
 
         // set service state in service
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -854,8 +875,8 @@
         sst.registerForNetworkAttached(mTestHandler, EVENT_REGISTERED_TO_NETWORK, null);
 
         // set service state in service and trigger events to post message on handler
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -881,8 +902,8 @@
         sst.registerForNetworkAttached(mTestHandler, EVENT_REGISTERED_TO_NETWORK, null);
 
         // set service state in service
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(100);
@@ -1021,8 +1042,8 @@
         // Enable roaming
         doReturn(true).when(mPhone).isPhoneTypeGsm();
 
-        mSimulatedCommands.setVoiceRegState(ServiceState.RIL_REG_STATE_ROAMING);
-        mSimulatedCommands.setDataRegState(ServiceState.RIL_REG_STATE_ROAMING);
+        mSimulatedCommands.setVoiceRegState(NetworkRegistrationState.REG_STATE_ROAMING);
+        mSimulatedCommands.setDataRegState(NetworkRegistrationState.REG_STATE_ROAMING);
         mSimulatedCommands.notifyNetworkStateChanged();
 
         waitForMs(200);