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

Commit e6d6949b authored by David Su's avatar David Su
Browse files

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
parent a52e3168
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+25 −1
Original line number Diff line number Diff line
@@ -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
+14 −0
Original line number Diff line number Diff line
@@ -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.