blob: 2bc3eb56ec2dea31c340e040ef1cbb4c4174159e [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 public NetworkSpecifier() {}
27
Etan Cohena7434272017-04-03 12:17:51 -070028 /**
29 * Returns true if a request with this {@link NetworkSpecifier} is satisfied by a network
30 * with the given NetworkSpecifier.
31 *
32 * @hide
33 */
34 public abstract boolean satisfiedBy(NetworkSpecifier other);
Etan Cohen859748f2017-04-03 17:42:34 -070035
36 /**
koprivadebd4ee2018-09-13 10:59:46 -070037 * Optional method which can be overridden by concrete implementations of NetworkSpecifier to
Etan Cohen859748f2017-04-03 17:42:34 -070038 * 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 */
48 public void assertValidFromUid(int requestorUid) {
49 // empty
50 }
Etan Cohen836ad572018-12-30 17:59:59 -080051
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 */
71 public NetworkSpecifier redact() {
72 // TODO (b/122160111): convert default to null once all platform NetworkSpecifiers
73 // implement this method.
74 return this;
75 }
Etan Cohena7434272017-04-03 12:17:51 -070076}