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.Nullable;
20 import android.annotation.SystemApi;
21 
22 /**
23  * Describes specific properties of a requested network for use in a {@link NetworkRequest}.
24  *
25  * Applications cannot instantiate this class by themselves, but can obtain instances of
26  * subclasses of this class via other APIs.
27  */
28 public abstract class NetworkSpecifier {
NetworkSpecifier()29     public NetworkSpecifier() {}
30 
31     /**
32      * Returns true if a request with this {@link NetworkSpecifier} is satisfied by a network
33      * with the given NetworkSpecifier.
34      *
35      * @hide
36      */
37     @SystemApi
canBeSatisfiedBy(@ullable NetworkSpecifier other)38     public boolean canBeSatisfiedBy(@Nullable NetworkSpecifier other) {
39         return false;
40     }
41 
42     /**
43      * Optional method which can be overridden by concrete implementations of NetworkSpecifier to
44      * perform any redaction of information from the NetworkSpecifier, e.g. if it contains
45      * sensitive information. The default implementation simply returns the object itself - i.e.
46      * no information is redacted. A concrete implementation may return a modified (copy) of the
47      * NetworkSpecifier, or even return a null to fully remove all information.
48      * <p>
49      * This method is relevant to NetworkSpecifier objects used by agents - those are shared with
50      * apps by default. Some agents may store sensitive matching information in the specifier,
51      * e.g. a Wi-Fi SSID (which should not be shared since it may leak location). Those classes
52      * can redact to a null. Other agents use the Network Specifier to share public information
53      * with apps - those should not be redacted.
54      * <p>
55      * The default implementation redacts no information.
56      *
57      * @return A NetworkSpecifier object to be passed along to the requesting app.
58      *
59      * @hide
60      */
61     @SystemApi
62     @Nullable
redact()63     public NetworkSpecifier redact() {
64         // TODO (b/122160111): convert default to null once all platform NetworkSpecifiers
65         // implement this method.
66         return this;
67     }
68 }
69