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

Commit 6dc98549 authored by Chalard Jean's avatar Chalard Jean Committed by Aaron Huang
Browse files

Add a systemapi constructor for NetworkAgent

Bug: 138306002
Bug: 139268426
Test: atest FrameworksNetTests FrameworksWifiTests FrameworksTelephonyTests
      make doc-comment-check-docs
Change-Id: I288ea32fac07a9a486e2ea451a2c9b098446a74c
Merged-In: I288ea32fac07a9a486e2ea451a2c9b098446a74c
parent a77fbc25
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -4593,6 +4593,7 @@ package android.net {
  }
  }
  public abstract class NetworkAgent {
  public abstract class NetworkAgent {
    ctor public NetworkAgent(@NonNull android.content.Context, @NonNull android.os.Looper, @NonNull String, @NonNull android.net.NetworkCapabilities, @NonNull android.net.LinkProperties, int, @NonNull android.net.NetworkAgentConfig, @Nullable android.net.NetworkProvider);
    method public void onAddKeepalivePacketFilter(int, @NonNull android.net.KeepalivePacketData);
    method public void onAddKeepalivePacketFilter(int, @NonNull android.net.KeepalivePacketData);
    method public void onAutomaticReconnectDisabled();
    method public void onAutomaticReconnectDisabled();
    method public void onBandwidthUpdateRequested();
    method public void onBandwidthUpdateRequested();
@@ -4615,6 +4616,8 @@ package android.net {
  public final class NetworkAgentConfig implements android.os.Parcelable {
  public final class NetworkAgentConfig implements android.os.Parcelable {
    method public int describeContents();
    method public int describeContents();
    method public int getLegacyType();
    method @NonNull public String getLegacyTypeName();
    method @Nullable public String getSubscriberId();
    method @Nullable public String getSubscriberId();
    method public boolean isNat64DetectionEnabled();
    method public boolean isNat64DetectionEnabled();
    method public boolean isProvisioningNotificationEnabled();
    method public boolean isProvisioningNotificationEnabled();
@@ -4627,6 +4630,8 @@ package android.net {
    method @NonNull public android.net.NetworkAgentConfig build();
    method @NonNull public android.net.NetworkAgentConfig build();
    method @NonNull public android.net.NetworkAgentConfig.Builder disableNat64Detection();
    method @NonNull public android.net.NetworkAgentConfig.Builder disableNat64Detection();
    method @NonNull public android.net.NetworkAgentConfig.Builder disableProvisioningNotification();
    method @NonNull public android.net.NetworkAgentConfig.Builder disableProvisioningNotification();
    method @NonNull public android.net.NetworkAgentConfig.Builder setLegacyType(int);
    method @NonNull public android.net.NetworkAgentConfig.Builder setLegacyTypeName(@NonNull String);
    method @NonNull public android.net.NetworkAgentConfig.Builder setSubscriberId(@Nullable String);
    method @NonNull public android.net.NetworkAgentConfig.Builder setSubscriberId(@Nullable String);
  }
  }
+36 −8
Original line number Original line Diff line number Diff line
@@ -262,32 +262,60 @@ public abstract class NetworkAgent {
     */
     */
    public static final int CMD_REMOVE_KEEPALIVE_PACKET_FILTER = BASE + 17;
    public static final int CMD_REMOVE_KEEPALIVE_PACKET_FILTER = BASE + 17;


    // TODO : remove these two constructors. They are a stopgap measure to help sheperding a number
    /** @hide TODO: remove and replace usage with the public constructor. */
    // of dependent changes that would conflict throughout the automerger graph. Having these
    // temporarily helps with the process of going through with all these dependent changes across
    // the entire tree.
    /** @hide TODO: decide which of these to expose. */
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score) {
            NetworkCapabilities nc, LinkProperties lp, int score) {
        this(looper, context, logTag, ni, nc, lp, score, null, NetworkProvider.ID_NONE);
        this(looper, context, logTag, ni, nc, lp, score, null, NetworkProvider.ID_NONE);
    }
    }


    /** @hide TODO: decide which of these to expose. */
    /** @hide TODO: remove and replace usage with the public constructor. */
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config) {
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config) {
        this(looper, context, logTag, ni, nc, lp, score, config, NetworkProvider.ID_NONE);
        this(looper, context, logTag, ni, nc, lp, score, config, NetworkProvider.ID_NONE);
    }
    }


    /** @hide TODO: decide which of these to expose. */
    /** @hide TODO: remove and replace usage with the public constructor. */
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score, int providerId) {
            NetworkCapabilities nc, LinkProperties lp, int score, int providerId) {
        this(looper, context, logTag, ni, nc, lp, score, null, providerId);
        this(looper, context, logTag, ni, nc, lp, score, null, providerId);
    }
    }


    /** @hide TODO: decide which of these to expose. */
    /** @hide TODO: remove and replace usage with the public constructor. */
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config,
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config,
            int providerId) {
            int providerId) {
        this(looper, context, logTag, nc, lp, score, config, providerId, ni);
    }

    private static NetworkInfo getLegacyNetworkInfo(final NetworkAgentConfig config) {
        // The subtype can be changed with (TODO) setLegacySubtype, but it starts
        // with the type and an empty description.
        return new NetworkInfo(config.legacyType, config.legacyType, config.legacyTypeName, "");
    }

    /**
     * Create a new network agent.
     * @param context a {@link Context} to get system services from.
     * @param looper the {@link Looper} on which to invoke the callbacks.
     * @param logTag the tag for logs
     * @param nc the initial {@link NetworkCapabilities} of this network. Update with
     *           sendNetworkCapabilities.
     * @param lp the initial {@link LinkProperties} of this network. Update with sendLinkProperties.
     * @param score the initial score of this network. Update with sendNetworkScore.
     * @param config an immutable {@link NetworkAgentConfig} for this agent.
     * @param provider the {@link NetworkProvider} managing this agent.
     */
    public NetworkAgent(@NonNull Context context, @NonNull Looper looper, @NonNull String logTag,
            @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, int score,
            @NonNull NetworkAgentConfig config, @Nullable NetworkProvider provider) {
        this(looper, context, logTag, nc, lp, score, config,
                provider == null ? NetworkProvider.ID_NONE : provider.getProviderId(),
                getLegacyNetworkInfo(config));
    }

    private NetworkAgent(Looper looper, Context context, String logTag, NetworkCapabilities nc,
            LinkProperties lp, int score, NetworkAgentConfig config, int providerId,
            NetworkInfo ni) {
        mHandler = new NetworkAgentHandler(looper);
        mHandler = new NetworkAgentHandler(looper);
        LOG_TAG = logTag;
        LOG_TAG = logTag;
        mContext = context;
        mContext = context;
+55 −3
Original line number Original line Diff line number Diff line
@@ -21,12 +21,11 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.text.TextUtils;


/**
/**
 * Allows a network transport to provide the system with policy and configuration information about
 * Allows a network transport to provide the system with policy and configuration information about
 * a particular network when registering a {@link NetworkAgent}. This information cannot change once
 * a particular network when registering a {@link NetworkAgent}.
 * the agent is registered.
 * @note This information cannot change once the agent is registered.
 *
 *
 * @hide
 * @hide
 */
 */
@@ -119,6 +118,19 @@ public final class NetworkAgentConfig implements Parcelable {
        return !skip464xlat;
        return !skip464xlat;
    }
    }


    /**
     * The legacy type of this network agent, or TYPE_NONE if unset.
     * @hide
     */
    public int legacyType = ConnectivityManager.TYPE_NONE;

    /**
     * @return the legacy type
     */
    public int getLegacyType() {
        return legacyType;
    }

    /**
    /**
     * Set to true if the PRIVATE_DNS_BROKEN notification has shown for this network.
     * Set to true if the PRIVATE_DNS_BROKEN notification has shown for this network.
     * Reset this bit when private DNS mode is changed from strict mode to opportunistic/off mode.
     * Reset this bit when private DNS mode is changed from strict mode to opportunistic/off mode.
@@ -127,6 +139,21 @@ public final class NetworkAgentConfig implements Parcelable {
     */
     */
    public boolean hasShownBroken;
    public boolean hasShownBroken;


    /**
     * The name of the legacy network type. It's a free-form string used in logging.
     * @hide
     */
    @NonNull
    public String legacyTypeName = "";

    /**
     * @return the name of the legacy network type. It's a free-form string used in logging.
     */
    @NonNull
    public String getLegacyTypeName() {
        return legacyTypeName;
    }

    /** @hide */
    /** @hide */
    public NetworkAgentConfig() {
    public NetworkAgentConfig() {
    }
    }
