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

Commit eb81e130 authored by SongFerng Wang's avatar SongFerng Wang Committed by Android (Google) Code Review
Browse files

Merge "Avoid to show provisioning sim card" into main

parents 0fc2cd22 738347a4
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;
@@ -190,7 +192,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;
@@ -298,7 +300,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
                mExecutor);
        // Listen the subscription changes
        mOnSubscriptionsChangedListener = new InternetOnSubscriptionChangedListener();
        refreshHasActiveSubId();
        refreshHasActiveSubIdOnDds();
        mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
                mOnSubscriptionsChangedListener);
        mDefaultDataSubId = getDefaultDataSubscriptionId();
@@ -428,7 +430,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.");
@@ -901,23 +903,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);
    }

    /**
@@ -1209,7 +1230,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi

        @Override
        public void onSubscriptionsChanged() {
            refreshHasActiveSubId();
            refreshHasActiveSubIdOnDds();
            updateListener();
        }
    }
@@ -1306,6 +1327,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
@@ -429,7 +429,7 @@ public class InternetDialogDelegate implements
        }

        boolean isWifiEnabled = mInternetDialogController.isWifiEnabled();
        if (!mInternetDialogController.hasActiveSubId()
        if (!mInternetDialogController.hasActiveSubIdOnDds()
                && (!isWifiEnabled || !isCarrierNetworkActive)) {
            mMobileNetworkLayout.setVisibility(View.GONE);
            if (mSecondaryMobileNetworkLayout != null) {
+24 −6
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ 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;
@@ -217,6 +218,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);
@@ -1083,19 +1086,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
@@ -251,7 +251,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);

@@ -336,7 +336,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);
@@ -348,7 +348,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);
@@ -361,7 +361,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();
@@ -522,7 +522,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();