1 /* //device/java/android/android/os/INetworkManagementService.aidl
2 **
3 ** Copyright 2007, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 package android.os;
19 
20 import android.net.InterfaceConfiguration;
21 import android.net.INetworkManagementEventObserver;
22 import android.net.ITetheringStatsProvider;
23 import android.net.Network;
24 import android.net.NetworkStats;
25 import android.net.RouteInfo;
26 
27 /**
28  * @hide
29  */
30 interface INetworkManagementService
31 {
32     /**
33      ** GENERAL
34      **/
35 
36     /**
37      * Register an observer to receive events.
38      */
39     @UnsupportedAppUsage
registerObserver(INetworkManagementEventObserver obs)40     void registerObserver(INetworkManagementEventObserver obs);
41 
42     /**
43      * Unregister an observer from receiving events.
44      */
45     @UnsupportedAppUsage
unregisterObserver(INetworkManagementEventObserver obs)46     void unregisterObserver(INetworkManagementEventObserver obs);
47 
48     /**
49      * Returns a list of currently known network interfaces
50      */
listInterfaces()51     String[] listInterfaces();
52 
53     /**
54      * Retrieves the specified interface config
55      *
56      */
57     @UnsupportedAppUsage
getInterfaceConfig(String iface)58     InterfaceConfiguration getInterfaceConfig(String iface);
59 
60     /**
61      * Sets the configuration of the specified interface
62      */
63     @UnsupportedAppUsage
setInterfaceConfig(String iface, in InterfaceConfiguration cfg)64     void setInterfaceConfig(String iface, in InterfaceConfiguration cfg);
65 
66     /**
67      * Clear all IP addresses on the specified interface
68      */
69     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
clearInterfaceAddresses(String iface)70     void clearInterfaceAddresses(String iface);
71 
72     /**
73      * Set interface down
74      */
setInterfaceDown(String iface)75     void setInterfaceDown(String iface);
76 
77     /**
78      * Set interface up
79      */
setInterfaceUp(String iface)80     void setInterfaceUp(String iface);
81 
82     /**
83      * Set interface IPv6 privacy extensions
84      */
85     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
setInterfaceIpv6PrivacyExtensions(String iface, boolean enable)86     void setInterfaceIpv6PrivacyExtensions(String iface, boolean enable);
87 
88     /**
89      * Disable IPv6 on an interface
90      */
91     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
disableIpv6(String iface)92     void disableIpv6(String iface);
93 
94     /**
95      * Enable IPv6 on an interface
96      */
97     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
enableIpv6(String iface)98     void enableIpv6(String iface);
99 
100     /**
101      * Set IPv6 autoconf address generation mode.
102      * This is a no-op if an unsupported mode is requested.
103      */
104     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
setIPv6AddrGenMode(String iface, int mode)105     void setIPv6AddrGenMode(String iface, int mode);
106 
107     /**
108      * Add the specified route to the interface.
109      */
addRoute(int netId, in RouteInfo route)110     void addRoute(int netId, in RouteInfo route);
111 
112     /**
113      * Remove the specified route from the interface.
114      */
removeRoute(int netId, in RouteInfo route)115     void removeRoute(int netId, in RouteInfo route);
116 
117     /**
118      * Shuts down the service
119      */
shutdown()120     void shutdown();
121 
122     /**
123      ** TETHERING RELATED
124      **/
125 
126     /**
127      * Returns true if IP forwarding is enabled
128      */
129     @UnsupportedAppUsage
getIpForwardingEnabled()130     boolean getIpForwardingEnabled();
131 
132     /**
133      * Enables/Disables IP Forwarding
134      */
135     @UnsupportedAppUsage
setIpForwardingEnabled(boolean enabled)136     void setIpForwardingEnabled(boolean enabled);
137 
138     /**
139      * Start tethering services with the specified dhcp server range
140      * arg is a set of start end pairs defining the ranges.
141      */
142     @UnsupportedAppUsage
startTethering(in String[] dhcpRanges)143     void startTethering(in String[] dhcpRanges);
144 
145     /**
146      * Start tethering services with the specified dhcp server range and
147      * DNS proxy config.
148      * {@code boolean} is used to control legacy DNS proxy server.
149      * {@code String[]} is a set of start end pairs defining the ranges.
150      */
startTetheringWithConfiguration(boolean usingLegacyDnsProxy, in String[] dhcpRanges)151     void startTetheringWithConfiguration(boolean usingLegacyDnsProxy, in String[] dhcpRanges);
152 
153     /**
154      * Stop currently running tethering services
155      */
156     @UnsupportedAppUsage
stopTethering()157     void stopTethering();
158 
159     /**
160      * Returns true if tethering services are started
161      */
162     @UnsupportedAppUsage
isTetheringStarted()163     boolean isTetheringStarted();
164 
165     /**
166      * Tethers the specified interface
167      */
168     @UnsupportedAppUsage
tetherInterface(String iface)169     void tetherInterface(String iface);
170 
171     /**
172      * Untethers the specified interface
173      */
174     @UnsupportedAppUsage
untetherInterface(String iface)175     void untetherInterface(String iface);
176 
177     /**
178      * Returns a list of currently tethered interfaces
179      */
180     @UnsupportedAppUsage
listTetheredInterfaces()181     String[] listTetheredInterfaces();
182 
183     /**
184      * Returns the list of DNS forwarders (in order of priority)
185      */
getDnsForwarders()186     String[] getDnsForwarders();
187 
188     /**
189      * Enables unidirectional packet forwarding from {@code fromIface} to
190      * {@code toIface}.
191      */
startInterfaceForwarding(String fromIface, String toIface)192     void startInterfaceForwarding(String fromIface, String toIface);
193 
194     /**
195      * Disables unidirectional packet forwarding from {@code fromIface} to
196      * {@code toIface}.
197      */
stopInterfaceForwarding(String fromIface, String toIface)198     void stopInterfaceForwarding(String fromIface, String toIface);
199 
200     /**
201      *  Enables Network Address Translation between two interfaces.
202      *  The address and netmask of the external interface is used for
203      *  the NAT'ed network.
204      */
205     @UnsupportedAppUsage
enableNat(String internalInterface, String externalInterface)206     void enableNat(String internalInterface, String externalInterface);
207 
208     /**
209      *  Disables Network Address Translation between two interfaces.
210      */
211     @UnsupportedAppUsage
disableNat(String internalInterface, String externalInterface)212     void disableNat(String internalInterface, String externalInterface);
213 
214     /**
215      * Registers a {@code ITetheringStatsProvider} to provide tethering statistics.
216      * All registered providers will be called in order, and their results will be added together.
217      * Netd is always registered as a tethering stats provider.
218      */
registerTetheringStatsProvider(ITetheringStatsProvider provider, String name)219     void registerTetheringStatsProvider(ITetheringStatsProvider provider, String name);
220 
221     /**
222      * Unregisters a previously-registered {@code ITetheringStatsProvider}.
223      */
unregisterTetheringStatsProvider(ITetheringStatsProvider provider)224     void unregisterTetheringStatsProvider(ITetheringStatsProvider provider);
225 
226     /**
227      * Reports that a tethering provider has reached a data limit.
228      *
229      * Currently triggers a global alert, which causes NetworkStatsService to poll counters and
230      * re-evaluate data usage.
231      *
232      * This does not take an interface name because:
233      * 1. The tethering offload stats provider cannot reliably determine the interface on which the
234      *    limit was reached, because the HAL does not provide it.
235      * 2. Firing an interface-specific alert instead of a global alert isn't really useful since in
236      *    all cases of interest, the system responds to both in the same way - it polls stats, and
237      *    then notifies NetworkPolicyManagerService of the fact.
238      */
tetherLimitReached(ITetheringStatsProvider provider)239     void tetherLimitReached(ITetheringStatsProvider provider);
240 
241     /**
242      ** DATA USAGE RELATED
243      **/
244 
245     /**
246      * Return summary of network statistics all tethering interfaces.
247      */
getNetworkStatsTethering(int how)248     NetworkStats getNetworkStatsTethering(int how);
249 
250     /**
251      * Set quota for an interface.
252      */
setInterfaceQuota(String iface, long quotaBytes)253     void setInterfaceQuota(String iface, long quotaBytes);
254 
255     /**
256      * Remove quota for an interface.
257      */
removeInterfaceQuota(String iface)258     void removeInterfaceQuota(String iface);
259 
260     /**
261      * Set alert for an interface; requires that iface already has quota.
262      */
setInterfaceAlert(String iface, long alertBytes)263     void setInterfaceAlert(String iface, long alertBytes);
264 
265     /**
266      * Remove alert for an interface.
267      */
removeInterfaceAlert(String iface)268     void removeInterfaceAlert(String iface);
269 
270     /**
271      * Set alert across all interfaces.
272      */
setGlobalAlert(long alertBytes)273     void setGlobalAlert(long alertBytes);
274 
275     /**
276      * Control network activity of a UID over interfaces with a quota limit.
277      */
setUidOnMeteredNetworkDenylist(int uid, boolean enable)278     void setUidOnMeteredNetworkDenylist(int uid, boolean enable);
setUidOnMeteredNetworkAllowlist(int uid, boolean enable)279     void setUidOnMeteredNetworkAllowlist(int uid, boolean enable);
setDataSaverModeEnabled(boolean enable)280     boolean setDataSaverModeEnabled(boolean enable);
281 
setUidCleartextNetworkPolicy(int uid, int policy)282     void setUidCleartextNetworkPolicy(int uid, int policy);
283 
284     /**
285      * Return status of bandwidth control module.
286      */
287     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
isBandwidthControlEnabled()288     boolean isBandwidthControlEnabled();
289 
setFirewallEnabled(boolean enabled)290     void setFirewallEnabled(boolean enabled);
isFirewallEnabled()291     boolean isFirewallEnabled();
setFirewallInterfaceRule(String iface, boolean allow)292     void setFirewallInterfaceRule(String iface, boolean allow);
setFirewallUidRule(int chain, int uid, int rule)293     void setFirewallUidRule(int chain, int uid, int rule);
setFirewallUidRules(int chain, in int[] uids, in int[] rules)294     void setFirewallUidRules(int chain, in int[] uids, in int[] rules);
setFirewallChainEnabled(int chain, boolean enable)295     void setFirewallChainEnabled(int chain, boolean enable);
296 
297     /**
298      * Allow UID to call protect().
299      */
allowProtect(int uid)300     void allowProtect(int uid);
301 
302     /**
303      * Deny UID from calling protect().
304      */
denyProtect(int uid)305     void denyProtect(int uid);
306 
addInterfaceToLocalNetwork(String iface, in List<RouteInfo> routes)307     void addInterfaceToLocalNetwork(String iface, in List<RouteInfo> routes);
removeInterfaceFromLocalNetwork(String iface)308     void removeInterfaceFromLocalNetwork(String iface);
removeRoutesFromLocalNetwork(in List<RouteInfo> routes)309     int removeRoutesFromLocalNetwork(in List<RouteInfo> routes);
310 
isNetworkRestricted(int uid)311     boolean isNetworkRestricted(int uid);
312 }
313