Merge "Remove References to ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 32733cc..461b18e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -424,6 +424,10 @@
                             "android.telephony.euicc.action.MANAGE_EMBEDDED_SUBSCRIPTIONS" />
                 <action android:name=
                             "android.telephony.euicc.action.PROVISION_EMBEDDED_SUBSCRIPTION" />
+                <action android:name=
+                    "android.telephony.euicc.action.TRANSFER_EMBEDDED_SUBSCRIPTIONS" />
+                <action android:name=
+                    "android.telephony.euicc.action.CONVERT_TO_EMBEDDED_SUBSCRIPTION" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </activity>
@@ -573,6 +577,14 @@
             android:configChanges="orientation|screenSize|keyboardHidden"
             android:theme="@style/Theme.Transparent"/>
 
+        <activity
+            android:name="com.android.phone.ErrorDialogActivity"
+            android:exported="false"
+            android:excludeFromRecents="true"
+            android:launchMode="singleTop"
+            android:configChanges="orientation|screenSize|keyboardHidden"
+            android:theme="@style/Theme.Telephony.Transparent"/>
+
         <service
             android:name="com.android.phone.vvm.RemoteVvmTaskManager"
             android:exported="false"/>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 79119a3..e21f761 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2203,4 +2203,10 @@
     <!-- Telephony notification channel name for a channel containing SIP accounts removed
      notificatios -->
     <string name="notification_channel_sip_account">Deprecated SIP accounts</string>
+
+    <string name="send_from_work_profile_title">Can\'t send message from this profile</string>
+    <string name="send_from_work_profile_description">Your work policy allows you to send message only from the work profile</string>
+    <string name="send_from_work_profile_cancel">Cancel</string>
+    <string name="send_from_work_profile_action_str">Switch to work profile</string>
+
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index d0f427c..19798f0 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -309,6 +309,17 @@
         <item name="android:backgroundDimEnabled">false</item>
     </style>
 
+    <style name="Theme.Telephony.Transparent" parent="@android:style/Theme.DeviceDefault.Light">
+        <item name="android:forceDarkAllowed">true</item>
+        <item name="android:windowIsTranslucent">true</item>
+        <item name="android:windowBackground">@android:color/transparent</item>
+        <item name="android:windowContentOverlay">@null</item>
+        <item name="android:windowNoTitle">true</item>
+        <item name="android:windowIsFloating">true</item>
+        <item name="android:backgroundDimEnabled">true</item>
+        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
+    </style>
+
     <style name="CallSettingsWithoutDividerTheme" parent="DialerSettingsLight">
         <item name="android:listDivider">@null</item>
     </style>
