Merge "Fix Wifi & Bluetooth slice can't show on search result"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9f8d648..4996aeb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -384,12 +384,10 @@
                 android:value="true" />
         </activity>
 
-        <!-- Runs in the phone process since it needs access to UiccController -->
         <activity android:name="Settings$ApnSettingsActivity"
                 android:label="@string/apn_settings"
                 android:launchMode="singleTask"
-                android:configChanges="orientation|keyboardHidden|screenSize"
-                android:process="com.android.phone">
+                android:configChanges="orientation|keyboardHidden|screenSize">
             <intent-filter android:priority="1">
                 <action android:name="android.settings.APN_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
@@ -1422,8 +1420,7 @@
         </activity>
 
         <activity android:name="Settings$IccLockSettingsActivity"
-                android:label="@string/sim_lock_settings"
-                android:process="com.android.phone">
+                android:label="@string/sim_lock_settings">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3effe22..c32d557 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3750,6 +3750,14 @@
     <!-- Tethering controls, footer note displayed when tethering is disabled because Data Saver mode is on [CHAR LIMIT=none]-->
     <string name="tether_settings_disabled_on_data_saver">"Can\u2019t tether or use portable hotspots while Data Saver is on"</string>
 
+    <!-- Disable Wifi Hotspot option-->
+    <!-- Don't use Wi-Fi hotspot summary when USB tethering is chosen [CHAR LIMIT=NONE]-->
+    <string name="disable_wifi_hotspot_when_usb_on">Only share internet via USB</string>
+    <!-- Don't use Wi-Fi hotspot summary when Bluetooth tethering is chosen [CHAR LIMIT=NONE]-->
+    <string name="disable_wifi_hotspot_when_bluetooth_on">Only share internet via Bluetooth</string>
+    <!-- Don't use Wi-Fi hotspot summary when USB tethering and Bluetooth tethering are chosen [CHAR LIMIT=NONE]-->
+    <string name="disable_wifi_hotspot_when_usb_and_bluetooth_on">Only share internet via USB and Bluetooth</string>
+
     <!-- USB Tethering options -->
     <string name="usb_title">USB</string>
     <string name="usb_tethering_button_text">USB tethering</string>
@@ -8057,6 +8065,9 @@
     <!-- Notification history screen; summary when history is off [CHAR LIMIT=200] -->
     <string name="notification_history_off_title_extended">Notification history is turned off</string>
 
+    <!-- Notification history screen; content description describing what happens when you tap on a notification history entry [CHAR LIMIT=NONE] -->
+    <string name="notification_history_view_settings">view notification settings</string>
+
     <!-- Configure Notifications: setting title, whether the snooze menu is shown on notifications [CHAR LIMIT=80] -->
     <string name="snooze_options_title">Allow notification snoozing</string>
 
diff --git a/res/xml/all_tether_prefs.xml b/res/xml/all_tether_prefs.xml
index bc3471b..d16adc5 100644
--- a/res/xml/all_tether_prefs.xml
+++ b/res/xml/all_tether_prefs.xml
@@ -74,6 +74,7 @@
         <SwitchPreference
             android:key="disable_wifi_tethering"
             android:title="Don't use Wi-Fi hotspot"
+            android:summary="@string/summary_placeholder"
             settings:controller="com.android.settings.network.WifiTetherDisablePreferenceController"
             settings:keywords="@string/keywords_hotspot_tethering" />
     </PreferenceCategory>
diff --git a/src/com/android/settings/AllInOneTetherSettings.java b/src/com/android/settings/AllInOneTetherSettings.java
index f2a0f52..4576fb7 100644
--- a/src/com/android/settings/AllInOneTetherSettings.java
+++ b/src/com/android/settings/AllInOneTetherSettings.java
@@ -46,7 +46,10 @@
 import com.android.settings.core.FeatureFlags;
 import com.android.settings.dashboard.RestrictedDashboardFragment;
 import com.android.settings.datausage.DataSaverBackend;
+import com.android.settings.network.BluetoothTetherPreferenceController;
 import com.android.settings.network.TetherEnabler;
+import com.android.settings.network.UsbTetherPreferenceController;
+import com.android.settings.network.WifiTetherDisablePreferenceController;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.widget.SwitchBar;
 import com.android.settings.widget.SwitchBarController;
