Etan Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 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 | /** |
Etan Cohen | 836ad57 | 2018-12-30 17:59:59 -0800 | [diff] [blame] | 20 | * Describes specific properties of a requested network for use in a {@link NetworkRequest}. |
Etan Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 21 | * |
| 22 | * Applications cannot instantiate this class by themselves, but can obtain instances of |
| 23 | * subclasses of this class via other APIs. |
Etan Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 24 | */ |
| 25 | public abstract class NetworkSpecifier { |
Etan Cohen | 39c6014 | 2017-03-29 13:57:08 -0700 | [diff] [blame] | 26 | /** @hide */ |
| 27 | public NetworkSpecifier() {} |
| 28 | |
Etan Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 29 | /** |
| 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 Cohen | 859748f | 2017-04-03 17:42:34 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
kopriva | debd4ee | 2018-09-13 10:59:46 -0700 | [diff] [blame] | 38 | * Optional method which can be overridden by concrete implementations of NetworkSpecifier to |
Etan Cohen | 859748f | 2017-04-03 17:42:34 -0700 | [diff] [blame] | 39 | * 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 Cohen | 836ad57 | 2018-12-30 17:59:59 -0800 | [diff] [blame] | 52 | |
| 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 Cohen | a743427 | 2017-04-03 12:17:51 -0700 | [diff] [blame] | 77 | } |