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

Commit 27c3df8e authored by Hai Shalom's avatar Hai Shalom
Browse files

[Passpoint] Create an API to get a unique identifier

Create an API to get a unique identifier of a
PasspointConfiguration object.

Bug: 148555465
Test: atest PasspointConfigurationTest
Change-Id: I74ada04d21b1b8df28b78ca4dd91482bf79dc6cc
parent 505fb760
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31616,6 +31616,7 @@ package android.net.wifi.hotspot2 {
    method public android.net.wifi.hotspot2.pps.Credential getCredential();
    method public android.net.wifi.hotspot2.pps.HomeSp getHomeSp();
    method public long getSubscriptionExpirationTimeInMillis();
    method @NonNull public String getUniqueId() throws java.lang.IllegalStateException;
    method public boolean isOsuProvisioned();
    method public void setCredential(android.net.wifi.hotspot2.pps.Credential);
    method public void setHomeSp(android.net.wifi.hotspot2.pps.HomeSp);
+15 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.net.wifi.hotspot2;
import static android.net.wifi.WifiConfiguration.METERED_OVERRIDE_NONE;
import static android.net.wifi.WifiConfiguration.MeteredOverride;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.wifi.hotspot2.pps.Credential;
@@ -895,4 +896,18 @@ public final class PasspointConfiguration implements Parcelable {
    public boolean isOsuProvisioned() {
        return getUpdateIdentifier() != Integer.MIN_VALUE;
    }

    /**
     * Get a unique identifier for a PasspointConfiguration object.
     *
     * @return A unique identifier
     * @throws IllegalStateException if Credential or HomeSP nodes are not initialized
     */
    public @NonNull String getUniqueId() throws IllegalStateException {
        if (mCredential == null || mHomeSp == null || TextUtils.isEmpty(mHomeSp.getFqdn())) {
            throw new IllegalStateException("Credential or HomeSP are not initialized");
        }

        return mHomeSp.getFqdn();
    }
}
+51 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net.wifi.hotspot2;

import static android.net.wifi.WifiConfiguration.METERED_OVERRIDE_NONE;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@@ -364,4 +365,54 @@ public class PasspointConfigurationTest {
        assertTrue(config.validateForR2());
        assertTrue(config.isOsuProvisioned());
    }

    /**
     * Verify that the unique identifier generated is correct.
     *
     * @throws Exception
     */
    @Test
    public void validateUniqueId() throws Exception {
        PasspointConfiguration config = PasspointTestUtils.createConfig();
        String uniqueId;
        uniqueId = config.getUniqueId();
        assertEquals(uniqueId, config.getHomeSp().getFqdn());
    }

    /**
     * Verify that the unique identifier API generates an exception if HomeSP is not initialized.
     *
     * @throws Exception
     */
    @Test
    public void validateUniqueIdExceptionWithEmptyHomeSp() throws Exception {
        PasspointConfiguration config = PasspointTestUtils.createConfig();
        config.setHomeSp(null);
        boolean exceptionCaught = false;
        try {
            String uniqueId = config.getUniqueId();
        } catch (IllegalStateException e) {
            exceptionCaught = true;
        }
        assertTrue(exceptionCaught);
    }

    /**
     * Verify that the unique identifier API generates an exception if Credential is not
     * initialized.
     *
     * @throws Exception
     */
    @Test
    public void validateUniqueIdExceptionWithEmptyCredential() throws Exception {
        PasspointConfiguration config = PasspointTestUtils.createConfig();
        config.setCredential(null);
        boolean exceptionCaught = false;
        try {
            String uniqueId = config.getUniqueId();
        } catch (IllegalStateException e) {
            exceptionCaught = true;
        }
        assertTrue(exceptionCaught);
    }
}