Merge "Remove redundant code" into main
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 60d93b6..839d8cb 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -9454,17 +9454,17 @@
             enforceModifyPermission();
         }
 
-        if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
-                && null != callingPackage && opEnableMobileDataByUser()) {
-            mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, Binder.getCallingUid(),
-                    callingPackage, null, null);
-        }
-
         enforceTelephonyFeatureWithException(callingPackage,
                 PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason");
 
+        int callingUid = Binder.getCallingUid();
         final long identity = Binder.clearCallingIdentity();
         try {
+            if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled
+                    && null != callingPackage && opEnableMobileDataByUser()) {
+                mAppOps.noteOp(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER,
+                        callingUid, callingPackage, null, null);
+            }
             Phone phone = getPhone(subId);
             if (phone != null) {
                 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
@@ -13670,20 +13670,43 @@
     }
 
     /**
-     * This API can be used by only CTS to update the timeout duration in milliseconds whether
-     * the device is aligned with the satellite for demo mode
+     * This API can be used by only CTS to override the timeout durations used by the
+     * DatagramController module.
      *
      * @param timeoutMillis The timeout duration in millisecond.
      * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
      */
-    public boolean setSatelliteDeviceAlignedTimeoutDuration(long timeoutMillis) {
-        Log.d(LOG_TAG, "setDeviceAlignedTimeoutDuration - " + timeoutMillis);
+    public boolean setDatagramControllerTimeoutDuration(
+            boolean reset, int timeoutType, long timeoutMillis) {
+        Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset="
+                + reset + ", timeoutMillis=" + timeoutMillis);
         TelephonyPermissions.enforceShellOnly(
-                Binder.getCallingUid(), "setDeviceAlignedTimeoutDuration");
+                Binder.getCallingUid(), "setDatagramControllerTimeoutDuration");
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
                 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
-                "setDeviceAlignedTimeoutDuration");
-        return mSatelliteController.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
+                "setDatagramControllerTimeoutDuration");
+        return mSatelliteController.setDatagramControllerTimeoutDuration(
+                reset, timeoutType, timeoutMillis);
+    }
+
+    /**
+     * This API can be used by only CTS to override the timeout durations used by the
+     * SatelliteController module.
+     *
+     * @param timeoutMillis The timeout duration in millisecond.
+     * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise.
+     */
+    public boolean setSatelliteControllerTimeoutDuration(
+            boolean reset, int timeoutType, long timeoutMillis) {
+        Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset="
+                + reset + ", timeoutMillis=" + timeoutMillis);
+        TelephonyPermissions.enforceShellOnly(
+                Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration");
+        TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
+                SubscriptionManager.INVALID_SUBSCRIPTION_ID,
+                "setSatelliteControllerTimeoutDuration");
+        return mSatelliteController.setSatelliteControllerTimeoutDuration(
+                reset, timeoutType, timeoutMillis);
     }
 
     /**
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index 3e3d31d..c55cc6c 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -191,8 +191,11 @@
             "set-satellite-listening-timeout-duration";
     private static final String SET_SATELLITE_POINTING_UI_CLASS_NAME =
             "set-satellite-pointing-ui-class-name";
-    private static final String SET_SATELLITE_DEVICE_ALIGNED_TIMEOUT_DURATION =
-            "set-satellite-device-aligned-timeout-duration";
+    private static final String SET_DATAGRAM_CONTROLLER_TIMEOUT_DURATION =
+            "set-datagram-controller-timeout-duration";
+
+    private static final String SET_SATELLITE_CONTROLLER_TIMEOUT_DURATION =
+            "set-satellite-controller-timeout-duration";
     private static final String SET_EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE =
             "set-emergency-call-to-satellite-handover-type";
     private static final String SET_COUNTRY_CODES = "set-country-codes";
@@ -397,8 +400,10 @@
                 return handleSetSatelliteListeningTimeoutDuration();
             case SET_SATELLITE_POINTING_UI_CLASS_NAME:
                 return handleSetSatellitePointingUiClassNameCommand();
-            case SET_SATELLITE_DEVICE_ALIGNED_TIMEOUT_DURATION:
-                return handleSettSatelliteDeviceAlignedTimeoutDuration();
+            case SET_DATAGRAM_CONTROLLER_TIMEOUT_DURATION:
+                return handleSetDatagramControllerTimeoutDuration();
+            case SET_SATELLITE_CONTROLLER_TIMEOUT_DURATION:
+                return handleSetSatelliteControllerTimeoutDuration();
             case SET_EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE:
                 return handleSetEmergencyCallToSatelliteHandoverType();
             case SET_SHOULD_SEND_DATAGRAM_TO_MODEM_IN_DEMO_MODE:
@@ -3368,31 +3373,85 @@
         return 0;
     }
 
-    private int handleSettSatelliteDeviceAlignedTimeoutDuration() {
+    private int handleSetDatagramControllerTimeoutDuration() {
         PrintWriter errPw = getErrPrintWriter();
+        boolean reset = false;
+        int timeoutType = 0;
         long timeoutMillis = 0;
 
         String opt;
         while ((opt = getNextOption()) != null) {
             switch (opt) {
-                case "-t": {
+                case "-d": {
                     timeoutMillis = Long.parseLong(getNextArgRequired());
                     break;
                 }
+                case "-r": {
+                    reset = true;
+                    break;
+                }
+                case "-t": {
+                    timeoutType = Integer.parseInt(getNextArgRequired());
+                    break;
+                }
             }
         }
-        Log.d(LOG_TAG, "handleSettSatelliteDeviceAlignedTimeoutDuration: timeoutMillis="
-                + timeoutMillis);
+        Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration: timeoutMillis="
+                + timeoutMillis + ", reset=" + reset + ", timeoutType=" + timeoutType);
 
         try {
-            boolean result = mInterface.setSatelliteDeviceAlignedTimeoutDuration(timeoutMillis);
+            boolean result = mInterface.setDatagramControllerTimeoutDuration(
+                    reset, timeoutType, timeoutMillis);
             if (VDBG) {
-                Log.v(LOG_TAG, "setSatelliteDeviceAlignedTimeoutDuration " + timeoutMillis
+                Log.v(LOG_TAG, "setDatagramControllerTimeoutDuration " + timeoutMillis
                         + ", result = " + result);
             }
             getOutPrintWriter().println(result);
         } catch (RemoteException e) {
-            Log.w(LOG_TAG, "setSatelliteDeviceAlignedTimeoutDuration: " + timeoutMillis
+            Log.w(LOG_TAG, "setDatagramControllerTimeoutDuration: " + timeoutMillis
+                    + ", error = " + e.getMessage());
+            errPw.println("Exception: " + e.getMessage());
+            return -1;
+        }
+        return 0;
+    }
+
+    private int handleSetSatelliteControllerTimeoutDuration() {
+        PrintWriter errPw = getErrPrintWriter();
+        boolean reset = false;
+        int timeoutType = 0;
+        long timeoutMillis = 0;
+
+        String opt;
+        while ((opt = getNextOption()) != null) {
+            switch (opt) {
+                case "-d": {
+                    timeoutMillis = Long.parseLong(getNextArgRequired());
+                    break;
+                }
+                case "-r": {
+                    reset = true;
+                    break;
+                }
+                case "-t": {
+                    timeoutType = Integer.parseInt(getNextArgRequired());
+                    break;
+                }
+            }
+        }
+        Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration: timeoutMillis="
+                + timeoutMillis + ", reset=" + reset + ", timeoutType=" + timeoutType);
+
+        try {
+            boolean result = mInterface.setSatelliteControllerTimeoutDuration(
+                    reset, timeoutType, timeoutMillis);
+            if (VDBG) {
+                Log.v(LOG_TAG, "setSatelliteControllerTimeoutDuration " + timeoutMillis
+                        + ", result = " + result);
+            }
+            getOutPrintWriter().println(result);
+        } catch (RemoteException e) {
+            Log.w(LOG_TAG, "setSatelliteControllerTimeoutDuration: " + timeoutMillis
                     + ", error = " + e.getMessage());
             errPw.println("Exception: " + e.getMessage());
             return -1;
diff --git a/src/com/android/services/telephony/domainselection/NormalCallDomainSelector.java b/src/com/android/services/telephony/domainselection/NormalCallDomainSelector.java
index ede2af4..31a1cc2 100644
--- a/src/com/android/services/telephony/domainselection/NormalCallDomainSelector.java
+++ b/src/com/android/services/telephony/domainselection/NormalCallDomainSelector.java
@@ -34,6 +34,8 @@
 import android.telephony.TransportSelectorCallback;
 import android.telephony.ims.ImsReasonInfo;
 
+import com.android.internal.annotations.VisibleForTesting;
+
 /**
  * Implements domain selector for outgoing non-emergency calls.
  */
