diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java index 92a16fe538e..3c82701f361 100644 --- a/src/com/android/settings/wifi/WifiConfigController2.java +++ b/src/com/android/settings/wifi/WifiConfigController2.java @@ -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; diff --git a/src/com/android/settings/wifi/WifiEntryShell.java b/src/com/android/settings/wifi/WifiEntryShell.java deleted file mode 100644 index 385cca16f76..00000000000 --- a/src/com/android/settings/wifi/WifiEntryShell.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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; -} diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java index e3bb06b8fb0..244fe48c8be 100644 --- a/src/com/android/settings/wifi/WifiUtils.java +++ b/src/com/android/settings/wifi/WifiUtils.java @@ -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; - } - } } diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java index 5c48dfd4934..4ab005ebb25 100644 --- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java +++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java @@ -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 diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java index c2bb70a38fa..bd3eaa661dd 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java +++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java @@ -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; } diff --git a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java index 605879df445..e6195d19e16 100644 --- a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java +++ b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java @@ -48,9 +48,6 @@ public class WifiNetworkConfig { static final String FAKE_PASSWORD = "password"; private static final String TAG = "WifiNetworkConfig"; - // Security from WifiNetworkListFragment/WifiTrackerLib may be WPA3. - static final String SECURITY_WPA3 = "WPA3"; - private String mSecurity; private String mSsid; private String mPreSharedKey; @@ -62,9 +59,6 @@ public class WifiNetworkConfig { WifiNetworkConfig(String security, String ssid, String preSharedKey, boolean hiddenSsid, int networkId, boolean isHotspot) { mSecurity = security; - if (TextUtils.equals(mSecurity, SECURITY_WPA3)) { - mSecurity = SECURITY_SAE; - } mSsid = ssid; mPreSharedKey = preSharedKey; mHiddenSsid = hiddenSsid; diff --git a/src/com/android/settings/wifi/dpp/WifiNetworkListFragment.java b/src/com/android/settings/wifi/dpp/WifiNetworkListFragment.java index 9f8d0dc5794..a017fac38ee 100644 --- a/src/com/android/settings/wifi/dpp/WifiNetworkListFragment.java +++ b/src/com/android/settings/wifi/dpp/WifiNetworkListFragment.java @@ -233,7 +233,7 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen throw new IllegalArgumentException("Invalid access point"); } final WifiNetworkConfig networkConfig = WifiNetworkConfig.getValidConfigOrNull( - selectedWifiEntry.getSecurityString(/* concise */ true), + WifiDppUtils.getSecurityString(selectedWifiEntry), wifiConfig.getPrintableSsid(), wifiConfig.preSharedKey, wifiConfig.hiddenSSID, wifiConfig.networkId, /* isHotspot */ false); if (mOnChooseNetworkListener != null) { diff --git a/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java b/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java index 07444c14287..a3609f7eede 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.when; import android.net.wifi.WifiConfiguration; -import com.android.settingslib.wifi.AccessPoint; import com.android.wifitrackerlib.WifiEntry; import org.junit.Test; @@ -62,7 +61,7 @@ public class WifiUtilsTest { final WifiConfiguration config = WifiUtils.getWifiConfig(wifiEntry, null /* scanResult */); assertThat(config).isNotNull(); - assertThat(config.SSID).isEqualTo(AccessPoint.convertToQuotedString(testSSID)); + assertThat(config.SSID).isEqualTo("\"" + testSSID + "\""); } @Test(expected = IllegalArgumentException.class) diff --git a/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppUtilsTest.java b/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppUtilsTest.java index 694088af7d0..d8bcb598f63 100644 --- a/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppUtilsTest.java +++ b/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppUtilsTest.java @@ -27,9 +27,7 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiManager; -import com.android.settingslib.wifi.AccessPoint; - -import java.util.BitSet; +import com.android.wifitrackerlib.WifiEntry; import org.junit.Before; import org.junit.Test; @@ -40,6 +38,8 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.shadows.ShadowApplication; +import java.util.BitSet; + @RunWith(RobolectricTestRunner.class) public class WifiDppUtilsTest { @@ -47,7 +47,7 @@ public class WifiDppUtilsTest { private WifiManager mWifiManager; @Mock - private AccessPoint mAccessPoint; + private WifiEntry mWifiEntry; @Mock private WifiConfiguration mWifiConfiguration; @@ -66,16 +66,16 @@ public class WifiDppUtilsTest { @Test public void getConfiguratorQrCodeScannerIntentOrNull_hiddenSsidNetwork_hasHiddenSsidExtra() { when(mWifiManager.isEasyConnectSupported()).thenReturn(true); - when(mAccessPoint.isPasspoint()).thenReturn(false); - when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK); - when(mAccessPoint.getConfig()).thenReturn(mWifiConfiguration); + when(mWifiEntry.canEasyConnect()).thenReturn(true); + when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_PSK); + when(mWifiEntry.getWifiConfiguration()).thenReturn(mWifiConfiguration); mWifiConfiguration.SSID = "GuestNetwork"; mWifiConfiguration.allowedKeyManagement = new BitSet(); mWifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK); mWifiConfiguration.hiddenSSID = true; Intent intent = WifiDppUtils - .getConfiguratorQrCodeScannerIntentOrNull(mContext, mWifiManager, mAccessPoint); + .getConfiguratorQrCodeScannerIntentOrNull(mContext, mWifiManager, mWifiEntry); assertThat(intent.getBooleanExtra(WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID, false)) .isEqualTo(true);