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