@@ -66,7 +69,6 @@
 
 /**
  * Displays preferences for all Tethering options.
- * TODO(b/147323306): Add tether option preferences into this fragment after controllers created.
  */
 @SearchIndexable
 public final class AllInOneTetherSettings extends RestrictedDashboardFragment
@@ -172,6 +174,9 @@
         mSecurityPreferenceController = use(WifiTetherSecurityPreferenceController.class);
         mPasswordPreferenceController = use(WifiTetherPasswordPreferenceController.class);
         mApBandPreferenceController = use(WifiTetherApBandPreferenceController.class);
+        getSettingsLifecycle().addObserver(use(UsbTetherPreferenceController.class));
+        getSettingsLifecycle().addObserver(use(BluetoothTetherPreferenceController.class));
+        getSettingsLifecycle().addObserver(use(WifiTetherDisablePreferenceController.class));
     }
 
     @Override
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 07ba28f..80e5706 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -258,6 +258,18 @@
         return 0;
     }
 
+    /**
+     * Whether preference is allowing to be displayed to the user.
+     *
+     * @param preference to check if it can be displayed to the user (not hidding in expand area).
+     * @return {@code true} when preference is allowing to be displayed to the user.
+     * {@code false} when preference is hidden in expand area and not been displayed to the user.
+     */
+    protected boolean isPreferenceExpanded(Preference preference) {
+        return ((mAdapter == null)
+                || (mAdapter.getPreferenceAdapterPosition(preference) != RecyclerView.NO_POSITION));
+    }
+
     protected void onDataSetChanged() {
         highlightPreferenceIfNeeded();
         updateEmptyView();
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index 0d3d5b0..d121195 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -320,6 +320,13 @@
     }
 
     /**
+     * Get current PreferenceController(s)
+     */
+    protected Collection<List<AbstractPreferenceController>> getPreferenceControllers() {
+        return mPreferenceControllers.values();
+    }
+
+    /**
      * Update state of each preference managed by PreferenceController.
      */
     protected void updatePreferenceStates() {
diff --git a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
index a7242cf..32f841d 100644
--- a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
+++ b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
@@ -30,6 +30,7 @@
 import androidx.preference.SwitchPreference;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settingslib.TetherUtil;
 
@@ -95,8 +96,14 @@
 
     @Override
     public CharSequence getSummary() {
-        // TODO(b/146818850): Update summary accordingly.
-        return super.getSummary();
+        if (mUSBTetherEnabled && mBluetoothTetherEnabled) {
+            return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on);
+        } else if (mUSBTetherEnabled) {
+            return mContext.getString(R.string.disable_wifi_hotspot_when_usb_on);
+        } else if (mBluetoothTetherEnabled) {
+            return mContext.getString(R.string.disable_wifi_hotspot_when_bluetooth_on);
+        }
+        return mContext.getString(R.string.summary_placeholder);
     }
 
     @Override
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index a4b32e6..199564d 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -33,6 +33,7 @@
 
 import androidx.annotation.VisibleForTesting;
 import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
 import com.android.settings.dashboard.RestrictedDashboardFragment;
@@ -47,7 +48,9 @@
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.search.SearchIndexable;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 
 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
@@ -72,6 +75,8 @@
     private UserManager mUserManager;
     private String mClickedPrefKey;
 
+    private List<AbstractPreferenceController> mHiddenControllerList;
+
     public MobileNetworkSettings() {
         super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
     }
@@ -113,12 +118,12 @@
                 MobileNetworkUtils.getSearchableSubscriptionId(context));
         Log.i(LOG_TAG, "display subId: " + mSubId);
 
-        if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
-            return Arrays.asList(
-                    new DataUsageSummaryPreferenceController(getActivity(), getSettingsLifecycle(),
-                            this, mSubId));
+        if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
+            return Arrays.asList();
         }
-        return Arrays.asList();
+        return Arrays.asList(
+                new DataUsageSummaryPreferenceController(getActivity(), getSettingsLifecycle(),
+                        this, mSubId));
     }
 
     @Override
@@ -187,6 +192,50 @@
         onRestoreInstance(icicle);
     }
 
