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

Commit 166ece8f authored by Arc Wang's avatar Arc Wang
Browse files

[Wi-Fi] Remove WifiTrackerLib/AccessPoint constant & API usage

Bug: 152571756
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.wifi
      make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.wifi.dpp
      make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.wifi.details
Change-Id: I857cf0e261c1b07c3d7b6bc08632880ed8c71ee1
parent fef7216e
Loading
Loading
Loading
Loading
+6 −22
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.Utils;
import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.wifi.AccessPoint;
import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiEntry.ConnectedInfo;

@@ -363,19 +362,6 @@ public class WifiConfigController2 implements TextWatcher,
                            && signalLevel != null) {
                    mConfigUi.setSubmitButton(res.getString(R.string.wifi_connect));
                } else {
                    // TODO(b/143326832): Add fine-grained state information.
                    //WifiConfiguration config = mWifiEntry.getWifiConfiguration();
                    //String suggestionOrSpecifierPackageName = null;
                    //if (config != null
                    //        && (config.fromWifiNetworkSpecifier
                    //        || config.fromWifiNetworkSuggestion)) {
                    //    suggestionOrSpecifierPackageName = config.creatorName;
                    //}
                    //String summary = AccessPoint.getSummary(
                    //        mConfigUi.getContext(), /* ssid */ null, state, isEphemeral,
                    //        suggestionOrSpecifierPackageName);
                    //addRow(group, R.string.wifi_status, summary);

                    if (signalLevel != null) {
                        addRow(group, R.string.wifi_signal, signalLevel);
                    }
@@ -390,11 +376,11 @@ public class WifiConfigController2 implements TextWatcher,
                        final int frequency = info.frequencyMhz;
                        String band = null;

                        if (frequency >= WifiEntryShell.LOWER_FREQ_24GHZ
                                && frequency < WifiEntryShell.HIGHER_FREQ_24GHZ) {
                        if (frequency >= WifiEntry.MIN_FREQ_24GHZ
                                && frequency < WifiEntry.MAX_FREQ_24GHZ) {
                            band = res.getString(R.string.wifi_band_24ghz);
                        } else if (frequency >= WifiEntryShell.LOWER_FREQ_5GHZ
                                && frequency < WifiEntryShell.HIGHER_FREQ_5GHZ) {
                        } else if (frequency >= WifiEntry.MIN_FREQ_5GHZ
                                && frequency < WifiEntry.MAX_FREQ_5GHZ) {
                            band = res.getString(R.string.wifi_band_5ghz);
                        } else {
                            Log.e(TAG, "Unexpected frequency " + frequency);
@@ -598,13 +584,11 @@ public class WifiConfigController2 implements TextWatcher,
        WifiConfiguration config = new WifiConfiguration();

        if (mWifiEntry == null) {
            config.SSID = AccessPoint.convertToQuotedString(
                    mSsidView.getText().toString());
            config.SSID = "\"" + mSsidView.getText().toString() + "\"";
            // If the user adds a network manually, assume that it is hidden.
            config.hiddenSSID = mHiddenSettingsSpinner.getSelectedItemPosition() == HIDDEN_NETWORK;
        } else if (!mWifiEntry.isSaved()) {
            config.SSID = AccessPoint.convertToQuotedString(
                    mWifiEntry.getTitle());
            config.SSID = "\"" + mWifiEntry.getTitle() + "\"";
        } else {
            config.networkId = mWifiEntry.getWifiConfiguration().networkId;
            config.hiddenSSID = mWifiEntry.getWifiConfiguration().hiddenSSID;
+0 −49
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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;

import com.android.wifitrackerlib.WifiEntry;

/**
 * {@link WifiEntry is working in progess, many methods are not available, this class is to group
 * all the unavalable {@link AccessPoint} methods & constants.
 *
 * TODO(b/143326832): Replace all methods & constants with WifiEntry version when it's available.
 */
public class WifiEntryShell {
    public WifiEntryShell(){};

    /**
     * Lower bound on the 2.4 GHz (802.11b/g/n) WLAN channels
     */
    public static final int LOWER_FREQ_24GHZ = 2400;

    /**
     * Upper bound on the 2.4 GHz (802.11b/g/n) WLAN channels
     */
    public static final int HIGHER_FREQ_24GHZ = 2500;

    /**
     * Lower bound on the 5.0 GHz (802.11a/h/j/n/ac) WLAN channels
     */
    public static final int LOWER_FREQ_5GHZ = 4900;

    /**
     * Upper bound on the 5.0 GHz (802.11a/h/j/n/ac) WLAN channels
     */
    public static final int HIGHER_FREQ_5GHZ = 5900;
}
+2 −31
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.provider.Settings;
import android.text.TextUtils;

import com.android.settings.Utils;
import com.android.settingslib.wifi.AccessPoint;
import com.android.wifitrackerlib.WifiEntry;

import java.nio.charset.StandardCharsets;
@@ -158,11 +157,11 @@ public class WifiUtils {
        final int security;

        if (wifiEntry == null) {
            config.SSID = AccessPoint.convertToQuotedString(scanResult.SSID);
            config.SSID = "\"" + scanResult.SSID + "\"";
            security = getWifiEntrySecurity(scanResult);
        } else {
            if (wifiEntry.getWifiConfiguration() == null) {
                config.SSID = AccessPoint.convertToQuotedString(wifiEntry.getSsid());
                config.SSID = "\"" + wifiEntry.getSsid() + "\"";
            } else {
                config.networkId = wifiEntry.getWifiConfiguration().networkId;
                config.hiddenSSID = wifiEntry.getWifiConfiguration().hiddenSSID;
@@ -228,32 +227,4 @@ public class WifiUtils {

        return WifiEntry.SECURITY_NONE;
    }

    public static final int CONNECT_TYPE_OTHERS = 0;
    public static final int CONNECT_TYPE_OPEN_NETWORK = 1;
    public static final int CONNECT_TYPE_SAVED_NETWORK = 2;
    public static final int CONNECT_TYPE_OSU_PROVISION = 3;

    /**
     * Gets the connecting type of {@link AccessPoint}.
     */
    public static int getConnectingType(AccessPoint accessPoint) {
        final WifiConfiguration config = accessPoint.getConfig();
        if (accessPoint.isOsuProvider()) {
            return CONNECT_TYPE_OSU_PROVISION;
        } else if ((accessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
                (accessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
            return CONNECT_TYPE_OPEN_NETWORK;
        } else if (accessPoint.isSaved() && config != null
                && config.getNetworkSelectionStatus() != null
                && config.getNetworkSelectionStatus().hasEverConnected()) {
            return CONNECT_TYPE_SAVED_NETWORK;
        } else if (accessPoint.isPasspoint()) {
            // Access point provided by an installed Passpoint provider, connect using
            // the associated config.
            return CONNECT_TYPE_SAVED_NETWORK;
        } else {
            return CONNECT_TYPE_OTHERS;
        }
    }
}
+2 −5
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import com.android.settings.datausage.WifiDataUsageSummaryPreferenceController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settings.wifi.WifiDialog2;
import com.android.settings.wifi.WifiDialog2.WifiDialog2Listener;
import com.android.settings.wifi.WifiEntryShell;
import com.android.settings.wifi.WifiUtils;
import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -576,11 +575,9 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle

        final int frequency = connectedInfo.frequencyMhz;
        String band = null;
        if (frequency >= WifiEntryShell.LOWER_FREQ_24GHZ
                && frequency < WifiEntryShell.HIGHER_FREQ_24GHZ) {
        if (frequency >= WifiEntry.MIN_FREQ_24GHZ && frequency < WifiEntry.MAX_FREQ_24GHZ) {
            band = mContext.getResources().getString(R.string.wifi_band_24ghz);
        } else if (frequency >= WifiEntryShell.LOWER_FREQ_5GHZ
                && frequency < WifiEntryShell.HIGHER_FREQ_5GHZ) {
        } else if (frequency >= WifiEntry.MIN_FREQ_5GHZ && frequency < WifiEntry.MAX_FREQ_5GHZ) {
            band = mContext.getResources().getString(R.string.wifi_band_5ghz);
        } else {
            // Connecting state is unstable, make it disappeared if unexpected
+16 −61
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class WifiDppUtils {
     */
    static final String TAG_FRAGMENT_ADD_DEVICE = "add_device_fragment";

    /** The data is from {@code com.android.settingslib.wifi.AccessPoint.securityToString} */
    /** The data is one of the static String SECURITY_* in {@link WifiQrCode} */
    static final String EXTRA_WIFI_SECURITY = "security";

    /** The data corresponding to {@code WifiConfiguration} SSID */
@@ -251,36 +251,6 @@ public class WifiDppUtils {
        return intent;
    }

    /**
     * Returns an intent to launch QR code scanner. It may return null if the security is not
     * supported by QR code scanner.
     *
     * @param context     The context to use for the content resolver
     * @param wifiManager An instance of {@link WifiManager}
     * @param accessPoint An instance of {@link AccessPoint}
     * @return Intent for launching QR code scanner
     */
    public static Intent getConfiguratorQrCodeScannerIntentOrNull(Context context,
            WifiManager wifiManager, AccessPoint accessPoint) {
        final Intent intent = new Intent(context, WifiDppConfiguratorActivity.class);
        if (isSupportConfiguratorQrCodeScanner(context, accessPoint)) {
            intent.setAction(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
        } else {
            return null;
        }

        final WifiConfiguration wifiConfiguration = accessPoint.getConfig();
        setConfiguratorIntentExtra(intent, wifiManager, wifiConfiguration);

        if (wifiConfiguration.networkId == WifiConfiguration.INVALID_NETWORK_ID) {
            throw new IllegalArgumentException("Invalid network ID");
        } else {
            intent.putExtra(EXTRA_WIFI_NETWORK_ID, wifiConfiguration.networkId);
        }

        return intent;
    }

    /**
     * Returns an intent to launch QR code scanner. It may return null if the security is not
     * supported by QR code scanner.
@@ -434,20 +404,6 @@ public class WifiDppUtils {
        }
    }

    /**
     * Checks if QR code scanner supports to config other devices with the Wi-Fi network
     *
     * @param context The context to use for {@link WifiManager#isEasyConnectSupported()}
     * @param accessPoint The {@link AccessPoint} of the Wi-Fi network
     */
    public static boolean isSupportConfiguratorQrCodeScanner(Context context,
            AccessPoint accessPoint) {
        if (accessPoint.isPasspoint()) {
            return false;
        }
        return isSupportWifiDpp(context, accessPoint.getSecurity());
    }

    /**
     * Checks if QR code generator supports to config other devices with the Wi-Fi network
     *
@@ -466,12 +422,11 @@ public class WifiDppUtils {
     * Checks if this device supports to be configured by the Wi-Fi network of the security
     *
     * @param context The context to use for {@code WifiManager}
     * @param accesspointSecurity The security constants defined in {@link AccessPoint}
     * @param wifiEntrySecurity The security constants defined in {@link WifiEntry}
     */
    public static boolean isSupportEnrolleeQrCodeScanner(Context context,
            int accesspointSecurity) {
        return isSupportWifiDpp(context, accesspointSecurity) ||
                isSupportZxing(context, accesspointSecurity);
    public static boolean isSupportEnrolleeQrCodeScanner(Context context, int wifiEntrySecurity) {
        return isSupportWifiDpp(context, wifiEntrySecurity)
                || isSupportZxing(context, wifiEntrySecurity);
    }

    private static boolean isSupportHotspotConfiguratorQrCodeGenerator(
@@ -483,39 +438,39 @@ public class WifiDppUtils {
                || softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_OPEN;
    }

    private static boolean isSupportWifiDpp(Context context, int accesspointSecurity) {
    private static boolean isSupportWifiDpp(Context context, int wifiEntrySecurity) {
        if (!isWifiDppEnabled(context)) {
            return false;
        }

        // DPP 1.0 only supports SAE and PSK.
        final WifiManager wifiManager = context.getSystemService(WifiManager.class);
        switch (accesspointSecurity) {
            case AccessPoint.SECURITY_SAE:
        switch (wifiEntrySecurity) {
            case WifiEntry.SECURITY_SAE:
                if (wifiManager.isWpa3SaeSupported()) {
                    return true;
                }
                break;
            case AccessPoint.SECURITY_PSK:
            case WifiEntry.SECURITY_PSK:
                return true;
            default:
        }
        return false;
    }

    private static boolean isSupportZxing(Context context, int accesspointSecurity) {
    private static boolean isSupportZxing(Context context, int wifiEntrySecurity) {
        final WifiManager wifiManager = context.getSystemService(WifiManager.class);
        switch (accesspointSecurity) {
            case AccessPoint.SECURITY_PSK:
            case AccessPoint.SECURITY_WEP:
            case AccessPoint.SECURITY_NONE:
        switch (wifiEntrySecurity) {
            case WifiEntry.SECURITY_PSK:
            case WifiEntry.SECURITY_WEP:
            case WifiEntry.SECURITY_NONE:
                return true;
            case AccessPoint.SECURITY_SAE:
            case WifiEntry.SECURITY_SAE:
                if (wifiManager.isWpa3SaeSupported()) {
                    return true;
                }
                break;
            case AccessPoint.SECURITY_OWE:
            case WifiEntry.SECURITY_OWE:
                if (wifiManager.isEnhancedOpenSupported()) {
                    return true;
                }
Loading