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

Commit cbc40c91 authored by Ecco Park's avatar Ecco Park
Browse files

passpoint-r2: define getMatchingPasspointConfigsForOsuProviders API



Given a list of OSU providers, this only returns OSU providers
that already have Passpoint R2 configurations in the device.

This API is required to remove OSU provider entries that already have
the passpoint r2 profile in the device on Settings UI

Bug: 119514793
Test: ./frameworks/base/wifi/tests/runtests.sh
Test: tested with R1 AP for installing profile and R2 AP for connection
Change-Id: I111e380b3031ff268721c80501257c638f64e01a
Signed-off-by: default avatarEcco Park <eccopark@google.com>
parent 4258dfea
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ interface IWifiManager

    List<OsuProvider> getMatchingOsuProviders(in List<ScanResult> scanResult);

    Map getMatchingPasspointConfigsForOsuProviders(in List<OsuProvider> osuProviders);

    int addOrUpdateNetwork(in WifiConfiguration config, String packageName);

    boolean addOrUpdatePasspointConfiguration(in PasspointConfiguration config, String packageName);
+27 −0
Original line number Diff line number Diff line
@@ -57,8 +57,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;

/**
@@ -1229,6 +1232,30 @@ public class WifiManager {
        }
    }

    /**
     * Returns the matching Passpoint R2 configurations for given OSU (Online Sign-Up) providers.
     *
     * Given a list of OSU providers, this only returns OSU providers that already have Passpoint R2
     * configurations in the device.
     * An empty map will be returned when there is no matching Passpoint R2 configuration for the
     * given OsuProviders.
     *
     * @param osuProviders a set of {@link OsuProvider}
     * @return Map that consists of {@link OsuProvider} and matching {@link PasspointConfiguration}.
     * @throws UnsupportedOperationException if Passpoint is not enabled on the device.
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
    public Map<OsuProvider, PasspointConfiguration> getMatchingPasspointConfigsForOsuProviders(
            @NonNull Set<OsuProvider> osuProviders) {
        try {
            return mService.getMatchingPasspointConfigsForOsuProviders(
                    new ArrayList<>(osuProviders));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Add a new network description to the set of configured networks.
     * The {@code networkId} field of the supplied configuration object
+63 −29
Original line number Diff line number Diff line
@@ -19,13 +19,16 @@ package android.net.wifi.hotspot2;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.wifi.WifiSsid;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

/**
@@ -52,9 +55,9 @@ public final class OsuProvider implements Parcelable {
    private WifiSsid mOsuSsid;

    /**
     * Friendly name of the OSU provider.
     * Map of friendly names expressed as different language for the OSU provider.
     */
    private final String mFriendlyName;
    private final Map<String, String> mFriendlyNames;

    /**
     * Description of the OSU provider.
@@ -81,10 +84,11 @@ public final class OsuProvider implements Parcelable {
     */
    private final Icon mIcon;

    public OsuProvider(WifiSsid osuSsid, String friendlyName, String serviceDescription,
            Uri serverUri, String nai, List<Integer> methodList, Icon icon) {
    public OsuProvider(WifiSsid osuSsid, Map<String, String> friendlyNames,
            String serviceDescription, Uri serverUri, String nai, List<Integer> methodList,
            Icon icon) {
        mOsuSsid = osuSsid;
        mFriendlyName = friendlyName;
        mFriendlyNames = friendlyNames;
        mServiceDescription = serviceDescription;
        mServerUri = serverUri;
        mNetworkAccessIdentifier = nai;
@@ -104,7 +108,7 @@ public final class OsuProvider implements Parcelable {
    public OsuProvider(OsuProvider source) {
        if (source == null) {
            mOsuSsid = null;
            mFriendlyName = null;
            mFriendlyNames = null;
            mServiceDescription = null;
            mServerUri = null;
            mNetworkAccessIdentifier = null;
@@ -114,7 +118,7 @@ public final class OsuProvider implements Parcelable {
        }

        mOsuSsid = source.mOsuSsid;
        mFriendlyName = source.mFriendlyName;
        mFriendlyNames = source.mFriendlyNames;
        mServiceDescription = source.mServiceDescription;
        mServerUri = source.mServerUri;
        mNetworkAccessIdentifier = source.mNetworkAccessIdentifier;
@@ -134,8 +138,32 @@ public final class OsuProvider implements Parcelable {
        mOsuSsid = osuSsid;
    }

    /**
     * Return the friendly Name for current language from the list of friendly names of OSU
     * provider.
     *
     * The string matching the default locale will be returned if it is found, otherwise the string
     * in english or the first string in the list will be returned if english is not found.
     * A null will be returned if the list is empty.
     *
     * @return String matching the default locale, null otherwise
     */
    public String getFriendlyName() {
        return mFriendlyName;
        if (mFriendlyNames == null || mFriendlyNames.isEmpty()) return null;
        String lang = Locale.getDefault().getLanguage();
        String friendlyName = mFriendlyNames.get(lang);
        if (friendlyName != null) {
            return friendlyName;
        }
        friendlyName = mFriendlyNames.get("en");
        if (friendlyName != null) {
            return friendlyName;
        }
        return mFriendlyNames.get(mFriendlyNames.keySet().stream().findFirst().get());
    }

    public Map<String, String> getFriendlyNameList() {
        return mFriendlyNames;
    }

    public String getServiceDescription() {
@@ -151,7 +179,7 @@ public final class OsuProvider implements Parcelable {
    }

    public List<Integer> getMethodList() {
        return Collections.unmodifiableList(mMethodList);
        return mMethodList;
    }

    public Icon getIcon() {
@@ -166,12 +194,14 @@ public final class OsuProvider implements Parcelable {
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(mOsuSsid, flags);
        dest.writeString(mFriendlyName);
        dest.writeString(mServiceDescription);
        dest.writeParcelable(mServerUri, flags);
        dest.writeString(mNetworkAccessIdentifier);
        dest.writeList(mMethodList);
        dest.writeParcelable(mIcon, flags);
        Bundle bundle = new Bundle();
        bundle.putSerializable("friendlyNameMap", (HashMap<String, String>) mFriendlyNames);
        dest.writeBundle(bundle);
    }

    @Override
@@ -184,7 +214,8 @@ public final class OsuProvider implements Parcelable {
        }
        OsuProvider that = (OsuProvider) thatObject;
        return (mOsuSsid == null ? that.mOsuSsid == null : mOsuSsid.equals(that.mOsuSsid))
                && TextUtils.equals(mFriendlyName, that.mFriendlyName)
                && (mFriendlyNames == null) ? that.mFriendlyNames == null
                            : mFriendlyNames.equals(that.mFriendlyNames)
                && TextUtils.equals(mServiceDescription, that.mServiceDescription)
                && (mServerUri == null ? that.mServerUri == null
                            : mServerUri.equals(that.mServerUri))
@@ -196,14 +227,15 @@ public final class OsuProvider implements Parcelable {

    @Override
    public int hashCode() {
        return Objects.hash(mOsuSsid, mFriendlyName, mServiceDescription, mServerUri,
                mNetworkAccessIdentifier, mMethodList, mIcon);
        // mIcon is not hashable, skip the variable.
        return Objects.hash(mOsuSsid, mServiceDescription, mFriendlyNames,
                mServerUri, mNetworkAccessIdentifier, mMethodList);
    }

    @Override
    public String toString() {
        return "OsuProvider{mOsuSsid=" + mOsuSsid
                + " mFriendlyName=" + mFriendlyName
                + " mFriendlyNames=" + mFriendlyNames
                + " mServiceDescription=" + mServiceDescription
                + " mServerUri=" + mServerUri
                + " mNetworkAccessIdentifier=" + mNetworkAccessIdentifier
@@ -215,16 +247,18 @@ public final class OsuProvider implements Parcelable {
            new Creator<OsuProvider>() {
                @Override
                public OsuProvider createFromParcel(Parcel in) {
                WifiSsid osuSsid = (WifiSsid) in.readParcelable(null);
                String friendlyName = in.readString();
                    WifiSsid osuSsid = in.readParcelable(null);
                    String serviceDescription = in.readString();
                Uri serverUri = (Uri) in.readParcelable(null);
                    Uri serverUri = in.readParcelable(null);
                    String nai = in.readString();
                    List<Integer> methodList = new ArrayList<>();
                    in.readList(methodList, null);
                Icon icon = (Icon) in.readParcelable(null);
                return new OsuProvider(osuSsid, friendlyName, serviceDescription, serverUri,
                        nai, methodList, icon);
                    Icon icon = in.readParcelable(null);
                    Bundle bundle = in.readBundle();
                    Map<String, String> friendlyNamesMap = (HashMap) bundle.getSerializable(
                            "friendlyNameMap");
                    return new OsuProvider(osuSsid, friendlyNamesMap, serviceDescription,
                            serverUri, nai, methodList, icon);
                }

            @Override
+65 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.net.wifi.hotspot2.pps.Credential;
import android.net.wifi.hotspot2.pps.HomeSp;
import android.net.wifi.hotspot2.pps.Policy;
import android.net.wifi.hotspot2.pps.UpdateParameter;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -30,6 +31,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

@@ -323,6 +325,50 @@ public final class PasspointConfiguration implements Parcelable {
        return mUsageLimitTimeLimitInMinutes;
    }

    /**
     * The map of OSU service provider names whose each element is presented in different
     * languages for the service provider, which is used for finding a matching
     * PasspointConfiguration with a given service provider name.
     */
    private Map<String, String> mServiceFriendlyNames = null;

    /**
     * @hide
     */
    public void setServiceFriendlyNames(Map<String, String> serviceFriendlyNames) {
        mServiceFriendlyNames = serviceFriendlyNames;
    }

    /**
     * @hide
     */
    public Map<String, String> getServiceFriendlyNames() {
        return mServiceFriendlyNames;
    }

    /**
     * Return the friendly Name for current language from the list of friendly names of OSU
     * provider.
     * The string matching the default locale will be returned if it is found, otherwise the
     * first string in the list will be returned.  A null will be returned if the list is empty.
     *
     * @return String matching the default locale, null otherwise
     * @hide
     */
    public String getServiceFriendlyName() {
        if (mServiceFriendlyNames == null || mServiceFriendlyNames.isEmpty()) return null;
        String lang = Locale.getDefault().getLanguage();
        String friendlyName = mServiceFriendlyNames.get(lang);
        if (friendlyName != null) {
            return friendlyName;
        }
        friendlyName = mServiceFriendlyNames.get("en");
        if (friendlyName != null) {
            return friendlyName;
        }
        return mServiceFriendlyNames.get(mServiceFriendlyNames.keySet().stream().findFirst().get());
    }

    /**
     * Constructor for creating PasspointConfiguration with default values.
     */
@@ -362,6 +408,7 @@ public final class PasspointConfiguration implements Parcelable {
        mUsageLimitStartTimeInMillis = source.mUsageLimitStartTimeInMillis;
        mUsageLimitTimeLimitInMinutes = source.mUsageLimitTimeLimitInMinutes;
        mUsageLimitUsageTimePeriodInMinutes = source.mUsageLimitUsageTimePeriodInMinutes;
        mServiceFriendlyNames = source.mServiceFriendlyNames;
    }

    @Override
@@ -385,6 +432,10 @@ public final class PasspointConfiguration implements Parcelable {
        dest.writeLong(mUsageLimitStartTimeInMillis);
        dest.writeLong(mUsageLimitDataLimit);
        dest.writeLong(mUsageLimitTimeLimitInMinutes);
        Bundle bundle = new Bundle();
        bundle.putSerializable("serviceFriendlyNames",
                (HashMap<String, String>) mServiceFriendlyNames);
        dest.writeBundle(bundle);
    }

    @Override
@@ -411,7 +462,9 @@ public final class PasspointConfiguration implements Parcelable {
                && mUsageLimitUsageTimePeriodInMinutes == that.mUsageLimitUsageTimePeriodInMinutes
                && mUsageLimitStartTimeInMillis == that.mUsageLimitStartTimeInMillis
                && mUsageLimitDataLimit == that.mUsageLimitDataLimit
                && mUsageLimitTimeLimitInMinutes == that.mUsageLimitTimeLimitInMinutes;
                && mUsageLimitTimeLimitInMinutes == that.mUsageLimitTimeLimitInMinutes
                && (mServiceFriendlyNames == null ? that.mServiceFriendlyNames == null
                : mServiceFriendlyNames.equals(that.mServiceFriendlyNames));
    }

    @Override
@@ -419,7 +472,8 @@ public final class PasspointConfiguration implements Parcelable {
        return Objects.hash(mHomeSp, mCredential, mPolicy, mSubscriptionUpdate, mTrustRootCertList,
                mUpdateIdentifier, mCredentialPriority, mSubscriptionCreationTimeInMillis,
                mSubscriptionExpirationTimeInMillis, mUsageLimitUsageTimePeriodInMinutes,
                mUsageLimitStartTimeInMillis, mUsageLimitDataLimit, mUsageLimitTimeLimitInMinutes);
                mUsageLimitStartTimeInMillis, mUsageLimitDataLimit, mUsageLimitTimeLimitInMinutes,
                mServiceFriendlyNames);
    }

    @Override
@@ -463,6 +517,9 @@ public final class PasspointConfiguration implements Parcelable {
            builder.append("TrustRootCertServers: ").append(mTrustRootCertList.keySet())
                    .append("\n");
        }
        if (mServiceFriendlyNames != null) {
            builder.append("ServiceFriendlyNames: ").append(mServiceFriendlyNames);
        }
        return builder.toString();
    }

@@ -562,6 +619,10 @@ public final class PasspointConfiguration implements Parcelable {
                config.setUsageLimitStartTimeInMillis(in.readLong());
                config.setUsageLimitDataLimit(in.readLong());
                config.setUsageLimitTimeLimitInMinutes(in.readLong());
                Bundle bundle = in.readBundle();
                Map<String, String> friendlyNamesMap = (HashMap) bundle.getSerializable(
                        "serviceFriendlyNames");
                config.setServiceFriendlyNames(friendlyNamesMap);
                return config;
            }

+7 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.os.ResultReceiver;
import android.os.WorkSource;

import java.util.List;
import java.util.Map;

/**
 * Abstract class implementing IWifiManager with stub methods throwing runtime exceptions.
@@ -126,6 +127,12 @@ public abstract class AbstractWifiService extends IWifiManager.Stub {
        throw new UnsupportedOperationException();
    }

    @Override
    public Map<OsuProvider, PasspointConfiguration> getMatchingPasspointConfigsForOsuProviders(
            List<OsuProvider> osuProviders) {
        throw new UnsupportedOperationException();
    }

    @Override
    public int addOrUpdateNetwork(WifiConfiguration config, String packageName) {
        throw new UnsupportedOperationException();
Loading