Merge cherrypicks of [19034069, 19194541] into tm-release.

Change-Id: I5fe69b3f90b8feea172d4e5962844731a457fe70
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index f951501..4341851 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -70,6 +70,7 @@
 import com.android.settings.homepage.SettingsHomepageActivity;
 import com.android.settings.homepage.TopLevelSettings;
 import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.password.PasswordUtils;
 import com.android.settings.wfd.WifiDisplaySettings;
 import com.android.settings.widget.SettingsMainSwitchBar;
 import com.android.settingslib.core.instrumentation.Instrumentable;
@@ -154,6 +155,7 @@
     public static final String EXTRA_IS_FROM_SLICE = "is_from_slice";
 
     public static final String EXTRA_USER_HANDLE = "user_handle";
+    public static final String EXTRA_INITIAL_CALLING_PACKAGE = "initial_calling_package";
 
     /**
      * Personal or Work profile tab of {@link ProfileSelectFragment}
@@ -418,6 +420,8 @@
     }
 
     private boolean tryStartTwoPaneDeepLink(Intent intent) {
+        intent.putExtra(EXTRA_INITIAL_CALLING_PACKAGE, PasswordUtils.getCallingAppPackageName(
+                getActivityToken()));
         final Intent trampolineIntent;
         if (intent.getBooleanExtra(EXTRA_IS_FROM_SLICE, false)) {
             // Get menu key for slice deep link case.
@@ -505,6 +509,17 @@
         return true;
     }
 
+    /** Returns the initial calling package name that launches the activity. */
+    public String getInitialCallingPackage() {
+        String callingPackage = PasswordUtils.getCallingAppPackageName(getActivityToken());
+        if (!TextUtils.equals(callingPackage, getPackageName())) {
+            return callingPackage;
+        }
+
+        String initialCallingPackage = getIntent().getStringExtra(EXTRA_INITIAL_CALLING_PACKAGE);
+        return TextUtils.isEmpty(initialCallingPackage) ? callingPackage : initialCallingPackage;
+    }
+
     /** Returns the initial fragment name that the activity will launch. */
     @VisibleForTesting
     public String getInitialFragmentName(Intent intent) {
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index 7e6eefe..ea8a5f5 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -25,9 +25,9 @@
 import androidx.annotation.VisibleForTesting;
 
 import com.android.settings.R;
+import com.android.settings.SettingsActivity;
 import com.android.settings.core.SettingsUIDeviceConfig;
 import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.password.PasswordUtils;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.slices.SlicePreferenceController;
 import com.android.settingslib.search.SearchIndexable;
@@ -71,8 +71,8 @@
         super.onAttach(context);
         final boolean nearbyEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
                 SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true);
-        String callingAppPackageName = PasswordUtils.getCallingAppPackageName(
-                getActivity().getActivityToken());
+        String callingAppPackageName = ((SettingsActivity) getActivity())
+                .getInitialCallingPackage();
         String action = getIntent() != null ? getIntent().getAction() : "";
         if (DEBUG) {
             Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName
diff --git a/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java b/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java
index c509bac..391158f 100644
--- a/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java
+++ b/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java
@@ -60,8 +60,20 @@
      * @param message The string content should be displayed in the progress dialog.
      */
     protected void showProgressDialog(String message) {
+        showProgressDialog(message,false);
+    }
+
+    /**
+     * Displays a loading dialog.
+     *
+     * @param message The string content should be displayed in the progress dialog.
+     * @param updateIfNeeded is whether to update the progress state in the SharedPreferences.
+     */
+    protected void showProgressDialog(String message, boolean updateIfNeeded) {
         ProgressDialogFragment.show(getFragmentManager(), message, null);
-        setProgressState(PROGRESS_IS_SHOWING);
+        if (updateIfNeeded) {
+            setProgressState(PROGRESS_IS_SHOWING);
+        }
     }
 
     /** Dismisses the loading dialog. */
diff --git a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
index f5f18b4..a878cb3 100644
--- a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
+++ b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
@@ -220,8 +220,8 @@
                 showProgressDialog(
                         getString(
                                 R.string.sim_action_switch_sub_dialog_progress,
-                                SubscriptionUtil.getUniqueSubscriptionDisplayName(
-                                        mSubInfo, this)));
+                                SubscriptionUtil.getUniqueSubscriptionDisplayName(mSubInfo, this)),
+                        removedSubInfo != null ? true : false);
                 if (mIsEsimOperation) {
                     mSwitchToEuiccSubscriptionSidecar.run(mSubInfo.getSubscriptionId(),
                             UiccSlotUtil.INVALID_PORT_ID,