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

Commit 9f80cd2f authored by Weng Su's avatar Weng Su
Browse files

Add Wi-Fi hotspot > Security Settings page

- Restrict low security type when 6 GHz band is selected
  - Disable "WPA2/WPA3-Personal" security type
  - Disable "WPA2-Personal" security type
  - Disable "None" security type

- Automatically updated security type to WPA3 when 6 GHz band is selected
  - Regenerate password when security type is changed from None

Bug: 245258763
Test: manual test
atest -c WifiTetherSettingsTest
atest -c WifiTetherViewModelTest \
         WifiHotspotSecuritySettingsTest \
         WifiHotspotSecurityViewModelTest \
         WifiHotspotRepositoryTest

Change-Id: I31b08795419baed10dc40b876aeec175f6f41e69
parent 211b544e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2067,6 +2067,10 @@
    <string name="wifi_hotspot_speed_summary_unavailable">Not available in your country or region</string>
    <!-- The footer message for switch screen resolution [CHAR LIMIT=NONE] -->
    <string name="wifi_hotspot_speed_footer">If your preferred frequency isn\u0027t available, your hotspot may use a different one. Hotspot security settings may change if you change the frequency.</string>
    <!-- Summary for the Wi-Fi hotspot security unavailable [CHAR LIMIT=NONE] -->
    <string name="wifi_hotspot_security_summary_unavailable">Not available with 6 GHz</string>
    <!-- The footer message for Wi-Fi hotspot security settings [CHAR LIMIT=NONE] -->
    <string name="wifi_hotspot_security_footer">Security settings may change if you change the hotspot’s frequency</string>
    <!-- Summary text when turning hotspot on -->
    <string name="wifi_tether_starting">Turning hotspot on\u2026</string>
+42 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2023 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.
  -->
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:title="@string/wifi_security"
    settings:searchable="false">

    <com.android.settingslib.widget.SelectorWithWidgetPreference
        android:key="wifi_hotspot_security_wpa3"
        android:title="@string/wifi_security_sae"/>

    <com.android.settingslib.widget.SelectorWithWidgetPreference
        android:key="wifi_hotspot_security_wpa2_wpa3"
        android:title="@string/wifi_security_psk_sae"/>

    <com.android.settingslib.widget.SelectorWithWidgetPreference
        android:key="wifi_hotspot_security_wpa2"
        android:title="@string/wifi_security_wpa2"/>

    <com.android.settingslib.widget.SelectorWithWidgetPreference
        android:key="wifi_hotspot_security_none"
        android:title="@string/wifi_security_none"/>

    <com.android.settingslib.widget.FooterPreference
        android:title="@string/wifi_hotspot_security_footer"/>

</PreferenceScreen>
+7 −0
Original line number Diff line number Diff line
@@ -32,6 +32,13 @@
        android:entries="@array/wifi_tether_security"
        android:entryValues="@array/wifi_tether_security_values"/>

    <Preference
        android:key="wifi_hotspot_security"
        android:title="@string/wifi_security"
        android:summary="@string/summary_placeholder"
        android:fragment="com.android.settings.wifi.tether.WifiHotspotSecuritySettings"
        settings:isPreferenceVisible="@bool/config_show_wifi_hotspot_speed"/>

    <com.android.settings.widget.ValidatedEditTextPreference
        android:key="wifi_tether_network_password"
        android:persistent="false"
+12 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;

import com.android.settings.wifi.repository.WifiHotspotRepository;
import com.android.settings.wifi.tether.WifiHotspotSecurityViewModel;
import com.android.settings.wifi.tether.WifiHotspotSpeedViewModel;
import com.android.settings.wifi.tether.WifiTetherViewModel;

@@ -84,6 +85,17 @@ public class WifiFeatureProvider {
        return new ViewModelProvider(owner).get(WifiTetherViewModel.class);
    }

    /**
     * Get WifiHotspotSecurityViewModel
     */
    public WifiHotspotSecurityViewModel getWifiHotspotSecurityViewModel(
            @NotNull ViewModelStoreOwner owner) {
        WifiHotspotSecurityViewModel viewModel =
                new ViewModelProvider(owner).get(WifiHotspotSecurityViewModel.class);
        verboseLog(TAG, "getWifiHotspotSecurityViewModel():" + viewModel);
        return viewModel;
    }

    /**
     * Get WifiHotspotSpeedViewModel
     */