@@ -42,14 +44,15 @@
 
     private static final String LOG_TAG = "NCDS";
 
-    private enum SelectorState {
+    @VisibleForTesting
+    protected enum SelectorState {
         ACTIVE,
         INACTIVE,
         DESTROYED
     };
 
-    private SelectorState mSelectorState = SelectorState.INACTIVE;
-    private ServiceState mServiceState;
+    protected SelectorState mSelectorState = SelectorState.INACTIVE;
+    protected ServiceState mServiceState;
     private boolean mImsRegStateReceived;
     private boolean mMmTelCapabilitiesReceived;
     private boolean mReselectDomain;
@@ -75,6 +78,7 @@
         mSelectorState = SelectorState.ACTIVE;
 
         if (callback == null) {
+            mSelectorState = SelectorState.INACTIVE;
             loge("Invalid params: TransportSelectorCallback is null");
             return;
         }
@@ -101,6 +105,7 @@
             logd("NormalCallDomainSelection triggered. Sub-id:" + subId);
             post(() -> selectDomain());
         } else {
+            mSelectorState = SelectorState.INACTIVE;
             loge("Subscription-ids doesn't match. This instance is associated with sub-id:"
                     + getSubId() + ", requested sub-id:" + subId);
             // TODO: Throw anamoly here. This condition should never occur.
@@ -135,9 +140,20 @@
     @Override
     public void destroy() {
         logd("destroy");
-        if (mSelectorState == SelectorState.INACTIVE) {
-            mSelectorState = SelectorState.DESTROYED;
-            super.destroy();
+        switch (mSelectorState) {
+            case INACTIVE:
+                mSelectorState = SelectorState.DESTROYED;
+                super.destroy();
+                break;
+
+            case ACTIVE:
+                loge("destroy is called when selector state is in ACTIVE state");
+                cancelSelection();
+                break;
+
+            case DESTROYED:
+                super.destroy();
+                break;
         }
     }
 
@@ -411,4 +427,9 @@
             }
         }
     }
+
+    @VisibleForTesting
+    public SelectorState getSelectorState() {
+        return mSelectorState;
+    }
 }
diff --git a/testapps/GbaTestApp/res/values-eu/strings.xml b/testapps/GbaTestApp/res/values-eu/strings.xml
index 6774d99..c192a56 100644
--- a/testapps/GbaTestApp/res/values-eu/strings.xml
+++ b/testapps/GbaTestApp/res/values-eu/strings.xml
@@ -20,10 +20,10 @@
     <string name="request_naf_url" msgid="4487793541217737042">"Sareko aplikazioaren funtzioaren (NAF) URLa"</string>
     <string name="request_force_bootstrapping" msgid="206043602616214325">"Bootstrapping-a erabiltzera behartu nahi duzu?"</string>
     <string name="request_org" msgid="8416693445448308975">"Erakundearen kodea"</string>
-    <string name="request_security_protocol" msgid="1444164827561010482">"UA segurtasun-protokoloaren IDa"</string>
+    <string name="request_security_protocol" msgid="1444164827561010482">"UA segurtasun-protokoloaren identifikatzailea"</string>
     <string name="request_tls_cipher_suite" msgid="6659854717595308404">"TLS Cipher Suite ID"</string>
     <string name="response_success" msgid="2469204471244527663">"Burutu da GBA autentifikazioa?"</string>
-    <string name="response_fail_reason" msgid="3401426967253202496">"Hutsegitearen arrazoiaren IDa"</string>
+    <string name="response_fail_reason" msgid="3401426967253202496">"Hutsegitearen arrazoiaren identifikatzailea"</string>
     <string name="response_key" msgid="8839847772051686309">"GBA-ko gakoa (CK + IK)"</string>
     <string name="response_btid" msgid="2550216722679350756">"Bootstrapping Transaction Identifier (B-TID)"</string>
     <string name="sample_naf" msgid="255371174145881001">"3GPP-bootstrapping@naf1.operator.com"</string>
diff --git a/testapps/TestSatelliteApp/res/layout/activity_TestSatelliteWrapper.xml b/testapps/TestSatelliteApp/res/layout/activity_TestSatelliteWrapper.xml
index c136ce7..7f2f026 100644
--- a/testapps/TestSatelliteApp/res/layout/activity_TestSatelliteWrapper.xml
+++ b/testapps/TestSatelliteApp/res/layout/activity_TestSatelliteWrapper.xml
@@ -14,91 +14,157 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License
   -->
