Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f5bc2416 authored by Antony Sargent's avatar Antony Sargent
Browse files

Use helper method for determining whether eSIM is supported

It turns out to be more complicated than I had thought to determine if a
device should be considered to support eSIM. But the good news is that
we already had a helper method for this - this CL switches to using it
in some code for DSDS UI.

Fixes: 129061243
Test: make RunSettingsRoboTests
Change-Id: I41e500eb70b6c6b725c0ddf09fe1ca1a69df4563
parent 81f31ef4
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -24,12 +24,12 @@ import android.content.Intent;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.euicc.EuiccManager;
import android.util.ArrayMap;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.network.telephony.MobileNetworkActivity;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settingslib.core.AbstractPreferenceController;

import java.util.List;
@@ -81,8 +81,8 @@ public class MobileNetworkListController extends AbstractPreferenceController im
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreferenceScreen = screen;
        final EuiccManager euiccManager = mContext.getSystemService(EuiccManager.class);
        mPreferenceScreen.findPreference(KEY_ADD_MORE).setVisible(euiccManager.isEnabled());
        mPreferenceScreen.findPreference(KEY_ADD_MORE).setVisible(
                MobileNetworkUtils.showEuiccSettings(mContext));
        update();
    }

+4 −5
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.telephony.euicc.EuiccManager;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.network.telephony.MobileNetworkActivity;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.widget.AddPreference;
import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -49,7 +50,6 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController

    private SubscriptionManager mSubscriptionManager;
    private SubscriptionsChangeListener mChangeListener;
    private EuiccManager mEuiccManager;
    private AddPreference mPreference;

    /**
@@ -70,7 +70,6 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
    public MobileNetworkSummaryController(Context context, Lifecycle lifecycle) {
        super(context);
        mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
        mEuiccManager = mContext.getSystemService(EuiccManager.class);
        if (lifecycle != null) {
          mChangeListener = new SubscriptionsChangeListener(context, this);
          lifecycle.addObserver(this);
@@ -99,7 +98,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
        final List<SubscriptionInfo> subs = SubscriptionUtil.getAvailableSubscriptions(
                mSubscriptionManager);
        if (subs.isEmpty()) {
            if (mEuiccManager.isEnabled()) {
            if (MobileNetworkUtils.showEuiccSettings(mContext)) {
                return mContext.getResources().getString(
                        R.string.mobile_network_summary_add_a_network);
            }
@@ -133,7 +132,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
                mSubscriptionManager);

        if (subs.isEmpty()) {
            if (mEuiccManager.isEnabled()) {
            if (MobileNetworkUtils.showEuiccSettings(mContext)) {
                mPreference.setOnPreferenceClickListener((Preference pref) -> {
                    startAddSimFlow();
                    return true;
@@ -142,7 +141,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
        } else {
            // We have one or more existing subscriptions, so we want the plus button if eSIM is
            // supported.
            if (mEuiccManager.isEnabled()) {
            if (MobileNetworkUtils.showEuiccSettings(mContext)) {
                mPreference.setAddWidgetEnabled(!mChangeListener.isAirplaneModeOn());
                mPreference.setOnAddClickListener(p -> startAddSimFlow());
            }
+2 −2
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ public class MobileNetworkUtils {
     */
    public static boolean showEuiccSettings(Context context) {
        EuiccManager euiccManager =
                (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
                (EuiccManager) context.getSystemService(EuiccManager.class);
        if (!euiccManager.isEnabled()) {
            return false;
        }
@@ -185,7 +185,7 @@ public class MobileNetworkUtils {
        final ContentResolver cr = context.getContentResolver();

        TelephonyManager tm =
                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                (TelephonyManager) context.getSystemService(TelephonyManager.class);
        String currentCountry = tm.getNetworkCountryIso().toLowerCase();
        String supportedCountries =
                Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES);
+7 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -31,7 +30,9 @@ import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;

import org.junit.After;
@@ -52,6 +53,8 @@ import androidx.preference.PreferenceScreen;

@RunWith(RobolectricTestRunner.class)
public class MobileNetworkListControllerTest {
    @Mock
    TelephonyManager mTelephonyManager;
    @Mock
    EuiccManager mEuiccManager;

@@ -69,7 +72,9 @@ public class MobileNetworkListControllerTest {
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = spy(Robolectric.setupActivity(Activity.class));
        when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
        when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
        Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
        when(mPreferenceScreen.getContext()).thenReturn(mContext);
        mAddMorePreference = new Preference(mContext);
        when(mPreferenceScreen.findPreference(MobileNetworkListController.KEY_ADD_MORE)).thenReturn(
@@ -99,6 +104,7 @@ public class MobileNetworkListControllerTest {
    @Test
    public void displayPreference_eSimSupported_addMoreLinkIsVisible() {
        when(mEuiccManager.isEnabled()).thenReturn(true);
        when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
        mController.displayPreference(mPreferenceScreen);
        mController.onResume();
        assertThat(mAddMorePreference.isVisible()).isTrue();
+6 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.Intent;
import android.net.ConnectivityManager;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;
import android.text.TextUtils;

@@ -59,6 +60,8 @@ public class MobileNetworkSummaryControllerTest {
    @Mock
    private Lifecycle mLifecycle;
    @Mock
    private TelephonyManager mTelephonyManager;
    @Mock
    private EuiccManager mEuiccManager;
    @Mock
    private PreferenceScreen mPreferenceScreen;
@@ -71,8 +74,11 @@ public class MobileNetworkSummaryControllerTest {
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = spy(Robolectric.setupActivity(Activity.class));
        when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
        when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
        when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
        when(mEuiccManager.isEnabled()).thenReturn(true);
        Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);

        mController = new MobileNetworkSummaryController(mContext, mLifecycle);
        mPreference = spy(new AddPreference(mContext, null));