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