@@ -140,6 +167,8 @@ public final class NetworkAgentConfig implements Parcelable {
            subscriberId = nac.subscriberId;
            subscriberId = nac.subscriberId;
            provisioningNotificationDisabled = nac.provisioningNotificationDisabled;
            provisioningNotificationDisabled = nac.provisioningNotificationDisabled;
            skip464xlat = nac.skip464xlat;
            skip464xlat = nac.skip464xlat;
            legacyType = nac.legacyType;
            legacyTypeName = nac.legacyTypeName;
        }
        }
    }
    }


@@ -184,6 +213,29 @@ public final class NetworkAgentConfig implements Parcelable {
            return this;
            return this;
        }
        }


        /**
         * Sets the legacy type for this network.
         *
         * @param legacyType the type
         * @return this builder, to facilitate chaining.
         */
        @NonNull
        public Builder setLegacyType(int legacyType) {
            mConfig.legacyType = legacyType;
            return this;
        }

        /**
         * Sets the name of the legacy type of the agent. It's a free-form string used in logging.
         * @param legacyTypeName the name
         * @return this builder, to facilitate chaining.
         */
        @NonNull
        public Builder setLegacyTypeName(@NonNull String legacyTypeName) {
            mConfig.legacyTypeName = legacyTypeName;
            return this;
        }

        /**
        /**
         * Returns the constructed {@link NetworkAgentConfig} object.
         * Returns the constructed {@link NetworkAgentConfig} object.
         */
         */