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

Commit ac75faa2 authored by Arc Wang's avatar Arc Wang
Browse files

Fix back arrow in wifi settings "connect to this network connection qr code" does not work

When clicking back button, pop fragment and Finish the activity if there is nothing to pop

Bug: 132132756
Test: atest WifiDppConfiguratorActivityTest
Change-Id: Ia16951e79e578f1625e5fadd26553735fa90bffa
parent 1dfc4387
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -323,15 +323,10 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements

    @Override
    public boolean onNavigateUp() {
        Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
        if (fragment instanceof WifiDppQrCodeGeneratorFragment) {
        if (!mFragmentManager.popBackStackImmediate()) {
            finish();
            return true;
        } else if (fragment instanceof WifiDppQrCodeScannerFragment) {
            mFragmentManager.popBackStackImmediate();
        }

        return false;
        return true;
    }

    @Override
+36 −0
Original line number Diff line number Diff line
@@ -175,4 +175,40 @@ public class WifiDppConfiguratorActivityTest {
        assertThat(restoredWifiNetworkConfig.getNetworkId()).isEqualTo(0);
        assertThat(restoredWifiNetworkConfig.isHotspot()).isTrue();
    }

    @Test
    public void launchScanner_onNavigateUp_shouldFinish() {
        Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
        intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
        intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
        intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
        final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

        mActivityRule.launchActivity(intent);

        instrumentation.runOnMainSync(() -> {
            mActivityRule.getActivity().onNavigateUp();

            assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(true);
        });
    }

    @Test
    public void launchGenerator_onNavigateUp_shouldFinish() {
        Intent intent = new Intent(
                WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
        intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
        intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
        intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
        final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

        mActivityRule.launchActivity(intent);

        instrumentation.runOnMainSync(() -> {
            mActivityRule.getActivity().onNavigateUp();

            assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(true);
        });
    }

}