1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.net.TetheringManager.TetheringType; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import java.util.Objects; 27 28 /** 29 * The mapping of tethering interface and type. 30 * @hide 31 */ 32 @SystemApi 33 public final class TetheringInterface implements Parcelable { 34 private final int mType; 35 private final String mInterface; 36 TetheringInterface(@etheringType int type, @NonNull String iface)37 public TetheringInterface(@TetheringType int type, @NonNull String iface) { 38 Objects.requireNonNull(iface); 39 mType = type; 40 mInterface = iface; 41 } 42 TetheringInterface(@onNull Parcel in)43 private TetheringInterface(@NonNull Parcel in) { 44 this(in.readInt(), in.readString()); 45 } 46 47 /** Get tethering type. */ getType()48 public int getType() { 49 return mType; 50 } 51 52 /** Get tethering interface. */ 53 @NonNull getInterface()54 public String getInterface() { 55 return mInterface; 56 } 57 58 @Override writeToParcel(@onNull Parcel dest, int flags)59 public void writeToParcel(@NonNull Parcel dest, int flags) { 60 dest.writeInt(mType); 61 dest.writeString(mInterface); 62 } 63 64 @Override hashCode()65 public int hashCode() { 66 return Objects.hash(mType, mInterface); 67 } 68 69 @Override equals(@ullable Object obj)70 public boolean equals(@Nullable Object obj) { 71 if (!(obj instanceof TetheringInterface)) return false; 72 final TetheringInterface other = (TetheringInterface) obj; 73 return mType == other.mType && mInterface.equals(other.mInterface); 74 } 75 76 @Override describeContents()77 public int describeContents() { 78 return 0; 79 } 80 81 @NonNull 82 public static final Creator<TetheringInterface> CREATOR = new Creator<TetheringInterface>() { 83 @NonNull 84 @Override 85 public TetheringInterface createFromParcel(@NonNull Parcel in) { 86 return new TetheringInterface(in); 87 } 88 89 @NonNull 90 @Override 91 public TetheringInterface[] newArray(int size) { 92 return new TetheringInterface[size]; 93 } 94 }; 95 96 @NonNull 97 @Override toString()98 public String toString() { 99 return "TetheringInterface {mType=" + mType 100 + ", mInterface=" + mInterface + "}"; 101 } 102 } 103