[Settings] Fix conflict of AOSP merge on wifi call

Merge for fixing conflict of Ib4b0e1191c83e23377ccf8ed013252728ef9dd95

Bug: 144960427
Test: build pass
Change-Id: I2979a9a2ee1bc690486e25b7d470cf905cf02d17
Merged-In: Idb063bdab3d3b11c348804c1c0ecb268cca3068e
This commit is contained in:
Bonian Chen
2019-11-23 02:56:24 +08:00
parent 0e7b8f7a93
commit cacf047daa
11 changed files with 345 additions and 202 deletions

View File

@@ -38,7 +38,10 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager; import android.telephony.euicc.EuiccManager;
import android.telephony.ims.ProvisioningManager;
import android.telephony.ims.feature.ImsFeature; import android.telephony.ims.feature.ImsFeature;
import android.telephony.ims.feature.MmTelFeature;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
@@ -96,7 +99,7 @@ public class MobileNetworkUtils {
* Returns true if Wifi calling is enabled for at least one subscription. * Returns true if Wifi calling is enabled for at least one subscription.
*/ */
public static boolean isWifiCallingEnabled(Context context) { public static boolean isWifiCallingEnabled(Context context) {
SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class); final SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class);
if (subManager == null) { if (subManager == null) {
Log.e(TAG, "isWifiCallingEnabled: couldn't get system service."); Log.e(TAG, "isWifiCallingEnabled: couldn't get system service.");
return false; return false;
@@ -109,6 +112,22 @@ public class MobileNetworkUtils {
return false; return false;
} }
/**
* 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}. * Returns true if Wifi calling is enabled for the specific subscription with id {@code subId}.
*/ */
@@ -119,15 +138,15 @@ public class MobileNetworkUtils {
boolean isWifiCallingEnabled; boolean isWifiCallingEnabled;
if (simCallManager != null) { if (simCallManager != null) {
Intent intent = buildPhoneAccountConfigureIntent( final Intent intent = buildPhoneAccountConfigureIntent(
context, simCallManager); context, simCallManager);
isWifiCallingEnabled = intent != null; isWifiCallingEnabled = intent != null;
} else { } else {
ImsManager imsMgr = ImsManager.getInstance(context, phoneId); final ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
isWifiCallingEnabled = imsMgr != null isWifiCallingEnabled = imsMgr != null
&& imsMgr.isWfcEnabledByPlatform() && imsMgr.isWfcEnabledByPlatform()
&& imsMgr.isWfcProvisionedOnDevice() && isWfcProvisionedOnDevice(subId)
&& isImsServiceStateReady(imsMgr); && isImsServiceStateReady(imsMgr);
} }
@@ -162,8 +181,8 @@ public class MobileNetworkUtils {
intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle); intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
// Check to see that the phone account package can handle the setting intent. // Check to see that the phone account package can handle the setting intent.
PackageManager pm = context.getPackageManager(); final PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0); final List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
if (resolutions.size() == 0) { if (resolutions.size() == 0) {
intent = null; // set no intent if the package cannot handle it. intent = null; // set no intent if the package cannot handle it.
} }
@@ -194,7 +213,7 @@ public class MobileNetworkUtils {
* the user has enabled development mode. * the user has enabled development mode.
*/ */
public static boolean showEuiccSettings(Context context) { public static boolean showEuiccSettings(Context context) {
EuiccManager euiccManager = final EuiccManager euiccManager =
(EuiccManager) context.getSystemService(EuiccManager.class); (EuiccManager) context.getSystemService(EuiccManager.class);
if (!euiccManager.isEnabled()) { if (!euiccManager.isEnabled()) {
return false; return false;
@@ -202,16 +221,16 @@ public class MobileNetworkUtils {
final ContentResolver cr = context.getContentResolver(); final ContentResolver cr = context.getContentResolver();
TelephonyManager tm = final TelephonyManager tm =
(TelephonyManager) context.getSystemService(TelephonyManager.class); (TelephonyManager) context.getSystemService(TelephonyManager.class);
String currentCountry = tm.getNetworkCountryIso().toLowerCase(); final String currentCountry = tm.getNetworkCountryIso().toLowerCase();
String supportedCountries = final String supportedCountries =
Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES); Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES);
boolean inEsimSupportedCountries = false; boolean inEsimSupportedCountries = false;
if (TextUtils.isEmpty(currentCountry)) { if (TextUtils.isEmpty(currentCountry)) {
inEsimSupportedCountries = true; inEsimSupportedCountries = true;
} else if (!TextUtils.isEmpty(supportedCountries)) { } else if (!TextUtils.isEmpty(supportedCountries)) {
List<String> supportedCountryList = final List<String> supportedCountryList =
Arrays.asList(TextUtils.split(supportedCountries.toLowerCase(), ",")); Arrays.asList(TextUtils.split(supportedCountries.toLowerCase(), ","));
if (supportedCountryList.contains(currentCountry)) { if (supportedCountryList.contains(currentCountry)) {
inEsimSupportedCountries = true; inEsimSupportedCountries = true;
@@ -244,7 +263,7 @@ public class MobileNetworkUtils {
telephonyManager.setDataEnabled(enabled); telephonyManager.setDataEnabled(enabled);
if (disableOtherSubscriptions) { if (disableOtherSubscriptions) {
List<SubscriptionInfo> subInfoList = final List<SubscriptionInfo> subInfoList =
subscriptionManager.getActiveSubscriptionInfoList(true); subscriptionManager.getActiveSubscriptionInfoList(true);
if (subInfoList != null) { if (subInfoList != null) {
for (SubscriptionInfo subInfo : subInfoList) { for (SubscriptionInfo subInfo : subInfoList) {
@@ -358,7 +377,7 @@ public class MobileNetworkUtils {
* Return {@code true} if we need show settings for network selection(i.e. Verizon) * Return {@code true} if we need show settings for network selection(i.e. Verizon)
*/ */
public static boolean shouldDisplayNetworkSelectOptions(Context context, int subId) { public static boolean shouldDisplayNetworkSelectOptions(Context context, int subId) {
final TelephonyManager telephonyManager = TelephonyManager.from(context) final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(subId); .createForSubscriptionId(subId);
final PersistableBundle carrierConfig = context.getSystemService( final PersistableBundle carrierConfig = context.getSystemService(
CarrierConfigManager.class).getConfigForSubId(subId); CarrierConfigManager.class).getConfigForSubId(subId);
@@ -419,8 +438,8 @@ public class MobileNetworkUtils {
return true; return true;
} }
String operatorNumeric = telephonyManager.getServiceState().getOperatorNumeric(); final String operatorNumeric = telephonyManager.getServiceState().getOperatorNumeric();
String[] numericArray = carrierConfig.getStringArray( final String[] numericArray = carrierConfig.getStringArray(
CarrierConfigManager.KEY_SUPPORT_TDSCDMA_ROAMING_NETWORKS_STRING_ARRAY); CarrierConfigManager.KEY_SUPPORT_TDSCDMA_ROAMING_NETWORKS_STRING_ARRAY);
if (numericArray == null || operatorNumeric == null) { if (numericArray == null || operatorNumeric == null) {
return false; return false;
@@ -511,12 +530,12 @@ public class MobileNetworkUtils {
public static Drawable getSignalStrengthIcon(Context context, int level, int numLevels, public static Drawable getSignalStrengthIcon(Context context, int level, int numLevels,
int iconType, boolean cutOut) { int iconType, boolean cutOut) {
SignalDrawable signalDrawable = new SignalDrawable(context); final SignalDrawable signalDrawable = new SignalDrawable(context);
signalDrawable.setLevel( signalDrawable.setLevel(
SignalDrawable.getState(level, numLevels, cutOut)); SignalDrawable.getState(level, numLevels, cutOut));
// Make the network type drawable // Make the network type drawable
Drawable networkDrawable = final Drawable networkDrawable =
iconType == NO_CELL_DATA_TYPE_ICON iconType == NO_CELL_DATA_TYPE_ICON
? EMPTY_DRAWABLE ? EMPTY_DRAWABLE
: context : context
@@ -527,7 +546,7 @@ public class MobileNetworkUtils {
final int iconSize = final int iconSize =
context.getResources().getDimensionPixelSize(R.dimen.signal_strength_icon_size); 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 // Set the network type icon at the top left
icons.setLayerGravity(0 /* index of networkDrawable */, Gravity.TOP | Gravity.LEFT); icons.setLayerGravity(0 /* index of networkDrawable */, Gravity.TOP | Gravity.LEFT);
// Set the signal strength icon at the bottom right // Set the signal strength icon at the bottom right
@@ -545,9 +564,9 @@ public class MobileNetworkUtils {
* 2. Similar design which aligned with operator name displayed in status bar * 2. Similar design which aligned with operator name displayed in status bar
*/ */
public static CharSequence getCurrentCarrierNameForDisplay(Context context, int subId) { public static CharSequence getCurrentCarrierNameForDisplay(Context context, int subId) {
SubscriptionManager sm = context.getSystemService(SubscriptionManager.class); final SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
if (sm != null) { if (sm != null) {
SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId); final SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId);
if (subInfo != null) { if (subInfo != null) {
return subInfo.getCarrierName(); return subInfo.getCarrierName();
} }
@@ -556,10 +575,10 @@ public class MobileNetworkUtils {
} }
public static CharSequence getCurrentCarrierNameForDisplay(Context context) { public static CharSequence getCurrentCarrierNameForDisplay(Context context) {
SubscriptionManager sm = context.getSystemService(SubscriptionManager.class); final SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
if (sm != null) { if (sm != null) {
int subId = sm.getDefaultSubscriptionId(); final int subId = sm.getDefaultSubscriptionId();
SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId); final SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId);
if (subInfo != null) { if (subInfo != null) {
return subInfo.getCarrierName(); return subInfo.getCarrierName();
} }
@@ -585,7 +604,7 @@ public class MobileNetworkUtils {
} }
private static String getOperatorNameFromTelephonyManager(Context context) { private static String getOperatorNameFromTelephonyManager(Context context) {
TelephonyManager tm = final TelephonyManager tm =
(TelephonyManager) context.getSystemService(TelephonyManager.class); (TelephonyManager) context.getSystemService(TelephonyManager.class);
if (tm == null) { if (tm == null) {
return null; return null;

View File

@@ -20,7 +20,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Looper;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.provider.Settings; import android.provider.Settings;
import android.telecom.PhoneAccountHandle; import android.telecom.PhoneAccountHandle;
@@ -29,12 +28,12 @@ import android.telephony.CarrierConfigManager;
import android.telephony.PhoneStateListener; import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.ims.ImsMmTelManager;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.ims.ImsConfig;
import com.android.ims.ImsManager; import com.android.ims.ImsManager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -49,11 +48,13 @@ import java.util.List;
public class WifiCallingPreferenceController extends TelephonyBasePreferenceController implements public class WifiCallingPreferenceController extends TelephonyBasePreferenceController implements
LifecycleObserver, OnStart, OnStop { LifecycleObserver, OnStart, OnStop {
private TelephonyManager mTelephonyManager; @VisibleForTesting
Integer mCallState;
@VisibleForTesting @VisibleForTesting
CarrierConfigManager mCarrierConfigManager; CarrierConfigManager mCarrierConfigManager;
@VisibleForTesting @VisibleForTesting
ImsManager mImsManager; ImsManager mImsManager;
private ImsMmTelManager mImsMmTelManager;
@VisibleForTesting @VisibleForTesting
PhoneAccountHandle mSimCallManager; PhoneAccountHandle mSimCallManager;
private PhoneCallStateListener mPhoneStateListener; private PhoneCallStateListener mPhoneStateListener;
@@ -62,8 +63,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
public WifiCallingPreferenceController(Context context, String key) { public WifiCallingPreferenceController(Context context, String key) {
super(context, key); super(context, key);
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class); mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
mTelephonyManager = context.getSystemService(TelephonyManager.class); mPhoneStateListener = new PhoneCallStateListener();
mPhoneStateListener = new PhoneCallStateListener(Looper.getMainLooper());
} }
@Override @Override
@@ -76,7 +76,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
@Override @Override
public void onStart() { public void onStart() {
mPhoneStateListener.register(mSubId); mPhoneStateListener.register(mContext, mSubId);
} }
@Override @Override
@@ -88,7 +88,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
public void displayPreference(PreferenceScreen screen) { public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen); super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey()); mPreference = screen.findPreference(getPreferenceKey());
Intent intent = mPreference.getIntent(); final Intent intent = mPreference.getIntent();
if (intent != null) { if (intent != null) {
intent.putExtra(Settings.EXTRA_SUB_ID, mSubId); intent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
} }
@@ -97,15 +97,18 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
if (mCallState == null) {
return;
}
if (mSimCallManager != null) { if (mSimCallManager != null) {
Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext, final Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
mSimCallManager); mSimCallManager);
if (intent == null) { if (intent == null) {
// Do nothing in this case since preference is invisible // Do nothing in this case since preference is invisible
return; return;
} }
final PackageManager pm = mContext.getPackageManager(); 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.setTitle(resolutions.get(0).loadLabel(pm));
preference.setSummary(null); preference.setSummary(null);
preference.setIntent(intent); preference.setIntent(intent);
@@ -125,17 +128,20 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL); .KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL);
} }
} }
final boolean isRoaming = mTelephonyManager.isNetworkRoaming(); final boolean isRoaming = getTelephonyManager(mContext, mSubId)
int wfcMode = mImsManager.getWfcMode(isRoaming && !useWfcHomeModeForRoaming); .isNetworkRoaming();
final int wfcMode = (isRoaming && !useWfcHomeModeForRoaming)
? mImsMmTelManager.getVoWiFiRoamingModeSetting() :
mImsMmTelManager.getVoWiFiModeSetting();
switch (wfcMode) { switch (wfcMode) {
case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY: case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
resId = com.android.internal.R.string.wfc_mode_wifi_only_summary; resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
break; break;
case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED: case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
resId = com.android.internal.R.string resId = com.android.internal.R.string
.wfc_mode_cellular_preferred_summary; .wfc_mode_cellular_preferred_summary;
break; break;
case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED: case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary; resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
break; break;
default: default:
@@ -144,37 +150,56 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
} }
preference.setSummary(resId); preference.setSummary(resId);
} }
preference.setEnabled( preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE);
mTelephonyManager.getCallState(mSubId) == TelephonyManager.CALL_STATE_IDLE);
} }
public WifiCallingPreferenceController init(int subId) { public WifiCallingPreferenceController init(int subId) {
mSubId = subId; mSubId = subId;
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId)); mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId));
mImsMmTelManager = getImsMmTelManager(mSubId);
mSimCallManager = mContext.getSystemService(TelecomManager.class) mSimCallManager = mContext.getSystemService(TelecomManager.class)
.getSimCallManagerForSubscription(mSubId); .getSimCallManagerForSubscription(mSubId);
return this; 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 { private class PhoneCallStateListener extends PhoneStateListener {
public PhoneCallStateListener(Looper looper) { PhoneCallStateListener() {
super(looper); super();
} }
private TelephonyManager mTelephonyManager;
@Override @Override
public void onCallStateChanged(int state, String incomingNumber) { public void onCallStateChanged(int state, String incomingNumber) {
mCallState = state;
updateState(mPreference); updateState(mPreference);
} }
public void register(int subId) { public void register(Context context, int subId) {
mSubId = subId; mTelephonyManager = getTelephonyManager(context, subId);
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE); mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
} }
public void unregister() { public void unregister() {
mCallState = null;
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE); mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
} }
} }

View File

@@ -22,6 +22,9 @@ import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; 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.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -100,11 +103,11 @@ public class WifiCallingSettings extends InstrumentedFragment implements HelpRes
if (mSil == null) { if (mSil == null) {
return; return;
} }
Intent intent = getActivity().getIntent(); final Intent intent = getActivity().getIntent();
if (intent == null) { if (intent == null) {
return; return;
} }
int subId = intent.getIntExtra(Settings.EXTRA_SUB_ID, final int subId = intent.getIntExtra(Settings.EXTRA_SUB_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID); SubscriptionManager.INVALID_SUBSCRIPTION_ID);
if (SubscriptionManager.isValidSubscriptionId(subId)) { if (SubscriptionManager.isValidSubscriptionId(subId)) {
for (SubscriptionInfo subInfo : mSil) { for (SubscriptionInfo subInfo : mSil) {
@@ -168,7 +171,7 @@ public class WifiCallingSettings extends InstrumentedFragment implements HelpRes
args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false); args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false);
args.putInt(WifiCallingSettingsForSub.FRAGMENT_BUNDLE_SUBID, args.putInt(WifiCallingSettingsForSub.FRAGMENT_BUNDLE_SUBID,
mSil.get(position).getSubscriptionId()); mSil.get(position).getSubscriptionId());
WifiCallingSettingsForSub fragment = new WifiCallingSettingsForSub(); final WifiCallingSettingsForSub fragment = new WifiCallingSettingsForSub();
fragment.setArguments(args); fragment.setArguments(args);
return fragment; return fragment;
@@ -195,14 +198,21 @@ public class WifiCallingSettings extends InstrumentedFragment implements HelpRes
@VisibleForTesting @VisibleForTesting
boolean isWfcEnabledByPlatform(SubscriptionInfo info) { boolean isWfcEnabledByPlatform(SubscriptionInfo info) {
ImsManager imsManager = ImsManager.getInstance(getActivity(), info.getSimSlotIndex()); final ImsManager imsManager = ImsManager.getInstance(getActivity(),
info.getSimSlotIndex());
return imsManager.isWfcEnabledByPlatform(); return imsManager.isWfcEnabledByPlatform();
} }
@VisibleForTesting @VisibleForTesting
boolean isWfcProvisionedOnDevice(SubscriptionInfo info) { boolean isWfcProvisionedOnDevice(SubscriptionInfo info) {
ImsManager imsManager = ImsManager.getInstance(getActivity(), info.getSimSlotIndex()); final ProvisioningManager provisioningMgr =
return imsManager.isWfcProvisionedOnDevice(); ProvisioningManager.createForSubscriptionId(info.getSubscriptionId());
if (provisioningMgr == null) {
return true;
}
return provisioningMgr.getProvisioningStatusForCapability(
MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN);
} }
private void updateSubList() { private void updateSubList() {

View File

@@ -30,6 +30,7 @@ import android.telephony.CarrierConfigManager;
import android.telephony.PhoneStateListener; import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.ims.ImsMmTelManager;
import android.telephony.ims.ProvisioningManager; import android.telephony.ims.ProvisioningManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -54,6 +55,7 @@ import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.SubSettingLauncher;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.widget.SwitchBar; import com.android.settings.widget.SwitchBar;
/** /**
@@ -98,6 +100,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
private ImsManager mImsManager; private ImsManager mImsManager;
private ImsMmTelManager mImsMmTelManager;
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() { private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
@@ -110,8 +113,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
@Override @Override
public void onCallStateChanged(int state, String incomingNumber) { public void onCallStateChanged(int state, String incomingNumber) {
final SettingsActivity activity = (SettingsActivity) getActivity(); final SettingsActivity activity = (SettingsActivity) getActivity();
boolean isNonTtyOrTtyOnVolteEnabled = mImsManager.isNonTtyOrTtyOnVolteEnabled(); final boolean isNonTtyOrTtyOnVolteEnabled = mImsManager.isNonTtyOrTtyOnVolteEnabled();
boolean isWfcEnabled = mSwitchBar.isChecked() final boolean isWfcEnabled = mSwitchBar.isChecked()
&& isNonTtyOrTtyOnVolteEnabled; && isNonTtyOrTtyOnVolteEnabled;
mSwitchBar.setEnabled((state == TelephonyManager.CALL_STATE_IDLE) mSwitchBar.setEnabled((state == TelephonyManager.CALL_STATE_IDLE)
@@ -132,12 +135,12 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
} }
} }
Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE); final Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE);
if (pref != null) { if (pref != null) {
pref.setEnabled(isWfcEnabled && isWfcModeEditable pref.setEnabled(isWfcEnabled && isWfcModeEditable
&& (state == TelephonyManager.CALL_STATE_IDLE)); && (state == TelephonyManager.CALL_STATE_IDLE));
} }
Preference pref_roam = final Preference pref_roam =
getPreferenceScreen().findPreference(BUTTON_WFC_ROAMING_MODE); getPreferenceScreen().findPreference(BUTTON_WFC_ROAMING_MODE);
if (pref_roam != null) { if (pref_roam != null) {
pref_roam.setEnabled(isWfcEnabled && isWfcRoamingModeEditable pref_roam.setEnabled(isWfcEnabled && isWfcRoamingModeEditable
@@ -151,7 +154,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
*/ */
private final OnPreferenceClickListener mUpdateAddressListener = private final OnPreferenceClickListener mUpdateAddressListener =
preference -> { preference -> {
Intent carrierAppIntent = getCarrierActivityIntent(); final Intent carrierAppIntent = getCarrierActivityIntent();
if (carrierAppIntent != null) { if (carrierAppIntent != null) {
carrierAppIntent.putExtra(EXTRA_LAUNCH_CARRIER_APP, LAUCH_APP_UPDATE); carrierAppIntent.putExtra(EXTRA_LAUNCH_CARRIER_APP, LAUCH_APP_UPDATE);
startActivity(carrierAppIntent); startActivity(carrierAppIntent);
@@ -179,7 +182,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
mEmptyView = getView().findViewById(android.R.id.empty); mEmptyView = getView().findViewById(android.R.id.empty);
setEmptyView(mEmptyView); setEmptyView(mEmptyView);
final Resources res = getResourcesForSubId(); 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)); res.getString(R.string.wifi_calling_off_explanation_2));
mEmptyView.setText(emptyViewText); mEmptyView.setText(emptyViewText);
@@ -195,17 +198,17 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
} }
private void showAlert(Intent intent) { private void showAlert(Intent intent) {
Context context = getActivity(); final Context context = getActivity();
CharSequence title = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_TITLE); final CharSequence title = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_TITLE);
CharSequence message = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_MESSAGE); 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) builder.setMessage(message)
.setTitle(title) .setTitle(title)
.setIcon(android.R.drawable.ic_dialog_alert) .setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.ok, null); .setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create(); final AlertDialog dialog = builder.create();
dialog.show(); dialog.show();
} }
@@ -214,7 +217,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { 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 (action.equals(ImsManager.ACTION_IMS_REGISTRATION_ERROR)) {
// If this fragment is active then we are immediately // If this fragment is active then we are immediately
// showing alert on screen. There is no need to add // showing alert on screen. There is no need to add
@@ -245,6 +248,11 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
return ImsManager.getInstance(getActivity(), SubscriptionManager.getPhoneId(mSubId)); return ImsManager.getInstance(getActivity(), SubscriptionManager.getPhoneId(mSubId));
} }
@VisibleForTesting
ImsMmTelManager getImsMmTelManager() {
return ImsMmTelManager.createForSubscriptionId(mSubId);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -261,6 +269,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
} }
mImsManager = getImsManager(); mImsManager = getImsManager();
mImsMmTelManager = getImsMmTelManager();
mTelephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)) mTelephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE))
.createForSubscriptionId(mSubId); .createForSubscriptionId(mSubId);
@@ -288,31 +297,36 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate( final View view = inflater.inflate(
R.layout.wifi_calling_settings_preferences, container, false); R.layout.wifi_calling_settings_preferences, container, false);
final ViewGroup prefs_container = view.findViewById(R.id.prefs_container); final ViewGroup prefs_container = view.findViewById(R.id.prefs_container);
Utils.prepareCustomPreferencesList(container, view, prefs_container, false); 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); prefs_container.addView(prefs);
return view; return view;
} }
@VisibleForTesting
boolean isWfcProvisionedOnDevice() {
return MobileNetworkUtils.isWfcProvisionedOnDevice(mSubId);
}
private void updateBody() { private void updateBody() {
if (!mImsManager.isWfcProvisionedOnDevice()) { if (!isWfcProvisionedOnDevice()) {
// This screen is not allowed to be shown due to provisioning policy and should // This screen is not allowed to be shown due to provisioning policy and should
// therefore be closed. // therefore be closed.
finish(); finish();
return; return;
} }
CarrierConfigManager configManager = (CarrierConfigManager) final CarrierConfigManager configManager = (CarrierConfigManager)
getSystemService(Context.CARRIER_CONFIG_SERVICE); getSystemService(Context.CARRIER_CONFIG_SERVICE);
boolean isWifiOnlySupported = true; boolean isWifiOnlySupported = true;
if (configManager != null) { if (configManager != null) {
PersistableBundle b = configManager.getConfigForSubId(mSubId); final PersistableBundle b = configManager.getConfigForSubId(mSubId);
if (b != null) { if (b != null) {
mEditableWfcMode = b.getBoolean( mEditableWfcMode = b.getBoolean(
CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL); CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL);
@@ -341,11 +355,11 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
// NOTE: Buttons will be enabled/disabled in mPhoneStateListener // NOTE: Buttons will be enabled/disabled in mPhoneStateListener
boolean wfcEnabled = mImsManager.isWfcEnabledByUser() final boolean wfcEnabled = mImsManager.isWfcEnabledByUser()
&& mImsManager.isNonTtyOrTtyOnVolteEnabled(); && mImsManager.isNonTtyOrTtyOnVolteEnabled();
mSwitch.setChecked(wfcEnabled); mSwitch.setChecked(wfcEnabled);
int wfcMode = mImsManager.getWfcMode(false); final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
int wfcRoamingMode = mImsManager.getWfcMode(true); final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
mButtonWfcMode.setValue(Integer.toString(wfcMode)); mButtonWfcMode.setValue(Integer.toString(wfcMode));
mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode)); mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode));
updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode); updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode);
@@ -369,7 +383,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
context.registerReceiver(mIntentReceiver, mIntentFilter); context.registerReceiver(mIntentReceiver, mIntentFilter);
Intent intent = getActivity().getIntent(); final Intent intent = getActivity().getIntent();
if (intent.getBooleanExtra(Phone.EXTRA_KEY_ALERT_SHOW, false)) { if (intent.getBooleanExtra(Phone.EXTRA_KEY_ALERT_SHOW, false)) {
showAlert(intent); showAlert(intent);
} }
@@ -392,7 +406,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
if (mValidListener) { if (mValidListener) {
mValidListener = false; mValidListener = false;
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); final TelephonyManager tm = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
mSwitchBar.removeOnSwitchChangeListener(this); mSwitchBar.removeOnSwitchChangeListener(this);
@@ -441,22 +456,22 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
*/ */
private Intent getCarrierActivityIntent() { private Intent getCarrierActivityIntent() {
// Retrive component name from carrier config // Retrive component name from carrier config
CarrierConfigManager configManager = final CarrierConfigManager configManager =
getActivity().getSystemService(CarrierConfigManager.class); getActivity().getSystemService(CarrierConfigManager.class);
if (configManager == null) return null; if (configManager == null) return null;
PersistableBundle bundle = configManager.getConfigForSubId(mSubId); final PersistableBundle bundle = configManager.getConfigForSubId(mSubId);
if (bundle == null) return null; if (bundle == null) return null;
String carrierApp = bundle.getString( final String carrierApp = bundle.getString(
CarrierConfigManager.KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING); CarrierConfigManager.KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING);
if (TextUtils.isEmpty(carrierApp)) return null; if (TextUtils.isEmpty(carrierApp)) return null;
ComponentName componentName = ComponentName.unflattenFromString(carrierApp); final ComponentName componentName = ComponentName.unflattenFromString(carrierApp);
if (componentName == null) return null; if (componentName == null) return null;
// Build and return intent // Build and return intent
Intent intent = new Intent(); final Intent intent = new Intent();
intent.setComponent(componentName); intent.setComponent(componentName);
intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, mSubId); intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, mSubId);
return intent; return intent;
@@ -469,8 +484,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
Log.i(TAG, "updateWfcMode(" + wfcEnabled + ")"); Log.i(TAG, "updateWfcMode(" + wfcEnabled + ")");
mImsManager.setWfcSetting(wfcEnabled); mImsManager.setWfcSetting(wfcEnabled);
int wfcMode = mImsManager.getWfcMode(false); final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
int wfcRoamingMode = mImsManager.getWfcMode(true); final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode); updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode);
if (wfcEnabled) { if (wfcEnabled) {
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), wfcMode); mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), wfcMode);
@@ -496,7 +511,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
case REQUEST_CHECK_WFC_DISCLAIMER: case REQUEST_CHECK_WFC_DISCLAIMER:
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
// Call address management activity before turning on WFC // Call address management activity before turning on WFC
Intent carrierAppIntent = getCarrierActivityIntent(); final Intent carrierAppIntent = getCarrierActivityIntent();
if (carrierAppIntent != null) { if (carrierAppIntent != null) {
carrierAppIntent.putExtra(EXTRA_LAUNCH_CARRIER_APP, LAUCH_APP_ACTIVATE); carrierAppIntent.putExtra(EXTRA_LAUNCH_CARRIER_APP, LAUCH_APP_ACTIVATE);
startActivityForResult(carrierAppIntent, startActivityForResult(carrierAppIntent,
@@ -520,7 +535,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
mButtonWfcRoamingMode.setEnabled(wfcEnabled && mEditableWfcRoamingMode); mButtonWfcRoamingMode.setEnabled(wfcEnabled && mEditableWfcRoamingMode);
final PreferenceScreen preferenceScreen = getPreferenceScreen(); final PreferenceScreen preferenceScreen = getPreferenceScreen();
boolean updateAddressEnabled = (getCarrierActivityIntent() != null); final boolean updateAddressEnabled = (getCarrierActivityIntent() != null);
if (wfcEnabled) { if (wfcEnabled) {
if (mEditableWfcMode) { if (mEditableWfcMode) {
preferenceScreen.addPreference(mButtonWfcMode); preferenceScreen.addPreference(mButtonWfcMode);
@@ -551,24 +566,24 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
if (preference == mButtonWfcMode) { if (preference == mButtonWfcMode) {
Log.d(TAG, "onPreferenceChange mButtonWfcMode " + newValue); Log.d(TAG, "onPreferenceChange mButtonWfcMode " + newValue);
mButtonWfcMode.setValue((String) newValue); mButtonWfcMode.setValue((String) newValue);
int buttonMode = Integer.valueOf((String) newValue); final int buttonMode = Integer.valueOf((String) newValue);
int currentWfcMode = mImsManager.getWfcMode(false); final int currentWfcMode = mImsMmTelManager.getVoWiFiModeSetting();
if (buttonMode != currentWfcMode) { if (buttonMode != currentWfcMode) {
mImsManager.setWfcMode(buttonMode, false); mImsMmTelManager.setVoWiFiModeSetting(buttonMode);
mButtonWfcMode.setSummary(getWfcModeSummary(buttonMode)); mButtonWfcMode.setSummary(getWfcModeSummary(buttonMode));
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode); mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode);
if (mUseWfcHomeModeForRoaming) { if (mUseWfcHomeModeForRoaming) {
mImsManager.setWfcMode(buttonMode, true); mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode);
// mButtonWfcRoamingMode.setSummary is not needed; summary is selected value // mButtonWfcRoamingMode.setSummary is not needed; summary is selected value
} }
} }
} else if (preference == mButtonWfcRoamingMode) { } else if (preference == mButtonWfcRoamingMode) {
mButtonWfcRoamingMode.setValue((String) newValue); mButtonWfcRoamingMode.setValue((String) newValue);
int buttonMode = Integer.valueOf((String) newValue); final int buttonMode = Integer.valueOf((String) newValue);
int currentMode = mImsManager.getWfcMode(true); final int currentMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
if (buttonMode != currentMode) { if (buttonMode != currentMode) {
mImsManager.setWfcMode(buttonMode, true); mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode);
// mButtonWfcRoamingMode.setSummary is not needed; summary is just selected value. // mButtonWfcRoamingMode.setSummary is not needed; summary is just selected value.
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode); mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode);
} }
@@ -580,13 +595,13 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
int resId = com.android.internal.R.string.wifi_calling_off_summary; int resId = com.android.internal.R.string.wifi_calling_off_summary;
if (mImsManager.isWfcEnabledByUser()) { if (mImsManager.isWfcEnabledByUser()) {
switch (wfcMode) { switch (wfcMode) {
case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY: case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
resId = com.android.internal.R.string.wfc_mode_wifi_only_summary; resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
break; break;
case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED: case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary; resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
break; break;
case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED: case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary; resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
break; break;
default: default:

View File

@@ -30,6 +30,7 @@ import android.os.PersistableBundle;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.ims.ImsMmTelManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -44,6 +45,7 @@ import com.android.ims.ImsConfig;
import com.android.ims.ImsManager; import com.android.ims.ImsManager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.slices.SliceBroadcastReceiver; import com.android.settings.slices.SliceBroadcastReceiver;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@@ -138,7 +140,7 @@ public class WifiCallingSliceHelper {
final ImsManager imsManager = getImsManager(subId); final ImsManager imsManager = getImsManager(subId);
if (!imsManager.isWfcEnabledByPlatform() if (!imsManager.isWfcEnabledByPlatform()
|| !imsManager.isWfcProvisionedOnDevice()) { || !isWfcProvisionedOnDevice(subId)) {
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by Platform"); Log.d(TAG, "Wifi calling is either not provisioned or not enabled by Platform");
return null; return null;
} }
@@ -233,9 +235,10 @@ public class WifiCallingSliceHelper {
final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled( final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true); CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
final ImsManager imsManager = getImsManager(subId); final ImsManager imsManager = getImsManager(subId);
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
if (!imsManager.isWfcEnabledByPlatform() if (!imsManager.isWfcEnabledByPlatform()
|| !imsManager.isWfcProvisionedOnDevice()) { || !isWfcProvisionedOnDevice(subId)) {
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform"); Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
return null; return null;
} }
@@ -249,7 +252,7 @@ public class WifiCallingSliceHelper {
int wfcMode = -1; int wfcMode = -1;
try { try {
isWifiCallingEnabled = isWifiCallingEnabled(imsManager); isWifiCallingEnabled = isWifiCallingEnabled(imsManager);
wfcMode = getWfcMode(imsManager); wfcMode = getWfcMode(imsMmTelManager);
} catch (InterruptedException | ExecutionException | TimeoutException e) { } catch (InterruptedException | ExecutionException | TimeoutException e) {
Log.e(TAG, "Unable to get wifi calling preferred mode", e); Log.e(TAG, "Unable to get wifi calling preferred mode", e);
return null; return null;
@@ -279,7 +282,7 @@ public class WifiCallingSliceHelper {
Uri sliceUri) { Uri sliceUri) {
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal); final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
// Top row shows information on current preference state // 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)); .setAccentColor(Utils.getColorAccentDefaultColor(mContext));
listBuilder.setHeader(new ListBuilder.HeaderBuilder() listBuilder.setHeader(new ListBuilder.HeaderBuilder()
.setTitle(mContext.getText(R.string.wifi_calling_mode_title)) .setTitle(mContext.getText(R.string.wifi_calling_mode_title))
@@ -294,18 +297,18 @@ public class WifiCallingSliceHelper {
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder, listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_wifi_only_summary, com.android.internal.R.string.wfc_mode_wifi_only_summary,
ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY, ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY,
currentWfcPref == ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY)); currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_ONLY));
} }
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder, listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_wifi_preferred_summary, com.android.internal.R.string.wfc_mode_wifi_preferred_summary,
ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED, ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED,
currentWfcPref == ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED)); currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED));
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder, listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_cellular_preferred_summary, com.android.internal.R.string.wfc_mode_cellular_preferred_summary,
ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED, ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED,
currentWfcPref == ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED)); currentWfcPref == ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
return listBuilder.build(); return listBuilder.build();
} }
@@ -337,13 +340,13 @@ public class WifiCallingSliceHelper {
*/ */
private CharSequence getWifiCallingPreferenceSummary(int wfcMode) { private CharSequence getWifiCallingPreferenceSummary(int wfcMode) {
switch (wfcMode) { switch (wfcMode) {
case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY: case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
return mContext.getText( return mContext.getText(
com.android.internal.R.string.wfc_mode_wifi_only_summary); com.android.internal.R.string.wfc_mode_wifi_only_summary);
case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED: case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
return mContext.getText( return mContext.getText(
com.android.internal.R.string.wfc_mode_wifi_preferred_summary); com.android.internal.R.string.wfc_mode_wifi_preferred_summary);
case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED: case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
return mContext.getText( return mContext.getText(
com.android.internal.R.string.wfc_mode_cellular_preferred_summary); com.android.internal.R.string.wfc_mode_cellular_preferred_summary);
default: default:
@@ -355,15 +358,19 @@ public class WifiCallingSliceHelper {
return ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(subId)); 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 { throws InterruptedException, ExecutionException, TimeoutException {
FutureTask<Integer> wfcModeTask = new FutureTask<>(new Callable<Integer>() { final FutureTask<Integer> wfcModeTask = new FutureTask<>(new Callable<Integer>() {
@Override @Override
public Integer call() { public Integer call() {
return imsManager.getWfcMode(false); return imsMmTelManager.getVoWiFiModeSetting();
} }
}); });
ExecutorService executor = Executors.newSingleThreadExecutor(); final ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(wfcModeTask); executor.execute(wfcModeTask);
return wfcModeTask.get(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); return wfcModeTask.get(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
} }
@@ -380,7 +387,7 @@ public class WifiCallingSliceHelper {
if (subId > SubscriptionManager.INVALID_SUBSCRIPTION_ID) { if (subId > SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
final ImsManager imsManager = getImsManager(subId); final ImsManager imsManager = getImsManager(subId);
if (imsManager.isWfcEnabledByPlatform() if (imsManager.isWfcEnabledByPlatform()
&& imsManager.isWfcProvisionedOnDevice()) { && isWfcProvisionedOnDevice(subId)) {
final boolean currentValue = imsManager.isWfcEnabledByUser() final boolean currentValue = imsManager.isWfcEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled(); && imsManager.isNonTtyOrTtyOnVolteEnabled();
final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
@@ -420,33 +427,34 @@ public class WifiCallingSliceHelper {
final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled( final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true); CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
ImsManager imsManager = getImsManager(subId); final ImsManager imsManager = getImsManager(subId);
if (isWifiCallingPrefEditable if (isWifiCallingPrefEditable
&& imsManager.isWfcEnabledByPlatform() && imsManager.isWfcEnabledByPlatform()
&& imsManager.isWfcProvisionedOnDevice() && isWfcProvisionedOnDevice(subId)
&& imsManager.isWfcEnabledByUser() && imsManager.isWfcEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled()) { && imsManager.isNonTtyOrTtyOnVolteEnabled()) {
// Change the preference only when wifi calling is enabled // Change the preference only when wifi calling is enabled
// And when wifi calling preference is editable for the current carrier // 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; int newValue = errorValue;
switch (intent.getAction()) { switch (intent.getAction()) {
case ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY: case ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY:
if (isWifiOnlySupported) { if (isWifiOnlySupported) {
// change to wifi_only when wifi_only is enabled. // change to wifi_only when wifi_only is enabled.
newValue = ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY; newValue = ImsMmTelManager.WIFI_MODE_WIFI_ONLY;
} }
break; break;
case ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED: case ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED:
newValue = ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED; newValue = ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED;
break; break;
case ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED: case ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED:
newValue = ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED; newValue = ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED;
break; break;
} }
if (newValue != errorValue && newValue != currentValue) { if (newValue != errorValue && newValue != currentValue) {
// Update the setting only when there is a valid update // Update the setting only when there is a valid update
imsManager.setWfcMode(newValue, false); imsMmTelManager.setVoWiFiModeSetting(newValue);
} }
} }
} }
@@ -505,6 +513,11 @@ public class WifiCallingSliceHelper {
return SubscriptionManager.getDefaultVoiceSubscriptionId(); 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 * Returns Intent of the activation app required to activate wifi calling or null if there is no
* need for activation. * need for activation.

View File

@@ -17,15 +17,18 @@
package com.android.settings.wifi.calling; package com.android.settings.wifi.calling;
import android.content.Context; import android.content.Context;
import android.telephony.SubscriptionManager;
import com.android.ims.ImsManager; import com.android.ims.ImsManager;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.network.telephony.MobileNetworkUtils;
public class WifiCallingSuggestionActivity extends SettingsActivity { public class WifiCallingSuggestionActivity extends SettingsActivity {
public static boolean isSuggestionComplete(Context context) { public static boolean isSuggestionComplete(Context context) {
if (!ImsManager.isWfcEnabledByPlatform(context) || if (!ImsManager.isWfcEnabledByPlatform(context) ||
!ImsManager.isWfcProvisionedOnDevice(context)) { !MobileNetworkUtils.isWfcProvisionedOnDevice(
SubscriptionManager.getDefaultVoiceSubscriptionId())) {
return true; return true;
} }
return ImsManager.isWfcEnabledByUser(context) return ImsManager.isWfcEnabledByUser(context)

View File

@@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -58,6 +59,10 @@ public class MobileNetworkUtilsTest {
private static final String PACKAGE_NAME = "com.android.app"; private static final String PACKAGE_NAME = "com.android.app";
private static final int SUB_ID_1 = 1; private static final int SUB_ID_1 = 1;
private static final int SUB_ID_2 = 2; 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 @Mock
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
@@ -89,6 +94,7 @@ public class MobileNetworkUtilsTest {
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2); when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
@@ -102,10 +108,17 @@ public class MobileNetworkUtilsTest {
when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig); when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig);
when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1); 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.getSubscriptionId()).thenReturn(SUB_ID_2);
when(mSubscriptionInfo2.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_2);
when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true))).thenReturn( when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true))).thenReturn(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)); Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
when(mSubscriptionManager.getAccessibleSubscriptionInfoList()).thenReturn(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
when(mTelephonyManager.getNetworkOperatorName()).thenReturn(
PLMN_FROM_TELEPHONY_MANAGER_API);
} }
@Test @Test
@@ -301,4 +314,24 @@ public class MobileNetworkUtilsTest {
TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue(); 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();
}
} }

View File

@@ -19,7 +19,6 @@ package com.android.settings.network.telephony;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -31,12 +30,11 @@ import android.telecom.PhoneAccountHandle;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.ims.ImsMmTelManager;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.ims.ImsConfig;
import com.android.ims.ImsManager; import com.android.ims.ImsManager;
import com.android.internal.R; import com.android.internal.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
@@ -60,6 +58,8 @@ public class WifiCallingPreferenceControllerTest {
@Mock @Mock
private ImsManager mImsManager; private ImsManager mImsManager;
@Mock @Mock
private ImsMmTelManager mImsMmTelManager;
@Mock
private PreferenceScreen mPreferenceScreen; private PreferenceScreen mPreferenceScreen;
private WifiCallingPreferenceController mController; private WifiCallingPreferenceController mController;
@@ -72,17 +72,22 @@ public class WifiCallingPreferenceControllerTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application); 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); 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.mCarrierConfigManager = mCarrierConfigManager;
mController.init(SUB_ID); mController.init(SUB_ID);
mController.mImsManager = mImsManager; mController.mImsManager = mImsManager;
mController.mCallState = TelephonyManager.CALL_STATE_IDLE;
mPreference.setKey(mController.getPreferenceKey()); mPreference.setKey(mController.getPreferenceKey());
when(mController.getTelephonyManager(mContext, SUB_ID)).thenReturn(mTelephonyManager);
mCarrierConfig = new PersistableBundle(); mCarrierConfig = new PersistableBundle();
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig); when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
@@ -94,8 +99,10 @@ public class WifiCallingPreferenceControllerTest {
public void updateState_noSimCallManager_setCorrectSummary() { public void updateState_noSimCallManager_setCorrectSummary() {
mController.mSimCallManager = null; mController.mSimCallManager = null;
when(mImsManager.isWfcEnabledByUser()).thenReturn(true); when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mImsManager.getWfcMode(anyBoolean())).thenReturn( when(mImsMmTelManager.getVoWiFiRoamingModeSetting()).thenReturn(
ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY); ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -105,8 +112,7 @@ public class WifiCallingPreferenceControllerTest {
@Test @Test
public void updateState_notCallIdle_disable() { public void updateState_notCallIdle_disable() {
when(mTelephonyManager.getCallState(SUB_ID)).thenReturn( mController.mCallState = TelephonyManager.CALL_STATE_RINGING;
TelephonyManager.CALL_STATE_RINGING);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -129,10 +135,10 @@ public class WifiCallingPreferenceControllerTest {
mController.init(SUB_ID); mController.init(SUB_ID);
mController.mImsManager = mImsManager; mController.mImsManager = mImsManager;
when(mImsManager.getWfcMode(true)).thenReturn( when(mImsMmTelManager.getVoWiFiRoamingModeSetting()).thenReturn(
ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED); ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
when(mImsManager.getWfcMode(false)).thenReturn( when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED); ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
when(mImsManager.isWfcEnabledByUser()).thenReturn(true); when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mTelephonyManager.isNetworkRoaming()).thenReturn(true); when(mTelephonyManager.isNetworkRoaming()).thenReturn(true);
@@ -146,10 +152,10 @@ public class WifiCallingPreferenceControllerTest {
assertNull(mController.mSimCallManager); assertNull(mController.mSimCallManager);
// useWfcHomeModeForRoaming is false by default. In order to check wfc in roaming mode. We // 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. // need the device roaming, and not using home mode in roaming network.
when(mImsManager.getWfcMode(true)).thenReturn( when(mImsMmTelManager.getVoWiFiRoamingModeSetting()).thenReturn(
ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED); ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
when(mImsManager.getWfcMode(false)).thenReturn( when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED); ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
when(mImsManager.isWfcEnabledByUser()).thenReturn(true); when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mTelephonyManager.isNetworkRoaming()).thenReturn(true); when(mTelephonyManager.isNetworkRoaming()).thenReturn(true);
@@ -169,7 +175,7 @@ public class WifiCallingPreferenceControllerTest {
@Test @Test
public void displayPreference_available_setsSubscriptionIdOnIntent() { public void displayPreference_available_setsSubscriptionIdOnIntent() {
Intent intent = new Intent(); final Intent intent = new Intent();
mPreference.setIntent(intent); mPreference.setIntent(intent);
mController.displayPreference(mPreferenceScreen); mController.displayPreference(mPreferenceScreen);
assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID, assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID,

View File

@@ -17,11 +17,12 @@
package com.android.settings.wifi.calling; package com.android.settings.wifi.calling;
import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT; import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
@@ -42,6 +43,7 @@ import android.os.Bundle;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.ims.ImsMmTelManager;
import android.telephony.ims.ProvisioningManager; import android.telephony.ims.ProvisioningManager;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
@@ -53,8 +55,7 @@ import com.android.ims.ImsConfig;
import com.android.ims.ImsManager; import com.android.ims.ImsManager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.SwitchBar; import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch; import com.android.settings.widget.ToggleSwitch;
@@ -66,8 +67,10 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers;
@Config(shadows = ShadowFragment.class)
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class WifiCallingSettingsForSubTest { public class WifiCallingSettingsForSubTest {
private static final String BUTTON_WFC_MODE = "wifi_calling_mode"; private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
@@ -83,6 +86,7 @@ public class WifiCallingSettingsForSubTest {
@Mock private static CarrierConfigManager sCarrierConfigManager; @Mock private static CarrierConfigManager sCarrierConfigManager;
@Mock private CarrierConfigManager mMockConfigManager; @Mock private CarrierConfigManager mMockConfigManager;
@Mock private ImsManager mImsManager; @Mock private ImsManager mImsManager;
@Mock private ImsMmTelManager mImsMmTelManager;
@Mock private TelephonyManager mTelephonyManager; @Mock private TelephonyManager mTelephonyManager;
@Mock private PreferenceScreen mPreferenceScreen; @Mock private PreferenceScreen mPreferenceScreen;
@Mock private SettingsActivity mActivity; @Mock private SettingsActivity mActivity;
@@ -124,12 +128,15 @@ public class WifiCallingSettingsForSubTest {
doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar); doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar);
doReturn(mImsManager).when(mFragment).getImsManager(); doReturn(mImsManager).when(mFragment).getImsManager();
doReturn(mImsMmTelManager).when(mFragment).getImsMmTelManager();
doReturn(mImsConfig).when(mImsManager).getConfigInterface(); doReturn(mImsConfig).when(mImsManager).getConfigInterface();
doReturn(true).when(mImsManager).isWfcProvisionedOnDevice(); doReturn(true).when(mFragment).isWfcProvisionedOnDevice();
doReturn(true).when(mImsManager).isWfcEnabledByUser(); doReturn(true).when(mImsManager).isWfcEnabledByUser();
doReturn(true).when(mImsManager).isNonTtyOrTtyOnVolteEnabled(); doReturn(true).when(mImsManager).isNonTtyOrTtyOnVolteEnabled();
doReturn(ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED) doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
.when(mImsManager).getWfcMode(anyBoolean()); .when(mImsMmTelManager).getVoWiFiModeSetting();
doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
.when(mImsMmTelManager).getVoWiFiRoamingModeSetting();
doReturn(mBundle).when(sCarrierConfigManager).getConfigForSubId(anyInt()); doReturn(mBundle).when(sCarrierConfigManager).getConfigForSubId(anyInt());
setDefaultCarrierConfigValues(); setDefaultCarrierConfigValues();
@@ -171,7 +178,7 @@ public class WifiCallingSettingsForSubTest {
@Test @Test
public void onResume_provisioningDisallowed_shouldFinish() { public void onResume_provisioningDisallowed_shouldFinish() {
// Call onResume while provisioning is disallowed. // Call onResume while provisioning is disallowed.
doReturn(false).when(mImsManager).isWfcProvisionedOnDevice(); doReturn(false).when(mFragment).isWfcProvisionedOnDevice();
mFragment.onResume(); mFragment.onResume();
// Verify that finish() is called // Verify that finish() is called
@@ -248,15 +255,13 @@ public class WifiCallingSettingsForSubTest {
// Set the WFC home mode. // Set the WFC home mode.
mFragment.onPreferenceChange(mButtonWfcMode, mFragment.onPreferenceChange(mButtonWfcMode,
String.valueOf(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED)); String.valueOf(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
// Check that only WFC home mode is set. // Check that only WFC home mode is set.
verify(mImsManager, times(1)).setWfcMode( verify(mImsMmTelManager, times(1)).setVoWiFiModeSetting(
eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED), eq(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
eq(false)); verify(mImsMmTelManager, never()).setVoWiFiRoamingModeSetting(
verify(mImsManager, never()).setWfcMode( eq(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
eq(true));
} }
@Test @Test
@@ -269,34 +274,32 @@ public class WifiCallingSettingsForSubTest {
// Set the WFC home mode. // Set the WFC home mode.
mFragment.onPreferenceChange(mButtonWfcMode, 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. // Check that both WFC home mode and roaming mode are set.
verify(mImsManager, times(1)).setWfcMode( verify(mImsMmTelManager, times(1)).setVoWiFiModeSetting(
eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED), eq(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
eq(false)); verify(mImsMmTelManager, times(1)).setVoWiFiRoamingModeSetting(
verify(mImsManager, times(1)).setWfcMode( eq(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
eq(ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED),
eq(true));
} }
@Test @Test
public void onSwitchChanged_enableSetting_shouldLaunchWfcDisclaimerFragment() { public void onSwitchChanged_enableSetting_shouldLaunchWfcDisclaimerFragment() {
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
mFragment.onSwitchChanged(null, true); mFragment.onSwitchChanged(null, true);
// Check the WFC disclaimer fragment is launched. // Check the WFC disclaimer fragment is launched.
verify(mFragment).startActivityForResult(intentCaptor.capture(), verify(mFragment).startActivityForResult(intentCaptor.capture(),
eq(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_DISCLAIMER)); eq(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_DISCLAIMER));
Intent intent = intentCaptor.getValue(); final Intent intent = intentCaptor.getValue();
assertThat(intent.getStringExtra(EXTRA_SHOW_FRAGMENT)) assertThat(intent.getStringExtra(EXTRA_SHOW_FRAGMENT))
.isEqualTo(WifiCallingDisclaimerFragment.class.getName()); .isEqualTo(WifiCallingDisclaimerFragment.class.getName());
} }
@Test @Test
public void onActivityResult_finishWfcDisclaimerFragment_shouldLaunchCarrierActivity() { public void onActivityResult_finishWfcDisclaimerFragment_shouldLaunchCarrierActivity() {
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
// Emulate the WfcDisclaimerActivity finish. // Emulate the WfcDisclaimerActivity finish.
mFragment.onActivityResult(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_DISCLAIMER, mFragment.onActivityResult(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_DISCLAIMER,
@@ -305,7 +308,7 @@ public class WifiCallingSettingsForSubTest {
// Check the WFC emergency address activity is launched. // Check the WFC emergency address activity is launched.
verify(mFragment).startActivityForResult(intentCaptor.capture(), verify(mFragment).startActivityForResult(intentCaptor.capture(),
eq(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_EMERGENCY_ADDRESS)); eq(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_EMERGENCY_ADDRESS));
Intent intent = intentCaptor.getValue(); final Intent intent = intentCaptor.getValue();
assertEquals(intent.getComponent(), ComponentName.unflattenFromString( assertEquals(intent.getComponent(), ComponentName.unflattenFromString(
TEST_EMERGENCY_ADDRESS_CARRIER_APP)); TEST_EMERGENCY_ADDRESS_CARRIER_APP));
} }

View File

@@ -64,72 +64,75 @@ public class WifiCallingSettingsTest {
@Test @Test
public void setupFragment_oneSubscription_noCrash() { public void setupFragment_oneSubscription_noCrash() {
SubscriptionInfo info = mock(SubscriptionInfo.class); final SubscriptionInfo info = mock(SubscriptionInfo.class);
when(info.getSubscriptionId()).thenReturn(111); when(info.getSubscriptionId()).thenReturn(111);
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>( SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
Collections.singletonList(info))); Collections.singletonList(info)));
doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class)); 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()); intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
FragmentController.of(mFragment, intent).create(0 /* containerViewId*/, FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
null /* bundle */).start().resume().visible().get(); null /* bundle */).start().resume().visible().get();
View view = mFragment.getView(); final View view = mFragment.getView();
RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager); final RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
WifiCallingSettings.WifiCallingViewPagerAdapter adapter = final WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
(WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter(); (WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
assertThat(adapter.getCount()).isEqualTo(1); assertThat(adapter.getCount()).isEqualTo(1);
} }
@Test @Test
public void setupFragment_twoSubscriptions_correctSelection() { public void setupFragment_twoSubscriptions_correctSelection() {
SubscriptionInfo info1 = mock(SubscriptionInfo.class); final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
SubscriptionInfo info2 = mock(SubscriptionInfo.class); final SubscriptionInfo info2 = mock(SubscriptionInfo.class);
when(info1.getSubscriptionId()).thenReturn(111); when(info1.getSubscriptionId()).thenReturn(111);
when(info2.getSubscriptionId()).thenReturn(222); when(info2.getSubscriptionId()).thenReturn(222);
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>( SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
Arrays.asList(info1, info2))); Arrays.asList(info1, info2)));
doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class)); 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()); intent.putExtra(Settings.EXTRA_SUB_ID, info2.getSubscriptionId());
FragmentController.of(mFragment, intent).create(0 /* containerViewId*/, FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
null /* bundle */).start().resume().visible().get(); null /* bundle */).start().resume().visible().get();
View view = mFragment.getView(); final View view = mFragment.getView();
RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager); final RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
assertThat(pager.getCurrentItem()).isEqualTo(1); assertThat(pager.getCurrentItem()).isEqualTo(1);
WifiCallingSettings.WifiCallingViewPagerAdapter adapter = final WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
(WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter(); (WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
assertThat(adapter.getCount()).isEqualTo(2); assertThat(adapter.getCount()).isEqualTo(2);
} }
@Test @Test
public void setupFragment_twoSubscriptionsOneNotProvisionedOnDevice_oneResult() { public void setupFragment_twoSubscriptionsOneNotProvisionedOnDevice_oneResult() {
SubscriptionInfo info1 = mock(SubscriptionInfo.class); final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
SubscriptionInfo info2 = mock(SubscriptionInfo.class); final SubscriptionInfo info2 = mock(SubscriptionInfo.class);
when(info1.getSubscriptionId()).thenReturn(111); when(info1.getSubscriptionId()).thenReturn(111);
when(info2.getSubscriptionId()).thenReturn(222); when(info2.getSubscriptionId()).thenReturn(222);
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>( SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
Arrays.asList(info1, info2))); Arrays.asList(info1, info2)));
doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class)); doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class));
doReturn(true).when(mFragment).isWfcProvisionedOnDevice(eq(info1));
doReturn(false).when(mFragment).isWfcProvisionedOnDevice(eq(info2)); doReturn(false).when(mFragment).isWfcProvisionedOnDevice(eq(info2));
Intent intent = new Intent(); final Intent intent = new Intent();
intent.putExtra(Settings.EXTRA_SUB_ID, info1.getSubscriptionId()); intent.putExtra(Settings.EXTRA_SUB_ID, info1.getSubscriptionId());
FragmentController.of(mFragment, intent).create(0 /* containerViewId*/, FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
null /* bundle */).start().resume().visible().get(); null /* bundle */).start().resume().visible().get();
View view = mFragment.getView(); final View view = mFragment.getView();
RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager); final RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
assertThat(pager.getCurrentItem()).isEqualTo(0); assertThat(pager.getCurrentItem()).isEqualTo(0);
WifiCallingSettings.WifiCallingViewPagerAdapter adapter = final WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
(WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter(); (WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
assertThat(adapter.getCount()).isEqualTo(1); assertThat(adapter.getCount()).isEqualTo(1);
} }

View File

@@ -22,7 +22,7 @@ import static android.app.slice.SliceItem.FORMAT_TEXT;
import static com.google.common.truth.Truth.assertThat; 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.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -32,6 +32,7 @@ import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.ims.ImsMmTelManager;
import androidx.slice.Slice; import androidx.slice.Slice;
import androidx.slice.SliceItem; import androidx.slice.SliceItem;
@@ -44,7 +45,6 @@ import androidx.slice.widget.RowContent;
import androidx.slice.widget.SliceContent; import androidx.slice.widget.SliceContent;
import androidx.slice.widget.SliceLiveData; import androidx.slice.widget.SliceLiveData;
import com.android.ims.ImsConfig;
import com.android.ims.ImsManager; import com.android.ims.ImsManager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.slices.CustomSliceRegistry; import com.android.settings.slices.CustomSliceRegistry;
@@ -76,6 +76,9 @@ public class WifiCallingSliceHelperTest {
@Mock @Mock
private ImsManager mMockImsManager; private ImsManager mMockImsManager;
@Mock
private ImsMmTelManager mMockImsMmTelManager;
private FakeWifiCallingSliceHelper mWfcSliceHelper; private FakeWifiCallingSliceHelper mWfcSliceHelper;
private SettingsSliceProvider mProvider; private SettingsSliceProvider mProvider;
private SliceBroadcastReceiver mReceiver; private SliceBroadcastReceiver mReceiver;
@@ -98,7 +101,7 @@ public class WifiCallingSliceHelperTest {
mFeatureFactory = FakeFeatureFactory.setupForTest(); mFeatureFactory = FakeFeatureFactory.setupForTest();
mSlicesFeatureProvider = mFeatureFactory.getSlicesFeatureProvider(); mSlicesFeatureProvider = mFeatureFactory.getSlicesFeatureProvider();
mWfcSliceHelper = new FakeWifiCallingSliceHelper(mContext); mWfcSliceHelper = spy(new FakeWifiCallingSliceHelper(mContext));
// Set-up specs for SliceMetadata. // Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS); SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
@@ -133,7 +136,7 @@ public class WifiCallingSliceHelperTest {
activity so the user can perform the activation there.(PrimaryAction) activity so the user can perform the activation there.(PrimaryAction)
*/ */
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(false); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(false);
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null); when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -151,7 +154,7 @@ public class WifiCallingSliceHelperTest {
@Test @Test
public void test_CreateWifiCallingSlice_success() { public void test_CreateWifiCallingSlice_success() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null); when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -166,7 +169,7 @@ public class WifiCallingSliceHelperTest {
@Test @Test
public void test_SettingSliceProvider_getsRightSliceWifiCalling() { public void test_SettingSliceProvider_getsRightSliceWifiCalling() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null); when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
@@ -182,17 +185,17 @@ public class WifiCallingSliceHelperTest {
@Test @Test
public void test_SliceBroadcastReceiver_toggleOnWifiCalling() { public void test_SliceBroadcastReceiver_toggleOnWifiCalling() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext)) when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext))
.thenReturn(mWfcSliceHelper); .thenReturn(mWfcSliceHelper);
mWfcSliceHelper.setActivationAppIntent(null); mWfcSliceHelper.setActivationAppIntent(null);
ArgumentCaptor<Boolean> mWfcSettingCaptor = ArgumentCaptor.forClass(Boolean.class); final ArgumentCaptor<Boolean> mWfcSettingCaptor = ArgumentCaptor.forClass(Boolean.class);
// turn on Wifi calling setting // 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); intent.putExtra(EXTRA_TOGGLE_STATE, true);
// change the setting // change the setting
@@ -207,7 +210,7 @@ public class WifiCallingSliceHelperTest {
@Test @Test
public void test_CreateWifiCallingPreferenceSlice_prefNotEditable() { public void test_CreateWifiCallingPreferenceSlice_prefNotEditable() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
mWfcSliceHelper.setIsWifiCallingPrefEditable(false); mWfcSliceHelper.setIsWifiCallingPrefEditable(false);
@@ -222,7 +225,7 @@ public class WifiCallingSliceHelperTest {
@Test @Test
public void test_CreateWifiCallingPreferenceSlice_wfcOff() { public void test_CreateWifiCallingPreferenceSlice_wfcOff() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(false);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
mWfcSliceHelper.setIsWifiCallingPrefEditable(true); mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
@@ -239,11 +242,11 @@ public class WifiCallingSliceHelperTest {
@Test @Test
public void test_CreateWifiCallingPreferenceSlice_success() { public void test_CreateWifiCallingPreferenceSlice_success() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mMockImsManager.getWfcMode(false)).thenReturn( when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED); ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
mWfcSliceHelper.setIsWifiCallingPrefEditable(true); mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
final Slice slice = mWfcSliceHelper.createWifiCallingPreferenceSlice( final Slice slice = mWfcSliceHelper.createWifiCallingPreferenceSlice(
@@ -257,11 +260,11 @@ public class WifiCallingSliceHelperTest {
@Test @Test
public void test_SettingsSliceProvider_getWfcPreferenceSlice() { public void test_SettingsSliceProvider_getWfcPreferenceSlice() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mMockImsManager.getWfcMode(false)).thenReturn( when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED); ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext)) when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext))
.thenReturn(mWfcSliceHelper); .thenReturn(mWfcSliceHelper);
mWfcSliceHelper.setIsWifiCallingPrefEditable(true); mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
@@ -276,28 +279,29 @@ public class WifiCallingSliceHelperTest {
@Test @Test
public void test_SliceBroadcastReceiver_setWfcPrefCellularPref() { public void test_SliceBroadcastReceiver_setWfcPrefCellularPref() {
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true); when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
when(mMockImsManager.isWfcProvisionedOnDevice()).thenReturn(true); when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true); when(mMockImsManager.isWfcEnabledByUser()).thenReturn(true);
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true); when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
when(mMockImsManager.getWfcMode(false)).thenReturn( when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED); ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext)) when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext))
.thenReturn(mWfcSliceHelper); .thenReturn(mWfcSliceHelper);
mWfcSliceHelper.setIsWifiCallingPrefEditable(true); mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
ArgumentCaptor<Integer> mWfcPreferenceCaptor = ArgumentCaptor.forClass(Integer.class); final ArgumentCaptor<Integer> mWfcPreferenceCaptor =
ArgumentCaptor.forClass(Integer.class);
// Change preference to Cellular pref // Change preference to Cellular pref
Intent intent = new Intent( final Intent intent = new Intent(
WifiCallingSliceHelper.ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED); WifiCallingSliceHelper.ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED);
mReceiver.onReceive(mContext, intent); mReceiver.onReceive(mContext, intent);
verify((mMockImsManager)).setWfcMode(mWfcPreferenceCaptor.capture(), eq(false)); verify((mMockImsMmTelManager)).setVoWiFiModeSetting(mWfcPreferenceCaptor.capture());
// assert the change // assert the change
assertThat(mWfcPreferenceCaptor.getValue()).isEqualTo( assertThat(mWfcPreferenceCaptor.getValue()).isEqualTo(
ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED); ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
} }
private void testWifiCallingSettingsUnavailableSlice(Slice slice, private void testWifiCallingSettingsUnavailableSlice(Slice slice,
@@ -400,7 +404,7 @@ public class WifiCallingSliceHelperTest {
private void assertTitle(List<SliceItem> sliceItems, String title) { private void assertTitle(List<SliceItem> sliceItems, String title) {
boolean hasTitle = false; boolean hasTitle = false;
for (SliceItem item : sliceItems) { 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 */); null /* non-hints */);
if (titleItems == null) { if (titleItems == null) {
continue; continue;
@@ -434,6 +438,11 @@ public class WifiCallingSliceHelperTest {
return mMockImsManager; return mMockImsManager;
} }
@Override
protected ImsMmTelManager getImsMmTelManager(int subId) {
return mMockImsMmTelManager;
}
protected int getDefaultVoiceSubId() { protected int getDefaultVoiceSubId() {
return mSubId; return mSubId;
} }
@@ -442,6 +451,10 @@ public class WifiCallingSliceHelperTest {
mSubId = id; mSubId = id;
} }
boolean isWfcProvisionedOnDevice(int subId) {
return true;
}
@Override @Override
protected Intent getWifiCallingCarrierActivityIntent(int subId) { protected Intent getWifiCallingCarrierActivityIntent(int subId) {
return mActivationAppIntent; return mActivationAppIntent;