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.INetworkAgent;
24 import android.net.IOnCompleteListener;
25 import android.net.INetworkActivityListener;
26 import android.net.INetworkOfferCallback;
27 import android.net.IQosCallback;
28 import android.net.ISocketKeepaliveCallback;
29 import android.net.LinkProperties;
30 import android.net.LocalNetworkConfig;
31 import android.net.Network;
32 import android.net.NetworkAgentConfig;
33 import android.net.NetworkCapabilities;
34 import android.net.NetworkInfo;
35 import android.net.NetworkRequest;
36 import android.net.NetworkScore;
37 import android.net.NetworkState;
38 import android.net.NetworkStateSnapshot;
39 import android.net.OemNetworkPreferences;
40 import android.net.ProfileNetworkPreference;
41 import android.net.ProxyInfo;
42 import android.net.UidRange;
43 import android.net.QosSocketInfo;
44 import android.os.Bundle;
45 import android.os.IBinder;
46 import android.os.Messenger;
47 import android.os.ParcelFileDescriptor;
48 import android.os.PersistableBundle;
49 import android.os.ResultReceiver;
50 import android.os.UserHandle;
51 
52 /**
53  * Interface that answers queries about, and allows changing, the
54  * state of network connectivity.
55  */
56 /** {@hide} */
57 interface IConnectivityManager
58 {
getActiveNetwork()59     Network getActiveNetwork();
getActiveNetworkForUid(int uid, boolean ignoreBlocked)60     Network getActiveNetworkForUid(int uid, boolean ignoreBlocked);
61     @UnsupportedAppUsage
getActiveNetworkInfo()62     NetworkInfo getActiveNetworkInfo();
getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked)63     NetworkInfo getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked);
64     @UnsupportedAppUsage(maxTargetSdk = 28)
getNetworkInfo(int networkType)65     NetworkInfo getNetworkInfo(int networkType);
getNetworkInfoForUid(in Network network, int uid, boolean ignoreBlocked)66     NetworkInfo getNetworkInfoForUid(in Network network, int uid, boolean ignoreBlocked);
67     @UnsupportedAppUsage
getAllNetworkInfo()68     NetworkInfo[] getAllNetworkInfo();
getNetworkForType(int networkType)69     Network getNetworkForType(int networkType);
getAllNetworks()70     Network[] getAllNetworks();
getDefaultNetworkCapabilitiesForUser( int userId, String callingPackageName, String callingAttributionTag)71     NetworkCapabilities[] getDefaultNetworkCapabilitiesForUser(
72             int userId, String callingPackageName, String callingAttributionTag);
73 
isNetworkSupported(int networkType)74     boolean isNetworkSupported(int networkType);
75 
76     @UnsupportedAppUsage
getActiveLinkProperties()77     LinkProperties getActiveLinkProperties();
getLinkPropertiesForType(int networkType)78     LinkProperties getLinkPropertiesForType(int networkType);
getLinkProperties(in Network network)79     LinkProperties getLinkProperties(in Network network);
getRedactedLinkPropertiesForPackage(in LinkProperties lp, int uid, String packageName, String callingAttributionTag)80     LinkProperties getRedactedLinkPropertiesForPackage(in LinkProperties lp, int uid,
81             String packageName, String callingAttributionTag);
82 
getNetworkCapabilities(in Network network, String callingPackageName, String callingAttributionTag)83     NetworkCapabilities getNetworkCapabilities(in Network network, String callingPackageName,
84             String callingAttributionTag);
85 
getRedactedNetworkCapabilitiesForPackage(in NetworkCapabilities nc, int uid, String callingPackageName, String callingAttributionTag)86     NetworkCapabilities getRedactedNetworkCapabilitiesForPackage(in NetworkCapabilities nc, int uid,
87             String callingPackageName, String callingAttributionTag);
88 
89     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
getAllNetworkState()90     NetworkState[] getAllNetworkState();
91 
getAllNetworkStateSnapshots()92     List<NetworkStateSnapshot> getAllNetworkStateSnapshots();
93 
isActiveNetworkMetered()94     boolean isActiveNetworkMetered();
95 
requestRouteToHostAddress(int networkType, in byte[] hostAddress, String callingPackageName, String callingAttributionTag)96     boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress,
97             String callingPackageName, String callingAttributionTag);
98 
99     @UnsupportedAppUsage(maxTargetSdk = 29,
100             publicAlternatives = "Use {@code TetheringManager#getLastTetherError} as alternative")
getLastTetherError(String iface)101     int getLastTetherError(String iface);
102 
103     @UnsupportedAppUsage(maxTargetSdk = 29,
104             publicAlternatives = "Use {@code TetheringManager#getTetherableIfaces} as alternative")
getTetherableIfaces()105     String[] getTetherableIfaces();
106 
107     @UnsupportedAppUsage(maxTargetSdk = 29,
108             publicAlternatives = "Use {@code TetheringManager#getTetheredIfaces} as alternative")
getTetheredIfaces()109     String[] getTetheredIfaces();
110 
111     @UnsupportedAppUsage(maxTargetSdk = 29,
112             publicAlternatives = "Use {@code TetheringManager#getTetheringErroredIfaces} "
113             + "as Alternative")
getTetheringErroredIfaces()114     String[] getTetheringErroredIfaces();
115 
116     @UnsupportedAppUsage(maxTargetSdk = 29,
117             publicAlternatives = "Use {@code TetheringManager#getTetherableUsbRegexs} as alternative")
getTetherableUsbRegexs()118     String[] getTetherableUsbRegexs();
119 
120     @UnsupportedAppUsage(maxTargetSdk = 29,
121             publicAlternatives = "Use {@code TetheringManager#getTetherableWifiRegexs} as alternative")
getTetherableWifiRegexs()122     String[] getTetherableWifiRegexs();
123 
124     @UnsupportedAppUsage(maxTargetSdk = 28)
reportInetCondition(int networkType, int percentage)125     void reportInetCondition(int networkType, int percentage);
126 
reportNetworkConnectivity(in Network network, boolean hasConnectivity)127     void reportNetworkConnectivity(in Network network, boolean hasConnectivity);
128 
getGlobalProxy()129     ProxyInfo getGlobalProxy();
130 
setGlobalProxy(in ProxyInfo p)131     void setGlobalProxy(in ProxyInfo p);
132 
getProxyForNetwork(in Network nework)133     ProxyInfo getProxyForNetwork(in Network nework);
134 
setRequireVpnForUids(boolean requireVpn, in UidRange[] ranges)135     void setRequireVpnForUids(boolean requireVpn, in UidRange[] ranges);
setLegacyLockdownVpnEnabled(boolean enabled)136     void setLegacyLockdownVpnEnabled(boolean enabled);
137 
setProvisioningNotificationVisible(boolean visible, int networkType, in String action)138     void setProvisioningNotificationVisible(boolean visible, int networkType, in String action);
139 
setAirplaneMode(boolean enable)140     void setAirplaneMode(boolean enable);
141 
requestBandwidthUpdate(in Network network)142     boolean requestBandwidthUpdate(in Network network);
143 
registerNetworkProvider(in Messenger messenger, in String name)144     int registerNetworkProvider(in Messenger messenger, in String name);
unregisterNetworkProvider(in Messenger messenger)145     void unregisterNetworkProvider(in Messenger messenger);
146 
declareNetworkRequestUnfulfillable(in NetworkRequest request)147     void declareNetworkRequestUnfulfillable(in NetworkRequest request);
148 
registerNetworkAgent(in INetworkAgent na, in NetworkInfo ni, in LinkProperties lp, in NetworkCapabilities nc, in NetworkScore score, in LocalNetworkConfig localNetworkConfig, in NetworkAgentConfig config, in int factorySerialNumber)149     Network registerNetworkAgent(in INetworkAgent na, in NetworkInfo ni, in LinkProperties lp,
150             in NetworkCapabilities nc, in NetworkScore score,
151             in LocalNetworkConfig localNetworkConfig, in NetworkAgentConfig config,
152             in int factorySerialNumber);
153 
requestNetwork(int uid, in NetworkCapabilities networkCapabilities, int reqType, in Messenger messenger, int timeoutSec, in IBinder binder, int legacy, int callbackFlags, String callingPackageName, String callingAttributionTag)154     NetworkRequest requestNetwork(int uid, in NetworkCapabilities networkCapabilities, int reqType,
155             in Messenger messenger, int timeoutSec, in IBinder binder, int legacy,
156             int callbackFlags, String callingPackageName, String callingAttributionTag);
157 
pendingRequestForNetwork(in NetworkCapabilities networkCapabilities, in PendingIntent operation, String callingPackageName, String callingAttributionTag)158     NetworkRequest pendingRequestForNetwork(in NetworkCapabilities networkCapabilities,
159             in PendingIntent operation, String callingPackageName, String callingAttributionTag);
160 
releasePendingNetworkRequest(in PendingIntent operation)161     void releasePendingNetworkRequest(in PendingIntent operation);
162 
listenForNetwork(in NetworkCapabilities networkCapabilities, in Messenger messenger, in IBinder binder, int callbackFlags, String callingPackageName, String callingAttributionTag)163     NetworkRequest listenForNetwork(in NetworkCapabilities networkCapabilities,
164             in Messenger messenger, in IBinder binder, int callbackFlags, String callingPackageName,
165             String callingAttributionTag);
166 
pendingListenForNetwork(in NetworkCapabilities networkCapabilities, in PendingIntent operation, String callingPackageName, String callingAttributionTag)167     void pendingListenForNetwork(in NetworkCapabilities networkCapabilities,
168             in PendingIntent operation, String callingPackageName,
169             String callingAttributionTag);
170 
releaseNetworkRequest(in NetworkRequest networkRequest)171     void releaseNetworkRequest(in NetworkRequest networkRequest);
172 
setAcceptUnvalidated(in Network network, boolean accept, boolean always)173     void setAcceptUnvalidated(in Network network, boolean accept, boolean always);
setAcceptPartialConnectivity(in Network network, boolean accept, boolean always)174     void setAcceptPartialConnectivity(in Network network, boolean accept, boolean always);
setAvoidUnvalidated(in Network network)175     void setAvoidUnvalidated(in Network network);
startCaptivePortalApp(in Network network)176     void startCaptivePortalApp(in Network network);
startCaptivePortalAppInternal(in Network network, in Bundle appExtras)177     void startCaptivePortalAppInternal(in Network network, in Bundle appExtras);
178 
shouldAvoidBadWifi()179     boolean shouldAvoidBadWifi();
getMultipathPreference(in Network Network)180     int getMultipathPreference(in Network Network);
181 
getDefaultRequest()182     NetworkRequest getDefaultRequest();
183 
getRestoreDefaultNetworkDelay(int networkType)184     int getRestoreDefaultNetworkDelay(int networkType);
185 
factoryReset()186     void factoryReset();
187 
startNattKeepalive(in Network network, int intervalSeconds, in ISocketKeepaliveCallback cb, String srcAddr, int srcPort, String dstAddr)188     void startNattKeepalive(in Network network, int intervalSeconds,
189             in ISocketKeepaliveCallback cb, String srcAddr, int srcPort, String dstAddr);
190 
startNattKeepaliveWithFd(in Network network, in ParcelFileDescriptor pfd, int resourceId, int intervalSeconds, in ISocketKeepaliveCallback cb, String srcAddr, String dstAddr, boolean automaticOnOffKeepalives, in Network underpinnedNetwork)191     void startNattKeepaliveWithFd(in Network network, in ParcelFileDescriptor pfd, int resourceId,
192             int intervalSeconds, in ISocketKeepaliveCallback cb, String srcAddr,
193             String dstAddr, boolean automaticOnOffKeepalives, in Network underpinnedNetwork);
194 
startTcpKeepalive(in Network network, in ParcelFileDescriptor pfd, int intervalSeconds, in ISocketKeepaliveCallback cb)195     void startTcpKeepalive(in Network network, in ParcelFileDescriptor pfd, int intervalSeconds,
196             in ISocketKeepaliveCallback cb);
197 
stopKeepalive(in ISocketKeepaliveCallback cb)198     void stopKeepalive(in ISocketKeepaliveCallback cb);
199 
getSupportedKeepalives()200     int[] getSupportedKeepalives();
201 
getCaptivePortalServerUrl()202     String getCaptivePortalServerUrl();
203 
getNetworkWatchlistConfigHash()204     byte[] getNetworkWatchlistConfigHash();
205 
getConnectionOwnerUid(in ConnectionInfo connectionInfo)206     int getConnectionOwnerUid(in ConnectionInfo connectionInfo);
207 
registerConnectivityDiagnosticsCallback(in IConnectivityDiagnosticsCallback callback, in NetworkRequest request, String callingPackageName)208     void registerConnectivityDiagnosticsCallback(in IConnectivityDiagnosticsCallback callback,
209             in NetworkRequest request, String callingPackageName);
unregisterConnectivityDiagnosticsCallback(in IConnectivityDiagnosticsCallback callback)210     void unregisterConnectivityDiagnosticsCallback(in IConnectivityDiagnosticsCallback callback);
211 
startOrGetTestNetworkService()212     IBinder startOrGetTestNetworkService();
213 
simulateDataStall(int detectionMethod, long timestampMillis, in Network network, in PersistableBundle extras)214     void simulateDataStall(int detectionMethod, long timestampMillis, in Network network,
215                 in PersistableBundle extras);
216 
systemReady()217     void systemReady();
218 
registerNetworkActivityListener(in INetworkActivityListener l)219     void registerNetworkActivityListener(in INetworkActivityListener l);
220 
unregisterNetworkActivityListener(in INetworkActivityListener l)221     void unregisterNetworkActivityListener(in INetworkActivityListener l);
222 
isDefaultNetworkActive()223     boolean isDefaultNetworkActive();
224 
registerQosSocketCallback(in QosSocketInfo socketInfo, in IQosCallback callback)225     void registerQosSocketCallback(in QosSocketInfo socketInfo, in IQosCallback callback);
unregisterQosCallback(in IQosCallback callback)226     void unregisterQosCallback(in IQosCallback callback);
227 
setOemNetworkPreference(in OemNetworkPreferences preference, in IOnCompleteListener listener)228     void setOemNetworkPreference(in OemNetworkPreferences preference,
229             in IOnCompleteListener listener);
230 
setProfileNetworkPreferences(in UserHandle profile, in List<ProfileNetworkPreference> preferences, in IOnCompleteListener listener)231     void setProfileNetworkPreferences(in UserHandle profile,
232             in List<ProfileNetworkPreference>  preferences,
233             in IOnCompleteListener listener);
234 
getRestrictBackgroundStatusByCaller()235     int getRestrictBackgroundStatusByCaller();
236 
offerNetwork(int providerId, in NetworkScore score, in NetworkCapabilities caps, in INetworkOfferCallback callback)237     void offerNetwork(int providerId, in NetworkScore score,
238             in NetworkCapabilities caps, in INetworkOfferCallback callback);
unofferNetwork(in INetworkOfferCallback callback)239     void unofferNetwork(in INetworkOfferCallback callback);
240 
setTestAllowBadWifiUntil(long timeMs)241     void setTestAllowBadWifiUntil(long timeMs);
242 
setDataSaverEnabled(boolean enable)243     void setDataSaverEnabled(boolean enable);
244 
setUidFirewallRule(int chain, int uid, int rule)245     void setUidFirewallRule(int chain, int uid, int rule);
246 
getUidFirewallRule(int chain, int uid)247     int getUidFirewallRule(int chain, int uid);
248 
setFirewallChainEnabled(int chain, boolean enable)249     void setFirewallChainEnabled(int chain, boolean enable);
250 
getFirewallChainEnabled(int chain)251     boolean getFirewallChainEnabled(int chain);
252 
replaceFirewallChain(int chain, in int[] uids)253     void replaceFirewallChain(int chain, in int[] uids);
254 
getCompanionDeviceManagerProxyService()255     IBinder getCompanionDeviceManagerProxyService();
256 
setVpnNetworkPreference(String session, in UidRange[] ranges)257     void setVpnNetworkPreference(String session, in UidRange[] ranges);
258 
setTestLowTcpPollingTimerForKeepalive(long timeMs)259     void setTestLowTcpPollingTimerForKeepalive(long timeMs);
260 
getRoutingCoordinatorService()261     IBinder getRoutingCoordinatorService();
262 
getEnabledConnectivityManagerFeatures()263     long getEnabledConnectivityManagerFeatures();
264 }
265