Merge "Switch settings to use TimeDetector"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5ff1197..17f95f2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10696,6 +10696,17 @@
<item>@string/game_driver_app_preference_system</item>
</string-array>
+ <!-- Title for App Compatibility Changes dashboard where developers can configure per-app overrides for compatibility changes [CHAR LIMIT=50] -->
+ <string name="platform_compat_dashboard_title">App Compatibility Changes</string>
+ <!-- Summary for App Compatibility Changes dashboard [CHAR LIMIT=NONE] -->
+ <string name="platform_compat_dashboard_summary">Modify app compatibility change overrides</string>
+ <!-- Title for default enabled app compat changes category [CHAR LIMIT=50] -->
+ <string name="platform_compat_default_enabled_title">Default enabled changes</string>
+ <!-- Title for default disabled app compat changes category [CHAR LIMIT=50] -->
+ <string name="platform_compat_default_disabled_title">Default disabled changes</string>
+ <!-- Title for target SDK gated app compat changes category [CHAR LIMIT=50] -->
+ <string name="platform_compat_target_sdk_title">Enabled after SDK <xliff:g id="number" example="29">%d</xliff:g></string>
+
<!-- Slices Strings -->
<!-- Summary text on a card explaining that a setting does not exist / is not supported on the device [CHAR_LIMIT=NONE]-->
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 7cf52fa..d3911ce 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -226,6 +226,13 @@
android:fragment="com.android.settings.development.gamedriver.GameDriverDashboard"
settings:searchable="false" />
+ <Preference
+ android:key="platform_compat_dashboard"
+ android:title="@string/platform_compat_dashboard_title"
+ android:summary="@string/platform_compat_dashboard_summary"
+ android:fragment="com.android.settings.development.compat.PlatformCompatDashboard"
+ />
+
</PreferenceCategory>
<PreferenceCategory
diff --git a/res/xml/platform_compat_settings.xml b/res/xml/platform_compat_settings.xml
new file mode 100644
index 0000000..bee2324
--- /dev/null
+++ b/res/xml/platform_compat_settings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2019 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.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="platform_compat_dashboard"
+ android:title="@string/platform_compat_dashboard_title">
+</PreferenceScreen>
diff --git a/src/com/android/settings/development/DevelopmentOptionsActivityRequestCodes.java b/src/com/android/settings/development/DevelopmentOptionsActivityRequestCodes.java
index 564f2c3..0d91fdd 100644
--- a/src/com/android/settings/development/DevelopmentOptionsActivityRequestCodes.java
+++ b/src/com/android/settings/development/DevelopmentOptionsActivityRequestCodes.java
@@ -31,4 +31,6 @@
int REQUEST_CODE_ANGLE_DRIVER_PKGS = 4;
int REQUEST_CODE_ANGLE_DRIVER_VALUES = 5;
+
+ int REQUEST_COMPAT_CHANGE_APP = 6;
}
diff --git a/src/com/android/settings/development/compat/PlatformCompatDashboard.java b/src/com/android/settings/development/compat/PlatformCompatDashboard.java
new file mode 100644
index 0000000..dab45f2
--- /dev/null
+++ b/src/com/android/settings/development/compat/PlatformCompatDashboard.java
@@ -0,0 +1,276 @@
+/*
+ * Copyright 2019 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.settings.development.compat;
+
+import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_COMPAT_CHANGE_APP;
+
+import android.app.Activity;
+import android.app.settings.SettingsEnums;
+import android.compat.Compatibility.ChangeConfig;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.util.ArraySet;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.compat.CompatibilityChangeConfig;
+import com.android.internal.compat.CompatibilityChangeInfo;
+import com.android.internal.compat.IPlatformCompat;
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.development.AppPicker;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+
+/**
+ * Dashboard for Platform Compat preferences.
+ */
+public class PlatformCompatDashboard extends DashboardFragment {
+ private static final String TAG = "PlatformCompatDashboard";
+ private static final String COMPAT_APP = "compat_app";
+
+ private IPlatformCompat mPlatformCompat;
+
+ private CompatibilityChangeInfo[] mChanges;
+
+ @VisibleForTesting
+ String mSelectedApp;
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.SETTINGS_PLATFORM_COMPAT_DASHBOARD;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.platform_compat_settings;
+ }
+
+ @Override
+ public int getHelpResource() {
+ return 0;
+ }
+
+ IPlatformCompat getPlatformCompat() {
+ if (mPlatformCompat == null) {
+ mPlatformCompat = IPlatformCompat.Stub
+ .asInterface(ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
+ }
+ return mPlatformCompat;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ try {
+ mChanges = getPlatformCompat().listAllChanges();
+ } catch (RemoteException e) {
+ throw new RuntimeException("Could not list changes!", e);
+ }
+ startAppPicker();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putString(COMPAT_APP, mSelectedApp);
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_COMPAT_CHANGE_APP) {
+ if (resultCode == Activity.RESULT_OK) {
+ mSelectedApp = data.getAction();
+ addPreferences();
+ }
+ return;
+ }
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ private void addPreferences() {
+ getPreferenceScreen().removeAll();
+ getPreferenceScreen().addPreference(
+ createAppPreference(getApplicationInfo().loadIcon(getPackageManager())));
+ // Differentiate compatibility changes into default enabled, default disabled and enabled
+ // after target sdk.
+ final CompatibilityChangeConfig configMappings = getAppChangeMappings();
+ final List<CompatibilityChangeInfo> enabledChanges = new ArrayList<>();
+ final List<CompatibilityChangeInfo> disabledChanges = new ArrayList<>();
+ final Map<Integer, List<CompatibilityChangeInfo>> targetSdkChanges = new TreeMap<>();
+ for (CompatibilityChangeInfo change : mChanges) {
+ if (change.getEnableAfterTargetSdk() != 0) {
+ List<CompatibilityChangeInfo> sdkChanges;
+ if (!targetSdkChanges.containsKey(change.getEnableAfterTargetSdk())) {
+ sdkChanges = new ArrayList<>();
+ targetSdkChanges.put(change.getEnableAfterTargetSdk(), sdkChanges);
+ } else {
+ sdkChanges = targetSdkChanges.get(change.getEnableAfterTargetSdk());
+ }
+ sdkChanges.add(change);
+ } else if (change.getDisabled()) {
+ disabledChanges.add(change);
+ } else {
+ enabledChanges.add(change);
+ }
+ }
+ createChangeCategoryPreference(enabledChanges, configMappings,
+ getString(R.string.platform_compat_default_enabled_title));
+ createChangeCategoryPreference(disabledChanges, configMappings,
+ getString(R.string.platform_compat_default_disabled_title));
+ for (Integer sdk : targetSdkChanges.keySet()) {
+ createChangeCategoryPreference(targetSdkChanges.get(sdk), configMappings,
+ getString(R.string.platform_compat_target_sdk_title, sdk));
+ }
+ }
+
+ private CompatibilityChangeConfig getAppChangeMappings() {
+ try {
+ final ApplicationInfo applicationInfo = getApplicationInfo();
+ return getPlatformCompat().getAppConfig(applicationInfo);
+ } catch (RemoteException e) {
+ throw new RuntimeException("Could not get app config!", e);
+ }
+ }
+
+ /**
+ * Create a {@link Preference} for a changeId.
+ *
+ * <p>The {@link Preference} is a toggle switch that can enable or disable the given change for
+ * the currently selected app.</p>
+ */
+ Preference createPreferenceForChange(Context context, CompatibilityChangeInfo change,
+ CompatibilityChangeConfig configMappings) {
+ final boolean currentValue = configMappings.isChangeEnabled(change.getId());
+ final SwitchPreference item = new SwitchPreference(context);
+ final String changeName =
+ change.getName() != null ? change.getName() : "Change_" + change.getId();
+ item.setSummary(changeName);
+ item.setKey(changeName);
+ item.setEnabled(true);
+ item.setChecked(currentValue);
+ item.setOnPreferenceChangeListener(
+ new CompatChangePreferenceChangeListener(change.getId()));
+ return item;
+ }
+
+ /**
+ * Get {@link ApplicationInfo} for the currently selected app.
+ *
+ * @return an {@link ApplicationInfo} instance.
+ */
+ ApplicationInfo getApplicationInfo() {
+ try {
+ return getPackageManager().getApplicationInfo(mSelectedApp, 0);
+ } catch (PackageManager.NameNotFoundException e) {
+ throw new RuntimeException("Could not get ApplicationInfo for selected app!", e);
+ }
+ }
+
+ /**
+ * Create a {@link Preference} for the selected app.
+ *
+ * <p>The {@link Preference} contains the icon, package name and target SDK for the selected
+ * app. Selecting this preference will also re-trigger the app selection dialog.</p>
+ */
+ Preference createAppPreference(Drawable icon) {
+ final ApplicationInfo applicationInfo = getApplicationInfo();
+ final Preference appPreference = new Preference(getPreferenceScreen().getContext());
+ appPreference.setIcon(icon);
+ appPreference.setSummary(mSelectedApp
+ + " SDK "
+ + applicationInfo.targetSdkVersion);
+ appPreference.setKey(mSelectedApp);
+ appPreference.setOnPreferenceClickListener(
+ preference -> {
+ startAppPicker();
+ return true;
+ });
+ return appPreference;
+ }
+
+ PreferenceCategory createChangeCategoryPreference(List<CompatibilityChangeInfo> changes,
+ CompatibilityChangeConfig configMappings, String title) {
+ final PreferenceCategory category =
+ new PreferenceCategory(getPreferenceScreen().getContext());
+ category.setTitle(title);
+ getPreferenceScreen().addPreference(category);
+ addChangePreferencesToCategory(changes, category, configMappings);
+ return category;
+ }
+
+ private void addChangePreferencesToCategory(List<CompatibilityChangeInfo> changes,
+ PreferenceCategory category, CompatibilityChangeConfig configMappings) {
+ for (CompatibilityChangeInfo change : changes) {
+ final Preference preference = createPreferenceForChange(getPreferenceScreen().getContext(),
+ change, configMappings);
+ category.addPreference(preference);
+ }
+ }
+
+ private void startAppPicker() {
+ final Intent intent = new Intent(getContext(), AppPicker.class);
+ startActivityForResult(intent, REQUEST_COMPAT_CHANGE_APP);
+ }
+
+ private class CompatChangePreferenceChangeListener implements OnPreferenceChangeListener {
+ private final long changeId;
+
+ CompatChangePreferenceChangeListener(long changeId) {
+ this.changeId = changeId;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ try {
+ final ArraySet<Long> enabled = new ArraySet<>();
+ final ArraySet<Long> disabled = new ArraySet<>();
+ if ((Boolean) newValue) {
+ enabled.add(changeId);
+ } else {
+ disabled.add(changeId);
+ }
+ final CompatibilityChangeConfig overrides =
+ new CompatibilityChangeConfig(new ChangeConfig(enabled, disabled));
+ getPlatformCompat().setOverrides(overrides, mSelectedApp);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
index 166eda3..857f535 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
@@ -26,10 +26,10 @@
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.telephony.CarrierConfigManager;
-import android.telephony.SmsCbMessage;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
+import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
@@ -141,9 +141,9 @@
mSlotIndex = slotId;
mSubscriptionInfo = getPhoneSubscriptionInfo(slotId);
- mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
- mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
- mEuiccManager = mContext.getSystemService(EuiccManager.class);
+ mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
+ mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
+ mEuiccManager = mContext.getSystemService(EuiccManager.class);
mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
mRes = mContext.getResources();
@@ -182,9 +182,9 @@
mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId())
.listen(mPhoneStateListener,
- PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
- | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
- | PhoneStateListener.LISTEN_SERVICE_STATE);
+ PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
+ | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
+ | PhoneStateListener.LISTEN_SERVICE_STATE);
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
if (mShowLatestAreaInfo) {
@@ -405,13 +405,14 @@
private void updateImsRegistrationState() {
final int subscriptionId = mSubscriptionInfo.getSubscriptionId();
final PersistableBundle carrierConfig =
- mCarrierConfigManager.getConfigForSubId(subscriptionId);
+ mCarrierConfigManager.getConfigForSubId(subscriptionId);
final boolean showImsRegState = carrierConfig == null ? false :
- carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL);
+ carrierConfig.getBoolean(
+ CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL);
if (showImsRegState) {
final boolean isImsRegistered = mTelephonyManager.isImsRegistered(subscriptionId);
mDialog.setText(IMS_REGISTRATION_STATE_VALUE_ID, mRes.getString(isImsRegistered ?
- R.string.ims_reg_status_registered : R.string.ims_reg_status_not_registered));
+ R.string.ims_reg_status_registered : R.string.ims_reg_status_not_registered));
} else {
mDialog.removeSettingFromScreen(IMS_REGISTRATION_STATE_LABEL_ID);
mDialog.removeSettingFromScreen(IMS_REGISTRATION_STATE_VALUE_ID);
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index 70b92c9..cd4489d 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -38,7 +38,10 @@
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;
+import android.telephony.ims.ProvisioningManager;
import android.telephony.ims.feature.ImsFeature;
+import android.telephony.ims.feature.MmTelFeature;
+import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
@@ -96,7 +99,7 @@
* Returns true if Wifi calling is enabled for at least one subscription.
*/
public static boolean isWifiCallingEnabled(Context context) {
- SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class);
+ final SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class);
if (subManager == null) {
Log.e(TAG, "isWifiCallingEnabled: couldn't get system service.");
return false;
@@ -110,6 +113,22 @@
}
/**
+ * Returns true if Wifi calling is provisioned for the specific subscription with id
+ * {@code subId}.
+ */
+ @VisibleForTesting
+ public static boolean isWfcProvisionedOnDevice(int subId) {
+ final ProvisioningManager provisioningMgr =
+ ProvisioningManager.createForSubscriptionId(subId);
+ if (provisioningMgr == null) {
+ return true;
+ }
+ return provisioningMgr.getProvisioningStatusForCapability(
+ MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
+ ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN);
+ }
+
+ /**
* Returns true if Wifi calling is enabled for the specific subscription with id {@code subId}.
*/
public static boolean isWifiCallingEnabled(Context context, int subId) {
@@ -119,15 +138,15 @@
boolean isWifiCallingEnabled;
if (simCallManager != null) {
- Intent intent = buildPhoneAccountConfigureIntent(
+ final Intent intent = buildPhoneAccountConfigureIntent(
context, simCallManager);
isWifiCallingEnabled = intent != null;
} else {
- ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
+ final ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
isWifiCallingEnabled = imsMgr != null
&& imsMgr.isWfcEnabledByPlatform()
- && imsMgr.isWfcProvisionedOnDevice()
+ && isWfcProvisionedOnDevice(subId)
&& isImsServiceStateReady(imsMgr);
}
@@ -162,8 +181,8 @@
intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
// Check to see that the phone account package can handle the setting intent.
- PackageManager pm = context.getPackageManager();
- List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
+ final PackageManager pm = context.getPackageManager();
+ final List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
if (resolutions.size() == 0) {
intent = null; // set no intent if the package cannot handle it.
}
@@ -194,7 +213,7 @@
* the user has enabled development mode.
*/
public static boolean showEuiccSettings(Context context) {
- EuiccManager euiccManager =
+ final EuiccManager euiccManager =
(EuiccManager) context.getSystemService(EuiccManager.class);
if (!euiccManager.isEnabled()) {
return false;
@@ -202,16 +221,16 @@
final ContentResolver cr = context.getContentResolver();
- TelephonyManager tm =
+ final TelephonyManager tm =
(TelephonyManager) context.getSystemService(TelephonyManager.class);
- String currentCountry = tm.getNetworkCountryIso().toLowerCase();
- String supportedCountries =
+ final String currentCountry = tm.getNetworkCountryIso().toLowerCase();
+ final String supportedCountries =
Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES);
boolean inEsimSupportedCountries = false;
if (TextUtils.isEmpty(currentCountry)) {
inEsimSupportedCountries = true;
} else if (!TextUtils.isEmpty(supportedCountries)) {
- List<String> supportedCountryList =
+ final List<String> supportedCountryList =
Arrays.asList(TextUtils.split(supportedCountries.toLowerCase(), ","));
if (supportedCountryList.contains(currentCountry)) {
inEsimSupportedCountries = true;
@@ -244,7 +263,7 @@
telephonyManager.setDataEnabled(enabled);
if (disableOtherSubscriptions) {
- List<SubscriptionInfo> subInfoList =
+ final List<SubscriptionInfo> subInfoList =
subscriptionManager.getActiveSubscriptionInfoList(true);
if (subInfoList != null) {
for (SubscriptionInfo subInfo : subInfoList) {
@@ -358,7 +377,7 @@
* Return {@code true} if we need show settings for network selection(i.e. Verizon)
*/
public static boolean shouldDisplayNetworkSelectOptions(Context context, int subId) {
- final TelephonyManager telephonyManager = TelephonyManager.from(context)
+ final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(subId);
final PersistableBundle carrierConfig = context.getSystemService(
CarrierConfigManager.class).getConfigForSubId(subId);
@@ -419,8 +438,8 @@
return true;
}
- String operatorNumeric = telephonyManager.getServiceState().getOperatorNumeric();
- String[] numericArray = carrierConfig.getStringArray(
+ final String operatorNumeric = telephonyManager.getServiceState().getOperatorNumeric();
+ final String[] numericArray = carrierConfig.getStringArray(
CarrierConfigManager.KEY_SUPPORT_TDSCDMA_ROAMING_NETWORKS_STRING_ARRAY);
if (numericArray == null || operatorNumeric == null) {
return false;
@@ -511,12 +530,12 @@
public static Drawable getSignalStrengthIcon(Context context, int level, int numLevels,
int iconType, boolean cutOut) {
- SignalDrawable signalDrawable = new SignalDrawable(context);
+ final SignalDrawable signalDrawable = new SignalDrawable(context);
signalDrawable.setLevel(
SignalDrawable.getState(level, numLevels, cutOut));
// Make the network type drawable
- Drawable networkDrawable =
+ final Drawable networkDrawable =
iconType == NO_CELL_DATA_TYPE_ICON
? EMPTY_DRAWABLE
: context
@@ -527,7 +546,7 @@
final int iconSize =
context.getResources().getDimensionPixelSize(R.dimen.signal_strength_icon_size);
- LayerDrawable icons = new LayerDrawable(layers);
+ final LayerDrawable icons = new LayerDrawable(layers);
// Set the network type icon at the top left
icons.setLayerGravity(0 /* index of networkDrawable */, Gravity.TOP | Gravity.LEFT);
// Set the signal strength icon at the bottom right
@@ -536,4 +555,60 @@
icons.setTintList(Utils.getColorAttr(context, android.R.attr.colorControlNormal));
return icons;
}
+
+ /**
+ * This method is migrated from
+ * {@link android.telephony.TelephonyManager.getNetworkOperatorName}. Which provides
+ *
+ * 1. Better support under multi-SIM environment.
+ * 2. Similar design which aligned with operator name displayed in status bar
+ */
+ public static CharSequence getCurrentCarrierNameForDisplay(Context context, int subId) {
+ final SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
+ if (sm != null) {
+ final SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId);
+ if (subInfo != null) {
+ return subInfo.getCarrierName();
+ }
+ }
+ return getOperatorNameFromTelephonyManager(context);
+ }
+
+ public static CharSequence getCurrentCarrierNameForDisplay(Context context) {
+ final SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
+ if (sm != null) {
+ final int subId = sm.getDefaultSubscriptionId();
+ final SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId);
+ if (subInfo != null) {
+ return subInfo.getCarrierName();
+ }
+ }
+ return getOperatorNameFromTelephonyManager(context);
+ }
+
+ private static SubscriptionInfo getSubscriptionInfo(SubscriptionManager subManager,
+ int subId) {
+ List<SubscriptionInfo> subInfos = subManager.getAccessibleSubscriptionInfoList();
+ if (subInfos == null) {
+ subInfos = subManager.getActiveSubscriptionInfoList();
+ }
+ if (subInfos == null) {
+ return null;
+ }
+ for (SubscriptionInfo subInfo : subInfos) {
+ if (subInfo.getSubscriptionId() == subId) {
+ return subInfo;
+ }
+ }
+ return null;
+ }
+
+ private static String getOperatorNameFromTelephonyManager(Context context) {
+ final TelephonyManager tm =
+ (TelephonyManager) context.getSystemService(TelephonyManager.class);
+ if (tm == null) {
+ return null;
+ }
+ return tm.getNetworkOperatorName();
+ }
}
diff --git a/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java b/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java
index 8f8d0d0..2f176ef 100644
--- a/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java
@@ -20,7 +20,6 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
-import android.os.Looper;
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telecom.PhoneAccountHandle;
@@ -29,12 +28,12 @@
import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import android.telephony.ims.ImsMmTelManager;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
-import com.android.ims.ImsConfig;
import com.android.ims.ImsManager;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -49,11 +48,13 @@
public class WifiCallingPreferenceController extends TelephonyBasePreferenceController implements
LifecycleObserver, OnStart, OnStop {
- private TelephonyManager mTelephonyManager;
+ @VisibleForTesting
+ Integer mCallState;
@VisibleForTesting
CarrierConfigManager mCarrierConfigManager;
@VisibleForTesting
ImsManager mImsManager;
+ private ImsMmTelManager mImsMmTelManager;
@VisibleForTesting
PhoneAccountHandle mSimCallManager;
private PhoneCallStateListener mPhoneStateListener;
@@ -62,8 +63,7 @@
public WifiCallingPreferenceController(Context context, String key) {
super(context, key);
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
- mTelephonyManager = context.getSystemService(TelephonyManager.class);
- mPhoneStateListener = new PhoneCallStateListener(Looper.getMainLooper());
+ mPhoneStateListener = new PhoneCallStateListener();
}
@Override
@@ -76,7 +76,7 @@
@Override
public void onStart() {
- mPhoneStateListener.register(mSubId);
+ mPhoneStateListener.register(mContext, mSubId);
}
@Override
@@ -88,7 +88,7 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
- Intent intent = mPreference.getIntent();
+ final Intent intent = mPreference.getIntent();
if (intent != null) {
intent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
}
@@ -97,15 +97,18 @@
@Override
public void updateState(Preference preference) {
super.updateState(preference);
+ if (mCallState == null) {
+ return;
+ }
if (mSimCallManager != null) {
- Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
+ final Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
mSimCallManager);
if (intent == null) {
// Do nothing in this case since preference is invisible
return;
}
final PackageManager pm = mContext.getPackageManager();
- List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
+ final List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
preference.setTitle(resolutions.get(0).loadLabel(pm));
preference.setSummary(null);
preference.setIntent(intent);
@@ -125,17 +128,20 @@
.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL);
}
}
- final boolean isRoaming = mTelephonyManager.isNetworkRoaming();
- int wfcMode = mImsManager.getWfcMode(isRoaming && !useWfcHomeModeForRoaming);
+ final boolean isRoaming = getTelephonyManager(mContext, mSubId)
+ .isNetworkRoaming();
+ final int wfcMode = (isRoaming && !useWfcHomeModeForRoaming)
+ ? mImsMmTelManager.getVoWiFiRoamingModeSetting() :
+ mImsMmTelManager.getVoWiFiModeSetting();
switch (wfcMode) {
- case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
+ case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
break;
- case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
+ case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
resId = com.android.internal.R.string
.wfc_mode_cellular_preferred_summary;
break;
- case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
+ case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
break;
default:
@@ -144,37 +150,56 @@
}
preference.setSummary(resId);
}
- preference.setEnabled(
- mTelephonyManager.getCallState(mSubId) == TelephonyManager.CALL_STATE_IDLE);
+ preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE);
}
public WifiCallingPreferenceController init(int subId) {
mSubId = subId;
- mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId));
+ mImsMmTelManager = getImsMmTelManager(mSubId);
mSimCallManager = mContext.getSystemService(TelecomManager.class)
.getSimCallManagerForSubscription(mSubId);
return this;
}
+ protected ImsMmTelManager getImsMmTelManager(int subId) {
+ return ImsMmTelManager.createForSubscriptionId(subId);
+ }
+
+ @VisibleForTesting
+ TelephonyManager getTelephonyManager(Context context, int subId) {
+ final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
+ if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ return telephonyMgr;
+ }
+ final TelephonyManager subscriptionTelephonyMgr =
+ telephonyMgr.createForSubscriptionId(subId);
+ return (subscriptionTelephonyMgr == null) ? telephonyMgr : subscriptionTelephonyMgr;
+ }
+
+
private class PhoneCallStateListener extends PhoneStateListener {
- public PhoneCallStateListener(Looper looper) {
- super(looper);
+ PhoneCallStateListener() {
+ super();
}
+ private TelephonyManager mTelephonyManager;
+
@Override
public void onCallStateChanged(int state, String incomingNumber) {
+ mCallState = state;
updateState(mPreference);
}
- public void register(int subId) {
- mSubId = subId;
+ public void register(Context context, int subId) {
+ mTelephonyManager = getTelephonyManager(context, subId);
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
}
public void unregister() {
+ mCallState = null;
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
}
}
diff --git a/src/com/android/settings/widget/VideoPreferenceController.java b/src/com/android/settings/widget/VideoPreferenceController.java
index 488a554..5b4d603 100644
--- a/src/com/android/settings/widget/VideoPreferenceController.java
+++ b/src/com/android/settings/widget/VideoPreferenceController.java
@@ -37,7 +37,7 @@
@Override
public int getAvailabilityStatus() {
- return mVideoPreference.isAnimationAvailable() ?
+ return mVideoPreference != null && mVideoPreference.isAnimationAvailable() ?
AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
}
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettings.java b/src/com/android/settings/wifi/calling/WifiCallingSettings.java
index 8a342c8..72e1df2 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettings.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettings.java
@@ -22,6 +22,9 @@
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
+import android.telephony.ims.ProvisioningManager;
+import android.telephony.ims.feature.MmTelFeature;
+import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -100,11 +103,11 @@
if (mSil == null) {
return;
}
- Intent intent = getActivity().getIntent();
+ final Intent intent = getActivity().getIntent();
if (intent == null) {
return;
}
- int subId = intent.getIntExtra(Settings.EXTRA_SUB_ID,
+ final int subId = intent.getIntExtra(Settings.EXTRA_SUB_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
if (SubscriptionManager.isValidSubscriptionId(subId)) {
for (SubscriptionInfo subInfo : mSil) {
@@ -168,7 +171,7 @@
args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false);
args.putInt(WifiCallingSettingsForSub.FRAGMENT_BUNDLE_SUBID,
mSil.get(position).getSubscriptionId());
- WifiCallingSettingsForSub fragment = new WifiCallingSettingsForSub();
+ final WifiCallingSettingsForSub fragment = new WifiCallingSettingsForSub();
fragment.setArguments(args);
return fragment;
@@ -195,14 +198,21 @@
@VisibleForTesting
boolean isWfcEnabledByPlatform(SubscriptionInfo info) {
- ImsManager imsManager = ImsManager.getInstance(getActivity(), info.getSimSlotIndex());
+ final ImsManager imsManager = ImsManager.getInstance(getActivity(),
+ info.getSimSlotIndex());
return imsManager.isWfcEnabledByPlatform();
}
@VisibleForTesting
boolean isWfcProvisionedOnDevice(SubscriptionInfo info) {
- ImsManager imsManager = ImsManager.getInstance(getActivity(), info.getSimSlotIndex());
- return imsManager.isWfcProvisionedOnDevice();
+ final ProvisioningManager provisioningMgr =
+ ProvisioningManager.createForSubscriptionId(info.getSubscriptionId());
+ if (provisioningMgr == null) {
+ return true;
+ }
+ return provisioningMgr.getProvisioningStatusForCapability(
+ MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
+ ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN);
}
private void updateSubList() {
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index 252193d..8447fcf 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -30,6 +30,7 @@
import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import android.telephony.ims.ImsMmTelManager;
import android.telephony.ims.ProvisioningManager;
import android.text.TextUtils;
import android.util.Log;
@@ -54,6 +55,7 @@
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.widget.SwitchBar;
/**
@@ -98,6 +100,7 @@
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
private ImsManager mImsManager;
+ private ImsMmTelManager mImsMmTelManager;
private TelephonyManager mTelephonyManager;
private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
@@ -110,11 +113,12 @@
@Override
public void onCallStateChanged(int state, String incomingNumber) {
final SettingsActivity activity = (SettingsActivity) getActivity();
- boolean isNonTtyOrTtyOnVolteEnabled = mImsManager.isNonTtyOrTtyOnVolteEnabled();
- boolean isWfcEnabled = mSwitchBar.isChecked()
+ final boolean isNonTtyOrTtyOnVolteEnabled = mImsManager.isNonTtyOrTtyOnVolteEnabled();
+ final boolean isWfcEnabled = mSwitchBar.isChecked()
&& isNonTtyOrTtyOnVolteEnabled;
-
- mSwitchBar.setEnabled((state == TelephonyManager.CALL_STATE_IDLE)
+ boolean isCallStateIdle =
+ mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE;
+ mSwitchBar.setEnabled(isCallStateIdle
&& isNonTtyOrTtyOnVolteEnabled);
boolean isWfcModeEditable = true;
@@ -132,16 +136,16 @@
}
}
- Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE);
+ final Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE);
if (pref != null) {
pref.setEnabled(isWfcEnabled && isWfcModeEditable
- && (state == TelephonyManager.CALL_STATE_IDLE));
+ && isCallStateIdle);
}
- Preference pref_roam =
+ final Preference pref_roam =
getPreferenceScreen().findPreference(BUTTON_WFC_ROAMING_MODE);
if (pref_roam != null) {
pref_roam.setEnabled(isWfcEnabled && isWfcRoamingModeEditable
- && (state == TelephonyManager.CALL_STATE_IDLE));
+ && isCallStateIdle);
}
}
};
@@ -151,7 +155,7 @@
*/
private final OnPreferenceClickListener mUpdateAddressListener =
preference -> {
- Intent carrierAppIntent = getCarrierActivityIntent();
+ final Intent carrierAppIntent = getCarrierActivityIntent();
if (carrierAppIntent != null) {
carrierAppIntent.putExtra(EXTRA_LAUNCH_CARRIER_APP, LAUCH_APP_UPDATE);
startActivity(carrierAppIntent);
@@ -179,7 +183,7 @@
mEmptyView = getView().findViewById(android.R.id.empty);
setEmptyView(mEmptyView);
final Resources res = getResourcesForSubId();
- String emptyViewText = res.getString(R.string.wifi_calling_off_explanation,
+ final String emptyViewText = res.getString(R.string.wifi_calling_off_explanation,
res.getString(R.string.wifi_calling_off_explanation_2));
mEmptyView.setText(emptyViewText);
@@ -195,17 +199,17 @@
}
private void showAlert(Intent intent) {
- Context context = getActivity();
+ final Context context = getActivity();
- CharSequence title = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_TITLE);
- CharSequence message = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_MESSAGE);
+ final CharSequence title = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_TITLE);
+ final CharSequence message = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_MESSAGE);
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message)
.setTitle(title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.ok, null);
- AlertDialog dialog = builder.create();
+ final AlertDialog dialog = builder.create();
dialog.show();
}
@@ -214,7 +218,7 @@
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
+ final String action = intent.getAction();
if (action.equals(ImsManager.ACTION_IMS_REGISTRATION_ERROR)) {
// If this fragment is active then we are immediately
// showing alert on screen. There is no need to add
@@ -245,6 +249,11 @@
return ImsManager.getInstance(getActivity(), SubscriptionManager.getPhoneId(mSubId));
}
+ @VisibleForTesting
+ ImsMmTelManager getImsMmTelManager() {
+ return ImsMmTelManager.createForSubscriptionId(mSubId);
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -261,9 +270,9 @@
}
mImsManager = getImsManager();
+ mImsMmTelManager = getImsMmTelManager();
- mTelephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
- .createForSubscriptionId(mSubId);
+ mTelephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE));
mButtonWfcMode = findPreference(BUTTON_WFC_MODE);
mButtonWfcMode.setOnPreferenceChangeListener(this);
@@ -288,31 +297,36 @@
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- View view = inflater.inflate(
+ final View view = inflater.inflate(
R.layout.wifi_calling_settings_preferences, container, false);
final ViewGroup prefs_container = view.findViewById(R.id.prefs_container);
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
- View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
+ final View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
prefs_container.addView(prefs);
return view;
}
+ @VisibleForTesting
+ boolean isWfcProvisionedOnDevice() {
+ return MobileNetworkUtils.isWfcProvisionedOnDevice(mSubId);
+ }
+
private void updateBody() {
- if (!mImsManager.isWfcProvisionedOnDevice()) {
+ if (!isWfcProvisionedOnDevice()) {
// This screen is not allowed to be shown due to provisioning policy and should
// therefore be closed.
finish();
return;
}
- CarrierConfigManager configManager = (CarrierConfigManager)
+ final CarrierConfigManager configManager = (CarrierConfigManager)
getSystemService(Context.CARRIER_CONFIG_SERVICE);
boolean isWifiOnlySupported = true;
if (configManager != null) {
- PersistableBundle b = configManager.getConfigForSubId(mSubId);
+ final PersistableBundle b = configManager.getConfigForSubId(mSubId);
if (b != null) {
mEditableWfcMode = b.getBoolean(
CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL);
@@ -341,11 +355,11 @@
// NOTE: Buttons will be enabled/disabled in mPhoneStateListener
- boolean wfcEnabled = mImsManager.isWfcEnabledByUser()
+ final boolean wfcEnabled = mImsManager.isWfcEnabledByUser()
&& mImsManager.isNonTtyOrTtyOnVolteEnabled();
mSwitch.setChecked(wfcEnabled);
- int wfcMode = mImsManager.getWfcMode(false);
- int wfcRoamingMode = mImsManager.getWfcMode(true);
+ final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
+ final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
mButtonWfcMode.setValue(Integer.toString(wfcMode));
mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode));
updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode);
@@ -369,7 +383,7 @@
context.registerReceiver(mIntentReceiver, mIntentFilter);
- Intent intent = getActivity().getIntent();
+ final Intent intent = getActivity().getIntent();
if (intent.getBooleanExtra(Phone.EXTRA_KEY_ALERT_SHOW, false)) {
showAlert(intent);
}
@@ -392,8 +406,7 @@
if (mValidListener) {
mValidListener = false;
- TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
+ mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
mSwitchBar.removeOnSwitchChangeListener(this);
}
@@ -441,22 +454,22 @@
*/
private Intent getCarrierActivityIntent() {
// Retrive component name from carrier config
- CarrierConfigManager configManager =
+ final CarrierConfigManager configManager =
getActivity().getSystemService(CarrierConfigManager.class);
if (configManager == null) return null;
- PersistableBundle bundle = configManager.getConfigForSubId(mSubId);
+ final PersistableBundle bundle = configManager.getConfigForSubId(mSubId);
if (bundle == null) return null;
- String carrierApp = bundle.getString(
+ final String carrierApp = bundle.getString(
CarrierConfigManager.KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING);
if (TextUtils.isEmpty(carrierApp)) return null;
- ComponentName componentName = ComponentName.unflattenFromString(carrierApp);
+ final ComponentName componentName = ComponentName.unflattenFromString(carrierApp);
if (componentName == null) return null;
// Build and return intent
- Intent intent = new Intent();
+ final Intent intent = new Intent();
intent.setComponent(componentName);
intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, mSubId);
return intent;
@@ -469,8 +482,8 @@
Log.i(TAG, "updateWfcMode(" + wfcEnabled + ")");
mImsManager.setWfcSetting(wfcEnabled);
- int wfcMode = mImsManager.getWfcMode(false);
- int wfcRoamingMode = mImsManager.getWfcMode(true);
+ final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
+ final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode);
if (wfcEnabled) {
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), wfcMode);
@@ -496,7 +509,7 @@
case REQUEST_CHECK_WFC_DISCLAIMER:
if (resultCode == Activity.RESULT_OK) {
// Call address management activity before turning on WFC
- Intent carrierAppIntent = getCarrierActivityIntent();
+ final Intent carrierAppIntent = getCarrierActivityIntent();
if (carrierAppIntent != null) {
carrierAppIntent.putExtra(EXTRA_LAUNCH_CARRIER_APP, LAUCH_APP_ACTIVATE);
startActivityForResult(carrierAppIntent,
@@ -520,7 +533,7 @@
mButtonWfcRoamingMode.setEnabled(wfcEnabled && mEditableWfcRoamingMode);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
- boolean updateAddressEnabled = (getCarrierActivityIntent() != null);
+ final boolean updateAddressEnabled = (getCarrierActivityIntent() != null);
if (wfcEnabled) {
if (mEditableWfcMode) {
preferenceScreen.addPreference(mButtonWfcMode);
@@ -551,24 +564,24 @@
if (preference == mButtonWfcMode) {
Log.d(TAG, "onPreferenceChange mButtonWfcMode " + newValue);
mButtonWfcMode.setValue((String) newValue);
- int buttonMode = Integer.valueOf((String) newValue);
- int currentWfcMode = mImsManager.getWfcMode(false);
+ final int buttonMode = Integer.valueOf((String) newValue);
+ final int currentWfcMode = mImsMmTelManager.getVoWiFiModeSetting();
if (buttonMode != currentWfcMode) {
- mImsManager.setWfcMode(buttonMode, false);
+ mImsMmTelManager.setVoWiFiModeSetting(buttonMode);
mButtonWfcMode.setSummary(getWfcModeSummary(buttonMode));
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode);
if (mUseWfcHomeModeForRoaming) {
- mImsManager.setWfcMode(buttonMode, true);
+ mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode);
// mButtonWfcRoamingMode.setSummary is not needed; summary is selected value
}
}
} else if (preference == mButtonWfcRoamingMode) {
mButtonWfcRoamingMode.setValue((String) newValue);
- int buttonMode = Integer.valueOf((String) newValue);
- int currentMode = mImsManager.getWfcMode(true);
+ final int buttonMode = Integer.valueOf((String) newValue);
+ final int currentMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
if (buttonMode != currentMode) {
- mImsManager.setWfcMode(buttonMode, true);
+ mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode);
// mButtonWfcRoamingMode.setSummary is not needed; summary is just selected value.
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode);
}
@@ -580,13 +593,13 @@
int resId = com.android.internal.R.string.wifi_calling_off_summary;
if (mImsManager.isWfcEnabledByUser()) {
switch (wfcMode) {
- case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
+ case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
break;
- case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
+ case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
break;
- case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
+ case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
break;
default:
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
index 70eef2c..68a4b40 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
@@ -30,6 +30,7 @@
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
+import android.telephony.ims.ImsMmTelManager;
import android.text.TextUtils;
import android.util.Log;
@@ -44,6 +45,7 @@
import com.android.ims.ImsManager;
import com.android.settings.R;
import com.android.settings.Utils;
+import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.slices.SliceBroadcastReceiver;
import java.util.concurrent.Callable;
@@ -138,7 +140,7 @@
final ImsManager imsManager = getImsManager(subId);
if (!imsManager.isWfcEnabledByPlatform()
- || !imsManager.isWfcProvisionedOnDevice()) {
+ || !isWfcProvisionedOnDevice(subId)) {
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by Platform");
return null;
}
@@ -233,9 +235,10 @@
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()
- || !imsManager.isWfcProvisionedOnDevice()) {
+ || !isWfcProvisionedOnDevice(subId)) {
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
return null;
}
@@ -249,7 +252,7 @@
int wfcMode = -1;
try {
isWifiCallingEnabled = isWifiCallingEnabled(imsManager);
- wfcMode = getWfcMode(imsManager);
+ wfcMode = getWfcMode(imsMmTelManager);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Log.e(TAG, "Unable to get wifi calling preferred mode", e);
return null;
@@ -279,7 +282,7 @@
Uri sliceUri) {
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
// Top row shows information on current preference state
- ListBuilder listBuilder = new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
+ final ListBuilder listBuilder = new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
.setAccentColor(Utils.getColorAccentDefaultColor(mContext));
listBuilder.setHeader(new ListBuilder.HeaderBuilder()
.setTitle(mContext.getText(R.string.wifi_calling_mode_title))
@@ -294,18 +297,18 @@
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_wifi_only_summary,
ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY,
- currentWfcPref == ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY));
+ currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_ONLY));
}
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_wifi_preferred_summary,
ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED,
- currentWfcPref == ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED));
+ currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED));
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_cellular_preferred_summary,
ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED,
- currentWfcPref == ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED));
+ currentWfcPref == ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
return listBuilder.build();
}
@@ -337,13 +340,13 @@
*/
private CharSequence getWifiCallingPreferenceSummary(int wfcMode) {
switch (wfcMode) {
- case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
+ case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
return mContext.getText(
com.android.internal.R.string.wfc_mode_wifi_only_summary);
- case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
+ case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
return mContext.getText(
com.android.internal.R.string.wfc_mode_wifi_preferred_summary);
- case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
+ case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
return mContext.getText(
com.android.internal.R.string.wfc_mode_cellular_preferred_summary);
default:
@@ -355,15 +358,19 @@
return ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(subId));
}
- private int getWfcMode(ImsManager imsManager)
+ protected ImsMmTelManager getImsMmTelManager(int subId) {
+ return ImsMmTelManager.createForSubscriptionId(subId);
+ }
+
+ private int getWfcMode(ImsMmTelManager imsMmTelManager)
throws InterruptedException, ExecutionException, TimeoutException {
- FutureTask<Integer> wfcModeTask = new FutureTask<>(new Callable<Integer>() {
+ final FutureTask<Integer> wfcModeTask = new FutureTask<>(new Callable<Integer>() {
@Override
public Integer call() {
- return imsManager.getWfcMode(false);
+ return imsMmTelManager.getVoWiFiModeSetting();
}
});
- ExecutorService executor = Executors.newSingleThreadExecutor();
+ final ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(wfcModeTask);
return wfcModeTask.get(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
}
@@ -380,7 +387,7 @@
if (subId > SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
final ImsManager imsManager = getImsManager(subId);
if (imsManager.isWfcEnabledByPlatform()
- && imsManager.isWfcProvisionedOnDevice()) {
+ && isWfcProvisionedOnDevice(subId)) {
final boolean currentValue = imsManager.isWfcEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled();
final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
@@ -420,33 +427,34 @@
final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
- ImsManager imsManager = getImsManager(subId);
+ final ImsManager imsManager = getImsManager(subId);
if (isWifiCallingPrefEditable
&& imsManager.isWfcEnabledByPlatform()
- && imsManager.isWfcProvisionedOnDevice()
+ && isWfcProvisionedOnDevice(subId)
&& imsManager.isWfcEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled()) {
// Change the preference only when wifi calling is enabled
// And when wifi calling preference is editable for the current carrier
- final int currentValue = imsManager.getWfcMode(false);
+ final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
+ final int currentValue = imsMmTelManager.getVoWiFiModeSetting();
int newValue = errorValue;
switch (intent.getAction()) {
case ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY:
if (isWifiOnlySupported) {
// change to wifi_only when wifi_only is enabled.
- newValue = ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY;
+ newValue = ImsMmTelManager.WIFI_MODE_WIFI_ONLY;
}
break;
case ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED:
- newValue = ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED;
+ newValue = ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED;
break;
case ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED:
- newValue = ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED;
+ newValue = ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED;
break;
}
if (newValue != errorValue && newValue != currentValue) {
// Update the setting only when there is a valid update
- imsManager.setWfcMode(newValue, false);
+ imsMmTelManager.setVoWiFiModeSetting(newValue);
}
}
}
@@ -505,6 +513,11 @@
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/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java b/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java
index 9a50a83..526e9c3 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java
@@ -17,15 +17,18 @@
package com.android.settings.wifi.calling;
import android.content.Context;
+import android.telephony.SubscriptionManager;
import com.android.ims.ImsManager;
import com.android.settings.SettingsActivity;
+import com.android.settings.network.telephony.MobileNetworkUtils;
public class WifiCallingSuggestionActivity extends SettingsActivity {
public static boolean isSuggestionComplete(Context context) {
if (!ImsManager.isWfcEnabledByPlatform(context) ||
- !ImsManager.isWfcProvisionedOnDevice(context)) {
+ !MobileNetworkUtils.isWfcProvisionedOnDevice(
+ SubscriptionManager.getDefaultVoiceSubscriptionId())) {
return true;
}
return ImsManager.isWfcEnabledByUser(context)
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSoftApManager.java b/src/com/android/settings/wifi/tether/WifiTetherSoftApManager.java
index 3de5869..2db037f 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSoftApManager.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSoftApManager.java
@@ -36,7 +36,7 @@
}
public void registerSoftApCallback() {
- mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler));
+ mWifiManager.registerSoftApCallback(new HandlerExecutor(mHandler), mSoftApCallback);
}
public void unRegisterSoftApCallback() {
diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp
index 28c987b..d7d1d51 100644
--- a/tests/robotests/Android.bp
+++ b/tests/robotests/Android.bp
@@ -59,6 +59,7 @@
static_libs: [
"SettingsLib-robo-testutils",
+ "android-support-annotations",
],
java_resource_dirs: ["config"],
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index 061a81e..cae3e46 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -30,6 +30,7 @@
com.android.settings.datausage.DataUsageList
com.android.settings.datausage.DataUsageSummary
com.android.settings.datetime.timezone.TimeZoneSettings
+com.android.settings.development.compat.PlatformCompatDashboard
com.android.settings.deviceinfo.PrivateVolumeSettings
com.android.settings.deviceinfo.PublicVolumeSettings
com.android.settings.deviceinfo.StorageProfileFragment
diff --git a/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java b/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
new file mode 100644
index 0000000..d13b927
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2019 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.settings.development.compat;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.compat.Compatibility.ChangeConfig;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.graphics.drawable.Drawable;
+import android.os.RemoteException;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.compat.CompatibilityChangeConfig;
+import com.android.internal.compat.CompatibilityChangeInfo;
+import com.android.internal.compat.IPlatformCompat;
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+@RunWith(RobolectricTestRunner.class)
+public class PlatformCompatDashboardTest {
+ private PlatformCompatDashboard mDashboard;
+
+ @Mock
+ private IPlatformCompat mPlatformCompat;
+ private PreferenceScreen mPreferenceScreen;
+ @Mock
+ private ApplicationInfo mApplicationInfo;
+ @Mock
+ private PreferenceManager mPreferenceManager;
+
+ private Context mContext;
+ private CompatibilityChangeInfo[] mChanges;
+ private static final String APP_NAME = "foo.bar.baz";
+
+ @Before
+ public void setUp() throws RemoteException, NameNotFoundException {
+ MockitoAnnotations.initMocks(this);
+ mChanges = new CompatibilityChangeInfo[5];
+ mChanges[0] = new CompatibilityChangeInfo(1L, "Default_Enabled", 0, false);
+ mChanges[1] = new CompatibilityChangeInfo(2L, "Default_Disabled", 0, true);
+ mChanges[2] = new CompatibilityChangeInfo(3L, "Enabled_After_SDK_1_1", 1, false);
+ mChanges[3] = new CompatibilityChangeInfo(4L, "Enabled_After_SDK_1_2", 1, false);
+ mChanges[4] = new CompatibilityChangeInfo(5L, "Enabled_After_SDK_2", 2, false);
+ when(mPlatformCompat.listAllChanges()).thenReturn(mChanges);
+ mContext = RuntimeEnvironment.application;
+ mPreferenceManager = new PreferenceManager(mContext);
+ mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
+ mApplicationInfo.packageName = APP_NAME;
+ mDashboard = spy(new PlatformCompatDashboard());
+ mDashboard.mSelectedApp = APP_NAME;
+ doReturn(mApplicationInfo).when(mDashboard).getApplicationInfo();
+ doReturn(mPlatformCompat).when(mDashboard).getPlatformCompat();
+ doReturn(mPreferenceScreen).when(mDashboard).getPreferenceScreen();
+ doReturn(mPreferenceManager).when(mDashboard).getPreferenceManager();
+ }
+
+ @Test
+ public void getHelpResource_shouldNotHaveHelpResource() {
+ assertThat(mDashboard.getHelpResource()).isEqualTo(0);
+ }
+
+ @Test
+ public void getPreferenceScreenResId_shouldBePlatformCompatSettingsResId() {
+ assertThat(mDashboard.getPreferenceScreenResId())
+ .isEqualTo(R.xml.platform_compat_settings);
+ }
+
+ @Test
+ public void createAppPreference_targetSdkEquals1_summaryReturnsAppNameAndTargetSdk() {
+ mApplicationInfo.targetSdkVersion = 1;
+
+ Preference appPreference = mDashboard.createAppPreference(any(Drawable.class));
+
+ assertThat(appPreference.getSummary()).isEqualTo(APP_NAME + " SDK 1");
+ }
+
+ @Test
+ public void createPreferenceForChange_defaultEnabledChange_createCheckedEntry() {
+ CompatibilityChangeInfo enabledChange = mChanges[0];
+ CompatibilityChangeConfig config = new CompatibilityChangeConfig(
+ new ChangeConfig(new HashSet<Long>(Arrays.asList(enabledChange.getId())),
+ new HashSet<Long>()));
+
+ Preference enabledPreference = mDashboard.createPreferenceForChange(mContext, enabledChange,
+ config);
+
+ SwitchPreference enabledSwitchPreference = (SwitchPreference) enabledPreference;
+
+ assertThat(enabledPreference.getSummary()).isEqualTo(mChanges[0].getName());
+ assertThat(enabledPreference instanceof SwitchPreference).isTrue();
+ assertThat(enabledSwitchPreference.isChecked()).isTrue();
+ }
+
+ @Test
+ public void createPreferenceForChange_defaultDisabledChange_createUncheckedEntry() {
+ CompatibilityChangeInfo disabledChange = mChanges[1];
+ CompatibilityChangeConfig config = new CompatibilityChangeConfig(
+ new ChangeConfig(new HashSet<Long>(),
+ new HashSet<Long>(Arrays.asList(disabledChange.getId()))));
+
+ Preference disabledPreference = mDashboard.createPreferenceForChange(mContext,
+ disabledChange, config);
+
+ assertThat(disabledPreference.getSummary()).isEqualTo(mChanges[1].getName());
+ SwitchPreference disabledSwitchPreference = (SwitchPreference) disabledPreference;
+ assertThat(disabledSwitchPreference.isChecked()).isFalse();
+ }
+
+ @Test
+ public void createChangeCategoryPreference_enabledAndDisabled_hasTitleAndEntries() {
+ Set<Long> enabledChanges = new HashSet<>();
+ enabledChanges.add(mChanges[0].getId());
+ enabledChanges.add(mChanges[1].getId());
+ enabledChanges.add(mChanges[2].getId());
+ Set<Long> disabledChanges = new HashSet<>();
+ disabledChanges.add(mChanges[3].getId());
+ disabledChanges.add(mChanges[4].getId());
+ CompatibilityChangeConfig config = new CompatibilityChangeConfig(
+ new ChangeConfig(enabledChanges, disabledChanges));
+ List<CompatibilityChangeInfo> changesToAdd = new ArrayList<>();
+ for (int i = 0; i < mChanges.length; ++i) {
+ changesToAdd.add(new CompatibilityChangeInfo(mChanges[i].getId(), mChanges[i]
+ .getName(),
+ mChanges[i].getEnableAfterTargetSdk(), mChanges[i].getDisabled()));
+ }
+
+ PreferenceCategory category = mDashboard.createChangeCategoryPreference(changesToAdd,
+ config, "foo");
+
+ assertThat(category.getTitle()).isEqualTo("foo");
+ assertThat(category.getPreferenceCount()).isEqualTo(mChanges.length);
+ for (int i = 0; i < mChanges.length; ++i) {
+ Preference childPreference = category.getPreference(i);
+ assertThat(childPreference instanceof SwitchPreference).isTrue();
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
index 147e627..3ecdcff 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
@@ -16,35 +16,21 @@
package com.android.settings.deviceinfo.simstatus;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .CELL_DATA_NETWORK_TYPE_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .CELL_VOICE_NETWORK_TYPE_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.CELL_DATA_NETWORK_TYPE_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.CELL_VOICE_NETWORK_TYPE_VALUE_ID;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.EID_INFO_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .ICCID_INFO_LABEL_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .ICCID_INFO_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .IMS_REGISTRATION_STATE_LABEL_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .IMS_REGISTRATION_STATE_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .NETWORK_PROVIDER_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .OPERATOR_INFO_LABEL_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .OPERATOR_INFO_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .PHONE_NUMBER_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .ROAMING_INFO_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .SERVICE_STATE_VALUE_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .SIGNAL_STRENGTH_LABEL_ID;
-import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
- .SIGNAL_STRENGTH_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.ICCID_INFO_LABEL_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.ICCID_INFO_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.IMS_REGISTRATION_STATE_LABEL_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.IMS_REGISTRATION_STATE_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.NETWORK_PROVIDER_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.OPERATOR_INFO_LABEL_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.OPERATOR_INFO_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.PHONE_NUMBER_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.ROAMING_INFO_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.SERVICE_STATE_VALUE_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.SIGNAL_STRENGTH_LABEL_ID;
+import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.SIGNAL_STRENGTH_VALUE_ID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -146,7 +132,7 @@
.thenReturn(true);
final ShadowPackageManager shadowPackageManager =
- Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager());
+ Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager());
final PackageInfo sysUIPackageInfo = new PackageInfo();
sysUIPackageInfo.packageName = "com.android.systemui";
shadowPackageManager.addPackage(sysUIPackageInfo);
@@ -251,7 +237,7 @@
mController.initialize();
final String signalStrengthString =
- mContext.getString(R.string.sim_signal_strength, signalDbm, signalAsu);
+ mContext.getString(R.string.sim_signal_strength, signalDbm, signalAsu);
verify(mDialog).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
}
@@ -333,7 +319,7 @@
public void initialize_doNotShowSignalStrength_shouldRemoveSignalStrengthSetting() {
when(mPersistableBundle.getBoolean(
CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL))
- .thenReturn(false);
+ .thenReturn(false);
mController.initialize();
@@ -389,31 +375,31 @@
@Test
public void initialize_imsRegistered_shouldSetImsRegistrationStateSummaryToRegisterd() {
when(mPersistableBundle.getBoolean(
- CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL)).thenReturn(true);
+ CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL)).thenReturn(true);
when(mTelephonyManager.isImsRegistered(anyInt())).thenReturn(true);
mController.initialize();
verify(mDialog).setText(IMS_REGISTRATION_STATE_VALUE_ID,
- mContext.getString(R.string.ims_reg_status_registered));
+ mContext.getString(R.string.ims_reg_status_registered));
}
@Test
public void initialize_imsNotRegistered_shouldSetImsRegistrationStateSummaryToNotRegisterd() {
when(mPersistableBundle.getBoolean(
- CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL)).thenReturn(true);
+ CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL)).thenReturn(true);
when(mTelephonyManager.isImsRegistered(anyInt())).thenReturn(false);
mController.initialize();
verify(mDialog).setText(IMS_REGISTRATION_STATE_VALUE_ID,
- mContext.getString(R.string.ims_reg_status_not_registered));
+ mContext.getString(R.string.ims_reg_status_not_registered));
}
@Test
public void initialize_showImsRegistration_shouldNotRemoveImsRegistrationStateSetting() {
when(mPersistableBundle.getBoolean(
- CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL)).thenReturn(true);
+ CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL)).thenReturn(true);
mController.initialize();
@@ -423,7 +409,7 @@
@Test
public void initialize_doNotShowImsRegistration_shouldRemoveImsRegistrationStateSetting() {
when(mPersistableBundle.getBoolean(
- CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL)).thenReturn(false);
+ CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL)).thenReturn(false);
mController.initialize();
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
index 2bfaeca..c6b8689 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
@@ -22,6 +22,7 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -58,6 +59,10 @@
private static final String PACKAGE_NAME = "com.android.app";
private static final int SUB_ID_1 = 1;
private static final int SUB_ID_2 = 2;
+ private static final int SUB_ID_INVALID = -1;
+ private static final String PLMN_FROM_TELEPHONY_MANAGER_API = "testPlmn";
+ private static final String PLMN_FROM_SUB_ID_1 = "testPlmnSub1";
+ private static final String PLMN_FROM_SUB_ID_2 = "testPlmnSub2";
@Mock
private TelephonyManager mTelephonyManager;
@@ -89,6 +94,7 @@
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
+ when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
@@ -102,10 +108,17 @@
when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig);
when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1);
+ when(mSubscriptionInfo1.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_1);
when(mSubscriptionInfo2.getSubscriptionId()).thenReturn(SUB_ID_2);
+ when(mSubscriptionInfo2.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_2);
when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true))).thenReturn(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+ when(mSubscriptionManager.getAccessibleSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+
+ when(mTelephonyManager.getNetworkOperatorName()).thenReturn(
+ PLMN_FROM_TELEPHONY_MANAGER_API);
}
@Test
@@ -301,4 +314,24 @@
TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
}
+
+ @Test
+ public void getCurrentCarrierNameForDisplay_withoutValidSubId_returnNetworkOperatorName() {
+ assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
+ mContext, SUB_ID_INVALID)).isEqualTo(PLMN_FROM_TELEPHONY_MANAGER_API);
+ }
+
+ @Test
+ public void getCurrentCarrierNameForDisplay_withValidSubId_returnCurrentCarrierName() {
+ assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
+ mContext, SUB_ID_1)).isEqualTo(PLMN_FROM_SUB_ID_1);
+ assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
+ mContext, SUB_ID_2)).isEqualTo(PLMN_FROM_SUB_ID_2);
+ }
+
+ @Test
+ public void getCurrentCarrierNameForDisplay_withoutSubId_returnNotNull() {
+ assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
+ mContext)).isNotNull();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java
index 1048acd..1c79266 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java
@@ -19,7 +19,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNull;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -31,12 +30,11 @@
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import android.telephony.ims.ImsMmTelManager;
import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
-import com.android.ims.ImsConfig;
import com.android.ims.ImsManager;
import com.android.internal.R;
import com.android.settings.core.BasePreferenceController;
@@ -60,6 +58,8 @@
@Mock
private ImsManager mImsManager;
@Mock
+ private ImsMmTelManager mImsMmTelManager;
+ @Mock
private PreferenceScreen mPreferenceScreen;
private WifiCallingPreferenceController mController;
@@ -72,17 +72,22 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
- when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
- when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
- when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
mPreference = new Preference(mContext);
- mController = new WifiCallingPreferenceController(mContext, "wifi_calling");
+ mController = spy(new WifiCallingPreferenceController(mContext, "wifi_calling") {
+ @Override
+ protected ImsMmTelManager getImsMmTelManager(int subId) {
+ return mImsMmTelManager;
+ }
+ });
mController.mCarrierConfigManager = mCarrierConfigManager;
mController.init(SUB_ID);
mController.mImsManager = mImsManager;
+ mController.mCallState = TelephonyManager.CALL_STATE_IDLE;
mPreference.setKey(mController.getPreferenceKey());
+ when(mController.getTelephonyManager(mContext, SUB_ID)).thenReturn(mTelephonyManager);
+
mCarrierConfig = new PersistableBundle();
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
@@ -94,8 +99,10 @@
public void updateState_noSimCallManager_setCorrectSummary() {
mController.mSimCallManager = null;
when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
- when(mImsManager.getWfcMode(anyBoolean())).thenReturn(
- ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY);
+ when(mImsMmTelManager.getVoWiFiRoamingModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
+ when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
mController.updateState(mPreference);
@@ -105,8 +112,7 @@
@Test
public void updateState_notCallIdle_disable() {
- when(mTelephonyManager.getCallState(SUB_ID)).thenReturn(
- TelephonyManager.CALL_STATE_RINGING);
+ mController.mCallState = TelephonyManager.CALL_STATE_RINGING;
mController.updateState(mPreference);
@@ -129,10 +135,10 @@
mController.init(SUB_ID);
mController.mImsManager = mImsManager;
- when(mImsManager.getWfcMode(true)).thenReturn(
- ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED);
- when(mImsManager.getWfcMode(false)).thenReturn(
- ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED);
+ when(mImsMmTelManager.getVoWiFiRoamingModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
+ when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mTelephonyManager.isNetworkRoaming()).thenReturn(true);
@@ -146,10 +152,10 @@
assertNull(mController.mSimCallManager);
// useWfcHomeModeForRoaming is false by default. In order to check wfc in roaming mode. We
// need the device roaming, and not using home mode in roaming network.
- when(mImsManager.getWfcMode(true)).thenReturn(
- ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED);
- when(mImsManager.getWfcMode(false)).thenReturn(
- ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED);
+ when(mImsMmTelManager.getVoWiFiRoamingModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
+ when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mTelephonyManager.isNetworkRoaming()).thenReturn(true);
@@ -169,7 +175,7 @@
@Test
public void displayPreference_available_setsSubscriptionIdOnIntent() {
- Intent intent = new Intent();
+ final Intent intent = new Intent();
mPreference.setIntent(intent);
mController.displayPreference(mPreferenceScreen);
assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID,
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
index ae88231..eb9a58d 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
@@ -17,11 +17,12 @@
package com.android.settings.wifi.calling;
import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT;
+
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
+
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
@@ -42,6 +43,7 @@
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager;
+import android.telephony.ims.ImsMmTelManager;
import android.telephony.ims.ProvisioningManager;
import android.view.View;
import android.widget.TextView;
@@ -53,8 +55,7 @@
import com.android.ims.ImsManager;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
-import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
@@ -66,8 +67,10 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
+@Config(shadows = ShadowFragment.class)
@RunWith(RobolectricTestRunner.class)
public class WifiCallingSettingsForSubTest {
private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
@@ -83,6 +86,7 @@
@Mock private static CarrierConfigManager sCarrierConfigManager;
@Mock private CarrierConfigManager mMockConfigManager;
@Mock private ImsManager mImsManager;
+ @Mock private ImsMmTelManager mImsMmTelManager;
@Mock private TelephonyManager mTelephonyManager;
@Mock private PreferenceScreen mPreferenceScreen;
@Mock private SettingsActivity mActivity;
@@ -124,12 +128,15 @@
doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar);
doReturn(mImsManager).when(mFragment).getImsManager();
+ doReturn(mImsMmTelManager).when(mFragment).getImsMmTelManager();
doReturn(mImsConfig).when(mImsManager).getConfigInterface();
- doReturn(true).when(mImsManager).isWfcProvisionedOnDevice();
+ doReturn(true).when(mFragment).isWfcProvisionedOnDevice();
doReturn(true).when(mImsManager).isWfcEnabledByUser();
doReturn(true).when(mImsManager).isNonTtyOrTtyOnVolteEnabled();
- doReturn(ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED)
- .when(mImsManager).getWfcMode(anyBoolean());
+ doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
+ .when(mImsMmTelManager).getVoWiFiModeSetting();
+ doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
+ .when(mImsMmTelManager).getVoWiFiRoamingModeSetting();
doReturn(mBundle).when(sCarrierConfigManager).getConfigForSubId(anyInt());
setDefaultCarrierConfigValues();
@@ -171,7 +178,7 @@
@Test
public void onResume_provisioningDisallowed_shouldFinish() {
// Call onResume while provisioning is disallowed.
- doReturn(false).when(mImsManager).isWfcProvisionedOnDevice();
+ doReturn(false).when(mFragment).isWfcProvisionedOnDevice();
mFragment.onResume();
// Verify that finish() is called
@@ -248,15 +255,13 @@
// Set the WFC home mode.
mFragment.onPreferenceChange(mButtonWfcMode,
- String.valueOf(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED));
+ String.valueOf(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
// Check that only WFC home mode is set.
- verify(mImsManager, times(1)).setWfcMode(
- eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
- eq(false));
- verify(mImsManager, never()).setWfcMode(
- eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
- eq(true));
+ verify(mImsMmTelManager, times(1)).setVoWiFiModeSetting(
+ eq(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
+ verify(mImsMmTelManager, never()).setVoWiFiRoamingModeSetting(
+ eq(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
}
@Test
@@ -269,34 +274,32 @@
// Set the WFC home mode.
mFragment.onPreferenceChange(mButtonWfcMode,
- String.valueOf(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED));
+ String.valueOf(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
// Check that both WFC home mode and roaming mode are set.
- verify(mImsManager, times(1)).setWfcMode(
- eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
- eq(false));
- verify(mImsManager, times(1)).setWfcMode(
- eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
- eq(true));
+ verify(mImsMmTelManager, times(1)).setVoWiFiModeSetting(
+ eq(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
+ verify(mImsMmTelManager, times(1)).setVoWiFiRoamingModeSetting(
+ eq(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
}
@Test
public void onSwitchChanged_enableSetting_shouldLaunchWfcDisclaimerFragment() {
- ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
mFragment.onSwitchChanged(null, true);
// Check the WFC disclaimer fragment is launched.
verify(mFragment).startActivityForResult(intentCaptor.capture(),
eq(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_DISCLAIMER));
- Intent intent = intentCaptor.getValue();
+ final Intent intent = intentCaptor.getValue();
assertThat(intent.getStringExtra(EXTRA_SHOW_FRAGMENT))
.isEqualTo(WifiCallingDisclaimerFragment.class.getName());
}
@Test
public void onActivityResult_finishWfcDisclaimerFragment_shouldLaunchCarrierActivity() {
- ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
// Emulate the WfcDisclaimerActivity finish.
mFragment.onActivityResult(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_DISCLAIMER,
@@ -305,7 +308,7 @@
// Check the WFC emergency address activity is launched.
verify(mFragment).startActivityForResult(intentCaptor.capture(),
eq(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_EMERGENCY_ADDRESS));
- Intent intent = intentCaptor.getValue();
+ final Intent intent = intentCaptor.getValue();
assertEquals(intent.getComponent(), ComponentName.unflattenFromString(
TEST_EMERGENCY_ADDRESS_CARRIER_APP));
}
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java
index cc9ebb3..7957ae0 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java
@@ -64,72 +64,75 @@
@Test
public void setupFragment_oneSubscription_noCrash() {
- SubscriptionInfo info = mock(SubscriptionInfo.class);
+ final SubscriptionInfo info = mock(SubscriptionInfo.class);
when(info.getSubscriptionId()).thenReturn(111);
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
Collections.singletonList(info)));
doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class));
+ doReturn(true).when(mFragment).isWfcProvisionedOnDevice(any(SubscriptionInfo.class));
- Intent intent = new Intent();
+ final Intent intent = new Intent();
intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
null /* bundle */).start().resume().visible().get();
- View view = mFragment.getView();
- RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
- WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
+ final View view = mFragment.getView();
+ final RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
+ final WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
(WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
assertThat(adapter.getCount()).isEqualTo(1);
}
@Test
public void setupFragment_twoSubscriptions_correctSelection() {
- SubscriptionInfo info1 = mock(SubscriptionInfo.class);
- SubscriptionInfo info2 = mock(SubscriptionInfo.class);
+ final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
+ final SubscriptionInfo info2 = mock(SubscriptionInfo.class);
when(info1.getSubscriptionId()).thenReturn(111);
when(info2.getSubscriptionId()).thenReturn(222);
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
Arrays.asList(info1, info2)));
doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class));
+ doReturn(true).when(mFragment).isWfcProvisionedOnDevice(any(SubscriptionInfo.class));
- Intent intent = new Intent();
+ final Intent intent = new Intent();
intent.putExtra(Settings.EXTRA_SUB_ID, info2.getSubscriptionId());
FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
null /* bundle */).start().resume().visible().get();
- View view = mFragment.getView();
- RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
+ final View view = mFragment.getView();
+ final RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
assertThat(pager.getCurrentItem()).isEqualTo(1);
- WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
+ final WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
(WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
assertThat(adapter.getCount()).isEqualTo(2);
}
@Test
public void setupFragment_twoSubscriptionsOneNotProvisionedOnDevice_oneResult() {
- SubscriptionInfo info1 = mock(SubscriptionInfo.class);
- SubscriptionInfo info2 = mock(SubscriptionInfo.class);
+ final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
+ final SubscriptionInfo info2 = mock(SubscriptionInfo.class);
when(info1.getSubscriptionId()).thenReturn(111);
when(info2.getSubscriptionId()).thenReturn(222);
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
Arrays.asList(info1, info2)));
doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class));
+ doReturn(true).when(mFragment).isWfcProvisionedOnDevice(eq(info1));
doReturn(false).when(mFragment).isWfcProvisionedOnDevice(eq(info2));
- Intent intent = new Intent();
+ final Intent intent = new Intent();
intent.putExtra(Settings.EXTRA_SUB_ID, info1.getSubscriptionId());
FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
null /* bundle */).start().resume().visible().get();
- View view = mFragment.getView();
- RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
+ final View view = mFragment.getView();
+ final RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
assertThat(pager.getCurrentItem()).isEqualTo(0);
- WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
+ final WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
(WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
assertThat(adapter.getCount()).isEqualTo(1);
}
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 644e5e8..274ce34 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
@@ -22,7 +22,7 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -32,6 +32,7 @@
import android.content.Context;
import android.content.Intent;
import android.telephony.CarrierConfigManager;
+import android.telephony.ims.ImsMmTelManager;
import androidx.slice.Slice;
import androidx.slice.SliceItem;
@@ -44,7 +45,6 @@
import androidx.slice.widget.SliceContent;
import androidx.slice.widget.SliceLiveData;
-import com.android.ims.ImsConfig;
import com.android.ims.ImsManager;
import com.android.settings.R;
import com.android.settings.slices.CustomSliceRegistry;
@@ -76,6 +76,9 @@
@Mock
private ImsManager mMockImsManager;
+ @Mock
+ private ImsMmTelManager mMockImsMmTelManager;
+
private FakeWifiCallingSliceHelper mWfcSliceHelper;
private SettingsSliceProvider mProvider;
private SliceBroadcastReceiver mReceiver;
@@ -98,7 +101,7 @@
mFeatureFactory = FakeFeatureFactory.setupForTest();
mSlicesFeatureProvider = mFeatureFactory.getSlicesFeatureProvider();
- mWfcSliceHelper = new FakeWifiCallingSliceHelper(mContext);
+ mWfcSliceHelper = spy(new FakeWifiCallingSliceHelper(mContext));
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
@@ -133,7 +136,7 @@
activity so the user can perform the activation there.(PrimaryAction)
*/
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(false);
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -151,7 +154,7 @@
@Test
public void test_CreateWifiCallingSlice_success() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -166,7 +169,7 @@
@Test
public void test_SettingSliceProvider_getsRightSliceWifiCalling() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -182,17 +185,17 @@
@Test
public void test_SliceBroadcastReceiver_toggleOnWifiCalling() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext))
.thenReturn(mWfcSliceHelper);
mWfcSliceHelper.setActivationAppIntent(null);
- ArgumentCaptor<Boolean> mWfcSettingCaptor = ArgumentCaptor.forClass(Boolean.class);
+ final ArgumentCaptor<Boolean> mWfcSettingCaptor = ArgumentCaptor.forClass(Boolean.class);
// turn on Wifi calling setting
- Intent intent = new Intent(WifiCallingSliceHelper.ACTION_WIFI_CALLING_CHANGED);
+ final Intent intent = new Intent(WifiCallingSliceHelper.ACTION_WIFI_CALLING_CHANGED);
intent.putExtra(EXTRA_TOGGLE_STATE, true);
// change the setting
@@ -207,7 +210,7 @@
@Test
public void test_CreateWifiCallingPreferenceSlice_prefNotEditable() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
mWfcSliceHelper.setIsWifiCallingPrefEditable(false);
@@ -222,7 +225,7 @@
@Test
public void test_CreateWifiCallingPreferenceSlice_wfcOff() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
@@ -239,11 +242,11 @@
@Test
public void test_CreateWifiCallingPreferenceSlice_success() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
- when(mMockImsManager.getWfcMode(false)).thenReturn(
- ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED);
+ when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
final Slice slice = mWfcSliceHelper.createWifiCallingPreferenceSlice(
@@ -257,11 +260,11 @@
@Test
public void test_SettingsSliceProvider_getWfcPreferenceSlice() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
- when(mMockImsManager.getWfcMode(false)).thenReturn(
- ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED);
+ when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext))
.thenReturn(mWfcSliceHelper);
mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
@@ -276,28 +279,29 @@
@Test
public void test_SliceBroadcastReceiver_setWfcPrefCellularPref() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
- when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true);
+ when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
- when(mMockImsManager.getWfcMode(false)).thenReturn(
- ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED);
+ when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
+ ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext))
.thenReturn(mWfcSliceHelper);
mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
- ArgumentCaptor<Integer> mWfcPreferenceCaptor = ArgumentCaptor.forClass(Integer.class);
+ final ArgumentCaptor<Integer> mWfcPreferenceCaptor =
+ ArgumentCaptor.forClass(Integer.class);
// Change preference to Cellular pref
- Intent intent = new Intent(
+ final Intent intent = new Intent(
WifiCallingSliceHelper.ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED);
mReceiver.onReceive(mContext, intent);
- verify((mMockImsManager)).setWfcMode(mWfcPreferenceCaptor.capture(), eq(false));
+ verify((mMockImsMmTelManager)).setVoWiFiModeSetting(mWfcPreferenceCaptor.capture());
// assert the change
assertThat(mWfcPreferenceCaptor.getValue()).isEqualTo(
- ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED);
+ ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
}
private void testWifiCallingSettingsUnavailableSlice(Slice slice,
@@ -400,7 +404,7 @@
private void assertTitle(List<SliceItem> sliceItems, String title) {
boolean hasTitle = false;
for (SliceItem item : sliceItems) {
- List<SliceItem> titleItems = SliceQuery.findAll(item, FORMAT_TEXT, HINT_TITLE,
+ final List<SliceItem> titleItems = SliceQuery.findAll(item, FORMAT_TEXT, HINT_TITLE,
null /* non-hints */);
if (titleItems == null) {
continue;
@@ -434,6 +438,11 @@
return mMockImsManager;
}
+ @Override
+ protected ImsMmTelManager getImsMmTelManager(int subId) {
+ return mMockImsMmTelManager;
+ }
+
protected int getDefaultVoiceSubId() {
return mSubId;
}
@@ -442,6 +451,10 @@
mSubId = id;
}
+ boolean isWfcProvisionedOnDevice(int subId) {
+ return true;
+ }
+
@Override
protected Intent getWifiCallingCarrierActivityIntent(int subId) {
return mActivationAppIntent;