1 /**
2  * Copyright (c) 2008, 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.app.PendingIntent;
20 import android.net.ConnectionInfo;
21 import android.net.ConnectivityDiagnosticsManager;
22 import android.net.IConnectivityDiagnosticsCallback;
23 import android.net.LinkProperties;
24 import android.net.Network;
25 import android.net.NetworkAgentConfig;
26 import android.net.NetworkCapabilities;
27 import android.net.NetworkInfo;
28 import android.net.NetworkQuotaInfo;
29 import android.net.NetworkRequest;
30 import android.net.NetworkState;
31 import android.net.ISocketKeepaliveCallback;
32 import android.net.ProxyInfo;
33 import android.os.Bundle;
34 import android.os.IBinder;
35 import android.os.Messenger;
36 import android.os.ParcelFileDescriptor;
37 import android.os.PersistableBundle;
38 import android.os.ResultReceiver;
39 
40 import com.android.internal.net.LegacyVpnInfo;
41 import com.android.internal.net.VpnConfig;
42 import com.android.internal.net.VpnInfo;
43 import com.android.internal.net.VpnProfile;
44 
45 /**
46  * Interface that answers queries about, and allows changing, the
47  * state of network connectivity.
48  */
49 /** {@hide} */
50 interface IConnectivityManager
51 {
getActiveNetwork()52     Network getActiveNetwork();
getActiveNetworkForUid(int uid, boolean ignoreBlocked)53     Network getActiveNetworkForUid(int uid, boolean ignoreBlocked);
54     @UnsupportedAppUsage
getActiveNetworkInfo()55     NetworkInfo getActiveNetworkInfo();
getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked)56     NetworkInfo getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked);
57     @UnsupportedAppUsage(maxTargetSdk = 28)
getNetworkInfo(int networkType)58     NetworkInfo getNetworkInfo(int networkType);
getNetworkInfoForUid(in Network network, int uid, boolean ignoreBlocked)59     NetworkInfo getNetworkInfoForUid(in Network network, int uid, boolean ignoreBlocked);
60     @UnsupportedAppUsage
getAllNetworkInfo()61     NetworkInfo[] getAllNetworkInfo();
getNetworkForType(int networkType)62     Network getNetworkForType(int networkType);
getAllNetworks()63     Network[] getAllNetworks();
getDefaultNetworkCapabilitiesForUser( int userId, String callingPackageName)64     NetworkCapabilities[] getDefaultNetworkCapabilitiesForUser(
65             int userId, String callingPackageName);
66 
isNetworkSupported(int networkType)67     boolean isNetworkSupported(int networkType);
68 
69     @UnsupportedAppUsage
getActiveLinkProperties()70     LinkProperties getActiveLinkProperties();
getLinkPropertiesForType(int networkType)71     LinkProperties getLinkPropertiesForType(int networkType);
getLinkProperties(in Network network)72     LinkProperties getLinkProperties(in Network network);
73 
getNetworkCapabilities(in Network network, String callingPackageName)74     NetworkCapabilities getNetworkCapabilities(in Network network, String callingPackageName);
75 
76     @UnsupportedAppUsage
getAllNetworkState()77     NetworkState[] getAllNetworkState();
78 
getActiveNetworkQuotaInfo()79     NetworkQuotaInfo getActiveNetworkQuotaInfo();
isActiveNetworkMetered()80     boolean isActiveNetworkMetered();
81 
requestRouteToHostAddress(int networkType, in byte[] hostAddress, String callingPackageName, String callingAttributionTag)82     boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress,
83             String callingPackageName, String callingAttributionTag);
84 
85     @UnsupportedAppUsage(maxTargetSdk = 29,
86             publicAlternatives = "Use {@code TetheringManager#getLastTetherError} as alternative")
getLastTetherError(String iface)87     int getLastTetherError(String iface);
88 
89     @UnsupportedAppUsage(maxTargetSdk = 29,
90             publicAlternatives = "Use {@code TetheringManager#getTetherableIfaces} as alternative")
getTetherableIfaces()91     String[] getTetherableIfaces();
92 
93     @UnsupportedAppUsage(maxTargetSdk = 29,
94             publicAlternatives = "Use {@code TetheringManager#getTetheredIfaces} as alternative")
getTetheredIfaces()95     String[] getTetheredIfaces();
96 
97     @UnsupportedAppUsage(maxTargetSdk = 29,
98             publicAlternatives = "Use {@code TetheringManager#getTetheringErroredIfaces} "
99             + "as Alternative")
getTetheringErroredIfaces()100     String[] getTetheringErroredIfaces();
101 
102     @UnsupportedAppUsage(maxTargetSdk = 29,
103             publicAlternatives = "Use {@code TetheringManager#getTetherableUsbRegexs} as alternative")
getTetherableUsbRegexs()104     String[] getTetherableUsbRegexs();
105 
106     @UnsupportedAppUsage(maxTargetSdk = 29,
107             publicAlternatives = "Use {@code TetheringManager#getTetherableWifiRegexs} as alternative")
getTetherableWifiRegexs()108     String[] getTetherableWifiRegexs();
109 
110     @UnsupportedAppUsage(maxTargetSdk = 28)
reportInetCondition(int networkType, int percentage)111     void reportInetCondition(int networkType, int percentage);
112 
reportNetworkConnectivity(in Network network, boolean hasConnectivity)113     void reportNetworkConnectivity(in Network network, boolean hasConnectivity);
114 
getGlobalProxy()115     ProxyInfo getGlobalProxy();
116 
setGlobalProxy(in ProxyInfo p)117     void setGlobalProxy(in ProxyInfo p);
118 
getProxyForNetwork(in Network nework)119     ProxyInfo getProxyForNetwork(in Network nework);
120 
prepareVpn(String oldPackage, String newPackage, int userId)121     boolean prepareVpn(String oldPackage, String newPackage, int userId);
122 
setVpnPackageAuthorization(String packageName, int userId, int vpnType)123     void setVpnPackageAuthorization(String packageName, int userId, int vpnType);
124 
establishVpn(in VpnConfig config)125     ParcelFileDescriptor establishVpn(in VpnConfig config);
126 
provisionVpnProfile(in VpnProfile profile, String packageName)127     boolean provisionVpnProfile(in VpnProfile profile, String packageName);
128 
deleteVpnProfile(String packageName)129     void deleteVpnProfile(String packageName);
130 
startVpnProfile(String packageName)131     void startVpnProfile(String packageName);
132 
stopVpnProfile(String packageName)133     void stopVpnProfile(String packageName);
134 
getVpnConfig(int userId)135     VpnConfig getVpnConfig(int userId);
136 
137     @UnsupportedAppUsage
startLegacyVpn(in VpnProfile profile)138     void startLegacyVpn(in VpnProfile profile);
139 
getLegacyVpnInfo(int userId)140     LegacyVpnInfo getLegacyVpnInfo(int userId);
141 
updateLockdownVpn()142     boolean updateLockdownVpn();
isAlwaysOnVpnPackageSupported(int userId, String packageName)143     boolean isAlwaysOnVpnPackageSupported(int userId, String packageName);
setAlwaysOnVpnPackage(int userId, String packageName, boolean lockdown, in List<String> lockdownWhitelist)144     boolean setAlwaysOnVpnPackage(int userId, String packageName, boolean lockdown,
145             in List<String> lockdownWhitelist);
getAlwaysOnVpnPackage(int userId)146     String getAlwaysOnVpnPackage(int userId);
isVpnLockdownEnabled(int userId)147     boolean isVpnLockdownEnabled(int userId);
getVpnLockdownWhitelist(int userId)148     List<String> getVpnLockdownWhitelist(int userId);
149 
checkMobileProvisioning(int suggestedTimeOutMs)150     int checkMobileProvisioning(int suggestedTimeOutMs);
151 
getMobileProvisioningUrl()152     String getMobileProvisioningUrl();
153 
setProvisioningNotificationVisible(boolean visible, int networkType, in String action)154     void setProvisioningNotificationVisible(boolean visible, int networkType, in String action);
155 
setAirplaneMode(boolean enable)156     void setAirplaneMode(boolean enable);
157 
requestBandwidthUpdate(in Network network)158     boolean requestBandwidthUpdate(in Network network);
159 
registerNetworkFactory(in Messenger messenger, in String name)160     int registerNetworkFactory(in Messenger messenger, in String name);
unregisterNetworkFactory(in Messenger messenger)161     void unregisterNetworkFactory(in Messenger messenger);
162 
registerNetworkProvider(in Messenger messenger, in String name)163     int registerNetworkProvider(in Messenger messenger, in String name);
unregisterNetworkProvider(in Messenger messenger)164     void unregisterNetworkProvider(in Messenger messenger);
165 
declareNetworkRequestUnfulfillable(in NetworkRequest request)166     void declareNetworkRequestUnfulfillable(in NetworkRequest request);
167 
registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp, in NetworkCapabilities nc, int score, in NetworkAgentConfig config, in int factorySerialNumber)168     Network registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp,
169             in NetworkCapabilities nc, int score, in NetworkAgentConfig config,
170             in int factorySerialNumber);
171 
requestNetwork(in NetworkCapabilities networkCapabilities, in Messenger messenger, int timeoutSec, in IBinder binder, int legacy, String callingPackageName, String callingAttributionTag)172     NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
173             in Messenger messenger, int timeoutSec, in IBinder binder, int legacy,
174             String callingPackageName, String callingAttributionTag);
175 
pendingRequestForNetwork(in NetworkCapabilities networkCapabilities, in PendingIntent operation, String callingPackageName, String callingAttributionTag)176     NetworkRequest pendingRequestForNetwork(in NetworkCapabilities networkCapabilities,
177             in PendingIntent operation, String callingPackageName, String callingAttributionTag);
178 
releasePendingNetworkRequest(in PendingIntent operation)179     void releasePendingNetworkRequest(in PendingIntent operation);
180 
listenForNetwork(in NetworkCapabilities networkCapabilities, in Messenger messenger, in IBinder binder, String callingPackageName)181     NetworkRequest listenForNetwork(in NetworkCapabilities networkCapabilities,
182             in Messenger messenger, in IBinder binder, String callingPackageName);
183 
pendingListenForNetwork(in NetworkCapabilities networkCapabilities, in PendingIntent operation, String callingPackageName)184     void pendingListenForNetwork(in NetworkCapabilities networkCapabilities,
185             in PendingIntent operation, String callingPackageName);
186 
releaseNetworkRequest(in NetworkRequest networkRequest)187     void releaseNetworkRequest(in NetworkRequest networkRequest);
188 
setAcceptUnvalidated(in Network network, boolean accept, boolean always)189     void setAcceptUnvalidated(in Network network, boolean accept, boolean always);
setAcceptPartialConnectivity(in Network network, boolean accept, boolean always)190     void setAcceptPartialConnectivity(in Network network, boolean accept, boolean always);
setAvoidUnvalidated(in Network network)191     void setAvoidUnvalidated(in Network network);
startCaptivePortalApp(in Network network)192     void startCaptivePortalApp(in Network network);
startCaptivePortalAppInternal(in Network network, in Bundle appExtras)193     void startCaptivePortalAppInternal(in Network network, in Bundle appExtras);
194 
shouldAvoidBadWifi()195     boolean shouldAvoidBadWifi();
getMultipathPreference(in Network Network)196     int getMultipathPreference(in Network Network);
197 
getDefaultRequest()198     NetworkRequest getDefaultRequest();
199 
getRestoreDefaultNetworkDelay(int networkType)200     int getRestoreDefaultNetworkDelay(int networkType);
201 
addVpnAddress(String address, int prefixLength)202     boolean addVpnAddress(String address, int prefixLength);
removeVpnAddress(String address, int prefixLength)203     boolean removeVpnAddress(String address, int prefixLength);
setUnderlyingNetworksForVpn(in Network[] networks)204     boolean setUnderlyingNetworksForVpn(in Network[] networks);
205 
factoryReset()206     void factoryReset();
207 
startNattKeepalive(in Network network, int intervalSeconds, in ISocketKeepaliveCallback cb, String srcAddr, int srcPort, String dstAddr)208     void startNattKeepalive(in Network network, int intervalSeconds,
209             in ISocketKeepaliveCallback cb, String srcAddr, int srcPort, String dstAddr);
210 
startNattKeepaliveWithFd(in Network network, in FileDescriptor fd, int resourceId, int intervalSeconds, in ISocketKeepaliveCallback cb, String srcAddr, String dstAddr)211     void startNattKeepaliveWithFd(in Network network, in FileDescriptor fd, int resourceId,
212             int intervalSeconds, in ISocketKeepaliveCallback cb, String srcAddr,
213             String dstAddr);
214 
startTcpKeepalive(in Network network, in FileDescriptor fd, int intervalSeconds, in ISocketKeepaliveCallback cb)215     void startTcpKeepalive(in Network network, in FileDescriptor fd, int intervalSeconds,
216             in ISocketKeepaliveCallback cb);
217 
stopKeepalive(in Network network, int slot)218     void stopKeepalive(in Network network, int slot);
219 
getCaptivePortalServerUrl()220     String getCaptivePortalServerUrl();
221 
getNetworkWatchlistConfigHash()222     byte[] getNetworkWatchlistConfigHash();
223 
getConnectionOwnerUid(in ConnectionInfo connectionInfo)224     int getConnectionOwnerUid(in ConnectionInfo connectionInfo);
isCallerCurrentAlwaysOnVpnApp()225     boolean isCallerCurrentAlwaysOnVpnApp();
isCallerCurrentAlwaysOnVpnLockdownApp()226     boolean isCallerCurrentAlwaysOnVpnLockdownApp();
227 
registerConnectivityDiagnosticsCallback(in IConnectivityDiagnosticsCallback callback, in NetworkRequest request, String callingPackageName)228     void registerConnectivityDiagnosticsCallback(in IConnectivityDiagnosticsCallback callback,
229             in NetworkRequest request, String callingPackageName);
unregisterConnectivityDiagnosticsCallback(in IConnectivityDiagnosticsCallback callback)230     void unregisterConnectivityDiagnosticsCallback(in IConnectivityDiagnosticsCallback callback);
231 
startOrGetTestNetworkService()232     IBinder startOrGetTestNetworkService();
233 
simulateDataStall(int detectionMethod, long timestampMillis, in Network network, in PersistableBundle extras)234     void simulateDataStall(int detectionMethod, long timestampMillis, in Network network,
235                 in PersistableBundle extras);
236 }
237