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.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * MatchAllNetworkSpecifier is a marker class used by NetworkFactory classes to indicate 26 * that they accept (match) any network specifier in requests. 27 * 28 * The class must never be used as part of a network request (those semantics aren't specified). 29 * 30 * @hide 31 */ 32 @SystemApi 33 public final class MatchAllNetworkSpecifier extends NetworkSpecifier implements Parcelable { 34 /** 35 * Utility method which verifies that the ns argument is not a MatchAllNetworkSpecifier and 36 * throws an IllegalArgumentException if it is. 37 * @hide 38 */ checkNotMatchAllNetworkSpecifier(NetworkSpecifier ns)39 public static void checkNotMatchAllNetworkSpecifier(NetworkSpecifier ns) { 40 if (ns instanceof MatchAllNetworkSpecifier) { 41 throw new IllegalArgumentException("A MatchAllNetworkSpecifier is not permitted"); 42 } 43 } 44 45 /** @hide */ satisfiedBy(NetworkSpecifier other)46 public boolean satisfiedBy(NetworkSpecifier other) { 47 /* 48 * The method is called by a NetworkRequest to see if it is satisfied by a proposed 49 * network (e.g. as offered by a network factory). Since MatchAllNetweorkSpecifier must 50 * not be used in network requests this method should never be called. 51 */ 52 throw new IllegalStateException( 53 "MatchAllNetworkSpecifier must not be used in NetworkRequests"); 54 } 55 56 @Override equals(Object o)57 public boolean equals(Object o) { 58 return o instanceof MatchAllNetworkSpecifier; 59 } 60 61 @Override hashCode()62 public int hashCode() { 63 return 0; 64 } 65 66 @Override describeContents()67 public int describeContents() { 68 return 0; 69 } 70 71 @Override writeToParcel(@onNull Parcel dest, int flags)72 public void writeToParcel(@NonNull Parcel dest, int flags) { 73 // Nothing to write. 74 } 75 76 public static final @NonNull Parcelable.Creator<MatchAllNetworkSpecifier> CREATOR = 77 new Parcelable.Creator<MatchAllNetworkSpecifier>() { 78 public MatchAllNetworkSpecifier createFromParcel(Parcel in) { 79 return new MatchAllNetworkSpecifier(); 80 } 81 public MatchAllNetworkSpecifier[] newArray(int size) { 82 return new MatchAllNetworkSpecifier[size]; 83 } 84 }; 85 } 86