blob: 21dee55eb0fb8665e671d204845d501364e3c18e [file] [log] [blame]
Etan Cohena7434272017-04-03 12:17:51 -07001/*
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
17package android.net;
18
Mathew Inwood53f089f2018-08-08 14:44:44 +010019import android.annotation.UnsupportedAppUsage;
Etan Cohena7434272017-04-03 12:17:51 -070020import android.os.Parcel;
21import android.os.Parcelable;
22import android.text.TextUtils;
23
24import com.android.internal.util.Preconditions;
25
26import java.util.Objects;
27
28/** @hide */
29public final class StringNetworkSpecifier extends NetworkSpecifier implements Parcelable {
30 /**
31 * Arbitrary string used to pass (additional) information to the network factory.
32 */
Mathew Inwood53f089f2018-08-08 14:44:44 +010033 @UnsupportedAppUsage
Etan Cohena7434272017-04-03 12:17:51 -070034 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 Sharkey9e8f83d2019-02-28 12:06:45 -070072 public static final @android.annotation.NonNull Parcelable.Creator<StringNetworkSpecifier> CREATOR =
Etan Cohena7434272017-04-03 12:17:51 -070073 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}