[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.style.TtsSpan;
|
||||
import android.util.ArraySet;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.IconDrawableFactory;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -1146,4 +1147,9 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
drawable.draw(canvas);
|
||||
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.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SignalStrength;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
@@ -71,7 +68,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
private String mPreferenceGroupKey;
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
private SubscriptionManager mManager;
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
private SubscriptionsChangeListener mSubscriptionsListener;
|
||||
private MobileDataEnabledListener mDataEnabledListener;
|
||||
private DataConnectivityListener mConnectivityListener;
|
||||
@@ -112,7 +108,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
mPreferenceGroupKey = preferenceGroupKey;
|
||||
mStartOrder = startOrder;
|
||||
mManager = context.getSystemService(SubscriptionManager.class);
|
||||
mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
|
||||
mSubscriptionPreferences = new ArrayMap<>();
|
||||
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
||||
mDataEnabledListener = new MobileDataEnabledListener(context, this);
|
||||
@@ -229,19 +224,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
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
|
||||
* subscription is the default for.
|
||||
@@ -271,7 +253,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
final TelephonyManager telMgrForSub = mContext.getSystemService(
|
||||
TelephonyManager.class).createForSubscriptionId(subId);
|
||||
final boolean dataEnabled = telMgrForSub.isDataEnabled();
|
||||
if (dataEnabled && activeNetworkIsCellular()) {
|
||||
if (dataEnabled && MobileNetworkUtils.activeNetworkIsCellular(mContext)) {
|
||||
line2 = mContext.getString(R.string.mobile_data_active);
|
||||
} else if (!dataEnabled) {
|
||||
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_GSM_WCDMA;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -41,6 +42,9 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.SystemClock;
|
||||
import android.os.SystemProperties;
|
||||
@@ -69,6 +73,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;
|
||||
@@ -202,8 +207,7 @@ public class MobileNetworkUtils {
|
||||
return bundle.getBoolean(CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, false /*default*/);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static Intent buildPhoneAccountConfigureIntent(
|
||||
public static Intent buildPhoneAccountConfigureIntent(
|
||||
Context context, PhoneAccountHandle accountHandle) {
|
||||
Intent intent = buildConfigureIntent(
|
||||
context, accountHandle, TelecomManager.ACTION_CONFIGURE_PHONE_ACCOUNT);
|
||||
@@ -854,4 +858,45 @@ public class MobileNetworkUtils {
|
||||
raf = ((NR & raf) > 0) ? (NR | raf) : 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
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
return SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& isWifiCallingEnabled(mContext, subId)
|
||||
&& MobileNetworkUtils.isWifiCallingEnabled(mContext, subId, null, null)
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
@@ -221,23 +221,4 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
||||
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;
|
||||
|
||||
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