Etan Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Mathew Inwood | 53f089f | 2018-08-08 14:44:44 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Etan Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | import android.text.TextUtils; |
| 23 | |
| 24 | import com.android.internal.util.Preconditions; |
| 25 | |
| 26 | import java.util.Objects; |
| 27 | |
| 28 | /** @hide */ |
| 29 | public final class StringNetworkSpecifier extends NetworkSpecifier implements Parcelable { |
| 30 | /** |
| 31 | * Arbitrary string used to pass (additional) information to the network factory. |
| 32 | */ |
Mathew Inwood | 53f089f | 2018-08-08 14:44:44 +0100 | [diff] [blame] | 33 | @UnsupportedAppUsage |
Etan Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 34 | public final String specifier; |
| 35 | |
| 36 | public StringNetworkSpecifier(String specifier) { |
| 37 | Preconditions.checkStringNotEmpty(specifier); |
| 38 | this.specifier = specifier; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public boolean satisfiedBy(NetworkSpecifier other) { |
| 43 | return equals(other); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public boolean equals(Object o) { |
| 48 | if (!(o instanceof StringNetworkSpecifier)) return false; |
| 49 | return TextUtils.equals(specifier, ((StringNetworkSpecifier) o).specifier); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public int hashCode() { |
| 54 | return Objects.hashCode(specifier); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String toString() { |
| 59 | return specifier; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public int describeContents() { |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void writeToParcel(Parcel dest, int flags) { |
| 69 | dest.writeString(specifier); |
| 70 | } |
| 71 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 72 | public static final @android.annotation.NonNull Parcelable.Creator<StringNetworkSpecifier> CREATOR = |
Etan Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 73 | new Parcelable.Creator<StringNetworkSpecifier>() { |
| 74 | public StringNetworkSpecifier createFromParcel(Parcel in) { |
| 75 | return new StringNetworkSpecifier(in.readString()); |
| 76 | } |
| 77 | public StringNetworkSpecifier[] newArray(int size) { |
| 78 | return new StringNetworkSpecifier[size]; |
| 79 | } |
| 80 | }; |
| 81 | } |