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

Commit 6776ba07 authored by Hai Shalom's avatar Hai Shalom Committed by Gerrit Code Review
Browse files

Merge "Support for Venue friendly name"

parents b942012f 206d707d
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.networkstack.apishim.api29;

import android.net.CaptivePortalData;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

@@ -48,8 +50,25 @@ public abstract class CaptivePortalDataShimImpl implements CaptivePortalDataShim
        throw new UnsupportedApiLevelException("CaptivePortalData not supported on API 29");
    }

    @Override
    public String getVenueFriendlyName() {
        // Not supported in API level 29
        return null;
    }

    @VisibleForTesting
    public static boolean isSupported() {
        return false;
    }

    /**
     * Generate a {@link CaptivePortalData} object with a friendly name set
     *
     * @param friendlyName The friendly name to set
     * @return a {@link CaptivePortalData} object with a friendly name set
     */
    public CaptivePortalData withVenueFriendlyName(String friendlyName) {
        // Not supported in API level 29
        return null;
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.networkstack.apishim.api29;

import android.net.CaptivePortalData;
import android.net.IpPrefix;
import android.net.LinkProperties;
import android.net.NetworkCapabilities;
@@ -57,6 +58,14 @@ public class NetworkInformationShimImpl implements NetworkInformationShim {
        return false;
    }

    /**
     * Indicates whether the shim can use APIs above the R SDK.
     */
    @VisibleForTesting
    public static boolean useApiAboveR() {
        return false;
    }

    @Nullable
    @Override
    public Uri getCaptivePortalApiUrl(@Nullable LinkProperties lp) {
@@ -105,4 +114,17 @@ public class NetworkInformationShimImpl implements NetworkInformationShim {
            @NonNull Inet4Address serverAddress) {
        // Not supported on this API level: no-op
    }

    /**
     * Set captive portal data in {@link LinkProperties}
     * @param lp Link properties object to be updated
     * @param captivePortalData Captive portal data to be used
     */
    public void setCaptivePortalData(@NonNull LinkProperties lp,
            @Nullable CaptivePortalData captivePortalData) {
        if (lp == null) {
            return;
        }
        lp.setCaptivePortalData(captivePortalData);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import org.json.JSONObject;
public class CaptivePortalDataShimImpl
        extends com.android.networkstack.apishim.api29.CaptivePortalDataShimImpl {
    @NonNull
    private final CaptivePortalData mData;
    protected final CaptivePortalData mData;

    protected CaptivePortalDataShimImpl(@NonNull CaptivePortalData data) {
        mData = data;
+19 −1
Original line number Diff line number Diff line
@@ -20,13 +20,31 @@ import android.net.CaptivePortalData;

import androidx.annotation.NonNull;

import com.android.networkstack.apishim.common.CaptivePortalDataShim;

/**
 * Compatibility implementation of {@link CaptivePortalDataShim}.
 */
public class CaptivePortalDataShimImpl
        extends com.android.networkstack.apishim.api30.CaptivePortalDataShimImpl {
    // Currently, this is the same as the API 30 shim, so inherit everything from that.
    protected CaptivePortalDataShimImpl(@NonNull CaptivePortalData data) {
        super(data);
    }

    @Override
    public String getVenueFriendlyName() {
        return mData.getVenueFriendlyName();
    }

    /**
     * Generate a {@link CaptivePortalData} object with a friendly name set
     *
     * @param friendlyName The friendly name to set
     * @return a {@link CaptivePortalData} object with a friendly name set
     */
    public CaptivePortalData withVenueFriendlyName(String friendlyName) {
        return new CaptivePortalData.Builder(mData)
                .setVenueFriendlyName(friendlyName)
                .build();
    }
}
+35 −1
Original line number Diff line number Diff line
@@ -16,11 +16,45 @@

package com.android.networkstack.apishim;

import android.net.LinkProperties;
import android.os.Build;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.networkstack.apishim.common.CaptivePortalDataShim;
import com.android.networkstack.apishim.common.NetworkInformationShim;
import com.android.networkstack.apishim.common.ShimUtils;

/**
 * Compatibility implementation of {@link NetworkInformationShim}.
 */
public class NetworkInformationShimImpl
        extends com.android.networkstack.apishim.api30.NetworkInformationShimImpl {
    // Currently, this is the same as the API 30 shim, so inherit everything from that.
    protected NetworkInformationShimImpl() {}

    /**
     * Indicates whether the shim can use APIs above the R SDK.
     */
    @VisibleForTesting
    public static boolean useApiAboveR() {
        return ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.R);
    }

    /**
     * Get a new instance of {@link NetworkInformationShim}.
     */
    public static NetworkInformationShim newInstance() {
        if (!useApiAboveR()) {
            return com.android.networkstack.apishim.api30.NetworkInformationShimImpl.newInstance();
        }
        return new com.android.networkstack.apishim.NetworkInformationShimImpl();
    }

    @Nullable
    @Override
    public CaptivePortalDataShim getCaptivePortalData(@Nullable LinkProperties lp) {
        if (lp == null || lp.getCaptivePortalData() == null) return null;
        return new CaptivePortalDataShimImpl(lp.getCaptivePortalData());
    }
}
Loading