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