diff options
| author | Xiao Ma <xiaom@google.com> | 2021-12-16 15:14:34 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-12-16 15:14:34 +0000 |
| commit | 5266f9e9d667f23b65b51dfcebaef210ef3c5ff7 (patch) | |
| tree | cd48da0a7f24eae9684440aa2846145e5da6ea34 /framework-t/src/android/net/EthernetNetworkSpecifier.java | |
| parent | b1b2a5ebd3c99a655005e1213a533d8b37731fc1 (diff) | |
| parent | 9a735b3dd095ec3e496d23b98855a3ff17eafca8 (diff) | |
Merge "Move Ethernet related files to f/b/packages/ConnectivityT." am: 84f212ded1 am: 3190e7cc92 am: 9a735b3dd0
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1922218
Change-Id: I36c9dea2d0026357c2292cf67d1a45424adeaf12
Diffstat (limited to 'framework-t/src/android/net/EthernetNetworkSpecifier.java')
| -rw-r--r-- | framework-t/src/android/net/EthernetNetworkSpecifier.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/framework-t/src/android/net/EthernetNetworkSpecifier.java b/framework-t/src/android/net/EthernetNetworkSpecifier.java new file mode 100644 index 0000000000..62c5761442 --- /dev/null +++ b/framework-t/src/android/net/EthernetNetworkSpecifier.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SystemApi; +import android.os.Parcel; +import android.os.Parcelable; +import android.text.TextUtils; + +import com.android.internal.util.Preconditions; + +import java.util.Objects; + +/** + * A {@link NetworkSpecifier} used to identify ethernet interfaces. + * + * @see EthernetManager + * @hide + */ +@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) +public final class EthernetNetworkSpecifier extends NetworkSpecifier implements Parcelable { + + /** + * Name of the network interface. + */ + @NonNull + private final String mInterfaceName; + + /** + * Create a new EthernetNetworkSpecifier. + * @param interfaceName Name of the ethernet interface the specifier refers to. + */ + public EthernetNetworkSpecifier(@NonNull String interfaceName) { + Preconditions.checkStringNotEmpty(interfaceName); + mInterfaceName = interfaceName; + } + + /** + * Get the name of the ethernet interface the specifier refers to. + */ + @Nullable + public String getInterfaceName() { + // This may be null in the future to support specifiers based on data other than the + // interface name. + return mInterfaceName; + } + + @Override + public boolean canBeSatisfiedBy(@Nullable NetworkSpecifier other) { + return equals(other); + } + + @Override + public boolean equals(@Nullable Object o) { + if (!(o instanceof EthernetNetworkSpecifier)) return false; + return TextUtils.equals(mInterfaceName, ((EthernetNetworkSpecifier) o).mInterfaceName); + } + + @Override + public int hashCode() { + return Objects.hashCode(mInterfaceName); + } + + @Override + public String toString() { + return "EthernetNetworkSpecifier (" + mInterfaceName + ")"; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeString(mInterfaceName); + } + + public static final @NonNull Parcelable.Creator<EthernetNetworkSpecifier> CREATOR = + new Parcelable.Creator<EthernetNetworkSpecifier>() { + public EthernetNetworkSpecifier createFromParcel(Parcel in) { + return new EthernetNetworkSpecifier(in.readString()); + } + public EthernetNetworkSpecifier[] newArray(int size) { + return new EthernetNetworkSpecifier[size]; + } + }; +} |