diff --git a/src/com/android/phone/ErrorDialogActivity.java b/src/com/android/phone/ErrorDialogActivity.java
new file mode 100644
index 0000000..11a92a8
--- /dev/null
+++ b/src/com/android/phone/ErrorDialogActivity.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2022 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.phone;
+
+import android.app.Activity;
+import android.app.ActivityOptions;
+import android.app.AlertDialog;
+import android.app.role.RoleManager;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.UserInfo;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.util.Log;
+
+import java.util.List;
+
+/** Used to display an error dialog from Telephony service. */
+public class ErrorDialogActivity extends Activity {
+
+    private static final String TAG = ErrorDialogActivity.class.getSimpleName();
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        getWindow()
+                .addSystemFlags(
+                        android.view.WindowManager.LayoutParams
+                                .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+        showDialog();
+    }
+
+    @Override
+    public void finish() {
+        super.finish();
+        // Don't show the return to previous task animation to avoid showing a black screen.
+        // Just dismiss the dialog and undim the previous activity immediately.
+        overridePendingTransition(0, 0);
+    }
+
+    private void showDialog() {
+        final DialogInterface.OnClickListener listener =
+                new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which) {
+                        switch (which) {
+                            case DialogInterface.BUTTON_POSITIVE:
+                                switchToManagedProfile();
+                                finish();
+                                break;
+                            case DialogInterface.BUTTON_NEGATIVE:
+                            default:
+                                finish();
+                        }
+                    }
+                };
+
+        new AlertDialog.Builder(this)
+            .setTitle(R.string.send_from_work_profile_title)
+            .setMessage(R.string.send_from_work_profile_description)
+            .setPositiveButton(R.string.send_from_work_profile_action_str, listener)
+            .setNegativeButton(R.string.send_from_work_profile_cancel, listener)
+            .setOnCancelListener(
+                new DialogInterface.OnCancelListener() {
+                    @Override
+                    public void onCancel(DialogInterface dialog) {
+                        finish();
+                    }
+                })
+            .show();
+    }
+
+    private void switchToManagedProfile() {
+        try {
+            int managedProfileUserId =
+                    getManagedProfileUserId(
+                            getApplicationContext(), getApplicationContext().getUserId());
+            if (managedProfileUserId == UserHandle.USER_NULL) {
+                finish();
+            }
+
+            String defaultMessagesAppPackage =
+                    getBaseContext()
+                            .getSystemService(RoleManager.class)
+                            .getSmsRoleHolder(managedProfileUserId);
+
+            Intent sendIntent = new Intent(Intent.ACTION_MAIN);
+            sendIntent.addCategory(Intent.CATEGORY_DEFAULT);
+            sendIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+            sendIntent.addCategory(Intent.CATEGORY_APP_MESSAGING);
+
+            sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+            if (defaultMessagesAppPackage != null) {
+                sendIntent.setPackage(defaultMessagesAppPackage);
+            }
+
+            startActivityAsUser(sendIntent,
+                    ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(),
+                    UserHandle.of(managedProfileUserId));
+        } catch (Exception e) {
+            Log.e(TAG, "Failed to switch to managed profile.", e);
+        }
+    }
+
+    private static int getManagedProfileUserId(Context context, int userId) {
+        UserManager um = context.getSystemService(UserManager.class);
+        List<UserInfo> userProfiles = um.getProfiles(userId);
+        for (UserInfo uInfo : userProfiles) {
+            if (uInfo.id == userId) {
+                continue;
+            }
+            if (uInfo.isManagedProfile()) {
+                return uInfo.id;
+            }
+        }
+        return UserHandle.USER_NULL;
+    }
+}
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 78a734a..200dc75 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -527,6 +527,8 @@
 
             imsRcsController = ImsRcsController.init(this);
 
+            configLoader = CarrierConfigLoader.init(this);
+
             if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
                 mImsStateCallbackController =
                         ImsStateCallbackController.make(this, PhoneFactory.getPhones().length);
@@ -538,8 +540,6 @@
                         ImsProvisioningController.make(this, PhoneFactory.getPhones().length);
             }
 
