[Settings] Code refactor for Wifi calling IMS API
Replacing logics of ImsManager#isWfcEnabledByPlatform() & MobileNetworkUtils#isWfcProvisionedOnDevice() into WifiCallingQueryImsState#isWifiCallingProvisioned(). Bug: 140542283 Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=WifiCallingSliceHelperTest Change-Id: I68462368669b81e10d09bbb93e74e23ea9a1f446
This commit is contained in:
@@ -18,6 +18,15 @@ package com.android.settings.network.telephony;
|
||||
|
||||
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
|
||||
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.EVDO;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.GSM;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.LTE;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.NR;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_TD_SCDMA;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_UNKNOWN;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.WCDMA;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -54,6 +63,7 @@ import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.graph.SignalDrawable;
|
||||
@@ -61,15 +71,6 @@ import com.android.settingslib.graph.SignalDrawable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.EVDO;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.GSM;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.LTE;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.NR;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_TD_SCDMA;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_UNKNOWN;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.WCDMA;
|
||||
|
||||
public class MobileNetworkUtils {
|
||||
|
||||
private static final String TAG = "MobileNetworkUtils";
|
||||
@@ -152,10 +153,10 @@ public class MobileNetworkUtils {
|
||||
|
||||
isWifiCallingEnabled = intent != null;
|
||||
} else {
|
||||
final WifiCallingQueryImsState queryState =
|
||||
new WifiCallingQueryImsState(context, subId);
|
||||
final ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
|
||||
isWifiCallingEnabled = imsMgr != null
|
||||
&& imsMgr.isWfcEnabledByPlatform()
|
||||
&& isWfcProvisionedOnDevice(subId)
|
||||
isWifiCallingEnabled = queryState.isWifiCallingProvisioned()
|
||||
&& isImsServiceStateReady(imsMgr);
|
||||
}
|
||||
|
||||
|
@@ -43,12 +43,9 @@ import androidx.slice.builders.ListBuilder.RowBuilder;
|
||||
import androidx.slice.builders.SliceAction;
|
||||
|
||||
import com.android.ims.ImsConfig;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -140,10 +137,7 @@ public class WifiCallingSliceHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ImsManager imsManager = getImsManager(subId);
|
||||
|
||||
if (!imsManager.isWfcEnabledByPlatform()
|
||||
|| !isWfcProvisionedOnDevice(subId)) {
|
||||
if (!queryImsState(subId).isWifiCallingProvisioned()) {
|
||||
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by Platform");
|
||||
return null;
|
||||
}
|
||||
@@ -168,9 +162,8 @@ public class WifiCallingSliceHelper {
|
||||
}
|
||||
|
||||
private boolean isWifiCallingEnabled() {
|
||||
final int subId = getDefaultVoiceSubId();
|
||||
return queryImsState(subId).isEnabledByUser()
|
||||
&& queryImsState(subId).isAllowUserControl();
|
||||
final WifiCallingQueryImsState queryState = queryImsState(getDefaultVoiceSubId());
|
||||
return queryState.isEnabledByUser() && queryState.isAllowUserControl();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,23 +217,21 @@ public class WifiCallingSliceHelper {
|
||||
CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, subId, false);
|
||||
final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
|
||||
CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
|
||||
final ImsManager imsManager = getImsManager(subId);
|
||||
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
|
||||
|
||||
if (!imsManager.isWfcEnabledByPlatform()
|
||||
|| !isWfcProvisionedOnDevice(subId)) {
|
||||
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isWifiCallingPrefEditable) {
|
||||
Log.d(TAG, "Wifi calling preference is not editable");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!queryImsState(subId).isWifiCallingProvisioned()) {
|
||||
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isWifiCallingEnabled = false;
|
||||
int wfcMode = -1;
|
||||
try {
|
||||
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
|
||||
isWifiCallingEnabled = isWifiCallingEnabled();
|
||||
wfcMode = getWfcMode(imsMmTelManager);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
@@ -351,10 +342,6 @@ public class WifiCallingSliceHelper {
|
||||
}
|
||||
}
|
||||
|
||||
protected ImsManager getImsManager(int subId) {
|
||||
return ImsManager.getInstance(mContext, SubscriptionUtil.getPhoneId(mContext, subId));
|
||||
}
|
||||
|
||||
protected ImsMmTelManager getImsMmTelManager(int subId) {
|
||||
return ImsMmTelManager.createForSubscriptionId(subId);
|
||||
}
|
||||
@@ -382,11 +369,10 @@ public class WifiCallingSliceHelper {
|
||||
final int subId = getDefaultVoiceSubId();
|
||||
|
||||
if (SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
final ImsManager imsManager = getImsManager(subId);
|
||||
if (imsManager.isWfcEnabledByPlatform()
|
||||
&& isWfcProvisionedOnDevice(subId)) {
|
||||
final boolean currentValue = queryImsState(subId).isEnabledByUser()
|
||||
&& queryImsState(subId).isAllowUserControl();
|
||||
final WifiCallingQueryImsState queryState = queryImsState(subId);
|
||||
if (queryState.isWifiCallingProvisioned()) {
|
||||
final boolean currentValue = queryState.isEnabledByUser()
|
||||
&& queryState.isAllowUserControl();
|
||||
final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
|
||||
currentValue);
|
||||
final Intent activationAppIntent =
|
||||
@@ -425,12 +411,11 @@ public class WifiCallingSliceHelper {
|
||||
final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
|
||||
CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
|
||||
|
||||
final ImsManager imsManager = getImsManager(subId);
|
||||
final WifiCallingQueryImsState queryState = queryImsState(subId);
|
||||
if (isWifiCallingPrefEditable
|
||||
&& imsManager.isWfcEnabledByPlatform()
|
||||
&& isWfcProvisionedOnDevice(subId)
|
||||
&& queryImsState(subId).isEnabledByUser()
|
||||
&& queryImsState(subId).isAllowUserControl()) {
|
||||
&& queryState.isWifiCallingProvisioned()
|
||||
&& queryState.isEnabledByUser()
|
||||
&& queryState.isAllowUserControl()) {
|
||||
// Change the preference only when wifi calling is enabled
|
||||
// And when wifi calling preference is editable for the current carrier
|
||||
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
|
||||
@@ -511,11 +496,6 @@ public class WifiCallingSliceHelper {
|
||||
return SubscriptionManager.getDefaultVoiceSubscriptionId();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isWfcProvisionedOnDevice(int subId) {
|
||||
return MobileNetworkUtils.isWfcProvisionedOnDevice(subId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Intent of the activation app required to activate wifi calling or null if there is no
|
||||
* need for activation.
|
||||
|
@@ -107,6 +107,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
mQueryImsState = spy(new WifiCallingQueryImsState(mContext, SUB_ID));
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
|
||||
mWfcSliceHelper = spy(new FakeWifiCallingSliceHelper(mContext));
|
||||
doReturn(mQueryImsState).when(mWfcSliceHelper).queryImsState(anyInt());
|
||||
@@ -117,6 +118,8 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_CreateWifiCallingSlice_invalidSubId() {
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
doReturn(false).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
mWfcSliceHelper.setDefaultVoiceSubId(-1);
|
||||
|
||||
final Slice slice = mWfcSliceHelper.createWifiCallingSlice(
|
||||
@@ -127,7 +130,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_CreateWifiCallingSlice_wfcNotSupported() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(false);
|
||||
doReturn(false).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
|
||||
final Slice slice = mWfcSliceHelper.createWifiCallingSlice(
|
||||
CustomSliceRegistry.WIFI_CALLING_URI);
|
||||
@@ -143,8 +146,7 @@ public class WifiCallingSliceHelperTest {
|
||||
turned off) we need to guide the user to wifi calling settings
|
||||
activity so the user can perform the activation there.(PrimaryAction)
|
||||
*/
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(false).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(false);
|
||||
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
|
||||
@@ -161,8 +163,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_CreateWifiCallingSlice_success() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
|
||||
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
|
||||
@@ -176,8 +177,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_SettingSliceProvider_getsRightSliceWifiCalling() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
|
||||
when(mMockCarrierConfigManager.getConfigForSubId(1)).thenReturn(null);
|
||||
@@ -192,8 +192,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_SliceBroadcastReceiver_toggleOnWifiCalling() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(false).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
|
||||
when(mSlicesFeatureProvider.getNewWifiCallingSliceHelper(mContext))
|
||||
@@ -217,8 +216,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_CreateWifiCallingPreferenceSlice_prefNotEditable() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
|
||||
mWfcSliceHelper.setIsWifiCallingPrefEditable(false);
|
||||
@@ -232,8 +230,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_CreateWifiCallingPreferenceSlice_wfcOff() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(false).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
|
||||
mWfcSliceHelper.setIsWifiCallingPrefEditable(true);
|
||||
@@ -249,8 +246,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_CreateWifiCallingPreferenceSlice_success() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
|
||||
when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
|
||||
@@ -267,8 +263,7 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
@Test
|
||||
public void test_SettingsSliceProvider_getWfcPreferenceSlice() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
|
||||
when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
|
||||
@@ -286,8 +281,7 @@ public class WifiCallingSliceHelperTest {
|
||||
}
|
||||
@Test
|
||||
public void test_SliceBroadcastReceiver_setWfcPrefCellularPref() {
|
||||
when(mMockImsManager.isWfcEnabledByPlatform()).thenReturn(true);
|
||||
when(mWfcSliceHelper.isWfcProvisionedOnDevice(anyInt())).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isWifiCallingProvisioned();
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mMockImsManager.isNonTtyOrTtyOnVolteEnabled()).thenReturn(true);
|
||||
when(mMockImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
|
||||
@@ -441,12 +435,6 @@ public class WifiCallingSliceHelperTest {
|
||||
return mMockCarrierConfigManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImsManager getImsManager(int subId) {
|
||||
return mMockImsManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImsMmTelManager getImsMmTelManager(int subId) {
|
||||
return mMockImsMmTelManager;
|
||||
}
|
||||
|
Reference in New Issue
Block a user