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

Commit 4ebe13b1 authored by Tom Hsu's avatar Tom Hsu Committed by Android (Google) Code Review
Browse files

Merge "Improve binder call usage and UI adjustment" into main

parents 319ca84d b91f29b9
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -149,7 +149,8 @@
                        android:clickable="false"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="start|center_vertical">
                        android:minHeight="72dp"
                        android:gravity="center_vertical">
                        <TextView
                            android:id="@+id/mobile_title"
                            android:maxLines="1"
+30 −14
Original line number Diff line number Diff line
@@ -195,7 +195,10 @@ public class InternetDialogController implements AccessPointController.AccessPoi
    private boolean mHasWifiEntries;
    private WifiStateWorker mWifiStateWorker;
    private boolean mHasActiveSubIdOnDds;
    private boolean mIsMobileDataEnabled = false;

    @VisibleForTesting
    Map<Integer, ServiceState> mSubIdServiceState = new HashMap<>();
    @VisibleForTesting
    static final float TOAST_PARAMS_HORIZONTAL_WEIGHT = 1.0f;
    @VisibleForTesting
@@ -453,7 +456,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
            return mContext.getText(SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE);
        }

        if (mCanConfigWifi && !isMobileDataEnabled()) {
        if (mCanConfigWifi && !mIsMobileDataEnabled) {
            if (DEBUG) {
                Log.d(TAG, "Mobile data off");
            }
@@ -551,7 +554,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
            numLevels += 1;
        }
        return getSignalStrengthIcon(subId, mContext, level, numLevels, NO_CELL_DATA_TYPE_ICON,
                !isMobileDataEnabled());
                !mIsMobileDataEnabled);
    }

    Drawable getSignalStrengthIcon(int subId, Context context, int level, int numLevels,
@@ -681,6 +684,12 @@ public class InternetDialogController implements AccessPointController.AccessPoi
            // sets the non-DDS to be not found to hide its visual
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        }
        int activeDataSubId = SubscriptionManager.getActiveDataSubscriptionId();
        if (activeDataSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
                || mDefaultDataSubId == activeDataSubId) {
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        }

        SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(
                SubscriptionManager.getActiveDataSubscriptionId());
        if (subInfo != null && subInfo.getSubscriptionId() != mDefaultDataSubId
@@ -740,7 +749,6 @@ public class InternetDialogController implements AccessPointController.AccessPoi
        if (!isMobileDataEnabled()) {
            return context.getString(R.string.mobile_data_off_summary);
        }

        String summary = networkTypeDescription;
        boolean isForDds = subId == mDefaultDataSubId;
        int activeSubId = getActiveAutoSwitchNonDdsSubId();
@@ -963,10 +971,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
     * Return {@code true} if mobile data is enabled
     */
    boolean isMobileDataEnabled() {
        if (mTelephonyManager == null || !mTelephonyManager.isDataEnabled()) {
            return false;
        }
        return true;
        return mIsMobileDataEnabled;
    }

    /**
@@ -1019,8 +1024,8 @@ public class InternetDialogController implements AccessPointController.AccessPoi
    }

    boolean isDataStateInService(int subId) {
        TelephonyManager tm = mSubIdTelephonyManagerMap.getOrDefault(subId, mTelephonyManager);
        final ServiceState serviceState = tm.getServiceState();
        final ServiceState serviceState = mSubIdServiceState.getOrDefault(subId,
                new ServiceState());
        NetworkRegistrationInfo regInfo =
                (serviceState == null) ? null : serviceState.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_PS,
@@ -1036,8 +1041,8 @@ public class InternetDialogController implements AccessPointController.AccessPoi
            return false;
        }

        TelephonyManager tm = mSubIdTelephonyManagerMap.getOrDefault(subId, mTelephonyManager);
        final ServiceState serviceState = tm.getServiceState();
        final ServiceState serviceState = mSubIdServiceState.getOrDefault(subId,
                new ServiceState());
        return serviceState != null
                && serviceState.getState() == serviceState.STATE_IN_SERVICE;
    }
@@ -1056,6 +1061,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi

        final Network activeNetwork = mConnectivityManager.getActiveNetwork();
        if (activeNetwork == null) {
            Log.d(TAG, "getActiveNetwork is null.");
            return false;
        }
        final NetworkCapabilities networkCapabilities =
@@ -1183,6 +1189,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
    }

    private class InternetTelephonyCallback extends TelephonyCallback implements
            TelephonyCallback.DataEnabledListener,
            TelephonyCallback.DataConnectionStateListener,
            TelephonyCallback.DisplayInfoListener,
            TelephonyCallback.ServiceStateListener,
@@ -1191,6 +1198,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
            TelephonyCallback.CarrierNetworkListener {

        private final int mSubId;

        private InternetTelephonyCallback(int subId) {
            mSubId = subId;
        }
@@ -1200,6 +1208,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
            if (mCallback != null) {
                mCallback.onServiceStateChanged(serviceState);
            }
            mSubIdServiceState.put(mSubId, serviceState);
        }

        @Override
@@ -1238,6 +1247,13 @@ public class InternetDialogController implements AccessPointController.AccessPoi
                mCallback.onCarrierNetworkChange(active);
            }
        }

        @Override
        public void onDataEnabledChanged(boolean b, int i) {
            if (mSubId == mDefaultDataSubId) {
                mIsMobileDataEnabled = b;
            }
        }
    }

    private class InternetOnSubscriptionChangedListener
+11 −6
Original line number Diff line number Diff line
@@ -416,9 +416,10 @@ public class InternetDialogDelegate implements
        internetContent.mHasEthernet = mInternetDialogController.hasEthernet();
        internetContent.mIsWifiEnabled = mInternetDialogController.isWifiEnabled();
        internetContent.mHasActiveSubIdOnDds = mInternetDialogController.hasActiveSubIdOnDds();
        internetContent.mIsMobileDataEnabled = mInternetDialogController.isMobileDataEnabled();
        internetContent.mIsDeviceLocked = mInternetDialogController.isDeviceLocked();
        internetContent.mIsWifiScanEnabled = mInternetDialogController.isWifiScanEnabled();
        internetContent.mActiveAutoSwitchNonDdsSubId =
                mInternetDialogController.getActiveAutoSwitchNonDdsSubId();
        return internetContent;
    }

@@ -433,7 +434,11 @@ public class InternetDialogDelegate implements

    private void setOnClickListener(SystemUIDialog dialog) {
        mMobileNetworkLayout.setOnClickListener(v -> {
            int autoSwitchNonDdsSubId = mInternetDialogController.getActiveAutoSwitchNonDdsSubId();
            int autoSwitchNonDdsSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
            if (mDataInternetContent.getValue() != null) {
                autoSwitchNonDdsSubId =
                        mDataInternetContent.getValue().mActiveAutoSwitchNonDdsSubId;
            }
            if (autoSwitchNonDdsSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
                showTurnOffAutoDataSwitchDialog(dialog, autoSwitchNonDdsSubId);
            }
@@ -524,7 +529,7 @@ public class InternetDialogDelegate implements
            }
        } else {
            mMobileNetworkLayout.setVisibility(View.VISIBLE);
            mMobileDataToggle.setChecked(internetContent.mIsMobileDataEnabled);
            mMobileDataToggle.setChecked(mInternetDialogController.isMobileDataEnabled());
            mMobileTitleText.setText(getMobileNetworkTitle(mDefaultDataSubId));
            String summary = getMobileNetworkSummary(mDefaultDataSubId);
            if (!TextUtils.isEmpty(summary)) {
@@ -549,9 +554,9 @@ public class InternetDialogDelegate implements
                    ? R.color.connected_network_primary_color
                    : R.color.disconnected_network_primary_color;
            mMobileToggleDivider.setBackgroundColor(dialog.getContext().getColor(primaryColor));

            // Display the info for the non-DDS if it's actively being used
            int autoSwitchNonDdsSubId = mInternetDialogController.getActiveAutoSwitchNonDdsSubId();
            int autoSwitchNonDdsSubId = internetContent.mActiveAutoSwitchNonDdsSubId;

            int nonDdsVisibility = autoSwitchNonDdsSubId
                    != SubscriptionManager.INVALID_SUBSCRIPTION_ID ? View.VISIBLE : View.GONE;

@@ -983,8 +988,8 @@ public class InternetDialogDelegate implements
        boolean mIsCarrierNetworkActive = false;
        boolean mIsWifiEnabled = false;
        boolean mHasActiveSubIdOnDds = false;
        boolean mIsMobileDataEnabled = false;
        boolean mIsDeviceLocked = false;
        boolean mIsWifiScanEnabled = false;
        int mActiveAutoSwitchNonDdsSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    }
}
+20 −16
Original line number Diff line number Diff line
@@ -260,7 +260,8 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {

    @Test
    public void connectCarrierNetwork_mergedCarrierEntryCanConnect_connectAndCreateSysUiToast() {
        when(mTelephonyManager.isDataEnabled()).thenReturn(true);
        InternetDialogController spyController = spy(mInternetDialogController);
        when(spyController.isMobileDataEnabled()).thenReturn(true);
        when(mKeyguardStateController.isUnlocked()).thenReturn(true);
        when(mConnectivityManager.getActiveNetwork()).thenReturn(mNetwork);
        when(mConnectivityManager.getNetworkCapabilities(mNetwork))
@@ -272,7 +273,7 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {
        mTestableResources.addOverride(R.string.wifi_wont_autoconnect_for_now,
            TOAST_MESSAGE_STRING);

        mInternetDialogController.connectCarrierNetwork();
        spyController.connectCarrierNetwork();

        verify(mMergedCarrierEntry).connect(null /* callback */, false /* showToast */);
        verify(mToastFactory).createToast(any(), any(), eq(TOAST_MESSAGE_STRING), anyString(),
@@ -281,11 +282,12 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {

    @Test
    public void connectCarrierNetwork_mergedCarrierEntryCanConnect_doNothingWhenSettingsOff() {
        when(mTelephonyManager.isDataEnabled()).thenReturn(false);

        InternetDialogController spyController = spy(mInternetDialogController);
        when(spyController.isMobileDataEnabled()).thenReturn(false);
        mTestableResources.addOverride(R.string.wifi_wont_autoconnect_for_now,
            TOAST_MESSAGE_STRING);
        mInternetDialogController.connectCarrierNetwork();

        spyController.connectCarrierNetwork();

        verify(mMergedCarrierEntry, never()).connect(null /* callback */, false /* showToast */);
        verify(mToastFactory, never()).createToast(any(), any(), anyString(), anyString(), anyInt(),
@@ -294,12 +296,13 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {

    @Test
    public void connectCarrierNetwork_mergedCarrierEntryCanConnect_doNothingWhenKeyguardLocked() {
        when(mTelephonyManager.isDataEnabled()).thenReturn(true);
        InternetDialogController spyController = spy(mInternetDialogController);
        when(spyController.isMobileDataEnabled()).thenReturn(true);
        when(mKeyguardStateController.isUnlocked()).thenReturn(false);

        mTestableResources.addOverride(R.string.wifi_wont_autoconnect_for_now,
            TOAST_MESSAGE_STRING);
        mInternetDialogController.connectCarrierNetwork();
        spyController.connectCarrierNetwork();

        verify(mMergedCarrierEntry, never()).connect(null /* callback */, false /* showToast */);
        verify(mToastFactory, never()).createToast(any(), any(), anyString(), anyString(), anyInt(),
@@ -308,7 +311,8 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {

    @Test
    public void connectCarrierNetwork_mergedCarrierEntryCanConnect_doNothingWhenMobileIsPrimary() {
        when(mTelephonyManager.isDataEnabled()).thenReturn(true);
        InternetDialogController spyController = spy(mInternetDialogController);
        when(spyController.isMobileDataEnabled()).thenReturn(true);
        when(mKeyguardStateController.isUnlocked()).thenReturn(true);
        when(mConnectivityManager.getActiveNetwork()).thenReturn(mNetwork);
        when(mConnectivityManager.getNetworkCapabilities(mNetwork))
@@ -446,10 +450,9 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {
        when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
        spyController.onAccessPointsChanged(null /* accessPoints */);

        doReturn(SUB_ID2).when(spyController).getActiveAutoSwitchNonDdsSubId();
        doReturn(SUB_ID).when(spyController).getActiveAutoSwitchNonDdsSubId();
        doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getState();
        doReturn(mServiceState).when(mTelephonyManager).getServiceState();
        doReturn(TelephonyManager.DATA_DISCONNECTED).when(mTelephonyManager).getDataState();
        spyController.mSubIdServiceState.put(SUB_ID2, mServiceState);

        assertFalse(TextUtils.equals(spyController.getSubtitleText(false),
                getResourcesString("all_network_unavailable")));
@@ -469,8 +472,7 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {
        spyController.onAccessPointsChanged(null /* accessPoints */);

        doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getState();
        doReturn(mServiceState).when(mTelephonyManager).getServiceState();
        doReturn(TelephonyManager.DATA_DISCONNECTED).when(mTelephonyManager).getDataState();
        spyController.mSubIdServiceState.put(SUB_ID, mServiceState);

        assertTrue(TextUtils.equals(spyController.getSubtitleText(false),
                getResourcesString("all_network_unavailable")));
@@ -487,11 +489,10 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {
        fakeAirplaneModeEnabled(false);
        when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
        mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
        InternetDialogController spyController = spy(mInternetDialogController);

        doReturn(ServiceState.STATE_IN_SERVICE).when(mServiceState).getState();
        doReturn(mServiceState).when(mTelephonyManager).getServiceState();

        when(mTelephonyManager.isDataEnabled()).thenReturn(false);
        spyController.mSubIdServiceState.put(SUB_ID, mServiceState);

        assertThat(mInternetDialogController.getSubtitleText(false))
                .isEqualTo(getResourcesString("non_carrier_network_unavailable"));
@@ -499,6 +500,9 @@ public class InternetDialogDelegateControllerTest extends SysuiTestCase {
        // if the Wi-Fi disallow config, then don't return Wi-Fi related string.
        mInternetDialogController.mCanConfigWifi = false;

        when(spyController.isMobileDataEnabled()).thenReturn(false);


        assertThat(mInternetDialogController.getSubtitleText(false))
                .isNotEqualTo(getResourcesString("non_carrier_network_unavailable"));
    }