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

Commit b795dcbc authored by cosmohsieh's avatar cosmohsieh
Browse files

[Network Connection] Implement new UI changing

1. Change title to multi-lines display
2. Add "SingleSpecifiedSSID" mode, will have connect button
3. Don't pop error dialog, if there is connection failure. Let user
retry.
4. Hide progress icon if list item exists

Bug: 128586511
Test: atest NetworkRequestDialogFragmentTest
Change-Id: Icc560e4882fbcd941574e44690a27d5082a7c4c7
parent 976995fa
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -25,14 +25,12 @@
  <TextView
      android:id="@+id/network_request_title_text"
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="24dp"
      android:paddingTop="18dp"
      android:layout_weight="1"
      android:textSize="18sp"
      android:gravity="center_vertical"
      android:maxLines="1"
      android:ellipsize="end"
      style="@style/info_label"/>

  <ProgressBar
+76 −8
Original line number Diff line number Diff line
@@ -82,11 +82,15 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp

    @VisibleForTesting
    final static String EXTRA_APP_NAME = "com.android.settings.wifi.extra.APP_NAME";
    final static String EXTRA_IS_SPECIFIED_SSID =
            "com.android.settings.wifi.extra.REQUEST_IS_FOR_SINGLE_NETWORK";

    private List<AccessPoint> mAccessPointList;
    private FilterWifiTracker mFilterWifiTracker;
    private AccessPointAdapter mDialogAdapter;
    private NetworkRequestUserSelectionCallback mUserSelectionCallback;
    private boolean mIsSpecifiedSsid;
    private boolean mWaitingConnectCallback;

    public static NetworkRequestDialogFragment newInstance() {
        NetworkRequestDialogFragment dialogFragment = new NetworkRequestDialogFragment();
@@ -104,6 +108,11 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
        final TextView title = customTitle.findViewById(R.id.network_request_title_text);
        title.setText(getTitle());

        final Intent intent = getActivity().getIntent();
        if (intent != null) {
            mIsSpecifiedSsid = intent.getBooleanExtra(EXTRA_IS_SPECIFIED_SSID, false);
        }

        final ProgressBar progressBar = customTitle.findViewById(
                R.id.network_request_title_progress);
        progressBar.setVisibility(View.VISIBLE);
@@ -115,10 +124,13 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
        final AlertDialog.Builder builder = new AlertDialog.Builder(context)
                .setCustomTitle(customTitle)
                .setAdapter(mDialogAdapter, this)
                .setPositiveButton(R.string.cancel, (dialog, which) -> getActivity().finish())
                .setNegativeButton(R.string.cancel, (dialog, which) -> getActivity().finish())
                // Do nothings, will replace the onClickListener to avoid auto closing dialog.
                .setNeutralButton(R.string.network_connection_request_dialog_showall,
                        null /* OnClickListener */);
        if (mIsSpecifiedSsid) {
            builder.setPositiveButton(R.string.wifi_connect, null /* OnClickListener */);
        }

        // Clicking list item is to connect wifi ap.
        final AlertDialog dialog = builder.create();
@@ -136,8 +148,19 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
                notifyAdapterRefresh();
                neutralBtn.setVisibility(View.GONE);
            });
        });

            // Replace Positive onClickListener to avoid closing dialog
            if (mIsSpecifiedSsid) {
                final Button positiveBtn = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                positiveBtn.setOnClickListener(v -> {
                    // When clicking connect button, should connect to the first and the only one
                    // list item.
                    this.onClick(dialog, 0 /* position */);
                });
                // Disable button in first, and enable it after there are some accesspoints in list.
                positiveBtn.setEnabled(false);
            }
        });
        return dialog;
    }

@@ -184,6 +207,9 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp

            if (wifiConfig != null) {
                mUserSelectionCallback.select(wifiConfig);

                mWaitingConnectCallback = true;
                updateConnectButton(false);
            }
        }
    }
