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

Commit a201611f authored by songferngwang's avatar songferngwang Committed by SongFerng Wang
Browse files

Avoid to show provisioning sim card

If the sim card has the CLASS_PROVISIONING profile, the UI
should not show this sim card at settings and quick settings.

Bug: 320862770
Flag: NA
Test: atest InternetDialogDelegateControllerTest (pass)
Change-Id: Id1b53772a88b79a59ff9ae8aef087e1c89ff0be0
Merged-In: Id1b53772a88b79a59ff9ae8aef087e1c89ff0be0
parent b17d3174
Loading
Loading
Loading
Loading
+32 −10
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.qs.tiles.dialog;

import static android.telephony.SubscriptionManager.PROFILE_CLASS_PROVISIONING;

import static com.android.settingslib.mobile.MobileMappings.getIconKey;
import static com.android.settingslib.mobile.MobileMappings.mapIconSets;
import static com.android.settingslib.wifi.WifiUtils.getHotspotIconResource;
@@ -192,7 +194,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
    private DialogTransitionAnimator mDialogTransitionAnimator;
    private boolean mHasWifiEntries;
    private WifiStateWorker mWifiStateWorker;
    private boolean mHasActiveSubId;
    private boolean mHasActiveSubIdOnDds;

    @VisibleForTesting
    static final float TOAST_PARAMS_HORIZONTAL_WEIGHT = 1.0f;
@@ -300,7 +302,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
                mExecutor);
        // Listen the subscription changes
        mOnSubscriptionsChangedListener = new InternetOnSubscriptionChangedListener();
        refreshHasActiveSubId();
        refreshHasActiveSubIdOnDds();
        mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
                mOnSubscriptionsChangedListener);
        mDefaultDataSubId = getDefaultDataSubscriptionId();
