• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
20  * Describes specific properties of a requested network for use in a {@link NetworkRequest}.
21  *
22  * Applications cannot instantiate this class by themselves, but can obtain instances of
23  * subclasses of this class via other APIs.
24  */
25 public abstract class NetworkSpecifier {
NetworkSpecifier()26     public NetworkSpecifier() {}
27 
28     /**
29      * Returns true if a request with this {@link NetworkSpecifier} is satisfied by a network
30      * with the given NetworkSpecifier.
31      *
32      * @hide
33      */
satisfiedBy(NetworkSpecifier other)34     public abstract boolean satisfiedBy(NetworkSpecifier other);
35 
36     /**
37      * Optional method which can be overridden by concrete implementations of NetworkSpecifier to
38      * check a self-reported UID. A concrete implementation may contain a UID which would be self-
39      * reported by the caller (since NetworkSpecifier implementations should be non-mutable). This
40      * function is called by ConnectivityService and is passed the actual UID of the caller -
41      * allowing the verification of the self-reported UID. In cases of mismatch the implementation
42      * should throw a SecurityException.
43      *
44      * @param requestorUid The UID of the requestor as obtained from its binder.
45      *
46      * @hide
47      */
assertValidFromUid(int requestorUid)48     public void assertValidFromUid(int requestorUid) {
49         // empty
50     }
51 
52     /**
53      * Optional method which can be overridden by concrete implementations of NetworkSpecifier to
54      * perform any redaction of information from the NetworkSpecifier, e.g. if it contains
55      * sensitive information. The default implementation simply returns the object itself - i.e.
56      * no information is redacted. A concrete implementation may return a modified (copy) of the
57      * NetworkSpecifier, or even return a null to fully remove all information.
58      * <p>
59      * This method is relevant to NetworkSpecifier objects used by agents - those are shared with
60      * apps by default. Some agents may store sensitive matching information in the specifier,
61      * e.g. a Wi-Fi SSID (which should not be shared since it may leak location). Those classes
62      * can redact to a null. Other agents use the Network Specifier to share public information
63      * with apps - those should not be redacted.
64      * <p>
65      * The default implementation redacts no information.
66      *
67      * @return A NetworkSpecifier object to be passed along to the requesting app.
68      *
69      * @hide
70      */
redact()71     public NetworkSpecifier redact() {
72         // TODO (b/122160111): convert default to null once all platform NetworkSpecifiers
73         // implement this method.
74         return this;
75     }
76 }
77