-
-<LinearLayout
+<ScrollView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:orientation="vertical"
-    android:gravity="center"
-    android:paddingStart="4dp">
+    android:layout_height="match_parent">
 
-    <TextView
-        android:layout_width="wrap_content"
-        android:layout_height="0dp"
-        android:layout_weight="0"
-        android:textColor="@android:color/holo_blue_dark"
-        android:textSize="20dp"
-        android:text="Satellite Wrapper Test"/>
-    <Button
-        android:id="@+id/requestNtnSignalStrength"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingRight="4dp"
-        android:text="@string/requestNtnSignalStrength"/>
-    <Button
-        android:id="@+id/registerForNtnSignalStrengthChanged"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingRight="4dp"
-        android:text="@string/registerForNtnSignalStrengthChanged"/>
-    <Button
-        android:id="@+id/unregisterForNtnSignalStrengthChanged"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingRight="4dp"
-        android:text="@string/unregisterForNtnSignalStrengthChanged"/>
-    <Button
-        android:id="@+id/isOnlyNonTerrestrialNetworkSubscription"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingRight="4dp"
-        android:text="@string/isOnlyNonTerrestrialNetworkSubscription"/>
-    <Button
-        android:id="@+id/registerForSatelliteCapabilitiesChanged"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingRight="4dp"
-        android:text="@string/registerForSatelliteCapabilitiesChanged"/>
-    <Button
-        android:id="@+id/unregisterForSatelliteCapabilitiesChanged"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingRight="4dp"
-        android:text="@string/unregisterForSatelliteCapabilitiesChanged"/>
     <LinearLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:orientation="horizontal">
-         <Button
-            android:id="@+id/Back"
-            android:onClick="Back"
+        android:orientation="vertical"
+        android:gravity="center"
+        android:paddingStart="4dp">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="0dp"
+            android:layout_weight="0"
             android:textColor="@android:color/holo_blue_dark"
-            android:layout_marginTop="10dp"
-            android:layout_marginBottom="10dp"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:paddingRight="4dp"
-            android:text="@string/Back"/>
+            android:textSize="20dp"
+            android:text="Satellite Wrapper Test"/>
         <Button
-            android:id="@+id/ClearLog"
-            android:onClick="ClearLog"
-            android:textColor="@android:color/holo_blue_dark"
-            android:layout_marginTop="10dp"
-            android:layout_marginBottom="10dp"
-            android:layout_width="0dp"
+            android:id="@+id/requestNtnSignalStrength"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_weight="1"
             android:paddingRight="4dp"
-            android:text="@string/ClearLog"/>
+            android:text="@string/requestNtnSignalStrength"/>
+        <Button
+            android:id="@+id/registerForNtnSignalStrengthChanged"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/registerForNtnSignalStrengthChanged"/>
+        <Button
+            android:id="@+id/unregisterForNtnSignalStrengthChanged"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/unregisterForNtnSignalStrengthChanged"/>
+        <Button
+            android:id="@+id/isOnlyNonTerrestrialNetworkSubscription"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/isOnlyNonTerrestrialNetworkSubscription"/>
+        <Button
+            android:id="@+id/registerForSatelliteCapabilitiesChanged"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/registerForSatelliteCapabilitiesChanged"/>
+        <Button
+            android:id="@+id/unregisterForSatelliteCapabilitiesChanged"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/unregisterForSatelliteCapabilitiesChanged"/>
+        <Button
+            android:id="@+id/isNonTerrestrialNetwork"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/isNonTerrestrialNetwork"/>
+        <Button
+            android:id="@+id/getAvailableServices"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/getAvailableServices"/>
+        <Button
+            android:id="@+id/isUsingNonTerrestrialNetwork"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/isUsingNonTerrestrialNetwork"/>
+        <Button
+            android:id="@+id/requestAttachEnabledForCarrier_enable"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/requestAttachEnabledForCarrier_enable"/>
+        <Button
+            android:id="@+id/requestAttachEnabledForCarrier_disable"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/requestAttachEnabledForCarrier_disable"/>
+        <Button
+            android:id="@+id/requestIsAttachEnabledForCarrier"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/requestIsAttachEnabledForCarrier"/>
+        <Button
+            android:id="@+id/addAttachRestrictionForCarrier"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/addAttachRestrictionForCarrier"/>
+        <Button
+            android:id="@+id/removeAttachRestrictionForCarrier"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/removeAttachRestrictionForCarrier"/>
+        <Button
+            android:id="@+id/getAttachRestrictionReasonsForCarrier"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/getAttachRestrictionReasonsForCarrier"/>
+        <Button
+            android:id="@+id/getSatellitePlmnsForCarrier"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/getSatellitePlmnsForCarrier"/>
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal">
+             <Button
+                android:id="@+id/Back"
+                android:onClick="Back"
+                android:textColor="@android:color/holo_blue_dark"
+                android:layout_marginTop="10dp"
+                android:layout_marginBottom="10dp"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:paddingRight="4dp"
+                android:text="@string/Back"/>
+            <Button
+                android:id="@+id/ClearLog"
+                android:onClick="ClearLog"
+                android:textColor="@android:color/holo_blue_dark"
+                android:layout_marginTop="10dp"
+                android:layout_marginBottom="10dp"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:paddingRight="4dp"
+                android:text="@string/ClearLog"/>
+        </LinearLayout>
+        <ListView
+            android:id="@+id/logListView"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:capitalize="characters"
+            android:textColor="@android:color/holo_blue_light"
+            android:layout_centerVertical="true"
+            android:textSize="8dp" />
     </LinearLayout>
-    <ListView
-        android:id="@+id/logListView"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:capitalize="characters"
-        android:textColor="@android:color/holo_blue_light"
-        android:layout_centerVertical="true"
-        android:textSize="8dp" />
-</LinearLayout>
+
+</ScrollView>
\ No newline at end of file
diff --git a/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml b/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
index 6c707dd..20f5ca8 100644
--- a/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
+++ b/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
@@ -64,6 +64,16 @@
     <string name="isOnlyNonTerrestrialNetworkSubscription">isOnlyNonTerrestrialNetworkSubscription</string>
     <string name="registerForSatelliteCapabilitiesChanged">registerForSatelliteCapabilitiesChanged</string>
     <string name="unregisterForSatelliteCapabilitiesChanged">unregisterForSatelliteCapabilitiesChanged</string>
