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

Commit a969d029 authored by Jimmy Chen's avatar Jimmy Chen
Browse files

p2p: add valid string documentation for network name and passphrase

Bug: 126614191
Test: Unit tests - atest FrameworksWifiApiTests
Change-Id: I105589aa3b6ee184be7fe82a8b657c76247f9ad6
parent d1ebd798
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -257,7 +257,9 @@ public class WifiP2pConfig implements Parcelable {
         * <p>
         * A network name shall begin with "DIRECT-xy". x and y are selected
         * from the following character set: upper case letters, lower case
         * letters and numbers.
         * letters and numbers. Any byte values allowed for an SSID according to
         * IEEE802.11-2012 [1] may be included after the string "DIRECT-xy"
         * (including none).
         * <p>
         *     Must be called - an empty network name or an network name
         *     not conforming to the P2P Group ID naming rule is not valid.
@@ -286,6 +288,9 @@ public class WifiP2pConfig implements Parcelable {
        /**
         * Specify the passphrase for creating or joining a group.
         * <p>
         * The passphrase must be an ASCII string whose length is between 8
         * and 63.
         * <p>
         *     Must be called - an empty passphrase is not valid.
         *
         * @param passphrase the passphrase of a group.
@@ -297,6 +302,10 @@ public class WifiP2pConfig implements Parcelable {
                throw new IllegalArgumentException(
                        "passphrase must be non-empty.");
            }
            if (passphrase.length() < 8 || passphrase.length() > 63) {
                throw new IllegalArgumentException(
                        "The length of a passphrase must be between 8 and 63.");
            }
            mPassphrase = passphrase;
            return this;
        }
+40 −0
Original line number Diff line number Diff line
@@ -73,4 +73,44 @@ public class WifiP2pConfigTest {
            fail("expected IllegalArgumentException");
        } catch (IllegalArgumentException e) { }
    }

    /**
     * Check passphrase setter
     */
    @Test
    public void testBuilderInvalidPassphrase() throws Exception {
        WifiP2pConfig.Builder b = new WifiP2pConfig.Builder();

        // sunny case
        try {
            b.setPassphrase("abcd1234");
        } catch (IllegalArgumentException e) {
            fail("Unexpected IllegalArgumentException");
        }

        // null string.
        try {
            b.setPassphrase(null);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected exception.
        }

        // less than 8 characters.
        try {
            b.setPassphrase("12abcde");
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected exception.
        }

        // more than 63 characters.
        try {
            b.setPassphrase(
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+/");
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected exception.
        }
    }
}