+    @Override
+    public void onExpandButtonClick() {
+        final PreferenceScreen screen = getPreferenceScreen();
+        mHiddenControllerList.stream()
+                .filter(controller -> controller.isAvailable())
+                .forEach(controller -> {
+                    final String key = controller.getPreferenceKey();
+                    final Preference preference = screen.findPreference(key);
+                    controller.updateState(preference);
+                });
+        super.onExpandButtonClick();
+    }
+
+    /*
+     * Replace design within {@link DashboardFragment#updatePreferenceStates()}
+     */
+    @Override
+    protected void updatePreferenceStates() {
+        mHiddenControllerList = new ArrayList<AbstractPreferenceController>();
+
+        final PreferenceScreen screen = getPreferenceScreen();
+        final Collection<List<AbstractPreferenceController>> controllerLists =
+                getPreferenceControllers();
+        controllerLists.stream().flatMap(Collection::stream)
+                .forEach(controller -> {
+                    final String key = controller.getPreferenceKey();
+                    if (TextUtils.isEmpty(key)) {
+                        return;
+                    }
+                    final Preference preference = screen.findPreference(key);
+                    if (preference == null) {
+                        return;
+                    }
+                    if (!isPreferenceExpanded(preference)) {
+                        mHiddenControllerList.add(controller);
+                        return;
+                    }
+                    if (!controller.isAvailable()) {
+                        return;
+                    }
+                    controller.updateState(preference);
+                });
+    }
+
     @VisibleForTesting
     void onRestoreInstance(Bundle icicle) {
         if (icicle != null) {
@@ -238,7 +287,7 @@
 
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
-        if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+        if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
             final MenuItem item = menu.add(Menu.NONE, R.id.edit_sim_name, Menu.NONE,
                     R.string.mobile_network_sim_name);
             item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
@@ -249,7 +298,7 @@
 
     @Override
     public boolean onOptionsItemSelected(MenuItem menuItem) {
-        if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+        if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
             if (menuItem.getItemId() == R.id.edit_sim_name) {
                 RenameMobileNetworkDialogFragment.newInstance(mSubId).show(
                         getFragmentManager(), RenameMobileNetworkDialogFragment.TAG);
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index 875a804..4f62f7f 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -18,6 +18,15 @@
 
 import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
 
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.EVDO;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.GSM;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.LTE;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.NR;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_TD_SCDMA;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_UNKNOWN;
+import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.WCDMA;
+
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
@@ -54,6 +63,7 @@
 import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settings.core.BasePreferenceController;
+import com.android.settings.network.ims.WifiCallingQueryImsState;
 import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
 import com.android.settingslib.development.DevelopmentSettingsEnabler;
 import com.android.settingslib.graph.SignalDrawable;
@@ -61,15 +71,6 @@
 import java.util.Arrays;
 import java.util.List;
 
-import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
-import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.EVDO;
-import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.GSM;
-import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.LTE;
-import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.NR;
-import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_TD_SCDMA;
-import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_UNKNOWN;
-import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.WCDMA;
-
 public class MobileNetworkUtils {
 
     private static final String TAG = "MobileNetworkUtils";
@@ -152,10 +153,10 @@
 
             isWifiCallingEnabled = intent != null;
         } else {
+            final WifiCallingQueryImsState queryState =
+                    new WifiCallingQueryImsState(context, subId);
             final ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
-            isWifiCallingEnabled = imsMgr != null
-                    && imsMgr.isWfcEnabledByPlatform()
-                    && isWfcProvisionedOnDevice(subId)
+            isWifiCallingEnabled = queryState.isWifiCallingProvisioned()
                     && isImsServiceStateReady(imsMgr);
         }
 
diff --git a/src/com/android/settings/network/telephony/RoamingPreferenceController.java b/src/com/android/settings/network/telephony/RoamingPreferenceController.java
index 08fe323..2e116d8 100644
--- a/src/com/android/settings/network/telephony/RoamingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/RoamingPreferenceController.java
@@ -22,7 +22,6 @@
 import android.telephony.CarrierConfigManager;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
-import android.text.TextUtils;
 import android.util.Log;
 
 import androidx.annotation.VisibleForTesting;
@@ -111,20 +110,10 @@
     }
 
     @Override
-    public boolean handlePreferenceTreeClick(Preference preference) {
-        if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
-            if (isDialogNeeded()) {
-                showDialog();
-            }
-            return true;
-        }
-
-        return false;
-    }
-
-    @Override
     public boolean setChecked(boolean isChecked) {
-        if (!isDialogNeeded()) {
+        if (isDialogNeeded()) {
+            showDialog();
+        } else {
             // Update data directly if we don't need dialog
             mTelephonyManager.setDataRoamingEnabled(isChecked);
             return true;
diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
index 7bd345f..a02d3aa 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java
@@ -77,12 +77,18 @@
             final View container = viewForPackage.findViewById(R.id.list_container);
             container.setVisibility(View.GONE);
             ImageButton expand = viewForPackage.findViewById(R.id.expand);
+            expand.setContentDescription(container.getVisibility() == View.VISIBLE
+                    ? getString(R.string.condition_expand_hide)
+                    : getString(R.string.condition_expand_show));
             expand.setOnClickListener(v -> {
                     container.setVisibility(container.getVisibility() == View.VISIBLE
                             ? View.GONE : View.VISIBLE);
                     expand.setImageResource(container.getVisibility() == View.VISIBLE
                             ? R.drawable.ic_expand_less
                             : com.android.internal.R.drawable.ic_expand_more);
+                    expand.setContentDescription(container.getVisibility() == View.VISIBLE
+                            ? getString(R.string.condition_expand_hide)
+                            : getString(R.string.condition_expand_show));
             });
 
             TextView label = viewForPackage.findViewById(R.id.label);
diff --git a/src/com/android/settings/notification/history/NotificationHistoryViewHolder.java b/src/com/android/settings/notification/history/NotificationHistoryViewHolder.java
index 35f5615..e7caa6a 100644
--- a/src/com/android/settings/notification/history/NotificationHistoryViewHolder.java
+++ b/src/com/android/settings/notification/history/NotificationHistoryViewHolder.java
@@ -26,6 +26,9 @@
 import android.widget.DateTimeView;
 import android.widget.TextView;
 
+import androidx.core.view.AccessibilityDelegateCompat;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
 import androidx.recyclerview.widget.RecyclerView;
 
 import com.android.settings.R;
@@ -66,5 +69,18 @@
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             itemView.getContext().startActivityAsUser(intent, UserHandle.of(userId));
         });
+        ViewCompat.setAccessibilityDelegate(itemView, new AccessibilityDelegateCompat() {
+            @Override
+            public void onInitializeAccessibilityNodeInfo(View host,
+                    AccessibilityNodeInfoCompat info) {
+                super.onInitializeAccessibilityNodeInfo(host, info);
+                CharSequence description =
+                        host.getResources().getText(R.string.notification_history_view_settings);
+                AccessibilityNodeInfoCompat.AccessibilityActionCompat customClick =
+                        new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
+                                AccessibilityNodeInfoCompat.ACTION_CLICK, description);
+                info.addAction(customClick);
+            }
+        });
     }
 }
