Merge "[Provider Model] Add new API to detect"
This commit is contained in:
@@ -17,10 +17,13 @@
|
||||
package com.android.settings.network.telephony;
|
||||
|
||||
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.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -31,9 +34,13 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.telecom.PhoneAccountHandle;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
@@ -42,6 +49,7 @@ import android.telephony.TelephonyManager;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.network.ims.MockWfcQueryImsState;
|
||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -79,11 +87,18 @@ public class MobileNetworkUtilsTest {
|
||||
private ResolveInfo mResolveInfo;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@Mock
|
||||
private TelecomManager mTelecomManager;
|
||||
|
||||
private Context mContext;
|
||||
private PersistableBundle mCarrierConfig;
|
||||
private PhoneAccountHandle mPhoneAccountHandle;
|
||||
private ComponentName mComponentName;
|
||||
private NetworkCapabilities mNetworkCapabilities;
|
||||
private Network mNetwork;
|
||||
private MockWfcQueryImsState mMockQueryWfcState;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -92,7 +107,6 @@ public class MobileNetworkUtilsTest {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
@@ -103,6 +117,10 @@ public class MobileNetworkUtilsTest {
|
||||
mCarrierConfig = new PersistableBundle();
|
||||
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.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_1);
|
||||
when(mSubscriptionInfo2.getSubscriptionId()).thenReturn(SUB_ID_2);
|
||||
@@ -115,6 +133,11 @@ public class MobileNetworkUtilsTest {
|
||||
|
||||
when(mTelephonyManager.getNetworkOperatorName()).thenReturn(
|
||||
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
|
||||
@@ -148,8 +171,7 @@ public class MobileNetworkUtilsTest {
|
||||
|
||||
@Test
|
||||
public void buildConfigureIntent_noActivityHandleIntent_returnNull() {
|
||||
when(mPackageManager.queryIntentActivities(nullable(Intent.class), anyInt()))
|
||||
.thenReturn(new ArrayList<>());
|
||||
buildPhoneAccountConfigureIntent(false);
|
||||
|
||||
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
||||
mPhoneAccountHandle)).isNull();
|
||||
@@ -157,10 +179,7 @@ public class MobileNetworkUtilsTest {
|
||||
|
||||
@Test
|
||||
public void buildConfigureIntent_hasActivityHandleIntent_returnIntent() {
|
||||
mComponentName = new ComponentName(PACKAGE_NAME, "testClass");
|
||||
mPhoneAccountHandle = new PhoneAccountHandle(mComponentName, "");
|
||||
when(mPackageManager.queryIntentActivities(nullable(Intent.class), anyInt()))
|
||||
.thenReturn(Arrays.asList(mResolveInfo));
|
||||
buildPhoneAccountConfigureIntent(true);
|
||||
|
||||
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
||||
mPhoneAccountHandle)).isNotNull();
|
||||
@@ -333,4 +352,71 @@ public class MobileNetworkUtilsTest {
|
||||
assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay(
|
||||
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