| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.net; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.os.Parcel; |
| 22 |
import android.os.Parcelable; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public final class TelephonyNetworkSpecifier extends NetworkSpecifier implements Parcelable { |
| 29 |
|
| 30 |
private final int mSubId; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public int getSubscriptionId() { |
| 38 |
return mSubId; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public TelephonyNetworkSpecifier(int subId) { |
| 45 |
this.mSubId = subId; |
| 46 |
} |
| 47 |
|
| 48 |
public static final @NonNull Creator<TelephonyNetworkSpecifier> CREATOR = |
| 49 |
new Creator<TelephonyNetworkSpecifier>() { |
| 50 |
@Override |
| 51 |
public TelephonyNetworkSpecifier createFromParcel(Parcel in) { |
| 52 |
int subId = in.readInt(); |
| 53 |
return new TelephonyNetworkSpecifier(subId); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public TelephonyNetworkSpecifier[] newArray(int size) { |
| 58 |
return new TelephonyNetworkSpecifier[size]; |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
@Override |
| 63 |
public int describeContents() { |
| 64 |
return 0; |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 69 |
dest.writeInt(mSubId); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public int hashCode() { |
| 74 |
return mSubId; |
| 75 |
} |
| 76 |
|
| 77 |
@Override |
| 78 |
public boolean equals(@Nullable Object obj) { |
| 79 |
if (this == obj) { |
| 80 |
return true; |
| 81 |
} |
| 82 |
if (!(obj instanceof TelephonyNetworkSpecifier)) { |
| 83 |
return false; |
| 84 |
} |
| 85 |
|
| 86 |
TelephonyNetworkSpecifier lhs = (TelephonyNetworkSpecifier) obj; |
| 87 |
return mSubId == lhs.mSubId; |
| 88 |
} |
| 89 |
|
| 90 |
@Override |
| 91 |
public String toString() { |
| 92 |
return new StringBuilder() |
| 93 |
.append("TelephonyNetworkSpecifier [") |
| 94 |
.append("mSubId = ").append(mSubId) |
| 95 |
.append("]") |
| 96 |
.toString(); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
@Override |
| 101 |
public boolean canBeSatisfiedBy(NetworkSpecifier other) { |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
return equals(other) || other instanceof MatchAllNetworkSpecifier; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public static final class Builder { |
| 113 |
|
| 114 |
|
| 115 |
private static final int SENTINEL_SUB_ID = Integer.MIN_VALUE; |
| 116 |
|
| 117 |
private int mSubId; |
| 118 |
|
| 119 |
public Builder() { |
| 120 |
mSubId = SENTINEL_SUB_ID; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public @NonNull Builder setSubscriptionId(int subId) { |
| 130 |
mSubId = subId; |
| 131 |
return this; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public @NonNull TelephonyNetworkSpecifier build() { |
| 142 |
if (mSubId == SENTINEL_SUB_ID) { |
| 143 |
throw new IllegalArgumentException("Subscription Id is not provided."); |
| 144 |
} |
| 145 |
return new TelephonyNetworkSpecifier(mSubId); |
| 146 |
} |
| 147 |
} |
| 148 |
} |