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

Commit 403a8c41 authored by songferngwang's avatar songferngwang
Browse files

Internet Dialog carrier name issue

according to bug comment#83, and correct the carrier name

Bug: 427829698
Test: veritied by test team
atest InternetDialogDelegateLegacyTest
atest InternetDetailsContentControllerTest
Flag: EXEMPT bugfix

Change-Id: I7aca0ee49be71f0e3ce16c97ce546297a15c6ca6
parent d259ca97
Loading
Loading
Loading
Loading
+64 −13
Original line number Diff line number Diff line
@@ -270,7 +270,11 @@ public class InternetDetailsContentController implements AccessPointController.A
                }
            };

    protected List<SubscriptionInfo> getSubscriptionInfo() {
    protected List<SubscriptionInfo> getActiveSubscriptionInfoList() {
        return mSubscriptionManager.getActiveSubscriptionInfoList();
    }

    protected List<SubscriptionInfo> getFilteredSubscriptionInfo() {
        return mKeyguardUpdateMonitor.getFilteredSubscriptionInfo();
    }

@@ -643,7 +647,12 @@ public class InternetDetailsContentController implements AccessPointController.A

    private CharSequence getUniqueSubscriptionDisplayName(int subscriptionId, Context context) {
        final Map<Integer, CharSequence> displayNames = getUniqueSubscriptionDisplayNames(context);
        return displayNames.getOrDefault(subscriptionId, "");
        CharSequence displayName =  displayNames.getOrDefault(subscriptionId, "");
        if (DEBUG) {
            Log.d(TAG, "getUniqueSubscriptionDisplayName(), subscriptionId: " + subscriptionId
                    + ", displayName:" + displayName);
        }
        return displayName;
    }

    private Map<Integer, CharSequence> getUniqueSubscriptionDisplayNames(Context context) {
@@ -660,7 +669,7 @@ public class InternetDetailsContentController implements AccessPointController.A

        // Map of SubscriptionId to DisplayName
        final Supplier<Stream<DisplayInfo>> originalInfos =
                () -> getSubscriptionInfo().stream().filter(i -> {
                () -> getActiveSubscriptionInfoList().stream().filter(i -> {
                    // Filter out null values.
                    return (i != null && i.getDisplayName() != null);
                }).map(i -> new DisplayInfo(i, i.getDisplayName().toString().trim()));
@@ -730,8 +739,7 @@ public class InternetDetailsContentController implements AccessPointController.A
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        }

        SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(
                SubscriptionManager.getActiveDataSubscriptionId());
        SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(activeDataSubId);
        if (subInfo != null && subInfo.getSubscriptionId() != mDefaultDataSubId
                && !subInfo.isOpportunistic()) {
            int subId = subInfo.getSubscriptionId();
@@ -743,7 +751,40 @@ public class InternetDetailsContentController implements AccessPointController.A
            return subId;
        }
        return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    }

    /**
     * @return the subId of the visible ActiveDataSubId, otherwise
     * return {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}.
     */
    int getActiveDataSubId() {
        // TODO(b/440352380): refactor and reduce the times of API calls
        int activeDataSubId = SubscriptionManager.getActiveDataSubscriptionId();
        if (activeDataSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        }
        SubscriptionInfo defaultDataSubInfo = mSubscriptionManager.getActiveSubscriptionInfo(
                mDefaultDataSubId);
        // get the visible Active SubscriptionInfo List from
        // KeyguardUpdateMonitor.getFilteredSubscriptionInfo() which is controlled by
        // CarrierConfigManager.KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN.
        SubscriptionInfo subInfo = getFilteredSubscriptionInfo().stream()
                .filter(it -> it.getSubscriptionId() == activeDataSubId)
                .findFirst().orElse(defaultDataSubInfo);
        if (subInfo != null) {
            if (DEBUG) {
                Log.d(TAG, "getActiveDataSubId(), subInfo:" + subInfo);
            }
            // register the listen
            int subId = subInfo.getSubscriptionId();
            if (mSubIdTelephonyManagerMap.get(subId) == null) {
                TelephonyManager secondaryTm = mTelephonyManager.createForSubscriptionId(subId);
                registerInternetTelephonyCallback(secondaryTm, subId);
                mSubIdTelephonyManagerMap.put(subId, secondaryTm);
            }
            return subId;
        }
        return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    }

    CharSequence getMobileNetworkTitle(int subId) {
@@ -751,8 +792,12 @@ public class InternetDetailsContentController implements AccessPointController.A
    }

    String getMobileNetworkSummary(int subId) {
        String description = getNetworkTypeDescription(mContext, mConfig, subId);
        return getMobileSummary(mContext, description, subId);
        String networkTypeDescription = getNetworkTypeDescription(mContext, mConfig, subId);
        if (DEBUG) {
            Log.d(TAG,
                    "getMobileNetworkSummary(), NetworkTypeDescription:" + networkTypeDescription);
        }
        return getMobileSummary(mContext, networkTypeDescription, subId);
    }

    /**
@@ -762,6 +807,10 @@ public class InternetDetailsContentController implements AccessPointController.A
            int subId) {
        TelephonyDisplayInfo telephonyDisplayInfo = mSubIdTelephonyDisplayInfoMap.getOrDefault(
                subId, DEFAULT_TELEPHONY_DISPLAY_INFO);
        if (DEBUG) {
            Log.d(TAG, "getNetworkTypeDescription(), subId:" + subId
                    + ",telephonyDisplayInfo:" + telephonyDisplayInfo);
        }
        String iconKey = getIconKey(telephonyDisplayInfo);

        if (mapIconSets(config) == null || mapIconSets(config).get(iconKey) == null) {
@@ -790,16 +839,19 @@ public class InternetDetailsContentController implements AccessPointController.A
            return context.getString(R.string.mobile_data_off_summary);
        }
        String summary = networkTypeDescription;
        boolean isForDds = subId == mDefaultDataSubId;
        int activeSubId = getActiveAutoSwitchNonDdsSubId();
        boolean isOnNonDds = activeSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        int activeDataSubId = getActiveDataSubId();
        boolean isForVisibleDds = subId == activeDataSubId;
        int activeAutoSwitchNonDdsSubId = getActiveAutoSwitchNonDdsSubId();
        boolean isOnNonDds =
                activeAutoSwitchNonDdsSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        // Set network description for the carrier network when connecting to the carrier network
        // under the airplane mode ON.
        if (activeNetworkIsCellular() || isCarrierNetworkActive()) {
            summary = context.getString(
                    com.android.settingslib.R.string.preference_summary_default_combination,
                    context.getString(
                            isForDds // if nonDds is active, explains Dds status as poor connection
                            isForVisibleDds
                                    // if nonDds is active, explains Dds status as poor connection
                                    ? (isOnNonDds ? R.string.mobile_data_poor_connection
                                    : R.string.mobile_data_connection_active)
                                    : R.string.mobile_data_temp_connection_active),
@@ -1051,8 +1103,7 @@ public class InternetDetailsContentController implements AccessPointController.A
        mTelephonyManager.setDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER,
                enabled);
        if (disableOtherSubscriptions) {
            final List<SubscriptionInfo> subInfoList =
                    mSubscriptionManager.getActiveSubscriptionInfoList();
            final List<SubscriptionInfo> subInfoList = getActiveSubscriptionInfoList();
            if (subInfoList != null) {
                for (SubscriptionInfo subInfo : subInfoList) {
                    // We never disable mobile data for opportunistic subscriptions.
+35 −19
Original line number Diff line number Diff line
@@ -442,6 +442,8 @@ public class InternetDialogDelegateLegacy implements
        internetContent.mIsWifiScanEnabled = mInternetDetailsContentController.isWifiScanEnabled();
        internetContent.mActiveAutoSwitchNonDdsSubId =
                mInternetDetailsContentController.getActiveAutoSwitchNonDdsSubId();
        internetContent.mActiveDataSubId =
                mInternetDetailsContentController.getActiveDataSubId();
        internetContent.mCurrentSatelliteState =
                mInternetDetailsContentController.getCurrentSatelliteState();
        internetContent.mDefaultSubSignalStrengthIcon =
@@ -576,7 +578,15 @@ public class InternetDialogDelegateLegacy implements
                mMobileDataToggle.setChecked(
                        mInternetDetailsContentController.isMobileDataEnabled());
                mMobileTitleText.setText(getMobileNetworkTitle(mDefaultDataSubId));
                String summary = getMobileNetworkSummary(mDefaultDataSubId);
                int activeDataSubId = internetContent.mActiveDataSubId;
                Log.d(TAG, "setMobileDataLayout(), activeDataSubId: " + activeDataSubId
                        + ", mDefaultDataSubId:" + mDefaultDataSubId);
                boolean validDataSubId =
                        activeDataSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
                mBackgroundExecutor.execute(() -> {
                    String summary = getMobileNetworkSummary(
                            validDataSubId ? activeDataSubId : mDefaultDataSubId);
                    mHandler.post(() -> {
                        if (!TextUtils.isEmpty(summary)) {
                            mMobileSummaryText.setText(
                                    Html.fromHtml(summary, Html.FROM_HTML_MODE_LEGACY));
@@ -585,7 +595,8 @@ public class InternetDialogDelegateLegacy implements
                        } else {
                            mMobileSummaryText.setVisibility(View.GONE);
                        }

                    });
                });
                mSignalIcon.setImageDrawable(internetContent.mDefaultSubSignalStrengthIcon);

                mMobileDataToggle.setVisibility(
@@ -627,15 +638,19 @@ public class InternetDialogDelegateLegacy implements

                    TextView mSecondaryMobileSummaryText =
                            mDialogView.requireViewById(R.id.secondary_mobile_summary);
                    summary = getMobileNetworkSummary(autoSwitchNonDdsSubId);
                    mBackgroundExecutor.execute(() -> {
                        String summary = getMobileNetworkSummary(autoSwitchNonDdsSubId);
                        mHandler.post(() -> {
                            if (!TextUtils.isEmpty(summary)) {
                                mSecondaryMobileSummaryText.setText(
                                        Html.fromHtml(summary, Html.FROM_HTML_MODE_LEGACY));
                        mSecondaryMobileSummaryText.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE);
                                mSecondaryMobileSummaryText.setBreakStrategy(
                                        Layout.BREAK_STRATEGY_SIMPLE);
                                mSecondaryMobileSummaryText.setTextAppearance(
                                        R.style.TextAppearance_InternetDialog_Active);
                            }

                        });
                    });
                    ImageView mSecondarySignalIcon =
                            mDialogView.requireViewById(R.id.secondary_signal_icon);
                    mBackgroundExecutor.execute(() -> {
@@ -1047,6 +1062,7 @@ public class InternetDialogDelegateLegacy implements
        boolean mIsDeviceLocked = false;
        boolean mIsWifiScanEnabled = false;
        int mActiveAutoSwitchNonDdsSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        int mActiveDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        int mCurrentSatelliteState = SATELLITE_NOT_STARTED;

        Drawable mDefaultSubSignalStrengthIcon = null;
+36 −0
Original line number Diff line number Diff line
@@ -958,6 +958,7 @@ public class InternetDetailsContentControllerTest extends SysuiTestCase {
        mSubIdTelephonyDisplayInfoMap.put(SUB_ID, info1);
        mSubIdTelephonyDisplayInfoMap.put(SUB_ID2, info2);

        doReturn(SUB_ID).when(spyController).getActiveDataSubId();
        doReturn(SUB_ID2).when(spyController).getActiveAutoSwitchNonDdsSubId();
        doReturn(true).when(spyController).isMobileDataEnabled();
        doReturn(true).when(spyController).activeNetworkIsCellular();
@@ -970,11 +971,46 @@ public class InternetDetailsContentControllerTest extends SysuiTestCase {
        assertThat(ddsNetworkType).isNotEqualTo(nonDdsNetworkType);
    }

    @Test
    public void getMobileNetworkSummary_activeDataOnCbrsSim_get5g() {
        mFlags.set(Flags.QS_SECONDARY_DATA_SUB_INFO, true);
        Resources res1 = mock(Resources.class);
        doReturn("LTE").when(res1).getString(anyInt());
        Resources res2 = mock(Resources.class);
        doReturn("5G").when(res2).getString(anyInt());
        when(SubscriptionManager.getResourcesForSubId(any(), eq(SUB_ID))).thenReturn(res1);
        when(SubscriptionManager.getResourcesForSubId(any(), eq(SUB_ID2))).thenReturn(res2);

        InternetDetailsContentController spyController = spy(mInternetDetailsContentController);
        Map<Integer, TelephonyDisplayInfo> mSubIdTelephonyDisplayInfoMap =
                spyController.mSubIdTelephonyDisplayInfoMap;
        TelephonyDisplayInfo info1 = new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_NR,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
        TelephonyDisplayInfo info2 = new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_LTE,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);

        mSubIdTelephonyDisplayInfoMap.put(SUB_ID, info1);
        mSubIdTelephonyDisplayInfoMap.put(SUB_ID2, info2);

        doReturn(SUB_ID2).when(spyController).getActiveDataSubId();
        doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(
                spyController).getActiveAutoSwitchNonDdsSubId();
        doReturn(true).when(spyController).isMobileDataEnabled();
        doReturn(true).when(spyController).activeNetworkIsCellular();
        String ddsSummary = spyController.getMobileNetworkSummary(SUB_ID2);

        String ddsNetworkType = ddsSummary.split("/")[1];
        assertThat(ddsSummary).contains(mContext.getString(R.string.mobile_data_connection_active));
        assertThat(ddsNetworkType).contains("5G");
    }

    @Test
    public void getMobileNetworkSummary_flagOff() {
        InternetDetailsContentController spyController = spy(mInternetDetailsContentController);
        doReturn(true).when(spyController).isMobileDataEnabled();
        doReturn(true).when(spyController).activeNetworkIsCellular();
        doReturn(SUB_ID).when(spyController).getActiveDataSubId();

        String dds = spyController.getMobileNetworkSummary(SUB_ID);

        assertThat(dds).contains(mContext.getString(R.string.mobile_data_connection_active));
+2 −0
Original line number Diff line number Diff line
@@ -676,6 +676,8 @@ public class InternetDialogDelegateLegacyTest extends SysuiTestCase {
                    LinearLayout secondaryLayout = mDialogView.requireViewById(
                            R.id.secondary_mobile_network_layout);

                    mBgExecutor.runAllReady();

                    verify(mInternetDetailsContentController).getMobileNetworkSummary(1);
                    assertThat(primaryLayout.getBackground()).isNotEqualTo(
                            secondaryLayout.getBackground());