@@ -429,7 +431,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
        }
        boolean isActiveOnNonDds = getActiveAutoSwitchNonDdsSubId() != SubscriptionManager
                .INVALID_SUBSCRIPTION_ID;
        if (!hasActiveSubId() || (!isVoiceStateInService(mDefaultDataSubId)
        if (!hasActiveSubIdOnDds() || (!isVoiceStateInService(mDefaultDataSubId)
                && !isDataStateInService(mDefaultDataSubId) && !isActiveOnNonDds)) {
            if (DEBUG) {
                Log.d(TAG, "No carrier or service is out of service.");
@@ -902,23 +904,42 @@ public class InternetDialogController implements AccessPointController.AccessPoi
    /**
     * @return whether there is the carrier item in the slice.
     */
    boolean hasActiveSubId() {
    boolean hasActiveSubIdOnDds() {
        if (isAirplaneModeEnabled() || mTelephonyManager == null) {
            return false;
        }

        return mHasActiveSubId;
        return mHasActiveSubIdOnDds;
    }

    private static boolean isEmbeddedSubscriptionVisible(@NonNull SubscriptionInfo subInfo) {
        if (subInfo.isEmbedded() && subInfo.getProfileClass() == PROFILE_CLASS_PROVISIONING) {
            return false;
        }
        return true;
    }

    private void refreshHasActiveSubId() {
    private void refreshHasActiveSubIdOnDds() {
        if (mSubscriptionManager == null) {
            mHasActiveSubId = false;
            mHasActiveSubIdOnDds = false;
            Log.e(TAG, "SubscriptionManager is null, set mHasActiveSubId = false");
            return;
        }
        int dds = getDefaultDataSubscriptionId();
        if (dds == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            mHasActiveSubIdOnDds = false;
            Log.d(TAG, "DDS is INVALID_SUBSCRIPTION_ID");
            return;
        }
        SubscriptionInfo ddsSubInfo = mSubscriptionManager.getActiveSubscriptionInfo(dds);
        if (ddsSubInfo == null) {
            mHasActiveSubIdOnDds = false;
            Log.e(TAG, "Can't get DDS subscriptionInfo");
            return;
        }

        mHasActiveSubId = mSubscriptionManager.getActiveSubscriptionIdList().length > 0;
        Log.i(TAG, "mHasActiveSubId:" + mHasActiveSubId);
        mHasActiveSubIdOnDds = isEmbeddedSubscriptionVisible(ddsSubInfo);
        Log.i(TAG, "mHasActiveSubId:" + mHasActiveSubIdOnDds);
    }

    /**
@@ -1210,7 +1231,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi

        @Override
        public void onSubscriptionsChanged() {
            refreshHasActiveSubId();
            refreshHasActiveSubIdOnDds();
            updateListener();
        }
    }
@@ -1307,6 +1328,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
                    Log.d(TAG, "ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED");
                }
                mConfig = MobileMappings.Config.readConfig(context);
                refreshHasActiveSubIdOnDds();
                updateListener();
            } else if (WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION.equals(action)) {
                updateListener();
+1 −1
Original line number Diff line number Diff line
@@ -425,7 +425,7 @@ public class InternetDialogDelegate implements
        }

        boolean isWifiEnabled = mInternetDialogController.isWifiEnabled();
        if (!mInternetDialogController.hasActiveSubId()
        if (!mInternetDialogController.hasActiveSubIdOnDds()
                && (!isWifiEnabled || !isCarrierNetworkActive)) {
            mMobileNetworkLayout.setVisibility(View.GONE);
            if (mSecondaryMobileNetworkLayout != null) {
+25 −6
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ import static android.provider.Settings.Global.AIRPLANE_MODE_ON;
import static android.telephony.SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
import static android.telephony.SignalStrength.SIGNAL_STRENGTH_GREAT;
import static android.telephony.SignalStrength.SIGNAL_STRENGTH_POOR;
import static android.telephony.SubscriptionManager.PROFILE_CLASS_PROVISIONING;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
import static com.android.settingslib.wifi.WifiUtils.getHotspotIconResource;
import static com.android.systemui.qs.tiles.dialog.InternetDialogController.TOAST_PARAMS_HORIZONTAL_WEIGHT;
@@ -211,6 +213,8 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {
        when(mAccessPointController.getMergedCarrierEntry()).thenReturn(mMergedCarrierEntry);
        when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{SUB_ID});
        when(SubscriptionManager.getDefaultDataSubscriptionId()).thenReturn(SUB_ID);
        SubscriptionInfo info = mock(SubscriptionInfo.class);
        when(mSubscriptionManager.getActiveSubscriptionInfo(SUB_ID)).thenReturn(info);
        when(mToastFactory.createToast(any(), anyString(), anyString(), anyInt(), anyInt()))
            .thenReturn(mSystemUIToast);
        when(mSystemUIToast.getView()).thenReturn(mToastView);
@@ -1067,19 +1071,34 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {
    }

    @Test
    public void hasActiveSubId_activeSubIdListIsEmpty_returnFalse() {
        when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{});
    public void hasActiveSubIdOnDds_noDds_returnFalse() {
        when(SubscriptionManager.getDefaultDataSubscriptionId())
                .thenReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID);

        mInternetDialogController.mOnSubscriptionsChangedListener.onSubscriptionsChanged();

        assertThat(mInternetDialogController.hasActiveSubId()).isFalse();
        assertThat(mInternetDialogController.hasActiveSubIdOnDds()).isFalse();
    }

    @Test
    public void hasActiveSubId_activeSubIdListNotEmpty_returnTrue() {
        when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{SUB_ID});
    public void hasActiveSubIdOnDds_activeDds_returnTrue() {
        mInternetDialogController.mOnSubscriptionsChangedListener.onSubscriptionsChanged();

        assertThat(mInternetDialogController.hasActiveSubIdOnDds()).isTrue();
    }

    @Test
    public void hasActiveSubIdOnDds_activeDdsAndHasProvisioning_returnFalse() {
        when(SubscriptionManager.getDefaultDataSubscriptionId())
                .thenReturn(SUB_ID);
        SubscriptionInfo info = mock(SubscriptionInfo.class);
        when(info.isEmbedded()).thenReturn(true);
        when(info.getProfileClass()).thenReturn(PROFILE_CLASS_PROVISIONING);
        when(mSubscriptionManager.getActiveSubscriptionInfo(SUB_ID)).thenReturn(info);

        mInternetDialogController.mOnSubscriptionsChangedListener.onSubscriptionsChanged();

        assertThat(mInternetDialogController.hasActiveSubId()).isTrue();
        assertThat(mInternetDialogController.hasActiveSubIdOnDds()).isFalse();
    }

    private String getResourcesString(String name) {
+5 −5
Original line number Diff line number Diff line
@@ -244,7 +244,7 @@ public class InternetDialogDelegateTest extends SysuiTestCase {
        // Mobile network should be gone if the list of active subscriptionId is null.
        when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(false);
        when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false);
        when(mInternetDialogController.hasActiveSubId()).thenReturn(false);
        when(mInternetDialogController.hasActiveSubIdOnDds()).thenReturn(false);

        mInternetDialogDelegate.updateDialog(true);

@@ -329,7 +329,7 @@ public class InternetDialogDelegateTest extends SysuiTestCase {

    @Test
    public void updateDialog_mobileDataIsEnabled_checkMobileDataSwitch() {
        doReturn(true).when(mInternetDialogController).hasActiveSubId();
        doReturn(true).when(mInternetDialogController).hasActiveSubIdOnDds();
        when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
        when(mInternetDialogController.isMobileDataEnabled()).thenReturn(true);
        mMobileToggleSwitch.setChecked(false);
@@ -341,7 +341,7 @@ public class InternetDialogDelegateTest extends SysuiTestCase {

    @Test
    public void updateDialog_mobileDataIsNotChanged_checkMobileDataSwitch() {
        doReturn(true).when(mInternetDialogController).hasActiveSubId();
        doReturn(true).when(mInternetDialogController).hasActiveSubIdOnDds();
        when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
        when(mInternetDialogController.isMobileDataEnabled()).thenReturn(false);
        mMobileToggleSwitch.setChecked(false);
@@ -354,7 +354,7 @@ public class InternetDialogDelegateTest extends SysuiTestCase {
    @Test
    public void updateDialog_wifiOnAndHasInternetWifi_showConnectedWifi() {
        mInternetDialogDelegate.dismissDialog();
        doReturn(true).when(mInternetDialogController).hasActiveSubId();
        doReturn(true).when(mInternetDialogController).hasActiveSubIdOnDds();
        createInternetDialog();
        // The preconditions WiFi ON and Internet WiFi are already in setUp()
        doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();
@@ -515,7 +515,7 @@ public class InternetDialogDelegateTest extends SysuiTestCase {
    public void updateDialog_showSecondaryDataSub() {
        mInternetDialogDelegate.dismissDialog();
        doReturn(1).when(mInternetDialogController).getActiveAutoSwitchNonDdsSubId();
        doReturn(true).when(mInternetDialogController).hasActiveSubId();
        doReturn(true).when(mInternetDialogController).hasActiveSubIdOnDds();
        doReturn(false).when(mInternetDialogController).isAirplaneModeEnabled();
        createInternetDialog();