Merge "[FUI09] Expose NetworkStateSnapshot as system API"

This commit is contained in:
Treehugger Robot
2021-03-02 16:08:03 +00:00
committed by Gerrit Code Review
2 changed files with 38 additions and 17 deletions

View File

@@ -187,8 +187,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
// TODO: Delete this function after NetworkPolicyManagerService finishes the migration. // TODO: Delete this function after NetworkPolicyManagerService finishes the migration.
public static NetworkIdentity buildNetworkIdentity(Context context, public static NetworkIdentity buildNetworkIdentity(Context context,
NetworkState state, boolean defaultNetwork, @NetworkType int subType) { NetworkState state, boolean defaultNetwork, @NetworkType int subType) {
final NetworkStateSnapshot snapshot = new NetworkStateSnapshot(state.linkProperties, final NetworkStateSnapshot snapshot = new NetworkStateSnapshot(state.network,
state.networkCapabilities, state.network, state.subscriberId, state.networkCapabilities, state.linkProperties, state.subscriberId,
state.legacyNetworkType); state.legacyNetworkType);
return buildNetworkIdentity(context, snapshot, defaultNetwork, subType); return buildNetworkIdentity(context, snapshot, defaultNetwork, subType);
} }

View File

@@ -16,8 +16,11 @@
package android.net; package android.net;
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -28,31 +31,49 @@ import java.util.Objects;
* *
* @hide * @hide
*/ */
@SystemApi(client = MODULE_LIBRARIES)
public final class NetworkStateSnapshot implements Parcelable { public final class NetworkStateSnapshot implements Parcelable {
@NonNull /** The network associated with this snapshot. */
public final LinkProperties linkProperties;
@NonNull
public final NetworkCapabilities networkCapabilities;
@NonNull @NonNull
public final Network network; public final Network network;
/** The {@link NetworkCapabilities} of the network associated with this snapshot. */
@NonNull
public final NetworkCapabilities networkCapabilities;
/** The {@link LinkProperties} of the network associated with this snapshot. */
@NonNull
public final LinkProperties linkProperties;
/**
* The Subscriber Id of the network associated with this snapshot. See
* {@link android.telephony.TelephonyManager#getSubscriberId()}.
*/
@Nullable @Nullable
public final String subscriberId; public final String subscriberId;
/**
* The legacy type of the network associated with this snapshot. See
* {@code ConnectivityManager#TYPE_*}.
*/
public final int legacyType; public final int legacyType;
public NetworkStateSnapshot(@NonNull LinkProperties linkProperties, public NetworkStateSnapshot(@NonNull Network network,
@NonNull NetworkCapabilities networkCapabilities, @NonNull Network network, @NonNull NetworkCapabilities networkCapabilities,
@NonNull LinkProperties linkProperties,
@Nullable String subscriberId, int legacyType) { @Nullable String subscriberId, int legacyType) {
this.linkProperties = Objects.requireNonNull(linkProperties);
this.networkCapabilities = Objects.requireNonNull(networkCapabilities);
this.network = Objects.requireNonNull(network); this.network = Objects.requireNonNull(network);
this.networkCapabilities = Objects.requireNonNull(networkCapabilities);
this.linkProperties = Objects.requireNonNull(linkProperties);
this.subscriberId = subscriberId; this.subscriberId = subscriberId;
this.legacyType = legacyType; this.legacyType = legacyType;
} }
/** @hide */
public NetworkStateSnapshot(@NonNull Parcel in) { public NetworkStateSnapshot(@NonNull Parcel in) {
linkProperties = in.readParcelable(null);
networkCapabilities = in.readParcelable(null);
network = in.readParcelable(null); network = in.readParcelable(null);
networkCapabilities = in.readParcelable(null);
linkProperties = in.readParcelable(null);
subscriberId = in.readString(); subscriberId = in.readString();
legacyType = in.readInt(); legacyType = in.readInt();
} }
@@ -64,9 +85,9 @@ public final class NetworkStateSnapshot implements Parcelable {
@Override @Override
public void writeToParcel(@NonNull Parcel out, int flags) { public void writeToParcel(@NonNull Parcel out, int flags) {
out.writeParcelable(linkProperties, flags);
out.writeParcelable(networkCapabilities, flags);
out.writeParcelable(network, flags); out.writeParcelable(network, flags);
out.writeParcelable(networkCapabilities, flags);
out.writeParcelable(linkProperties, flags);
out.writeString(subscriberId); out.writeString(subscriberId);
out.writeInt(legacyType); out.writeInt(legacyType);
} }
@@ -93,14 +114,14 @@ public final class NetworkStateSnapshot implements Parcelable {
if (!(o instanceof NetworkStateSnapshot)) return false; if (!(o instanceof NetworkStateSnapshot)) return false;
NetworkStateSnapshot that = (NetworkStateSnapshot) o; NetworkStateSnapshot that = (NetworkStateSnapshot) o;
return legacyType == that.legacyType return legacyType == that.legacyType
&& Objects.equals(linkProperties, that.linkProperties)
&& Objects.equals(networkCapabilities, that.networkCapabilities)
&& Objects.equals(network, that.network) && Objects.equals(network, that.network)
&& Objects.equals(networkCapabilities, that.networkCapabilities)
&& Objects.equals(linkProperties, that.linkProperties)
&& Objects.equals(subscriberId, that.subscriberId); && Objects.equals(subscriberId, that.subscriberId);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(linkProperties, networkCapabilities, network, subscriberId, legacyType); return Objects.hash(network, networkCapabilities, linkProperties, subscriberId, legacyType);
} }
} }