diff --git a/src/com/android/settings/notification/history/NotificationSbnAdapter.java b/src/com/android/settings/notification/history/NotificationSbnAdapter.java
index 80ba278..77740d7 100644
--- a/src/com/android/settings/notification/history/NotificationSbnAdapter.java
+++ b/src/com/android/settings/notification/history/NotificationSbnAdapter.java
@@ -28,6 +28,7 @@
 import android.service.notification.StatusBarNotification;
 import android.text.TextUtils;
 import android.util.Log;
+import android.util.Slog;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -70,17 +71,21 @@
     public void onBindViewHolder(final @NonNull NotificationSbnViewHolder holder,
             int position) {
         final StatusBarNotification sbn = mValues.get(position);
-        holder.setIcon(loadIcon(sbn));
-        holder.setPackageName(loadPackageName(sbn.getPackageName()).toString());
-        holder.setTitle(getTitleString(sbn.getNotification()));
-        holder.setSummary(getTextString(mContext, sbn.getNotification()));
-        holder.setPostedTime(sbn.getPostTime());
-        if (!mUserBadgeCache.containsKey(sbn.getUserId())) {
-            Drawable profile = mContext.getPackageManager().getUserBadgeForDensity(
-                    UserHandle.of(sbn.getUserId()), -1);
-            mUserBadgeCache.put(sbn.getUserId(), profile);
+        if (sbn != null) {
+            holder.setIcon(loadIcon(sbn));
+            holder.setPackageName(loadPackageName(sbn.getPackageName()).toString());
+            holder.setTitle(getTitleString(sbn.getNotification()));
+            holder.setSummary(getTextString(mContext, sbn.getNotification()));
+            holder.setPostedTime(sbn.getPostTime());
+            if (!mUserBadgeCache.containsKey(sbn.getUserId())) {
+                Drawable profile = mContext.getPackageManager().getUserBadgeForDensity(
+                        UserHandle.of(sbn.getUserId()), -1);
+                mUserBadgeCache.put(sbn.getUserId(), profile);
+            }
+            holder.setProfileBadge(mUserBadgeCache.get(sbn.getUserId()));
+        } else {
+            Slog.w(TAG, "null entry in list at position " + position);
         }
-        holder.setProfileBadge(mUserBadgeCache.get(sbn.getUserId()));
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
index 895bdba..69adf55 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
@@ -43,12 +43,9 @@
 import androidx.slice.builders.SliceAction;
 
 import com.android.ims.ImsConfig;
-import com.android.ims.ImsManager;
 import com.android.settings.R;
 import com.android.settings.Utils;
-import com.android.settings.network.SubscriptionUtil;
 import com.android.settings.network.ims.WifiCallingQueryImsState;
-import com.android.settings.network.telephony.MobileNetworkUtils;
 import com.android.settings.slices.SliceBroadcastReceiver;
 
 import java.util.concurrent.Callable;
@@ -140,10 +137,7 @@
             return null;
         }
 
-        final ImsManager imsManager = getImsManager(subId);
-
-        if (!imsManager.isWfcEnabledByPlatform()
-                || !isWfcProvisionedOnDevice(subId)) {
+        if (!queryImsState(subId).isWifiCallingProvisioned()) {
             Log.d(TAG, "Wifi calling is either not provisioned or not enabled by Platform");
             return null;
         }
@@ -168,9 +162,8 @@
     }
 
     private boolean isWifiCallingEnabled() {
-        final int subId = getDefaultVoiceSubId();
-        return queryImsState(subId).isEnabledByUser()
-                && queryImsState(subId).isAllowUserControl();
+        final WifiCallingQueryImsState queryState = queryImsState(getDefaultVoiceSubId());
+        return queryState.isEnabledByUser() && queryState.isAllowUserControl();
     }
 
     /**
@@ -224,23 +217,21 @@
                 CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, subId, false);
         final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
                 CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
-        final ImsManager imsManager = getImsManager(subId);
-        final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
-
-        if (!imsManager.isWfcEnabledByPlatform()
-                || !isWfcProvisionedOnDevice(subId)) {
-            Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
-            return null;
-        }
 
         if (!isWifiCallingPrefEditable) {
             Log.d(TAG, "Wifi calling preference is not editable");
             return null;
         }
 
+        if (!queryImsState(subId).isWifiCallingProvisioned()) {
+            Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
+            return null;
+        }
+
         boolean isWifiCallingEnabled = false;
         int wfcMode = -1;
         try {
+            final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
             isWifiCallingEnabled = isWifiCallingEnabled();
             wfcMode = getWfcMode(imsMmTelManager);
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
@@ -351,10 +342,6 @@
         }
     }
 
-    protected ImsManager getImsManager(int subId) {
-        return ImsManager.getInstance(mContext, SubscriptionUtil.getPhoneId(mContext, subId));
-    }
-
     protected ImsMmTelManager getImsMmTelManager(int subId) {
         return ImsMmTelManager.createForSubscriptionId(subId);
     }
@@ -382,11 +369,10 @@
         final int subId = getDefaultVoiceSubId();
 
         if (SubscriptionManager.isValidSubscriptionId(subId)) {
-            final ImsManager imsManager = getImsManager(subId);
-            if (imsManager.isWfcEnabledByPlatform()
-                    && isWfcProvisionedOnDevice(subId)) {
-                final boolean currentValue = queryImsState(subId).isEnabledByUser()
-                        && queryImsState(subId).isAllowUserControl();
+            final WifiCallingQueryImsState queryState = queryImsState(subId);
+            if (queryState.isWifiCallingProvisioned()) {
+                final boolean currentValue = queryState.isEnabledByUser()
+                        && queryState.isAllowUserControl();
                 final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
                         currentValue);
                 final Intent activationAppIntent =
@@ -425,12 +411,11 @@
             final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
                     CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
 
-            final ImsManager imsManager = getImsManager(subId);
+            final WifiCallingQueryImsState queryState = queryImsState(subId);
             if (isWifiCallingPrefEditable
-                    && imsManager.isWfcEnabledByPlatform()
-                    && isWfcProvisionedOnDevice(subId)
-                    && queryImsState(subId).isEnabledByUser()
-                    && queryImsState(subId).isAllowUserControl()) {
+                    && queryState.isWifiCallingProvisioned()
+                    && queryState.isEnabledByUser()
+                    && queryState.isAllowUserControl()) {
                 // Change the preference only when wifi calling is enabled
                 // And when wifi calling preference is editable for the current carrier
                 final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
@@ -511,11 +496,6 @@
         return SubscriptionManager.getDefaultVoiceSubscriptionId();
     }
 
-    @VisibleForTesting
-    boolean isWfcProvisionedOnDevice(int subId) {
-        return MobileNetworkUtils.isWfcProvisionedOnDevice(subId);
-    }
-
     /**
      * Returns Intent of the activation app required to activate wifi calling or null if there is no
      * need for activation.
diff --git a/tests/robotests/src/com/android/settings/network/telephony/RoamingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/RoamingPreferenceControllerTest.java
index 0abd6d5..092b9b7 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/RoamingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/RoamingPreferenceControllerTest.java
@@ -117,10 +117,10 @@
     }
 
     @Test
-    public void handlePreferenceTreeClick_needDialog_showDialog() {
+    public void setChecked_needDialog_showDialog() {
         doReturn(true).when(mController).isDialogNeeded();
 
-        mController.handlePreferenceTreeClick(mPreference);
+        mController.setChecked(true);
 
         verify(mFragmentManager).beginTransaction();
     }
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
index aaff22a..f537be3 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
@@ -107,6 +107,7 @@
 
         mQueryImsState = spy(new WifiCallingQueryImsState(mContext, SUB_ID));
         doReturn(true).when(mQueryImsState).isEnabledByUser();
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
 
         mWfcSliceHelper = spy(new FakeWifiCallingSliceHelper(mContext));
         doReturn(mQueryImsState).when(mWfcSliceHelper).queryImsState(anyInt());
@@ -117,6 +118,8 @@
 
     @Test
     public void test_CreateWifiCallingSlice_invalidSubId() {
+        doReturn(true).when(mQueryImsState).isEnabledByUser();
+        doReturn(false).when(mQueryImsState).isWifiCallingProvisioned();
         mWfcSliceHelper.setDefaultVoiceSubId(-1);
 
         final Slice slice = mWfcSliceHelper.createWifiCallingSlice(
@@ -127,7 +130,7 @@
 
     @Test
     public void test_CreateWifiCallingSlice_wfcNotSupported() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(false);
+        doReturn(false).when(mQueryImsState).isWifiCallingProvisioned();
 
         final Slice slice = mWfcSliceHelper.createWifiCallingSlice(
                 CustomSliceRegistry.WIFI_CALLING_URI);
@@ -143,8 +146,7 @@
         turned off) we need to guide the user to wifi calling settings
         activity so the user can perform the activation there.(PrimaryAction)
          */
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(false).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(false);
         when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -161,8 +163,7 @@
 
     @Test
     public void test_CreateWifiCallingSlice_success() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(true).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
         when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -176,8 +177,7 @@
 
     @Test
     public void test_SettingSliceProvider_getsRightSliceWifiCalling() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(true).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
         when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -192,8 +192,7 @@
 
     @Test
     public void test_SliceBroadcastReceiver_toggleOnWifiCalling() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(false).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
         when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext))
