1 /* 2 * Copyright (C) 2019 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 com.android.networkstack.apishim.common; 18 19 import android.net.IpPrefix; 20 import android.net.LinkProperties; 21 import android.net.NetworkCapabilities; 22 import android.net.Uri; 23 24 import androidx.annotation.NonNull; 25 import androidx.annotation.Nullable; 26 27 import java.net.Inet4Address; 28 29 /** 30 * Compatibility interface for network info classes such as {@link LinkProperties} and 31 * {@link NetworkCapabilities}. 32 */ 33 public interface NetworkInformationShim { 34 /** 35 * @see LinkProperties#getCaptivePortalApiUrl() 36 */ 37 @Nullable getCaptivePortalApiUrl(@ullable LinkProperties lp)38 Uri getCaptivePortalApiUrl(@Nullable LinkProperties lp); 39 40 /** 41 * @see LinkProperties#setCaptivePortalApiUrl(Uri) 42 */ setCaptivePortalApiUrl(@onNull LinkProperties lp, @Nullable Uri url)43 void setCaptivePortalApiUrl(@NonNull LinkProperties lp, @Nullable Uri url); 44 45 /** 46 * @see LinkProperties#getCaptivePortalData() 47 */ 48 @Nullable getCaptivePortalData(@ullable LinkProperties lp)49 CaptivePortalDataShim getCaptivePortalData(@Nullable LinkProperties lp); 50 51 /** 52 * @see LinkProperties#getNat64Prefix() 53 */ 54 @Nullable getNat64Prefix(@onNull LinkProperties lp)55 IpPrefix getNat64Prefix(@NonNull LinkProperties lp); 56 57 /** 58 * @see LinkProperties#setNat64Prefix() 59 */ setNat64Prefix(@onNull LinkProperties lp, @Nullable IpPrefix prefix)60 void setNat64Prefix(@NonNull LinkProperties lp, @Nullable IpPrefix prefix); 61 62 /** 63 * @see NetworkCapabilities#getSSID() 64 */ 65 @Nullable getSsid(@ullable NetworkCapabilities nc)66 String getSsid(@Nullable NetworkCapabilities nc); 67 68 /** 69 * @see LinkProperties#LinkProperties(LinkProperties, boolean) 70 */ 71 @NonNull makeSensitiveFieldsParcelingCopy(@onNull LinkProperties lp)72 LinkProperties makeSensitiveFieldsParcelingCopy(@NonNull LinkProperties lp); 73 74 /** 75 * @see LinkProperties#setDhcpServerAddress() 76 */ setDhcpServerAddress(@onNull LinkProperties lp, @NonNull Inet4Address serverAddress)77 void setDhcpServerAddress(@NonNull LinkProperties lp, @NonNull Inet4Address serverAddress); 78 79 /** 80 * Set captive portal data in {@link LinkProperties} 81 * @param lp Link properties object to be updated 82 * @param captivePortalData Captive portal data to be used 83 */ setCaptivePortalData(@onNull LinkProperties lp, @Nullable CaptivePortalDataShim captivePortalData)84 void setCaptivePortalData(@NonNull LinkProperties lp, 85 @Nullable CaptivePortalDataShim captivePortalData); 86 87 /** 88 * Get the name of the given capability that carriers use. 89 * If the capability does not have a carrier-name, returns null. 90 * 91 * @param capability The capability to get the carrier-name of. 92 * @return The carrier-name of the capability, or null if it doesn't exist. 93 * @hide 94 */ 95 @Nullable getCapabilityCarrierName(int capability)96 default String getCapabilityCarrierName(int capability) { 97 return null; 98 } 99 } 100