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

Commit 286184af authored by chelseahao's avatar chelseahao
Browse files

Only update share-wifi button visibility when there's a change of connected wifi entry.

Flag: EXEMPT, bug fix
Test: atest
Bug: 418987320
Change-Id: I0c64c14ae62693e29a9fefa36132825209556465
parent 8ae2f4fc
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.Job;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

/**
@@ -697,13 +698,6 @@ public class InternetDialogDelegateLegacy implements
                mInternetDetailsContentController.getInternetWifiDrawable(mConnectedWifiEntry));
        mWifiSettingsIcon.setColorFilter(
                mDialog.getContext().getColor(R.color.connected_network_primary_color));
        if (mInternetDetailsContentController.getConfiguratorQrCodeGeneratorIntentOrNull(
                mConnectedWifiEntry) != null) {
            mShareWifiButton.setVisibility(View.VISIBLE);
        } else {
            mShareWifiButton.setVisibility(View.GONE);
        }

        if (mSecondaryMobileNetworkLayout != null) {
            mSecondaryMobileNetworkLayout.setVisibility(View.GONE);
        }
@@ -956,11 +950,19 @@ public class InternetDialogDelegateLegacy implements
        // Should update the carrier network layout when it is connected under airplane mode ON.
        boolean shouldUpdateCarrierNetwork = mMobileNetworkLayout.getVisibility() == View.VISIBLE
                && mInternetDetailsContentController.isAirplaneModeEnabled();
        boolean hasConnectedEntryChanged = !Objects.equals(connectedEntry, mConnectedWifiEntry);
        // Determine if a share Wi-Fi intent is available for the newly connected entry.
        boolean canShareWifi = hasConnectedEntryChanged && connectedEntry != null
                && mInternetDetailsContentController.getConfiguratorQrCodeGeneratorIntentOrNull(
                        connectedEntry) != null;
        mHandler.post(() -> {
            mConnectedWifiEntry = connectedEntry;
            mWifiEntriesCount = wifiEntries == null ? 0 : wifiEntries.size();
            mHasMoreWifiEntries = hasMoreWifiEntries;
            updateDialog(shouldUpdateCarrierNetwork /* shouldUpdateMobileNetwork */);
            if (hasConnectedEntryChanged) {
                mShareWifiButton.setVisibility(canShareWifi ? View.VISIBLE : View.GONE);
            }
            mAdapter.setWifiEntries(wifiEntries, mWifiEntriesCount);
            mAdapter.notifyDataSetChanged();
        });
+21 −17
Original line number Diff line number Diff line
@@ -4,10 +4,12 @@ import static com.android.systemui.qs.tiles.dialog.InternetDetailsContentControl

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

import static org.mockito.AdditionalAnswers.answerVoid;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -810,32 +812,34 @@ public class InternetDialogDelegateLegacyTest extends SysuiTestCase {
    }

    @Test
    public void updateDialog_shareWifiIntentNull_hideButton() {
    public void onAccessPointsChanged_shareWifiIntentNull_hideButton() {
        doAnswer(answerVoid(Runnable::run)).when(mHandler).post(any(Runnable.class));
        when(mInternetDetailsContentController.getConfiguratorQrCodeGeneratorIntentOrNull(any()))
                .thenReturn(null);
        mInternetDialogDelegateLegacy.updateDialog(false);
        mBgExecutor.runAllReady();

        mInternetDialogDelegateLegacy.mDataInternetContent.observe(
                mInternetDialogDelegateLegacy.mLifecycleOwner, i -> {
        mInternetDialogDelegateLegacy.onAccessPointsChanged(mWifiEntries,
                null,
                mInternetDialogDelegateLegacy.mHasMoreWifiEntries);

        assertThat(
                mInternetDialogDelegateLegacy.mShareWifiButton.getVisibility())
                .isEqualTo(View.GONE);
                });
    }

    @Test
    public void updateDialog_shareWifiShareable_showButton() {
    public void onAccessPointsChanged_shareWifiShareable_showButton() {
        doAnswer(answerVoid(Runnable::run)).when(mHandler).post(any(Runnable.class));
        when(mInternetDetailsContentController.getConfiguratorQrCodeGeneratorIntentOrNull(any()))
                .thenReturn(new Intent());
        mInternetDialogDelegateLegacy.updateDialog(false);
        mBgExecutor.runAllReady();
        mInternetDialogDelegateLegacy.mConnectedWifiEntry = null;

        mInternetDialogDelegateLegacy.mDataInternetContent.observe(
                mInternetDialogDelegateLegacy.mLifecycleOwner, i -> {
                    assertThat(mInternetDialogDelegateLegacy.mShareWifiButton.getVisibility())
        mInternetDialogDelegateLegacy.onAccessPointsChanged(mWifiEntries,
                mInternetWifiEntry,
                mInternetDialogDelegateLegacy.mHasMoreWifiEntries);

        assertThat(
                mInternetDialogDelegateLegacy.mShareWifiButton.getVisibility())
                .isEqualTo(View.VISIBLE);
                });
    }

    @Test