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