Wifi: Hide NETWORK_SELECTION_DISABLED_MAX

NETWORK_SELECTION_DISABLED_MAX is a
constant, but it could change if a
new reason is added.

Instead expose a static method
getMaxNetworkSelectionDisableReason().

Bug: 146046526
Test: atest FrameworksWifiApiTests
Change-Id: I2fde8a0207b12d9055ed0cd4b6346b678a2819bf
This commit is contained in:
David Su
2020-02-04 17:26:46 -08:00
parent a52e3168d4
commit e6d6949b9a
3 changed files with 40 additions and 2 deletions

View File

@@ -7559,6 +7559,7 @@ package android.net.wifi {
@Deprecated public static class WifiConfiguration.NetworkSelectionStatus {
method @Deprecated public int getDisableReasonCounter(int);
method @Deprecated public long getDisableTime();
method @Deprecated public static int getMaxNetworkSelectionDisableReason();
method @Deprecated @Nullable public static String getNetworkDisableReasonString(int);
method @Deprecated public int getNetworkSelectionDisableReason();
method @Deprecated public int getNetworkSelectionStatus();
@@ -7574,7 +7575,6 @@ package android.net.wifi {
field @Deprecated public static final int DISABLED_NONE = 0; // 0x0
field @Deprecated public static final int DISABLED_NO_INTERNET_PERMANENT = 6; // 0x6
field @Deprecated public static final int DISABLED_NO_INTERNET_TEMPORARY = 4; // 0x4
field @Deprecated public static final int NETWORK_SELECTION_DISABLED_MAX = 10; // 0xa
field @Deprecated public static final int NETWORK_SELECTION_ENABLED = 0; // 0x0
field @Deprecated public static final int NETWORK_SELECTION_PERMANENTLY_DISABLED = 2; // 0x2
field @Deprecated public static final int NETWORK_SELECTION_TEMPORARY_DISABLED = 1; // 0x1

View File

@@ -1304,9 +1304,33 @@ public class WifiConfiguration implements Parcelable {
public static final int DISABLED_BY_WRONG_PASSWORD = 8;
/** This network is disabled because service is not subscribed. */
public static final int DISABLED_AUTHENTICATION_NO_SUBSCRIPTION = 9;
/** All other disable reasons should be strictly less than this value. */
/**
* All other disable reasons should be strictly less than this value.
* @hide
*/
public static final int NETWORK_SELECTION_DISABLED_MAX = 10;
/**
* Get an integer that is equal to the maximum integer value of all the
* DISABLED_* reasons
* e.g. {@link #DISABLED_NONE}, {@link #DISABLED_ASSOCIATION_REJECTION}, etc.
*
* All DISABLED_* constants will be contiguous in the range
* 0, 1, 2, 3, ..., getMaxNetworkSelectionDisableReasons()
*
* <br />
* For example, this can be used to iterate through all the network selection
* disable reasons like so:
* <pre>{@code
* for (int reason = 0; reason <= getMaxNetworkSelectionDisableReasons(); reason++) {
* ...
* }
* }</pre>
*/
public static int getMaxNetworkSelectionDisableReason() {
return NETWORK_SELECTION_DISABLED_MAX - 1;
}
/**
* Contains info about disable reasons.
* @hide

View File

@@ -335,6 +335,20 @@ public class WifiConfigurationTest {
}
}
/**
* Ensure that {@link NetworkSelectionStatus#getMaxNetworkSelectionDisableReason()} returns
* the maximum disable reason.
*/
@Test
public void testNetworkSelectionGetMaxNetworkSelectionDisableReason() {
int maxReason = Integer.MIN_VALUE;
for (int i = 0; i < NetworkSelectionStatus.DISABLE_REASON_INFOS.size(); i++) {
int reason = NetworkSelectionStatus.DISABLE_REASON_INFOS.keyAt(i);
maxReason = Math.max(maxReason, reason);
}
assertEquals(maxReason, NetworkSelectionStatus.getMaxNetworkSelectionDisableReason());
}
/**
* Ensure that {@link WifiConfiguration#setSecurityParams(int)} sets up the
* {@link WifiConfiguration} object correctly for SAE security type.