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

Commit 89cd026a authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by paulhu
Browse files

Show notifications after capport login

Add NetworkStackNotifier to manage notifications created by
NetworkStack.
NetworkStackNotifier handles the "connected" notifications shown after
connecting to a captive portal, which may contain information sourced
from the captive portal API.

Test: atest NetworkStackTests
Bug: 139269711
Change-Id: Iaf96f7e5f02be04b098230316595ad4c0777a9d8
parent f998552c
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ import android.net.Uri;

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

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

/**
@@ -44,6 +46,14 @@ public class NetworkInformationShimImpl implements NetworkInformationShim {
        return new NetworkInformationShimImpl();
    }

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

    @Nullable
    @Override
    public Uri getCaptivePortalApiUrl(@Nullable LinkProperties lp) {
@@ -56,6 +66,12 @@ public class NetworkInformationShimImpl implements NetworkInformationShim {
        // Not supported on this API level: no-op
    }

    @Nullable
    @Override
    public CaptivePortalDataShim getCaptivePortalData(@Nullable LinkProperties lp) {
        return null;
    }

    @Nullable
    @Override
    public String getSSID(@Nullable NetworkCapabilities nc) {
+5 −0
Original line number Diff line number Diff line
@@ -95,6 +95,11 @@ public class CaptivePortalDataShimImpl
        return mData.getUserPortalUrl();
    }

    @Override
    public Uri getVenueInfoUrl() {
        return mData.getVenueInfoUrl();
    }

    @Override
    public void notifyChanged(INetworkMonitorCallbacks cb) throws RemoteException {
        cb.notifyCaptivePortalDataChanged(mData);
+17 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Build;

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

/**
 * Compatibility implementation of {@link NetworkInformationShim}.
@@ -35,12 +36,20 @@ public class NetworkInformationShimImpl extends
     * Get a new instance of {@link NetworkInformationShim}.
     */
    public static NetworkInformationShim newInstance() {
        if (!ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) {
        if (!useApiAboveQ()) {
            return com.android.networkstack.apishim.api29.NetworkInformationShimImpl.newInstance();
        }
        return new NetworkInformationShimImpl();
    }

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

    @Nullable
    @Override
    public Uri getCaptivePortalApiUrl(@Nullable LinkProperties lp) {
@@ -53,6 +62,13 @@ public class NetworkInformationShimImpl extends
        lp.setCaptivePortalApiUrl(url);
    }

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

    @Nullable
    @Override
    public String getSSID(@Nullable NetworkCapabilities nc) {
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@ public interface CaptivePortalDataShim {
     */
    Uri getUserPortalUrl();

    /**
     * @see android.net.CaptivePortalData#getVenueInfoUrl()
     */
    Uri getVenueInfoUrl();

    /**
     * @see INetworkMonitorCallbacks#notifyCaptivePortalDataChanged(android.net.CaptivePortalData)
     */
+6 −0
Original line number Diff line number Diff line
@@ -39,6 +39,12 @@ public interface NetworkInformationShim {
     */
    void setCaptivePortalApiUrl(@NonNull LinkProperties lp, @Nullable Uri url);

    /**
     * @see LinkProperties#getCaptivePortalData()
     */
    @Nullable
    CaptivePortalDataShim getCaptivePortalData(@Nullable LinkProperties lp);

    /**
     * @see NetworkCapabilities#getSSID()
     */
Loading