-            configLoader = CarrierConfigLoader.init(this);
-
             // Create the CallNotifier singleton, which handles
             // asynchronous events from the telephony layer (like
             // launching the incoming-call UI when an incoming call comes
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index f82769a..d48d204 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -2953,6 +2953,10 @@
     public boolean setRadioPower(boolean turnOn) {
         enforceModifyPermission();
 
+        if (!turnOn) {
+            log("setRadioPower off: callingPackage=" + getCurrentPackageName());
+        }
+
         final long identity = Binder.clearCallingIdentity();
         try {
             final Phone defaultPhone = PhoneFactory.getDefaultPhone();
@@ -2971,6 +2975,10 @@
     public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
         enforceModifyPermission();
 
+        if (!turnOn) {
+            log("setRadioPowerForSubscriber off: subId=" + subId
+                    + ",callingPackage=" + getCurrentPackageName());
+        }
         final long identity = Binder.clearCallingIdentity();
         try {
             final Phone phone = getPhone(subId);
@@ -3005,6 +3013,8 @@
             @TelephonyManager.RadioPowerReason int reason) {
         enforceModifyPermission();
 
+        log("requestRadioPowerOffForReason: subId=" + subId
+                + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
         final long identity = Binder.clearCallingIdentity();
         try {
             final Phone phone = getPhone(subId);
@@ -3776,7 +3786,7 @@
     }
 
     private static void log(String msg) {
-        Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
+        Log.d(LOG_TAG, msg);
     }
 
     private static void logv(String msg) {
@@ -10202,6 +10212,16 @@
     }
 
     @Override
+    public void showSwitchToManagedProfileDialog() {
+        enforceModifyPermission();
+
+        Intent intent = new Intent();
+        intent.setClass(mApp, ErrorDialogActivity.class);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        mApp.startActivity(intent);
+    }
+
+    @Override
     public String getMmsUAProfUrl(int subId) {
         //TODO investigate if this API should require proper permission check in R b/133791609
         final long identity = Binder.clearCallingIdentity();
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index f002e25..1858fe2 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -57,6 +57,7 @@
 import com.android.internal.telephony.util.TelephonyUtils;
 import com.android.modules.utils.BasicShellCommandHandler;
 import com.android.phone.callcomposer.CallComposerPictureManager;
+import com.android.phone.euicc.EuiccUiDispatcherActivity;
 import com.android.phone.utils.CarrierAllowListInfo;
 
 import java.io.IOException;
@@ -121,6 +122,9 @@
     private static final String CC_SET_VALUES_FROM_XML = "set-values-from-xml";
     private static final String CC_CLEAR_VALUES = "clear-values";
 
+    private static final String EUICC_SUBCOMMAND = "euicc";
+    private static final String EUICC_SET_UI_COMPONENT = "set-euicc-uicomponent";
+
     private static final String GBA_SUBCOMMAND = "gba";
     private static final String GBA_SET_SERVICE = "set-service";
     private static final String GBA_GET_SERVICE = "get-service";
@@ -313,6 +317,8 @@
                 return handleDataTestModeCommand();
             case END_BLOCK_SUPPRESSION:
                 return handleEndBlockSuppressionCommand();
+            case EUICC_SUBCOMMAND:
+                return handleEuiccCommand();
             case GBA_SUBCOMMAND:
                 return handleGbaCommand();
             case D2D_SUBCOMMAND:
@@ -608,6 +614,15 @@
         pw.println("          is specified, it will choose the default voice SIM slot.");
     }
 
+    private void onHelpEuicc() {
+        PrintWriter pw = getOutPrintWriter();
+        pw.println("Euicc Commands:");
+        pw.println("  euicc set-euicc-uicomponent COMPONENT_NAME PACKAGE_NAME");
+        pw.println("  Sets the Euicc Ui-Component which handles EuiccService Actions.");
+        pw.println("  COMPONENT_NAME: The component name which handles UI Actions.");
+        pw.println("  PACKAGE_NAME: THe package name in which ui component belongs.");
+    }
+
     private void onHelpGba() {
         PrintWriter pw = getOutPrintWriter();
         pw.println("Gba Commands:");
@@ -2058,6 +2073,35 @@
         return 0;
     }
 
+    private int handleEuiccCommand() {
+        String arg = getNextArg();
+        if (arg == null) {
+            onHelpEuicc();
+            return 0;
+        }
+
+        switch (arg) {
+            case EUICC_SET_UI_COMPONENT: {
+                return handleEuiccServiceCommand();
+            }
+        }
+        return -1;
+    }
+
+    private int handleEuiccServiceCommand() {
+        String uiComponent = getNextArg();
+        String packageName = getNextArg();
+        if (packageName == null || uiComponent == null) {
+            return -1;
+        }
+        EuiccUiDispatcherActivity.setTestEuiccUiComponent(packageName, uiComponent);
+        if (VDBG) {
+            Log.v(LOG_TAG, "euicc set-euicc-uicomponent " + uiComponent +" "
+                    + packageName);
+        }
+        return 0;
+    }
+
     private int handleRestartModemCommand() {
         // Verify that the user is allowed to run the command. Only allowed in rooted device in a
         // non user build.
diff --git a/src/com/android/phone/euicc/EuiccUiDispatcherActivity.java b/src/com/android/phone/euicc/EuiccUiDispatcherActivity.java
index 804611f..5da52d6 100644
--- a/src/com/android/phone/euicc/EuiccUiDispatcherActivity.java
+++ b/src/com/android/phone/euicc/EuiccUiDispatcherActivity.java
@@ -29,6 +29,7 @@
 import android.permission.LegacyPermissionManager;
 import android.service.euicc.EuiccService;
 import android.telephony.euicc.EuiccManager;
+import android.text.TextUtils;
 import android.util.Log;
 
 import com.android.internal.annotations.VisibleForTesting;
@@ -58,6 +59,8 @@
     private LegacyPermissionManager mPermissionManager;
     private boolean mGrantPermissionDone = false;
     private ThreadPoolExecutor mExecutor;
+    // Used for CTS EuiccManager action verification
+    private static ComponentName mTestEuiccUiComponentName;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -94,6 +97,18 @@
         }
     }
 
+    /**
+    * This API used to set the Test EuiccUiComponent for CTS
+    * @param packageName package which handles the intent
+    * @param componentName ui component to be launched for testing
+    */
+    public static void setTestEuiccUiComponent(String packageName, String componentName) {
+        mTestEuiccUiComponentName = null;
+        if (!TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(componentName)) {
+            mTestEuiccUiComponentName = new ComponentName(packageName, componentName);
+        }
+    }
+
     @VisibleForTesting
     @Nullable
     Intent resolveEuiccUiIntent() {
@@ -109,6 +124,13 @@
             return null;
         }
 
+        if (mTestEuiccUiComponentName != null) {
+            Log.i(TAG, "Test mode");
+            euiccUiIntent.setComponent(mTestEuiccUiComponentName);
+            mTestEuiccUiComponentName = null;
+            return euiccUiIntent;
+        }
+
         revokePermissionFromLuiApps(euiccUiIntent);
 
         ActivityInfo activityInfo = findBestActivity(euiccUiIntent);
@@ -148,6 +170,12 @@
             case EuiccManager.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION:
                 intent.setAction(EuiccService.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION);
                 break;
+            case EuiccManager.ACTION_TRANSFER_EMBEDDED_SUBSCRIPTIONS:
+                intent.setAction(EuiccService.ACTION_TRANSFER_EMBEDDED_SUBSCRIPTIONS);
+                break;
+            case EuiccManager.ACTION_CONVERT_TO_EMBEDDED_SUBSCRIPTION:
+                intent.setAction(EuiccService.ACTION_CONVERT_TO_EMBEDDED_SUBSCRIPTION);
+                break;
             default:
                 Log.w(TAG, "Unsupported action: " + action);
                 return null;
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 1cf35a5..e278240 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -2494,6 +2494,7 @@
 
                         if (mTelephonyConnectionService.maybeReselectDomain(this,
                                   mOriginalConnection.getPreciseDisconnectCause(), reasonInfo)) {
+                            clearOriginalConnection();
                             break;
                         }
                     }
diff --git a/src/com/android/services/telephony/rcs/TelephonyRcsService.java b/src/com/android/services/telephony/rcs/TelephonyRcsService.java
index 13b3a7d..3a8ad62 100644
--- a/src/com/android/services/telephony/rcs/TelephonyRcsService.java
+++ b/src/com/android/services/telephony/rcs/TelephonyRcsService.java
@@ -25,6 +25,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
+import android.os.PersistableBundle;
 import android.telephony.CarrierConfigManager;
 import android.telephony.SubscriptionManager;
 import android.util.Log;
@@ -351,23 +352,17 @@
 
     private boolean doesSubscriptionSupportPresence(int subId) {
         if (!SubscriptionManager.isValidSubscriptionId(subId)) return false;
-        CarrierConfigManager carrierConfigManager =
-                mContext.getSystemService(CarrierConfigManager.class);
-        if (carrierConfigManager == null) return false;
-        boolean supportsUce = carrierConfigManager.getConfigForSubId(subId).getBoolean(
-                CarrierConfigManager.Ims.KEY_ENABLE_PRESENCE_PUBLISH_BOOL);
-        supportsUce |= carrierConfigManager.getConfigForSubId(subId).getBoolean(
-                CarrierConfigManager.KEY_USE_RCS_SIP_OPTIONS_BOOL);
+        boolean supportsUce = getConfig(subId,
+                CarrierConfigManager.Ims.KEY_ENABLE_PRESENCE_PUBLISH_BOOL, false /*default*/);
+        supportsUce |= getConfig(subId,
+                CarrierConfigManager.KEY_USE_RCS_SIP_OPTIONS_BOOL, false /*default*/);
         return supportsUce;
     }
 
     private boolean doesSubscriptionSupportSingleRegistration(int subId) {
         if (!SubscriptionManager.isValidSubscriptionId(subId)) return false;
-        CarrierConfigManager carrierConfigManager =
-                mContext.getSystemService(CarrierConfigManager.class);
-        if (carrierConfigManager == null) return false;
-        return carrierConfigManager.getConfigForSubId(subId).getBoolean(
-                CarrierConfigManager.Ims.KEY_IMS_SINGLE_REGISTRATION_REQUIRED_BOOL);
+        return getConfig(subId, CarrierConfigManager.Ims.KEY_IMS_SINGLE_REGISTRATION_REQUIRED_BOOL,
+                false /*defaultValue*/);
     }
 
     private int getSubscriptionFromSlot(int slotId) {
@@ -384,6 +379,16 @@
     }
 
     /**
+     * @return the boolean result corresponding to a boolean {@link CarrierConfigManager} key.
+     */
+    private boolean getConfig(int subId, String key, boolean defaultValue) {
+        CarrierConfigManager c = mContext.getSystemService(CarrierConfigManager.class);
+        if (c == null) return defaultValue;
+        PersistableBundle b = c.getConfigForSubId(subId, key);
+        return b != null ? b.getBoolean(key, defaultValue) : defaultValue;
+    }
+
+    /**
      * Dump this instance into a readable format for dumpsys usage.
      */
     public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
diff --git a/tests/src/com/android/TestContext.java b/tests/src/com/android/TestContext.java
index 720d235..111df53 100644
--- a/tests/src/com/android/TestContext.java
+++ b/tests/src/com/android/TestContext.java
@@ -17,6 +17,7 @@
 package com.android;
 
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doAnswer;
 
 import android.content.AttributionSource;
@@ -73,13 +74,12 @@
         MockitoAnnotations.initMocks(this);
         doAnswer((Answer<PersistableBundle>) invocation -> {
             int subId = (int) invocation.getArguments()[0];
-            if (subId < 0) {
-                return new PersistableBundle();
-            }
-            PersistableBundle b = mCarrierConfigs.get(subId);
-
-            return (b != null ? b : new PersistableBundle());
+            return getTestConfigs(subId);
         }).when(mMockCarrierConfigManager).getConfigForSubId(anyInt());
+        doAnswer((Answer<PersistableBundle>) invocation -> {
+            int subId = (int) invocation.getArguments()[0];
+            return getTestConfigs(subId);
+        }).when(mMockCarrierConfigManager).getConfigForSubId(anyInt(), anyString());
     }
 
     @Override
@@ -252,18 +252,16 @@
 
     public void grantPermission(String permission) {
         synchronized (mPermissionTable) {
-            if (mPermissionTable != null && permission != null) {
-                mPermissionTable.remove(STUB_PERMISSION_ENABLE_ALL);
-                mPermissionTable.add(permission);
-            }
+            if (permission == null) return;
+            mPermissionTable.remove(STUB_PERMISSION_ENABLE_ALL);
+            mPermissionTable.add(permission);
         }
     }
 
     public void revokePermission(String permission) {
         synchronized (mPermissionTable) {
-            if (mPermissionTable != null && permission != null) {
-                mPermissionTable.remove(permission);
-            }
+            if (permission == null) return;
+            mPermissionTable.remove(permission);
         }
     }
 
@@ -281,6 +279,14 @@
         return mReceiver;
     }
 
