Check wfc roaming config when read
Bug: 127913488 Test: Build Change-Id: I0a3e8d3f4bc0590f12085f5963892a1d8278efdc
This commit is contained in:
@@ -21,8 +21,10 @@ 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.Looper;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
import android.telecom.PhoneAccountHandle;
|
import android.telecom.PhoneAccountHandle;
|
||||||
import android.telecom.TelecomManager;
|
import android.telecom.TelecomManager;
|
||||||
|
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;
|
||||||
@@ -50,17 +52,24 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
|
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
CarrierConfigManager mCarrierConfigManager;
|
||||||
|
@VisibleForTesting
|
||||||
ImsManager mImsManager;
|
ImsManager mImsManager;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PhoneAccountHandle mSimCallManager;
|
PhoneAccountHandle mSimCallManager;
|
||||||
private PhoneCallStateListener mPhoneStateListener;
|
private PhoneCallStateListener mPhoneStateListener;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
private boolean mEditableWfcRoamingMode;
|
||||||
|
private boolean mUseWfcHomeModeForRoaming;
|
||||||
|
|
||||||
public WifiCallingPreferenceController(Context context, String key) {
|
public WifiCallingPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
|
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
||||||
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||||
mSimCallManager = context.getSystemService(TelecomManager.class).getSimCallManager();
|
mSimCallManager = context.getSystemService(TelecomManager.class).getSimCallManager();
|
||||||
mPhoneStateListener = new PhoneCallStateListener(Looper.getMainLooper());
|
mPhoneStateListener = new PhoneCallStateListener(Looper.getMainLooper());
|
||||||
|
mEditableWfcRoamingMode = true;
|
||||||
|
mUseWfcHomeModeForRoaming = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -109,9 +118,9 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
} else {
|
} else {
|
||||||
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()) {
|
||||||
|
boolean wfcRoamingEnabled = mEditableWfcRoamingMode && !mUseWfcHomeModeForRoaming;
|
||||||
final boolean isRoaming = mTelephonyManager.isNetworkRoaming();
|
final boolean isRoaming = mTelephonyManager.isNetworkRoaming();
|
||||||
int wfcMode = mImsManager.getWfcMode(isRoaming);
|
int wfcMode = mImsManager.getWfcMode(isRoaming && wfcRoamingEnabled);
|
||||||
|
|
||||||
switch (wfcMode) {
|
switch (wfcMode) {
|
||||||
case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
|
case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
|
||||||
resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
|
resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
|
||||||
@@ -137,6 +146,16 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
mSubId = subId;
|
mSubId = subId;
|
||||||
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
||||||
mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId));
|
mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId));
|
||||||
|
if (mCarrierConfigManager != null) {
|
||||||
|
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
||||||
|
if (carrierConfig != null) {
|
||||||
|
mEditableWfcRoamingMode = carrierConfig.getBoolean(
|
||||||
|
CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL);
|
||||||
|
mUseWfcHomeModeForRoaming = carrierConfig.getBoolean(
|
||||||
|
CarrierConfigManager
|
||||||
|
.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PhoneCallStateListener extends PhoneStateListener {
|
private class PhoneCallStateListener extends PhoneStateListener {
|
||||||
|
@@ -18,11 +18,14 @@ 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.mockito.ArgumentMatchers.anyBoolean;
|
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;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
@@ -32,6 +35,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.ims.ImsConfig;
|
import com.android.ims.ImsConfig;
|
||||||
import com.android.ims.ImsManager;
|
import com.android.ims.ImsManager;
|
||||||
|
import com.android.internal.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -46,6 +50,8 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
public class WifiCallingPreferenceControllerTest {
|
public class WifiCallingPreferenceControllerTest {
|
||||||
private static final int SUB_ID = 2;
|
private static final int SUB_ID = 2;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CarrierConfigManager mCarrierConfigManager;
|
||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -57,6 +63,7 @@ public class WifiCallingPreferenceControllerTest {
|
|||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private PreferenceCategory mPreferenceCategory;
|
private PreferenceCategory mPreferenceCategory;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private PersistableBundle mCarrierConfig;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -69,10 +76,14 @@ public class WifiCallingPreferenceControllerTest {
|
|||||||
|
|
||||||
mPreference = new Preference(mContext);
|
mPreference = new Preference(mContext);
|
||||||
mController = new WifiCallingPreferenceController(mContext, "wifi_calling");
|
mController = new WifiCallingPreferenceController(mContext, "wifi_calling");
|
||||||
|
mController.mCarrierConfigManager = mCarrierConfigManager;
|
||||||
mController.init(SUB_ID);
|
mController.init(SUB_ID);
|
||||||
mController.mImsManager = mImsManager;
|
mController.mImsManager = mImsManager;
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
|
|
||||||
|
mCarrierConfig = new PersistableBundle();
|
||||||
|
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
|
||||||
|
|
||||||
mPreferenceCategory = new PreferenceCategory(mContext);
|
mPreferenceCategory = new PreferenceCategory(mContext);
|
||||||
when(mPreferenceScreen.findPreference(
|
when(mPreferenceScreen.findPreference(
|
||||||
WifiCallingPreferenceController.KEY_PREFERENCE_CATEGORY)).thenReturn(
|
WifiCallingPreferenceController.KEY_PREFERENCE_CATEGORY)).thenReturn(
|
||||||
@@ -102,6 +113,42 @@ public class WifiCallingPreferenceControllerTest {
|
|||||||
assertThat(mPreference.isEnabled()).isFalse();
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_wfcNonRoaming() {
|
||||||
|
assertNull(mController.mSimCallManager);
|
||||||
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, false);
|
||||||
|
// update the config value by calling init again.
|
||||||
|
mController.init(SUB_ID);
|
||||||
|
mController.mImsManager = mImsManager;
|
||||||
|
|
||||||
|
when(mImsManager.getWfcMode(true)).thenReturn(
|
||||||
|
ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED);
|
||||||
|
when(mImsManager.getWfcMode(false)).thenReturn(
|
||||||
|
ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED);
|
||||||
|
when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
|
||||||
|
when(mTelephonyManager.isNetworkRoaming()).thenReturn(true);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getString(R.string.wfc_mode_cellular_preferred_summary));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_wfcRoaming() {
|
||||||
|
assertNull(mController.mSimCallManager);
|
||||||
|
|
||||||
|
when(mImsManager.getWfcMode(true)).thenReturn(
|
||||||
|
ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED);
|
||||||
|
when(mImsManager.getWfcMode(false)).thenReturn(
|
||||||
|
ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED);
|
||||||
|
when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
|
||||||
|
when(mTelephonyManager.isNetworkRoaming()).thenReturn(true);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getString(R.string.wfc_mode_wifi_preferred_summary));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_notAvailable_setCategoryInvisible() {
|
public void displayPreference_notAvailable_setCategoryInvisible() {
|
||||||
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
|
Reference in New Issue
Block a user