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

Commit 4ab0d168 authored by Arc Wang's avatar Arc Wang
Browse files

Implement Wi-Fi DPP UI.

  Add WifiDppEnrolleeActivity
  Remove bottom buttons of WifiDppQrCodeScannerFragment
  Add ActionBar in WifiDppQrCodeScannerFragment &
      WifiDppQrCodeGeneratorFragment

Bug: 118797380
Bug: 118794858
Test: atest WifiDppConfiguratorActivityTest
      atest WifiDppQrCodeScannerFragmentTest
      atest WifiDppQrCodeGeneratorFragmentTest
      atest atest RunSettingsRoboTests

Change-Id: I1d464dc9a8d54a896b8e0c9185a74bed7b193b60
parent f831f40d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -3054,6 +3054,14 @@
            </intent-filter>
        </activity>

        <activity
            android:name=".wifi.dpp.WifiDppEnrolleeActivity">
            <intent-filter>
                <action android:name="android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <activity android:name=".homepage.contextualcards.ContextualCardFeedbackDialog"
                  android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" />
        <!-- This is the longest AndroidManifest.xml ever. -->
+0 −3
Original line number Diff line number Diff line
@@ -44,8 +44,5 @@
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>

    <include layout="@layout/wifi_dpp_fragment_footer"
        android:gravity="center|bottom"/>

</LinearLayout>
+8 −0
Original line number Diff line number Diff line
@@ -2054,6 +2054,14 @@
    <string name="wifi_dpp_add_device_to_network">Add a device to this network</string>
    <!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=120] -->
    <string name="wifi_dpp_center_qr_code">Center the device\u2019s QR code below to add device to \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d</string>
    <!-- Title for the fragment to scan QR code [CHAR LIMIT=50]  -->
    <string name="wifi_dpp_scan_qr_code">Scan QR code</string>
    <!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=NONE] -->
    <string name="wifi_dpp_scan_qr_code_join_network">Join \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d by scanning a QR code</string>
    <!-- Title for the fragment to share Wi-Fi [CHAR LIMIT=50]  -->
    <string name="wifi_dpp_share_wifi">Share Wi\u2011Fi</string>
    <!-- Hint for the user to use another device to scan QR code on screen to join Wi-Fi [CHAR LIMIT=NONE] -->
    <string name="wifi_dpp_scan_qr_code_with_another_device">Scan this QR code with another device to join \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d</string>
    <!-- Label for the check box to share a network with other users on the same device -->
    <string name="wifi_shared">Share with other device users</string>
    <!-- Hint for unchanged fields -->
+86 −33
Original line number Diff line number Diff line
@@ -31,8 +31,26 @@ import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.core.InstrumentedActivity;
import com.android.settings.R;

/**
 * To provision "other" device with specified Wi-Fi network.
 *
 * Uses different intents to specify different provisioning ways.
 *
 * For intent action {@code ACTION_CONFIGURATOR_QR_CODE_SCANNER} and
 * {@code android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR}, specify the Wi-Fi network to be
 * provisioned in:
 *
 * {@code WifiDppUtils.EXTRA_WIFI_SECURITY}
 * {@code WifiDppUtils.EXTRA_WIFI_SSID}
 * {@code WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY}
 * {@code WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID}
 *
 * For intent action {@code ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK}, specify Wi-Fi (DPP)
 * QR code in {@code WifiDppUtils.EXTRA_QR_CODE}
 */
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
        WifiNetworkConfig.Retriever {
        WifiNetworkConfig.Retriever,
        WifiDppQrCodeGeneratorFragment.OnQrCodeGeneratorFragmentAddButtonClickedListener {
    private static final String TAG = "WifiDppConfiguratorActivity";

    public static final String ACTION_CONFIGURATOR_QR_CODE_SCANNER =
@@ -43,7 +61,6 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
            "android.settings.WIFI_DPP_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK";

    private FragmentManager mFragmentManager;
    private FragmentTransaction mFragmentTransaction;

    /** The Wi-Fi network which will be configured */
    private WifiNetworkConfig mWifiNetworkConfig;
@@ -57,12 +74,20 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wifi_dpp_activity);

        setContentView(R.layout.wifi_dpp_activity);
        mFragmentManager = getSupportFragmentManager();
        mFragmentTransaction = getSupportFragmentManager().beginTransaction();

        Intent intent = getIntent();
        handleIntent(getIntent());

        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setElevation(0);
            actionBar.setDisplayShowTitleEnabled(false);
        }
    }

    private void handleIntent(Intent intent) {
        boolean cancelActivity = false;
        WifiNetworkConfig config;
        switch (intent.getAction()) {
@@ -72,7 +97,7 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
                    cancelActivity = true;
                } else {
                    mWifiNetworkConfig = config;
                    addQrCodeScannerFragment(/* addToBackStack= */ false);
                    showQrCodeScannerFragment(/* addToBackStack= */ false);
                }
                break;
            case ACTION_CONFIGURATOR_QR_CODE_GENERATOR:
@@ -81,11 +106,11 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
                    cancelActivity = true;
                } else {
                    mWifiNetworkConfig = config;
                    addQrCodeGeneratorFragment();
                    showQrCodeGeneratorFragment();
                }
                break;
            case ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK:
                addChooseSavedWifiNetworkFragment(/* addToBackStack */ false);
                showChooseSavedWifiNetworkFragment(/* addToBackStack */ false);
                break;
            default:
                cancelActivity = true;
