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 19 import android.annotation.UnsupportedAppUsage; 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 */ 33 @UnsupportedAppUsage 34 public final String specifier; 35 StringNetworkSpecifier(String specifier)36 public StringNetworkSpecifier(String specifier) { 37 Preconditions.checkStringNotEmpty(specifier); 38 this.specifier = specifier; 39 } 40 41 @Override satisfiedBy(NetworkSpecifier other)42 public boolean satisfiedBy(NetworkSpecifier other) { 43 return equals(other); 44 } 45 46 @Override equals(Object o)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 hashCode()53 public int hashCode() { 54 return Objects.hashCode(specifier); 55 } 56 57 @Override toString()58 public String toString() { 59 return specifier; 60 } 61 62 @Override describeContents()63 public int describeContents() { 64 return 0; 65 } 66 67 @Override writeToParcel(Parcel dest, int flags)68 public void writeToParcel(Parcel dest, int flags) { 69 dest.writeString(specifier); 70 } 71 72 public static final @android.annotation.NonNull Parcelable.Creator<StringNetworkSpecifier> CREATOR = 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 } 82