@@ -223,7 +249,7 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
        }
    }

    private void showNeutralButton() {
    private void showAllButton() {
        final AlertDialog alertDialog = (AlertDialog) getDialog();
        if (alertDialog == null) {
            return;
@@ -235,6 +261,35 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
        }
    }

    private void updateConnectButton(boolean enabled) {
        // The button is only showed in single SSID mode.
        if (!mIsSpecifiedSsid) {
            return;
        }

        final AlertDialog alertDialog = (AlertDialog) getDialog();
        if (alertDialog == null) {
            return;
        }

        final Button positiveBtn = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        if (positiveBtn != null) {
            positiveBtn.setEnabled(enabled);
        }
    }

    private void hideProgressIcon() {
        final AlertDialog alertDialog = (AlertDialog) getDialog();
        if (alertDialog == null) {
            return;
        }

        final View progress = alertDialog.findViewById(R.id.network_request_title_progress);
        if (progress != null) {
            progress.setVisibility(View.GONE);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
@@ -403,7 +458,9 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp

    @Override
    public void onUserSelectionConnectFailure(WifiConfiguration wificonfiguration) {
        stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE.ABORT);
        // Do nothing when selection is failed, let user could try again easily.
        mWaitingConnectCallback = false;
        updateConnectButton(true);
    }

    private final class FilterWifiTracker {
@@ -427,10 +484,6 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
                    mAccessPointKeys.add(key);
                }
            }

            if (mShowLimitedItem && (mAccessPointKeys.size() > MAX_NUMBER_LIST_ITEM)) {
                showNeutralButton();
            }
        }

        /**
@@ -457,6 +510,21 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
                }
            }

            // Update related UI buttons
            if (mShowLimitedItem && (count >= MAX_NUMBER_LIST_ITEM)) {
                showAllButton();
            }
            if (count > 0) {
                hideProgressIcon();
            }
            // Enable connect button if there is Accesspoint item, except for the situation that
            // user click but connected status doesn't come back yet.
            if (count < 0) {
                updateConnectButton(false);
            } else if (!mWaitingConnectCallback) {
                updateConnectButton(true);
            }

            return result;
        }

+19 −27
Original line number Diff line number Diff line
@@ -106,12 +106,12 @@ public class NetworkRequestDialogFragmentTest {
    }

    @Test
    public void clickPositiveButton_shouldCloseTheDialog() {
    public void clickNegativeButton_shouldCloseTheDialog() {
        networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), null);
        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(alertDialog.isShowing()).isTrue();

        Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
        assertThat(positiveButton).isNotNull();

        positiveButton.performClick();
@@ -185,26 +185,6 @@ public class NetworkRequestDialogFragmentTest {
        verify(spyActivity).finish();
    }

    @Test
    public void updateAccessPointList_onUserSelectionConnectFailure_shouldCallAbortDialog() {
        FakeNetworkRequestDialogFragment fakeFragment = new FakeNetworkRequestDialogFragment();
        FakeNetworkRequestDialogFragment spyFakeFragment = spy(fakeFragment);
        List<AccessPoint> accessPointList = createAccessPointList();
        when(spyFakeFragment.getAccessPointList()).thenReturn(accessPointList);
        spyFakeFragment.show(mActivity.getSupportFragmentManager(), null);

        AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(alertDialog.isShowing()).isTrue();

        // Test if config would update list.
        WifiConfiguration config = new WifiConfiguration();
        config.SSID = "Test AP 3";
        fakeFragment.onUserSelectionConnectFailure(config);

        assertThat(fakeFragment.bCalledStopAndPop).isTrue();
        assertThat(fakeFragment.errorType).isEqualTo(ERROR_DIALOG_TYPE.ABORT);
    }

    @Test
    public void onUserSelectionCallbackRegistration_onClick_shouldCallSelect() {
        // Assert.
@@ -267,19 +247,27 @@ public class NetworkRequestDialogFragmentTest {
        Bundle bundle = new Bundle();

        bundle.putString(KEY_SSID, "Test AP 1");
        bundle.putInt(KEY_SECURITY, 1);
        bundle.putInt(KEY_SECURITY, 1 /* WEP */);
        accessPointList.add(new AccessPoint(mContext, bundle));

        bundle.putString(KEY_SSID, "Test AP 2");
        bundle.putInt(KEY_SECURITY, 1);
        bundle.putInt(KEY_SECURITY, 1 /* WEP */);
        accessPointList.add(new AccessPoint(mContext, bundle));

        bundle.putString(KEY_SSID, "Test AP 3");
        bundle.putInt(KEY_SECURITY, 2);
        bundle.putInt(KEY_SECURITY, 1 /* WEP */);
        accessPointList.add(new AccessPoint(mContext, bundle));

        bundle.putString(KEY_SSID, "Test AP 4");
        bundle.putInt(KEY_SECURITY, 0);
        bundle.putInt(KEY_SECURITY, 0 /* NONE */);
        accessPointList.add(new AccessPoint(mContext, bundle));

        bundle.putString(KEY_SSID, "Test AP 5");
        bundle.putInt(KEY_SECURITY, 1 /* WEP */);
        accessPointList.add(new AccessPoint(mContext, bundle));

        bundle.putString(KEY_SSID, "Test AP 6");
        bundle.putInt(KEY_SECURITY, 1 /* WEP */);
        accessPointList.add(new AccessPoint(mContext, bundle));

        return accessPointList;
@@ -300,9 +288,13 @@ public class NetworkRequestDialogFragmentTest {
        networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), /* tag */ null);
        final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();


        List<AccessPoint> accessPointList = createAccessPointList();
        when(mWifiTracker.getAccessPoints()).thenReturn(accessPointList);

        final String SSID_AP = "Test AP ";
        final List<ScanResult> scanResults = new ArrayList<>();
        for (int i = 0; i < 6 ; i ++) {
        for (int i = 0; i < 7 ; i ++) {
            ScanResult scanResult = new ScanResult();
            scanResult.SSID = SSID_AP + i;
            scanResult.capabilities = "WEP";