@@ -98,45 +123,55 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
        }
    }

    private void addQrCodeScannerFragment(boolean addToBackStack) {
    private void showQrCodeScannerFragment(boolean addToBackStack) {
        // Avoid to replace the same fragment during configuration change
        if (mFragmentManager.findFragmentByTag(WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER) != null) {
            return;
        }

        WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
        mFragmentTransaction.add(R.id.fragment_container, fragment);
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fragment_container, fragment,
                WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
        if (addToBackStack) {
            mFragmentTransaction.addToBackStack(/* name */ null);
            fragmentTransaction.addToBackStack(/* name */ null);
        }
        mFragmentTransaction.commit();
        fragmentTransaction.commit();
    }

    private void showQrCodeGeneratorFragment() {
        // Avoid to replace the same fragment during configuration change
        if (mFragmentManager.findFragmentByTag(
                WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR) != null) {
            return;
        }

    private void addQrCodeGeneratorFragment() {
        WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
        mFragmentTransaction.add(R.id.fragment_container, fragment);
        mFragmentTransaction.commit();
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fragment_container, fragment,
                WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR);
        fragmentTransaction.commit();
    }

    private void addChooseSavedWifiNetworkFragment(boolean addToBackStack) {
        ActionBar action = getActionBar();
        if (action != null) {
            action.hide();
    private void showChooseSavedWifiNetworkFragment(boolean addToBackStack) {
        // Avoid to replace the same fragment during configuration change
        if (mFragmentManager.findFragmentByTag(
                WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK) != null) {
            return;
        }

        WifiDppChooseSavedWifiNetworkFragment fragment =
                new WifiDppChooseSavedWifiNetworkFragment();
        mFragmentTransaction.add(R.id.fragment_container, fragment);
        if (addToBackStack) {
            mFragmentTransaction.addToBackStack(/* name */ null);
        }
        mFragmentTransaction.commit();
    }
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

    @Override
    protected void onStop() {
        Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
        if (fragment != null) {
            // Remove it to prevent stacking multiple fragments after screen rotated.
            mFragmentManager.beginTransaction().remove(fragment).commit();
        fragmentTransaction.replace(R.id.fragment_container, fragment,
                WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK);
        if (addToBackStack) {
            fragmentTransaction.addToBackStack(/* name */ null);
        }

        super.onStop();
        fragmentTransaction.commit();
    }

    @Override
@@ -153,4 +188,22 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
            return true;
        }
    }

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

        return false;
    }

    @Override public void onQrCodeGeneratorFragmentAddButtonClicked() {
        showQrCodeScannerFragment(/* addToBackStack */ true);
    }
}
+106 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.wifi.dpp;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.android.internal.logging.nano.MetricsProto;

import com.android.settings.core.InstrumentedActivity;
import com.android.settings.R;

/**
 * To provision "this" device with specified Wi-Fi network.
 *
 * To use intent action {@code ACTION_ENROLLEE_QR_CODE_SCANNER}, specify the SSID string of the
 * Wi-Fi network to be provisioned in {@code WifiDppUtils.EXTRA_QR_CODE}.
 */
public class WifiDppEnrolleeActivity extends InstrumentedActivity {
    private static final String TAG = "WifiDppEnrolleeActivity";

    public static final String ACTION_ENROLLEE_QR_CODE_SCANNER =
            "android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER";

    private FragmentManager mFragmentManager;

    @Override
    public int getMetricsCategory() {
        //TODO:Should we use a new metrics category for Wi-Fi DPP?
        return MetricsProto.MetricsEvent.WIFI_NETWORK_DETAILS;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.wifi_dpp_activity);
        mFragmentManager = getSupportFragmentManager();

        handleIntent(getIntent());

        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setElevation(0);
            actionBar.setDisplayShowTitleEnabled(false);
        }
    }

    private void handleIntent(Intent intent) {
        switch (intent.getAction()) {
            case ACTION_ENROLLEE_QR_CODE_SCANNER:
                String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);
                showQrCodeScannerFragment(/* addToBackStack */ false, ssid);
                break;
            default:
                Log.e(TAG, "Launch with an invalid action");
                setResult(Activity.RESULT_CANCELED);
                finish();
        }
    }

    private void showQrCodeScannerFragment(boolean addToBackStack, String ssid) {
        // Avoid to replace the same fragment during configuration change
        if (mFragmentManager.findFragmentByTag(WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER) != null) {
            return;
        }

        WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment(ssid);
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fragment_container, fragment,
                WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
        if (addToBackStack) {
            fragmentTransaction.addToBackStack(/* name */ null);
        }
        fragmentTransaction.commit();
    }

    @Override
    public boolean onNavigateUp(){
        setResult(Activity.RESULT_CANCELED);
        finish();
        return true;
    }
}
Loading