+68 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.settings.wifi.repository;
import static android.net.wifi.SoftApConfiguration.BAND_2GHZ;
import static android.net.wifi.SoftApConfiguration.BAND_5GHZ;
import static android.net.wifi.SoftApConfiguration.BAND_6GHZ;
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_OPEN;
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA3_SAE;
import static android.net.wifi.WifiAvailableChannel.OP_MODE_SAP;

import android.content.Context;
@@ -81,6 +83,7 @@ public class WifiHotspotRepository {
    protected String mLastPassword;
    protected LastPasswordListener mLastPasswordListener = new LastPasswordListener();

    protected MutableLiveData<Integer> mSecurityType;
    protected MutableLiveData<Integer> mSpeedType;

    protected Boolean mIsDualBand;
@@ -144,6 +147,7 @@ public class WifiHotspotRepository {
     * Refresh data from the SoftApConfiguration.
     */
    public void refresh() {
        updateSecurityType();
        update6gAvailable();
        update5gAvailable();
        updateSpeedType();
@@ -162,11 +166,71 @@ public class WifiHotspotRepository {
        }
    }

    /**
     * Gets SecurityType LiveData
     */
    public LiveData<Integer> getSecurityType() {
        if (mSecurityType == null) {
            startAutoRefresh();
            mSecurityType = new MutableLiveData<>();
            updateSecurityType();
            log("getSecurityType():" + mSecurityType.getValue());
        }
        return mSecurityType;
    }

    protected void updateSecurityType() {
        if (mSecurityType == null) {
            return;
        }
        SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
        int securityType = (config != null) ? config.getSecurityType() : SECURITY_TYPE_OPEN;
        log("updateSecurityType(), securityType:" + securityType);
        mSecurityType.setValue(securityType);
    }

    /**
     * Sets SecurityType
     *
     * @param securityType the Wi-Fi hotspot security type.
     */
    public void setSecurityType(int securityType) {
        log("setSecurityType():" + securityType);
        if (mSecurityType == null) {
            getSecurityType();
        }
        if (securityType == mSecurityType.getValue()) {
            Log.w(TAG, "setSecurityType() is no changed! mSecurityType:"
                    + mSecurityType.getValue());
            return;
        }
        SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
        if (config == null) {
            mSecurityType.setValue(SECURITY_TYPE_OPEN);
            Log.e(TAG, "setSecurityType(), WifiManager#getSoftApConfiguration() return null!");
            return;
        }
        SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(config);
        String passphrase = null;
        if (securityType != SECURITY_TYPE_OPEN) {
            passphrase = config.getPassphrase();
            if (TextUtils.isEmpty(passphrase)) {
                passphrase = generatePassword();
            }
        }
        configBuilder.setPassphrase(passphrase, securityType);
        setSoftApConfiguration(configBuilder.build());

        mWifiManager.queryLastConfiguredTetheredApPassphraseSinceBoot(
                mAppContext.getMainExecutor(), mLastPasswordListener);
    }

    /**
     * Gets SpeedType LiveData
     */
    public LiveData<Integer> getSpeedType() {
        if (mSpeedType == null) {
            startAutoRefresh();
            mSpeedType = new MutableLiveData<>();
            updateSpeedType();
            log("getSpeedType():" + mSpeedType.getValue());
@@ -230,6 +294,10 @@ public class WifiHotspotRepository {
        if (speedType == SPEED_6GHZ) {
            log("setSpeedType(), setBand(BAND_2GHZ_5GHZ_6GHZ)");
            configBuilder.setBand(BAND_2GHZ_5GHZ_6GHZ);
            if (config.getSecurityType() != SECURITY_TYPE_WPA3_SAE) {
                log("setSpeedType(), setPassphrase(SECURITY_TYPE_WPA3_SAE)");
                configBuilder.setPassphrase(generatePassword(), SECURITY_TYPE_WPA3_SAE);
            }
        } else if (speedType == SPEED_5GHZ) {
            log("setSpeedType(), setBand(BAND_2GHZ_5GHZ)");
            configBuilder.setBand(BAND_2GHZ_5GHZ);
Loading