+    private PersistableBundle getTestConfigs(int subId) {
+        if (subId < 0) {
+            return new PersistableBundle();
+        }
+        PersistableBundle b = getCarrierConfig(subId);
+        return (b != null ? b : new PersistableBundle());
+    }
+
     private static void logd(String s) {
         Log.d(TAG, s);
     }
diff --git a/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java b/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
index 8aa5923..3d6a0aa 100644
--- a/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
+++ b/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
@@ -207,7 +207,6 @@
         mTestConnectionService.setDisconnectCauseFactory(mDisconnectCauseFactory);
         mTestConnectionService.onCreate();
         mTestConnectionService.setTelephonyManagerProxy(mTelephonyManagerProxy);
-        DomainSelectionResolver.setDomainSelectionResolver(mDomainSelectionResolver);
         replaceInstance(TelephonyConnectionService.class, "mDomainSelectionResolver",
                 mTestConnectionService, mDomainSelectionResolver);
         mEmergencyStateTracker = Mockito.mock(EmergencyStateTracker.class);
diff --git a/tests/src/com/android/services/telephony/TelephonyConnectionTest.java b/tests/src/com/android/services/telephony/TelephonyConnectionTest.java
index 3c309ba..758ded7 100644
--- a/tests/src/com/android/services/telephony/TelephonyConnectionTest.java
+++ b/tests/src/com/android/services/telephony/TelephonyConnectionTest.java
@@ -294,13 +294,16 @@
     public void testDomainSelectionDisconnected_Redial() {
         TestTelephonyConnection c = new TestTelephonyConnection();
         c.setOriginalConnection(mImsPhoneConnection);
+
         doReturn(Call.State.DISCONNECTED).when(mImsPhoneConnection)
                 .getState();
         c.setTelephonyConnectionService(mTelephonyConnectionService);
         doReturn(true).when(mTelephonyConnectionService)
                 .maybeReselectDomain(any(), anyInt(), any());
+        c.resetOriginalConnectionCleared();
         c.updateState();
 
         assertNotEquals(STATE_DISCONNECTED, c.getState());
+        assertTrue(c.isOriginalConnectionCleared());
     }
 }
diff --git a/tests/src/com/android/services/telephony/TestTelephonyConnection.java b/tests/src/com/android/services/telephony/TestTelephonyConnection.java
index e149d3b..d91435c 100644
--- a/tests/src/com/android/services/telephony/TestTelephonyConnection.java
+++ b/tests/src/com/android/services/telephony/TestTelephonyConnection.java
@@ -50,8 +50,6 @@
 
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -107,6 +105,7 @@
     private List<Bundle> mLastConnectionEventExtras = new ArrayList<>();
     private Object mLock = new Object();
     private PersistableBundle mCarrierConfig = new PersistableBundle();
+    private boolean mOriginalConnectionCleared;
 
     @Override
     public com.android.internal.telephony.Connection getOriginalConnection() {
@@ -211,7 +210,15 @@
 
     @Override
     void clearOriginalConnection() {
-        // Do nothing since the original connection is mock object
+        mOriginalConnectionCleared = true;
+    }
+
+    boolean isOriginalConnectionCleared() {
+        return mOriginalConnectionCleared;
+    }
+
+    void resetOriginalConnectionCleared() {
+        mOriginalConnectionCleared = false;
     }
 
     @Override