Migrate to getNetworkSelectionStatus()

isNetworkEnabled() & isNetworkPermanentlyDisabled()
should not be formal APIs. Instead,
getNetworkSelectionStatus() with a set of constants
is sufficient as an API surface, and will be more
maintainable in the future.

Also fixed testOsuAccessPointSummary_showsProvisioningUpdates
that was previously broken.

Bug: 146046526
Test: atest FrameworksWifiApiTests SettingsLibTests
Test: make RunSettingsLibRoboTests -j40
Change-Id: I89ed4f0de0ce693bbf4f77be84f08b82a89037bb
This commit is contained in:
David Su
2020-01-30 20:24:49 -08:00
parent 1b74411bc3
commit a52e3168d4
5 changed files with 27 additions and 10 deletions

View File

@@ -7564,8 +7564,6 @@ package android.net.wifi {
method @Deprecated public int getNetworkSelectionStatus();
method @Deprecated @NonNull public String getNetworkStatusString();
method @Deprecated public boolean hasEverConnected();
method @Deprecated public boolean isNetworkEnabled();
method @Deprecated public boolean isNetworkPermanentlyDisabled();
field @Deprecated public static final int DISABLED_ASSOCIATION_REJECTION = 1; // 0x1
field @Deprecated public static final int DISABLED_AUTHENTICATION_FAILURE = 2; // 0x2
field @Deprecated public static final int DISABLED_AUTHENTICATION_NO_CREDENTIALS = 5; // 0x5

View File

@@ -16,6 +16,9 @@
package com.android.settingslib.wifi;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_ENABLED;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_PERMANENTLY_DISABLED;
import android.annotation.IntDef;
import android.annotation.MainThread;
import android.annotation.Nullable;
@@ -1144,11 +1147,15 @@ public class AccessPoint implements Comparable<AccessPoint> {
mInfo != null ? mInfo.getRequestingPackageName() : null));
} else { // not active
if (mConfig != null && mConfig.hasNoInternetAccess()) {
int messageID = mConfig.getNetworkSelectionStatus().isNetworkPermanentlyDisabled()
int messageID =
mConfig.getNetworkSelectionStatus().getNetworkSelectionStatus()
== NETWORK_SELECTION_PERMANENTLY_DISABLED
? R.string.wifi_no_internet_no_reconnect
: R.string.wifi_no_internet;
summary.append(mContext.getString(messageID));
} else if (mConfig != null && !mConfig.getNetworkSelectionStatus().isNetworkEnabled()) {
} else if (mConfig != null
&& (mConfig.getNetworkSelectionStatus().getNetworkSelectionStatus()
!= NETWORK_SELECTION_ENABLED)) {
WifiConfiguration.NetworkSelectionStatus networkStatus =
mConfig.getNetworkSelectionStatus();
switch (networkStatus.getNetworkSelectionDisableReason()) {

View File

@@ -16,6 +16,8 @@
package com.android.settingslib.wifi;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_ENABLED;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
@@ -41,7 +43,9 @@ public class WifiUtils {
summary.append(" f=" + Integer.toString(info.getFrequency()));
}
summary.append(" " + getVisibilityStatus(accessPoint));
if (config != null && !config.getNetworkSelectionStatus().isNetworkEnabled()) {
if (config != null
&& (config.getNetworkSelectionStatus().getNetworkSelectionStatus()
!= NETWORK_SELECTION_ENABLED)) {
summary.append(" (" + config.getNetworkSelectionStatus().getNetworkStatusString());
if (config.getNetworkSelectionStatus().getDisableTime() > 0) {
long now = System.currentTimeMillis();

View File

@@ -465,6 +465,8 @@ public class AccessPointTest {
WifiConfiguration.NetworkSelectionStatus status =
mock(WifiConfiguration.NetworkSelectionStatus.class);
when(configuration.getNetworkSelectionStatus()).thenReturn(status);
when(status.getNetworkSelectionStatus()).thenReturn(
WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED);
when(status.getNetworkSelectionDisableReason()).thenReturn(
WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD);
AccessPoint ap = new AccessPoint(mContext, configuration);
@@ -1370,13 +1372,13 @@ public class AccessPointTest {
public void testOsuAccessPointSummary_showsProvisioningUpdates() {
OsuProvider provider = createOsuProvider();
Context spyContext = spy(new ContextWrapper(mContext));
AccessPoint osuAccessPoint = new AccessPoint(spyContext, provider,
mScanResults);
when(spyContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mMockWifiManager);
Map<OsuProvider, PasspointConfiguration> osuProviderConfigMap = new HashMap<>();
osuProviderConfigMap.put(provider, null);
when(spyContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mMockWifiManager);
when(mMockWifiManager.getMatchingPasspointConfigsForOsuProviders(
Collections.singleton(provider))).thenReturn(osuProviderConfigMap);
AccessPoint osuAccessPoint = new AccessPoint(spyContext, provider,
mScanResults);
osuAccessPoint.setListener(mMockAccessPointListener);

View File

@@ -1709,7 +1709,10 @@ public class WifiConfiguration implements Parcelable {
return mStatus;
}
/** True if the current network is enabled to join network selection, false otherwise. */
/**
* True if the current network is enabled to join network selection, false otherwise.
* @hide
*/
public boolean isNetworkEnabled() {
return mStatus == NETWORK_SELECTION_ENABLED;
}
@@ -1722,7 +1725,10 @@ public class WifiConfiguration implements Parcelable {
return mStatus == NETWORK_SELECTION_TEMPORARY_DISABLED;
}
/** True if the current network is permanently disabled, false otherwise. */
/**
* True if the current network is permanently disabled, false otherwise.
* @hide
*/
public boolean isNetworkPermanentlyDisabled() {
return mStatus == NETWORK_SELECTION_PERMANENTLY_DISABLED;
}