+    <string name="isNonTerrestrialNetwork">isNonTerrestrialNetwork</string>
+    <string name="getAvailableServices">getAvailableServices</string>
+    <string name="isUsingNonTerrestrialNetwork">isUsingNonTerrestrialNetwork</string>
+    <string name="requestAttachEnabledForCarrier_enable">requestAttachEnabledForCarrier_enable</string>
+    <string name="requestAttachEnabledForCarrier_disable">requestAttachEnabledForCarrier_disable</string>
+    <string name="requestIsAttachEnabledForCarrier">requestIsAttachEnabledForCarrier</string>
+    <string name="addAttachRestrictionForCarrier">addAttachRestrictionForCarrier</string>
+    <string name="removeAttachRestrictionForCarrier">removeAttachRestrictionForCarrier</string>
+    <string name="getAttachRestrictionReasonsForCarrier">getAttachRestrictionReasonsForCarrier</string>
+    <string name="getSatellitePlmnsForCarrier">getSatellitePlmnsForCarrier</string>
 
     <string name="removeUserRestrictReason">removeUserRestrictReason</string>
     <string name="addUserRestrictReason">addUserRestrictReason</string>
diff --git a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
index e4c2005..4f0679d 100644
--- a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
+++ b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
@@ -36,8 +36,10 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.function.Consumer;
 import java.util.stream.Collectors;
 
 /**
@@ -53,6 +55,7 @@
     private NtnSignalStrengthCallback mNtnSignalStrengthCallback = null;
     private SatelliteCapabilitiesCallbackWrapper mSatelliteCapabilitiesCallback;
     private SubscriptionManager mSubscriptionManager;
+    private int mSubId;
 
     private ListView mLogListView;
 
@@ -61,6 +64,7 @@
         super.onCreate(savedInstanceState);
         mSatelliteManagerWrapper = SatelliteManagerWrapper.getInstance(this);
         mSubscriptionManager = getSystemService(SubscriptionManager.class);
+        mSubId = getActiveSubId();
 
         setContentView(R.layout.activity_TestSatelliteWrapper);
         findViewById(R.id.requestNtnSignalStrength)
@@ -75,6 +79,26 @@
                 .setOnClickListener(this::registerForCapabilitiesChanged);
         findViewById(R.id.unregisterForSatelliteCapabilitiesChanged)
                 .setOnClickListener(this::unregisterForCapabilitiesChanged);
+        findViewById(R.id.isNonTerrestrialNetwork)
+                .setOnClickListener(this::isNonTerrestrialNetwork);
+        findViewById(R.id.getAvailableServices)
+                .setOnClickListener(this::getAvailableServices);
+        findViewById(R.id.isUsingNonTerrestrialNetwork)
+                .setOnClickListener(this::isUsingNonTerrestrialNetwork);
+        findViewById(R.id.requestAttachEnabledForCarrier_enable)
+                .setOnClickListener(this::requestAttachEnabledForCarrier_enable);
+        findViewById(R.id.requestAttachEnabledForCarrier_disable)
+                .setOnClickListener(this::requestAttachEnabledForCarrier_disable);
+        findViewById(R.id.requestIsAttachEnabledForCarrier)
+                .setOnClickListener(this::requestIsAttachEnabledForCarrier);
+        findViewById(R.id.addAttachRestrictionForCarrier)
+                .setOnClickListener(this::addAttachRestrictionForCarrier);
+        findViewById(R.id.removeAttachRestrictionForCarrier)
+                .setOnClickListener(this::removeAttachRestrictionForCarrier);
+        findViewById(R.id.getAttachRestrictionReasonsForCarrier)
+                .setOnClickListener(this::getAttachRestrictionReasonsForCarrier);
+        findViewById(R.id.getSatellitePlmnsForCarrier)
+                .setOnClickListener(this::getSatellitePlmnsForCarrier);
         findViewById(R.id.Back).setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View view) {
@@ -107,21 +131,24 @@
 
         if (mSatelliteManagerWrapper != null) {
             if (mNtnSignalStrengthCallback != null) {
-                Log.d(TAG, "unregisterForNtnSignalStrengthChanged()");
+                logd("unregisterForNtnSignalStrengthChanged()");
                 mSatelliteManagerWrapper.unregisterForNtnSignalStrengthChanged(
                         mNtnSignalStrengthCallback);
             }
             if (mSatelliteCapabilitiesCallback != null) {
-                Log.d(TAG, "unregisterForCapabilitiesChanged()");
+                logd("unregisterForCapabilitiesChanged()");
                 mSatelliteManagerWrapper.unregisterForCapabilitiesChanged(
                         mSatelliteCapabilitiesCallback);
             }
         }
+        mSubscriptionManager = null;
+        mSatelliteManagerWrapper = null;
+        mExecutor.shutdown();
     }
 
     private void requestNtnSignalStrength(View view) {
         addLogMessage("requestNtnSignalStrength");
-        Log.d(TAG, "requestNtnSignalStrength");
+        logd("requestNtnSignalStrength");
         OutcomeReceiver<NtnSignalStrengthWrapper,
                 SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver =
                 new OutcomeReceiver<>() {
@@ -138,7 +165,7 @@
                         if (exception != null) {
                             String onError = "requestNtnSignalStrength exception: "
                                     + translateResultCodeToString(exception.getErrorCode());
-                            Log.d(TAG, onError);
+                            logd(onError);
                             addLogMessage(onError);
                         }
                     }
@@ -148,16 +175,16 @@
             mSatelliteManagerWrapper.requestNtnSignalStrength(mExecutor, receiver);
         } catch (SecurityException ex) {
             String errorMessage = "requestNtnSignalStrength: " + ex.getMessage();
-            Log.d(TAG, errorMessage);
+            logd(errorMessage);
             addLogMessage(errorMessage);
         }
     }
 
     private void registerForNtnSignalStrengthChanged(View view) {
         addLogMessage("registerForNtnSignalStrengthChanged");
-        Log.d(TAG, "registerForNtnSignalStrengthChanged()");
+        logd("registerForNtnSignalStrengthChanged()");
         if (mNtnSignalStrengthCallback == null) {
-            Log.d(TAG, "create new NtnSignalStrengthCallback instance.");
+            logd("create new NtnSignalStrengthCallback instance.");
             mNtnSignalStrengthCallback = new NtnSignalStrengthCallback();
         }
 
@@ -166,7 +193,7 @@
                     mNtnSignalStrengthCallback);
         } catch (Exception ex) {
             String errorMessage = "registerForNtnSignalStrengthChanged: " + ex.getMessage();
-            Log.d(TAG, errorMessage);
+            logd(errorMessage);
             addLogMessage(errorMessage);
             mNtnSignalStrengthCallback = null;
         }
@@ -174,7 +201,7 @@
 
     private void unregisterForNtnSignalStrengthChanged(View view) {
         addLogMessage("unregisterForNtnSignalStrengthChanged");
-        Log.d(TAG, "unregisterForNtnSignalStrengthChanged()");
+        logd("unregisterForNtnSignalStrengthChanged()");
         if (mNtnSignalStrengthCallback != null) {
             mSatelliteManagerWrapper.unregisterForNtnSignalStrengthChanged(
                     mNtnSignalStrengthCallback);
@@ -187,7 +214,7 @@
 
     private void isOnlyNonTerrestrialNetworkSubscription(View view) {
         addLogMessage("isOnlyNonTerrestrialNetworkSubscription");
-        Log.d(TAG, "isOnlyNonTerrestrialNetworkSubscription()");
+        logd("isOnlyNonTerrestrialNetworkSubscription()");
         List<SubscriptionInfo> infoList = mSubscriptionManager.getAvailableSubscriptionInfoList();
         List<Integer> subIdList = infoList.stream()
                 .map(SubscriptionInfo::getSubscriptionId)
@@ -214,13 +241,13 @@
 
     private void registerForCapabilitiesChanged(View view) {
         addLogMessage("registerForCapabilitiesChanged");
-        Log.d(TAG, "registerForCapabilitiesChanged()");
+        logd("registerForCapabilitiesChanged()");
         if (mSatelliteCapabilitiesCallback == null) {
             mSatelliteCapabilitiesCallback =
                     SatelliteCapabilities -> {
                         String message = "Received SatelliteCapabillities : "
                                 + SatelliteCapabilities;
-                        Log.d(TAG, message);
+                        logd(message);
                         runOnUiThread(() -> addLogMessage(message));
                     };
         }
@@ -229,7 +256,7 @@
                 mSatelliteCapabilitiesCallback);
         if (result != SatelliteManagerWrapper.SATELLITE_RESULT_SUCCESS) {
             String onError = translateResultCodeToString(result);
-            Log.d(TAG, onError);
+            logd(onError);
             addLogMessage(onError);
             mSatelliteCapabilitiesCallback = null;
         }
@@ -237,7 +264,7 @@
 
     private void unregisterForCapabilitiesChanged(View view) {
         addLogMessage("unregisterForCapabilitiesChanged");
-        Log.d(TAG, "unregisterForCapabilitiesChanged()");
+        logd("unregisterForCapabilitiesChanged()");
         if (mSatelliteCapabilitiesCallback != null) {
             mSatelliteManagerWrapper.unregisterForCapabilitiesChanged(
                     mSatelliteCapabilitiesCallback);
@@ -253,11 +280,238 @@
         public void onNtnSignalStrengthChanged(
                 @NonNull NtnSignalStrengthWrapper ntnSignalStrength) {
             String message = "Received NTN SignalStrength : " + ntnSignalStrength.getLevel();
-            Log.d(TAG, message);
+            logd(message);
             runOnUiThread(() -> addLogMessage(message));
         }
     }
 
+    private void isNonTerrestrialNetwork(View view) {
+        boolean isNonTerrestrialNetwork = mSatelliteManagerWrapper.isNonTerrestrialNetwork(mSubId);
+        addLogMessage("isNonTerrestrialNetwork=" + isNonTerrestrialNetwork);
+        logd("isNonTerrestrialNetwork=" + isNonTerrestrialNetwork);
+    }
+
+    private void getAvailableServices(View view) {
+        List<Integer> as = mSatelliteManagerWrapper.getAvailableServices(mSubId);
+        String availableServices = as.stream().map(Object::toString).collect(
+                Collectors.joining(", "));
+        addLogMessage("getAvailableServices=" + availableServices);
+        logd("getAvailableServices=" + availableServices);
+    }
+
+    private void isUsingNonTerrestrialNetwork(View view) {
+        boolean isUsingNonTerrestrialNetwork =
+                mSatelliteManagerWrapper.isUsingNonTerrestrialNetwork(mSubId);
+        addLogMessage("isUsingNonTerrestrialNetwork=" + isUsingNonTerrestrialNetwork);
+        logd("isUsingNonTerrestrialNetwork=" + isUsingNonTerrestrialNetwork);
+    }
+
+    private void requestAttachEnabledForCarrier_enable(View view) {
+        addLogMessage("requestAttachEnabledForCarrier");
+        logd("requestAttachEnabledForCarrier");
+
+        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            addLogMessage("requestAttachEnabledForCarrier: Subscription ID is invalid");
+            logd("requestAttachEnabledForCarrier: Subscription ID is invalid");
+            return;
+        }
+
+        Consumer<Integer> callback = result -> {
+            runOnUiThread(() -> addLogMessage("requestAttachEnabledForCarrier result: " + result));
+            logd("requestAttachEnabledForCarrier result: " + result);
+        };
+
+        try {
+            mSatelliteManagerWrapper.requestAttachEnabledForCarrier(mSubId, true, mExecutor,
+                    callback);
+        } catch (SecurityException | IllegalArgumentException ex) {
+            String errorMessage = "requestAttachEnabledForCarrier: " + ex.getMessage();
+            logd(errorMessage);
+            addLogMessage(errorMessage);
+        }
+    }
+
+    private void requestAttachEnabledForCarrier_disable(View view) {
+        addLogMessage("requestAttachEnabledForCarrier");
+        logd("requestAttachEnabledForCarrier");
+
+        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            addLogMessage("requestAttachEnabledForCarrier: Subscription ID is invalid");
+            logd("requestAttachEnabledForCarrier: Subscription ID is invalid");
+            return;
+        }
+
+        Consumer<Integer> callback = result -> {
+            runOnUiThread(() -> addLogMessage("requestAttachEnabledForCarrier result: " + result));
+            logd("requestAttachEnabledForCarrier result: " + result);
+        };
+
+        try {
+            mSatelliteManagerWrapper.requestAttachEnabledForCarrier(mSubId, false, mExecutor,
+                    callback);
+        } catch (SecurityException | IllegalArgumentException ex) {
+            String errorMessage = "requestAttachEnabledForCarrier: " + ex.getMessage();
+            logd(errorMessage);
+            addLogMessage(errorMessage);
+        }
+    }
+
+    private void requestIsAttachEnabledForCarrier(View view) {
+        logd("requestIsAttachEnabledForCarrier");
+        addLogMessage("requestIsAttachEnabledForCarrier");
+
+        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            addLogMessage("requestIsAttachEnabledForCarrier: Subscription ID is invalid");
+            logd("requestIsAttachEnabledForCarrier: Subscription ID is invalid");
+            return;
+        }
+
+        OutcomeReceiver<Boolean,
+                SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver =
+                new OutcomeReceiver<>() {
+                    @Override
+                    public void onResult(Boolean result) {
+                        logd("requestIsAttachEnabledForCarrier: onResult=" + result);
+                        addLogMessage("requestIsAttachEnabledForCarrier: onResult=" + result);
+                    }
+
+                    @Override
+                    public void onError(
+                            SatelliteManagerWrapper.SatelliteExceptionWrapper exception) {
+                        if (exception != null) {
+                            String onError = "requestIsAttachEnabledForCarrier exception: "
+                                    + translateResultCodeToString(exception.getErrorCode());
+                            logd(onError);
+                            addLogMessage(onError);
+                        }
+                    }
+                };
+
+        try {
+            mSatelliteManagerWrapper.requestIsAttachEnabledForCarrier(mSubId, mExecutor, receiver);
+        } catch (SecurityException | IllegalStateException | IllegalArgumentException ex) {
+            String errorMessage = "requestIsAttachEnabledForCarrier: " + ex.getMessage();
+            logd(errorMessage);
+            addLogMessage(errorMessage);
+        }
+    }
+
+    private void addAttachRestrictionForCarrier(View view) {
+        addLogMessage("addAttachRestrictionForCarrier");
+        logd("addAttachRestrictionForCarrier");
+
+        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            addLogMessage("addAttachRestrictionForCarrier: Subscription ID is invalid");
+            logd("addAttachRestrictionForCarrier: Subscription ID is invalid");
+            return;
+        }
+
+        int reason = SatelliteManagerWrapper.SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER;
+
+        Consumer<Integer> callback = result -> {
+            runOnUiThread(() -> addLogMessage("addAttachRestrictionForCarrier result: " + result));
+            logd("addAttachRestrictionForCarrier result: " + result);
+        };
+
+        try {
+            mSatelliteManagerWrapper.addAttachRestrictionForCarrier(mSubId, reason, mExecutor,
+                    callback);
+        } catch (SecurityException | IllegalArgumentException ex) {
+            String errorMessage = "addAttachRestrictionForCarrier: " + ex.getMessage();
+            logd(errorMessage);
+            addLogMessage(errorMessage);
+        }
+    }
+
+    private void removeAttachRestrictionForCarrier(View view) {
+        addLogMessage("removeAttachRestrictionForCarrier");
+        logd("removeAttachRestrictionForCarrier");
+
+        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            addLogMessage("removeAttachRestrictionForCarrier: Subscription ID is invalid");
+            logd("removeAttachRestrictionForCarrier: Subscription ID is invalid");
+            return;
+        }
+
+        int reason = SatelliteManagerWrapper.SATELLITE_COMMUNICATION_RESTRICTION_REASON_USER;
+
+        Consumer<Integer> callback = result -> {
+            runOnUiThread(
+                    () -> addLogMessage("removeAttachRestrictionForCarrier result: " + result));
+            logd("removeAttachRestrictionForCarrier result: " + result);
+        };
+
+        try {
+            mSatelliteManagerWrapper.removeAttachRestrictionForCarrier(mSubId, reason, mExecutor,
+                    callback);
+        } catch (SecurityException | IllegalArgumentException ex) {
+            String errorMessage = "removeAttachRestrictionForCarrier: " + ex.getMessage();
+            logd(errorMessage);
+            addLogMessage(errorMessage);
+        }
+    }
+
+    private void getAttachRestrictionReasonsForCarrier(View view) {
+        addLogMessage("getAttachRestrictionReasonsForCarrier");
+        logd("getAttachRestrictionReasonsForCarrier");
+
+        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            addLogMessage("getAttachRestrictionReasonsForCarrier: Subscription ID is invalid");
+            logd("getAttachRestrictionReasonsForCarrier: Subscription ID is invalid");
+            return;
+        }
+
+        try {
+            Set<Integer> reasons = mSatelliteManagerWrapper.getAttachRestrictionReasonsForCarrier(
+                    mSubId);
+            String stringReasons = reasons.stream().map(Object::toString).collect(
+                    Collectors.joining(", "));
+            logd("getAttachRestrictionReasonsForCarrier=" + stringReasons);
+            addLogMessage("getAttachRestrictionReasonsForCarrier=" + stringReasons);
+        } catch (SecurityException | IllegalArgumentException ex) {
+            String errorMessage = "getAttachRestrictionReasonsForCarrier: " + ex.getMessage();
+            logd(errorMessage);
+            addLogMessage(errorMessage);
+        }
+    }
+
+    private void getSatellitePlmnsForCarrier(View view) {
+        addLogMessage("getSatellitePlmnsForCarrier");
+        logd("getSatellitePlmnsForCarrier");
+
+        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            addLogMessage("getSatellitePlmnsForCarrier: Subscription ID is invalid");
+            logd("getSatellitePlmnsForCarrier: Subscription ID is invalid");
+            return;
+        }
+
+        try {
+            List<String> reasons = mSatelliteManagerWrapper.getSatellitePlmnsForCarrier(
+                    mSubId);
+            String stringReasons = reasons.stream().collect(Collectors.joining(", "));
+            logd("getSatellitePlmnsForCarrier=" + stringReasons);
+            addLogMessage("getSatellitePlmnsForCarrier=" + stringReasons);
+        } catch (SecurityException | IllegalArgumentException ex) {
+            String errorMessage = "getSatellitePlmnsForCarrier: " + ex.getMessage();
+            logd(errorMessage);
+            addLogMessage(errorMessage);
+        }
+    }
+
+    private int getActiveSubId() {
+        int subId;
+        List<SubscriptionInfo> subscriptionInfoList =
+                mSubscriptionManager.getActiveSubscriptionInfoList();
+
+        if (subscriptionInfoList != null && subscriptionInfoList.size() > 0) {
+            subId = subscriptionInfoList.get(0).getSubscriptionId();
+        } else {
+            subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+        }
+        logd("getActiveSubId() returns " + subId);
+        return subId;
+    }
+
     private String translateResultCodeToString(
             @SatelliteManagerWrapper.SatelliteResult int result) {
         switch (result) {
@@ -319,4 +573,10 @@
         mAdapter.notifyDataSetChanged();
         mLogListView.setSelection(mAdapter.getCount() - 1);
     }
+
+    private static void logd(String message) {
+        if (message != null) {
+            Log.d(TAG, message);
+        }
+    }
 }
diff --git a/tests/src/com/android/services/telephony/domainselection/NormalCallDomainSelectorTest.java b/tests/src/com/android/services/telephony/domainselection/NormalCallDomainSelectorTest.java
index 76a62af..6e438bf 100644
--- a/tests/src/com/android/services/telephony/domainselection/NormalCallDomainSelectorTest.java
+++ b/tests/src/com/android/services/telephony/domainselection/NormalCallDomainSelectorTest.java
@@ -153,9 +153,49 @@
     }
 
     @Test
+    public void testInitialState() {
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+    }
+
+    @Test
+    public void testDestroyedState() {
+        mNormalCallDomainSelector.destroy();
+
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.DESTROYED);
+    }
+
+    @Test
+    public void testDestroyedDuringActiveState() {
+        MockTransportSelectorCallback transportSelectorCallback =
+                new MockTransportSelectorCallback(mNormalCallDomainSelector);
+
+        DomainSelectionService.SelectionAttributes attributes =
+                new DomainSelectionService.SelectionAttributes.Builder(
+                        SLOT_ID, SUB_ID_1, SELECTOR_TYPE_CALLING)
+                        .setAddress(TEST_URI)
+                        .setCallId(TEST_CALLID)
+                        .setEmergency(false)
+                        .setVideoCall(true)
+                        .setExitedFromAirplaneMode(false)
+                        .build();
+
+        mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.ACTIVE);
+
+        mNormalCallDomainSelector.destroy();
+
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.DESTROYED);
+    }
+
+    @Test
     public void testSelectDomainInputParams() {
         MockTransportSelectorCallback transportSelectorCallback =
-                new MockTransportSelectorCallback();
+                new MockTransportSelectorCallback(mNormalCallDomainSelector);
 
         DomainSelectionService.SelectionAttributes attributes =
                 new DomainSelectionService.SelectionAttributes.Builder(
@@ -168,6 +208,8 @@
                         .build();
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.ACTIVE);
 
         // Case 1: null inputs
         try {
@@ -176,6 +218,9 @@
             fail("Invalid input params not handled." + e.getMessage());
         }
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         // Case 2: null TransportSelectorCallback
         try {
             mNormalCallDomainSelector.selectDomain(attributes, null);
@@ -183,6 +228,9 @@
             fail("Invalid params (SelectionAttributes) not handled." + e.getMessage());
         }
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         // Case 3: null SelectionAttributes
         transportSelectorCallback.mSelectionTerminated = false;
         try {
@@ -194,6 +242,9 @@
         assertTrue(transportSelectorCallback
                 .verifyOnSelectionTerminated(DisconnectCause.OUTGOING_FAILURE));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.DESTROYED);
+
         // Case 4: Invalid Subscription-id
         attributes = new DomainSelectionService.SelectionAttributes.Builder(
                 SLOT_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, SELECTOR_TYPE_CALLING)
@@ -212,6 +263,9 @@
         assertTrue(transportSelectorCallback
                 .verifyOnSelectionTerminated(DisconnectCause.OUTGOING_FAILURE));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.DESTROYED);
+
         // Case 5: Invalid SELECTOR_TYPE
         attributes =
                 new DomainSelectionService.SelectionAttributes.Builder(
@@ -231,6 +285,9 @@
         assertTrue(transportSelectorCallback
                 .verifyOnSelectionTerminated(DisconnectCause.OUTGOING_FAILURE));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.DESTROYED);
+
         // Case 6: Emergency Call
         attributes = new DomainSelectionService.SelectionAttributes.Builder(
                 SLOT_ID, SUB_ID_1, SELECTOR_TYPE_CALLING)
@@ -246,6 +303,9 @@
             fail("Invalid params (SelectionAttributes) not handled." + e.getMessage());
         }
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.DESTROYED);
+
         assertTrue(transportSelectorCallback
                 .verifyOnSelectionTerminated(DisconnectCause.OUTGOING_FAILURE));
     }
@@ -253,7 +313,7 @@
     @Test
     public void testOutOfService() {
         MockTransportSelectorCallback transportSelectorCallback =
-                new MockTransportSelectorCallback();
+                new MockTransportSelectorCallback(mNormalCallDomainSelector);
         DomainSelectionService.SelectionAttributes attributes =
                 new DomainSelectionService.SelectionAttributes.Builder(
                         SLOT_ID, SUB_ID_1, SELECTOR_TYPE_CALLING)
@@ -263,18 +323,24 @@
                         .setVideoCall(true)
                         .setExitedFromAirplaneMode(false)
                         .build();
+
         ServiceState serviceState = new ServiceState();
         serviceState.setStateOutOfService();
         initialize(serviceState, false, false, false, false);
+
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback
                 .verifyOnSelectionTerminated(DisconnectCause.OUT_OF_SERVICE));
+
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.DESTROYED);
     }
 
     @Test
     public void testDomainSelection() {
         MockTransportSelectorCallback transportSelectorCallback =
-                new MockTransportSelectorCallback();
+                new MockTransportSelectorCallback(mNormalCallDomainSelector);
         DomainSelectionService.SelectionAttributes attributes =
                 new DomainSelectionService.SelectionAttributes.Builder(
                         SLOT_ID, SUB_ID_1, SELECTOR_TYPE_CALLING)
@@ -289,17 +355,28 @@
         ServiceState serviceState = new ServiceState();
         serviceState.setState(ServiceState.STATE_IN_SERVICE);
         initialize(serviceState, true, true, true, true);
+
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWlanSelected());
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         // Case 2: 5G
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         initialize(serviceState, true, false, true, true);
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWwanSelected());
+
         assertTrue(transportSelectorCallback
                 .verifyOnDomainSelected(NetworkRegistrationInfo.DOMAIN_PS));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         // Case 3: PS -> CS redial
         ImsReasonInfo imsReasonInfo = new ImsReasonInfo();
         imsReasonInfo.mCode = ImsReasonInfo.CODE_LOCAL_CALL_CS_RETRY_REQUIRED;
@@ -312,10 +389,15 @@
                 .setExitedFromAirplaneMode(false)
                 .setPsDisconnectCause(imsReasonInfo)
                 .build();
+
         mNormalCallDomainSelector.reselectDomain(attributes);
+
         assertTrue(transportSelectorCallback
                 .verifyOnDomainSelected(NetworkRegistrationInfo.DOMAIN_CS));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         // Case 4: CS call
         NetworkRegistrationInfo nwRegistrationInfo = new NetworkRegistrationInfo(
                 NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
@@ -323,24 +405,36 @@
                 AccessNetworkConstants.AccessNetworkType.UTRAN, 0, false,
                 null, null, null, false, 0, 0, 0);
         serviceState.addNetworkRegistrationInfo(nwRegistrationInfo);
+
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         initialize(serviceState, false, false, false, false);
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWwanSelected());
+
         assertTrue(transportSelectorCallback
                 .verifyOnDomainSelected(NetworkRegistrationInfo.DOMAIN_CS));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         //Case 5: Backup calling
         serviceState.setStateOutOfService();
         initialize(serviceState, true, true, true, true);
+
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWlanSelected());
+
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.ACTIVE);
     }
 
     @Test
     public void testWPSCallDomainSelection() {
         MockTransportSelectorCallback transportSelectorCallback =
-                new MockTransportSelectorCallback();
+                new MockTransportSelectorCallback(mNormalCallDomainSelector);
         DomainSelectionService.SelectionAttributes attributes =
                 new DomainSelectionService.SelectionAttributes.Builder(
                         SLOT_ID, SUB_ID_1, SELECTOR_TYPE_CALLING)
@@ -356,35 +450,53 @@
         config.putBoolean(CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, false);
         doReturn(config).when(mMockCarrierConfigMgr).getConfigForSubId(SUB_ID_1,
                 new String[]{CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL});
+
         ServiceState serviceState = new ServiceState();
         serviceState.setState(ServiceState.STATE_IN_SERVICE);
         initialize(serviceState, true, true, true, true);
+
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWwanSelected());
+
         assertTrue(transportSelectorCallback
                 .verifyOnDomainSelected(NetworkRegistrationInfo.DOMAIN_CS));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         //Case 2: WPS supported by IMS and WLAN registered
         config.putBoolean(CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, true);
         serviceState.setState(ServiceState.STATE_IN_SERVICE);
         initialize(serviceState, true, true, true, true);
+
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWlanSelected());
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         //Case 2: WPS supported by IMS and LTE registered
         config.putBoolean(CarrierConfigManager.KEY_SUPPORT_WPS_OVER_IMS_BOOL, true);
         serviceState.setState(ServiceState.STATE_IN_SERVICE);
         initialize(serviceState, true, false, true, true);
+
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWwanSelected());
+
         assertTrue(transportSelectorCallback
                 .verifyOnDomainSelected(NetworkRegistrationInfo.DOMAIN_PS));
+
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
     }
 
     @Test
     public void testTtyCallDomainSelection() {
         MockTransportSelectorCallback transportSelectorCallback =
-                new MockTransportSelectorCallback();
+                new MockTransportSelectorCallback(mNormalCallDomainSelector);
         DomainSelectionService.SelectionAttributes attributes =
                 new DomainSelectionService.SelectionAttributes.Builder(
                         SLOT_ID, SUB_ID_1, SELECTOR_TYPE_CALLING)
@@ -401,29 +513,48 @@
         config.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL, false);
         doReturn(config).when(mMockCarrierConfigMgr).getConfigForSubId(SUB_ID_1,
                 new String[]{CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL});
+
         ServiceState serviceState = new ServiceState();
         serviceState.setState(ServiceState.STATE_IN_SERVICE);
         initialize(serviceState, true, false, true, true);
+
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWwanSelected());
+
         assertTrue(transportSelectorCallback
                 .verifyOnDomainSelected(NetworkRegistrationInfo.DOMAIN_CS));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         //Case 2: TTY supported by IMS and TTY enabled
         config.putBoolean(CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL, true);
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWwanSelected());
+
         assertTrue(transportSelectorCallback
                 .verifyOnDomainSelected(NetworkRegistrationInfo.DOMAIN_PS));
 
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
+
         //Case 3: TTY supported by IMS and TTY disabled
         doReturn(TelecomManager.TTY_MODE_OFF).when(mMockTelecomManager).getCurrentTtyMode();
         mNormalCallDomainSelector.selectDomain(attributes, transportSelectorCallback);
+
         assertTrue(transportSelectorCallback.verifyOnWwanSelected());
+
         assertTrue(transportSelectorCallback
                 .verifyOnDomainSelected(NetworkRegistrationInfo.DOMAIN_PS));
+
+        assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                NormalCallDomainSelector.SelectorState.INACTIVE);
     }
 
+
+
     static class MockTransportSelectorCallback implements TransportSelectorCallback,
             WwanSelectorCallback {
         public boolean mCreated;
@@ -433,11 +564,20 @@
         public boolean mDomainSelected;
         int mCauseCode;
         int mSelectedDomain;
+        NormalCallDomainSelector mNormalCallDomainSelector;
+
+        MockTransportSelectorCallback(NormalCallDomainSelector normalCallDomainSelector) {
+            mNormalCallDomainSelector = normalCallDomainSelector;
+        }
 
         @Override
         public synchronized void onCreated(DomainSelector selector) {
             Log.d(TAG, "onCreated");
             mCreated = true;
+
+            assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                    NormalCallDomainSelector.SelectorState.INACTIVE);
+
             notifyAll();
         }
 
@@ -452,6 +592,10 @@
         public synchronized void onWlanSelected(boolean useEmergencyPdn) {
             Log.d(TAG, "onWlanSelected");
             mWlanSelected = true;
+
+            assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                    NormalCallDomainSelector.SelectorState.INACTIVE);
+
             notifyAll();
         }
 
@@ -467,6 +611,9 @@
             Executors.newSingleThreadExecutor().execute(() -> {
                 consumer.accept(this);
             });
+
+            assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                    NormalCallDomainSelector.SelectorState.INACTIVE);
         }
 
         public boolean verifyOnWwanSelected() {
@@ -479,6 +626,10 @@
             Log.i(TAG, "onSelectionTerminated - called");
             mCauseCode = cause;
             mSelectionTerminated = true;
+
+            assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                    NormalCallDomainSelector.SelectorState.INACTIVE);
+
             notifyAll();
         }
 
@@ -516,6 +667,10 @@
             Log.i(TAG, "onDomainSelected - called");
             mSelectedDomain = domain;
             mDomainSelected = true;
+
+            assertEquals(mNormalCallDomainSelector.getSelectorState(),
+                    NormalCallDomainSelector.SelectorState.INACTIVE);
+
             notifyAll();
         }