[Provider Model] Add new API to detect
1. current connection is mobile data - remove the SubscriptionsPreferenceController#activeNetworkIsCellular() and move into MobileNetworkUtils 2. isProviderModel API - Add it in Util for Provider Model 3. isWiFiCallingEnabled - remove WifiCallingPreferenceController#isWifiCallingEnabled() and move into MobileNetworkUtils 4. Add nes test case for MobileNetworkUtils Bug: 171873895 Test: atest -c MobileNetworkUtilsTest Change-Id: I4bfdf0537fe07d064d6c0ba4a2c44b4a4f158d91
This commit is contained in:
@@ -83,6 +83,7 @@ import android.text.TextUtils;
|
|||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.text.style.TtsSpan;
|
import android.text.style.TtsSpan;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.IconDrawableFactory;
|
import android.util.IconDrawableFactory;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -1146,4 +1147,9 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
drawable.draw(canvas);
|
drawable.draw(canvas);
|
||||||
return roundedBitmap;
|
return roundedBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isProviderModelEnabled(Context context) {
|
||||||
|
return FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -24,9 +24,6 @@ import static com.android.settings.network.telephony.MobileNetworkUtils.NO_CELL_
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.Network;
|
|
||||||
import android.net.NetworkCapabilities;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.SignalStrength;
|
import android.telephony.SignalStrength;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
@@ -71,7 +68,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
|||||||
private String mPreferenceGroupKey;
|
private String mPreferenceGroupKey;
|
||||||
private PreferenceGroup mPreferenceGroup;
|
private PreferenceGroup mPreferenceGroup;
|
||||||
private SubscriptionManager mManager;
|
private SubscriptionManager mManager;
|
||||||
private ConnectivityManager mConnectivityManager;
|
|
||||||
private SubscriptionsChangeListener mSubscriptionsListener;
|
private SubscriptionsChangeListener mSubscriptionsListener;
|
||||||
private MobileDataEnabledListener mDataEnabledListener;
|
private MobileDataEnabledListener mDataEnabledListener;
|
||||||
private DataConnectivityListener mConnectivityListener;
|
private DataConnectivityListener mConnectivityListener;
|
||||||
@@ -112,7 +108,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
|||||||
mPreferenceGroupKey = preferenceGroupKey;
|
mPreferenceGroupKey = preferenceGroupKey;
|
||||||
mStartOrder = startOrder;
|
mStartOrder = startOrder;
|
||||||
mManager = context.getSystemService(SubscriptionManager.class);
|
mManager = context.getSystemService(SubscriptionManager.class);
|
||||||
mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
|
|
||||||
mSubscriptionPreferences = new ArrayMap<>();
|
mSubscriptionPreferences = new ArrayMap<>();
|
||||||
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
||||||
mDataEnabledListener = new MobileDataEnabledListener(context, this);
|
mDataEnabledListener = new MobileDataEnabledListener(context, this);
|
||||||
@@ -229,19 +224,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
|||||||
NO_CELL_DATA_TYPE_ICON, cutOut);
|
NO_CELL_DATA_TYPE_ICON, cutOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean activeNetworkIsCellular() {
|
|
||||||
final Network activeNetwork = mConnectivityManager.getActiveNetwork();
|
|
||||||
if (activeNetwork == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final NetworkCapabilities networkCapabilities = mConnectivityManager.getNetworkCapabilities(
|
|
||||||
activeNetwork);
|
|
||||||
if (networkCapabilities == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The summary can have either 1 or 2 lines depending on which services (calls, SMS, data) this
|
* The summary can have either 1 or 2 lines depending on which services (calls, SMS, data) this
|
||||||
* subscription is the default for.
|
* subscription is the default for.
|
||||||
@@ -271,7 +253,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
|||||||
final TelephonyManager telMgrForSub = mContext.getSystemService(
|
final TelephonyManager telMgrForSub = mContext.getSystemService(
|
||||||
TelephonyManager.class).createForSubscriptionId(subId);
|
TelephonyManager.class).createForSubscriptionId(subId);
|
||||||
final boolean dataEnabled = telMgrForSub.isDataEnabled();
|
final boolean dataEnabled = telMgrForSub.isDataEnabled();
|
||||||
if (dataEnabled && activeNetworkIsCellular()) {
|
if (dataEnabled && MobileNetworkUtils.activeNetworkIsCellular(mContext)) {
|
||||||
line2 = mContext.getString(R.string.mobile_data_active);
|
line2 = mContext.getString(R.string.mobile_data_active);
|
||||||
} else if (!dataEnabled) {
|
} else if (!dataEnabled) {
|
||||||
line2 = mContext.getString(R.string.mobile_data_off);
|
line2 = mContext.getString(R.string.mobile_data_off);
|
||||||
|
@@ -31,6 +31,7 @@ import static com.android.settings.network.telephony.TelephonyConstants.Telephon
|
|||||||
import static com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO;
|
import static com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO;
|
||||||
import static com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA;
|
import static com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -41,6 +42,9 @@ import android.graphics.Color;
|
|||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
@@ -69,6 +73,7 @@ import com.android.internal.util.ArrayUtils;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
import com.android.settingslib.graph.SignalDrawable;
|
import com.android.settingslib.graph.SignalDrawable;
|
||||||
@@ -202,8 +207,7 @@ public class MobileNetworkUtils {
|
|||||||
return bundle.getBoolean(CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, false /*default*/);
|
return bundle.getBoolean(CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, false /*default*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
public static Intent buildPhoneAccountConfigureIntent(
|
||||||
static Intent buildPhoneAccountConfigureIntent(
|
|
||||||
Context context, PhoneAccountHandle accountHandle) {
|
Context context, PhoneAccountHandle accountHandle) {
|
||||||
Intent intent = buildConfigureIntent(
|
Intent intent = buildConfigureIntent(
|
||||||
context, accountHandle, TelecomManager.ACTION_CONFIGURE_PHONE_ACCOUNT);
|
context, accountHandle, TelecomManager.ACTION_CONFIGURE_PHONE_ACCOUNT);
|
||||||
@@ -854,4 +858,45 @@ public class MobileNetworkUtils {
|
|||||||
raf = ((NR & raf) > 0) ? (NR | raf) : raf;
|
raf = ((NR & raf) > 0) ? (NR | raf) : raf;
|
||||||
return raf;
|
return raf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copied from SubscriptionsPreferenceController#activeNetworkIsCellular()
|
||||||
|
*/
|
||||||
|
public static boolean activeNetworkIsCellular(Context context) {
|
||||||
|
final ConnectivityManager connectivityManager =
|
||||||
|
context.getSystemService(ConnectivityManager.class);
|
||||||
|
final Network activeNetwork = connectivityManager.getActiveNetwork();
|
||||||
|
if (activeNetwork == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final NetworkCapabilities networkCapabilities =
|
||||||
|
connectivityManager.getNetworkCapabilities(activeNetwork);
|
||||||
|
if (networkCapabilities == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copied from WifiCallingPreferenceController#isWifiCallingEnabled()
|
||||||
|
*/
|
||||||
|
public static boolean isWifiCallingEnabled(Context context, int subId,
|
||||||
|
@Nullable WifiCallingQueryImsState queryImsState,
|
||||||
|
@Nullable PhoneAccountHandle phoneAccountHandle) {
|
||||||
|
if (phoneAccountHandle == null){
|
||||||
|
phoneAccountHandle = context.getSystemService(TelecomManager.class)
|
||||||
|
.getSimCallManagerForSubscription(subId);
|
||||||
|
}
|
||||||
|
boolean isWifiCallingEnabled;
|
||||||
|
if (phoneAccountHandle != null) {
|
||||||
|
final Intent intent = buildPhoneAccountConfigureIntent(context, phoneAccountHandle);
|
||||||
|
isWifiCallingEnabled = intent != null;
|
||||||
|
} else {
|
||||||
|
if (queryImsState == null) {
|
||||||
|
queryImsState = new WifiCallingQueryImsState(context, subId);
|
||||||
|
}
|
||||||
|
isWifiCallingEnabled = queryImsState.isReadyToWifiCalling();
|
||||||
|
}
|
||||||
|
return isWifiCallingEnabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -71,7 +71,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
return SubscriptionManager.isValidSubscriptionId(subId)
|
return SubscriptionManager.isValidSubscriptionId(subId)
|
||||||
&& isWifiCallingEnabled(mContext, subId)
|
&& MobileNetworkUtils.isWifiCallingEnabled(mContext, subId, null, null)
|
||||||
? AVAILABLE
|
? AVAILABLE
|
||||||
: UNSUPPORTED_ON_DEVICE;
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
@@ -221,23 +221,4 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
|
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isWifiCallingEnabled(Context context, int subId) {
|
|
||||||
final PhoneAccountHandle simCallManager =
|
|
||||||
context.getSystemService(TelecomManager.class)
|
|
||||||
.getSimCallManagerForSubscription(subId);
|
|
||||||
final int phoneId = SubscriptionManager.getSlotIndex(subId);
|
|
||||||
|
|
||||||
boolean isWifiCallingEnabled;
|
|
||||||
if (simCallManager != null) {
|
|
||||||
final Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(
|
|
||||||
context, simCallManager);
|
|
||||||
|
|
||||||
isWifiCallingEnabled = intent != null;
|
|
||||||
} else {
|
|
||||||
isWifiCallingEnabled = queryImsState(subId).isReadyToWifiCalling();
|
|
||||||
}
|
|
||||||
|
|
||||||
return isWifiCallingEnabled;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -17,10 +17,13 @@
|
|||||||
package com.android.settings.network.telephony;
|
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.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
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;
|
||||||
@@ -31,9 +34,13 @@ 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.net.ConnectivityManager;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telecom.PhoneAccountHandle;
|
import android.telecom.PhoneAccountHandle;
|
||||||
|
import android.telecom.TelecomManager;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
@@ -42,6 +49,7 @@ import android.telephony.TelephonyManager;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.ims.MockWfcQueryImsState;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -79,11 +87,18 @@ public class MobileNetworkUtilsTest {
|
|||||||
private ResolveInfo mResolveInfo;
|
private ResolveInfo mResolveInfo;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigManager mCarrierConfigManager;
|
||||||
|
@Mock
|
||||||
|
private ConnectivityManager mConnectivityManager;
|
||||||
|
@Mock
|
||||||
|
private TelecomManager mTelecomManager;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PersistableBundle mCarrierConfig;
|
private PersistableBundle mCarrierConfig;
|
||||||
private PhoneAccountHandle mPhoneAccountHandle;
|
private PhoneAccountHandle mPhoneAccountHandle;
|
||||||
private ComponentName mComponentName;
|
private ComponentName mComponentName;
|
||||||
|
private NetworkCapabilities mNetworkCapabilities;
|
||||||
|
private Network mNetwork;
|
||||||
|
private MockWfcQueryImsState mMockQueryWfcState;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -92,7 +107,6 @@ public class MobileNetworkUtilsTest {
|
|||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
|
||||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
|
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
|
||||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
|
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
|
||||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
@@ -103,6 +117,10 @@ public class MobileNetworkUtilsTest {
|
|||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig);
|
when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig);
|
||||||
|
|
||||||
|
mNetwork = new Network(anyInt());
|
||||||
|
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
|
||||||
|
when(mConnectivityManager.getActiveNetwork()).thenReturn(mNetwork);
|
||||||
|
|
||||||
when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1);
|
when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1);
|
||||||
when(mSubscriptionInfo1.getCarrierName()).thenReturn(PLMN_FROM_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);
|
||||||
@@ -115,6 +133,11 @@ public class MobileNetworkUtilsTest {
|
|||||||
|
|
||||||
when(mTelephonyManager.getNetworkOperatorName()).thenReturn(
|
when(mTelephonyManager.getNetworkOperatorName()).thenReturn(
|
||||||
PLMN_FROM_TELEPHONY_MANAGER_API);
|
PLMN_FROM_TELEPHONY_MANAGER_API);
|
||||||
|
|
||||||
|
when(mContext.getSystemService(TelecomManager.class)).thenReturn(mTelecomManager);
|
||||||
|
when(mTelecomManager.getSimCallManagerForSubscription(SUB_ID_1))
|
||||||
|
.thenReturn(mPhoneAccountHandle);
|
||||||
|
mMockQueryWfcState = new MockWfcQueryImsState(mContext, SUB_ID_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -148,8 +171,7 @@ public class MobileNetworkUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildConfigureIntent_noActivityHandleIntent_returnNull() {
|
public void buildConfigureIntent_noActivityHandleIntent_returnNull() {
|
||||||
when(mPackageManager.queryIntentActivities(nullable(Intent.class), anyInt()))
|
buildPhoneAccountConfigureIntent(false);
|
||||||
.thenReturn(new ArrayList<>());
|
|
||||||
|
|
||||||
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
||||||
mPhoneAccountHandle)).isNull();
|
mPhoneAccountHandle)).isNull();
|
||||||
@@ -157,10 +179,7 @@ public class MobileNetworkUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildConfigureIntent_hasActivityHandleIntent_returnIntent() {
|
public void buildConfigureIntent_hasActivityHandleIntent_returnIntent() {
|
||||||
mComponentName = new ComponentName(PACKAGE_NAME, "testClass");
|
buildPhoneAccountConfigureIntent(true);
|
||||||
mPhoneAccountHandle = new PhoneAccountHandle(mComponentName, "");
|
|
||||||
when(mPackageManager.queryIntentActivities(nullable(Intent.class), anyInt()))
|
|
||||||
.thenReturn(Arrays.asList(mResolveInfo));
|
|
||||||
|
|
||||||
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
||||||
mPhoneAccountHandle)).isNotNull();
|
mPhoneAccountHandle)).isNotNull();
|
||||||
@@ -333,4 +352,71 @@ public class MobileNetworkUtilsTest {
|
|||||||
assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
|
assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
|
||||||
mContext)).isNotNull();
|
mContext)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isCellularNetwork_withCellularNetwork_returnTrue() {
|
||||||
|
addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
|
||||||
|
|
||||||
|
assertTrue(MobileNetworkUtils.activeNetworkIsCellular(mContext));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isCellularNetwork_withWifiNetwork_returnFalse() {
|
||||||
|
addNetworkTransportType(NetworkCapabilities.TRANSPORT_WIFI);
|
||||||
|
|
||||||
|
assertFalse(MobileNetworkUtils.activeNetworkIsCellular(mContext));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addNetworkTransportType (int networkType) {
|
||||||
|
mNetworkCapabilities = new NetworkCapabilities().addTransportType(networkType);
|
||||||
|
when(mConnectivityManager.getNetworkCapabilities(mNetwork)).thenReturn(
|
||||||
|
mNetworkCapabilities);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isWifiCallingEnabled_hasPhoneAccountHandleAndHasActivityHandleIntent_returnTrue() {
|
||||||
|
buildPhoneAccountConfigureIntent(true);
|
||||||
|
|
||||||
|
assertTrue(MobileNetworkUtils.isWifiCallingEnabled(mContext, SUB_ID_1,
|
||||||
|
null, mPhoneAccountHandle));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isWifiCallingEnabled_hasPhoneAccountHandleAndNoActivityHandleIntent_returnFalse() {
|
||||||
|
buildPhoneAccountConfigureIntent(false);
|
||||||
|
|
||||||
|
assertFalse(MobileNetworkUtils.isWifiCallingEnabled(mContext, SUB_ID_1,
|
||||||
|
null, mPhoneAccountHandle));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isWifiCallingEnabled_noPhoneAccountHandleAndWifiCallingIsReady_returnTrue() {
|
||||||
|
setWifiCallingEnabled(true);
|
||||||
|
|
||||||
|
assertTrue(MobileNetworkUtils.isWifiCallingEnabled(mContext, SUB_ID_1,
|
||||||
|
mMockQueryWfcState, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isWifiCallingEnabled_noPhoneAccountHandleAndWifiCallingNotReady_returnFalse() {
|
||||||
|
setWifiCallingEnabled(false);
|
||||||
|
|
||||||
|
assertFalse(MobileNetworkUtils.isWifiCallingEnabled(mContext, SUB_ID_1,
|
||||||
|
mMockQueryWfcState, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setWifiCallingEnabled(boolean enabled){
|
||||||
|
mMockQueryWfcState.setIsEnabledByUser(enabled);
|
||||||
|
mMockQueryWfcState.setServiceStateReady(enabled);
|
||||||
|
mMockQueryWfcState.setIsEnabledByPlatform(enabled);
|
||||||
|
mMockQueryWfcState.setIsProvisionedOnDevice(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildPhoneAccountConfigureIntent(boolean hasActivityHandleIntent) {
|
||||||
|
mComponentName = new ComponentName(PACKAGE_NAME, "testClass");
|
||||||
|
mPhoneAccountHandle = new PhoneAccountHandle(mComponentName, "");
|
||||||
|
when(mPackageManager.queryIntentActivities(nullable(Intent.class), anyInt()))
|
||||||
|
.thenReturn(
|
||||||
|
hasActivityHandleIntent ? Arrays.asList(mResolveInfo) : new ArrayList<>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user