@@ -217,8 +216,7 @@
 
     @Test
     public void test_CreateWifiCallingPreferenceSlice_prefNotEditable() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(true).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
         mWfcSliceHelper.setIsWifiCallingPrefEditable(false);
@@ -232,8 +230,7 @@
 
     @Test
     public void test_CreateWifiCallingPreferenceSlice_wfcOff() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(false).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
         mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
@@ -249,8 +246,7 @@
 
     @Test
     public void test_CreateWifiCallingPreferenceSlice_success() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(true).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
         when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
@@ -267,8 +263,7 @@
 
     @Test
     public void test_SettingsSliceProvider_getWfcPreferenceSlice() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(true).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
         when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
@@ -286,8 +281,7 @@
     }
     @Test
     public void test_SliceBroadcastReceiver_setWfcPrefCellularPref() {
-        when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
-        when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
+        doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
         doReturn(true).when(mQueryImsState).isEnabledByUser();
         when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
         when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
@@ -441,12 +435,6 @@
             return mMockCarrierConfigManager;
         }
 
-        @Override
-        protected ImsManager getImsManager(int subId) {
-            return mMockImsManager;
-        }
-
-        @Override
         protected ImsMmTelManager getImsMmTelManager(int subId) {
             return mMockImsMmTelManager;
         }