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      */
120     @EnforcePermission("SHUTDOWN")
shutdown()121     void shutdown();
122 
123     /**
124      ** TETHERING RELATED
125      **/
126 
127     /**
128      * Returns true if IP forwarding is enabled
129      */
130     @UnsupportedAppUsage
getIpForwardingEnabled()131     boolean getIpForwardingEnabled();
132 
133     /**
134      * Enables/Disables IP Forwarding
135      */
136     @UnsupportedAppUsage
setIpForwardingEnabled(boolean enabled)137     void setIpForwardingEnabled(boolean enabled);
138 
139     /**
140      * Start tethering services with the specified dhcp server range
141      * arg is a set of start end pairs defining the ranges.
142      */
143     @UnsupportedAppUsage
startTethering(in String[] dhcpRanges)144     void startTethering(in String[] dhcpRanges);
145 
146     /**
147      * Start tethering services with the specified dhcp server range and
148      * DNS proxy config.
149      * {@code boolean} is used to control legacy DNS proxy server.
150      * {@code String[]} is a set of start end pairs defining the ranges.
151      */
startTetheringWithConfiguration(boolean usingLegacyDnsProxy, in String[] dhcpRanges)152     void startTetheringWithConfiguration(boolean usingLegacyDnsProxy, in String[] dhcpRanges);
153 
154     /**
155      * Stop currently running tethering services
156      */
157     @UnsupportedAppUsage
stopTethering()158     void stopTethering();
159 
160     /**
161      * Returns true if tethering services are started
162      */
163     @UnsupportedAppUsage
isTetheringStarted()164     boolean isTetheringStarted();
165 
166     /**
167      * Tethers the specified interface
168      */
169     @UnsupportedAppUsage
tetherInterface(String iface)170     void tetherInterface(String iface);
171 
172     /**
173      * Untethers the specified interface
174      */
175     @UnsupportedAppUsage
untetherInterface(String iface)176     void untetherInterface(String iface);
177 
178     /**
179      * Returns a list of currently tethered interfaces
180      */
181     @UnsupportedAppUsage
listTetheredInterfaces()182     String[] listTetheredInterfaces();
183 
184     /**
185      * Returns the list of DNS forwarders (in order of priority)
186      */
getDnsForwarders()187     String[] getDnsForwarders();
188 
189     /**
190      * Enables unidirectional packet forwarding from {@code fromIface} to
191      * {@code toIface}.
192      */
startInterfaceForwarding(String fromIface, String toIface)193     void startInterfaceForwarding(String fromIface, String toIface);
194 
195     /**
196      * Disables unidirectional packet forwarding from {@code fromIface} to
197      * {@code toIface}.
198      */
stopInterfaceForwarding(String fromIface, String toIface)199     void stopInterfaceForwarding(String fromIface, String toIface);
200 
201     /**
202      *  Enables Network Address Translation between two interfaces.
203      *  The address and netmask of the external interface is used for
204      *  the NAT'ed network.
205      */
206     @UnsupportedAppUsage
enableNat(String internalInterface, String externalInterface)207     void enableNat(String internalInterface, String externalInterface);
208 
209     /**
210      *  Disables Network Address Translation between two interfaces.
211      */
212     @UnsupportedAppUsage
disableNat(String internalInterface, String externalInterface)213     void disableNat(String internalInterface, String externalInterface);
214 
215     /**
216      * Registers a {@code ITetheringStatsProvider} to provide tethering statistics.
217      * All registered providers will be called in order, and their results will be added together.
218      * Netd is always registered as a tethering stats provider.
219      */
registerTetheringStatsProvider(ITetheringStatsProvider provider, String name)220     void registerTetheringStatsProvider(ITetheringStatsProvider provider, String name);
221 
222     /**
223      * Unregisters a previously-registered {@code ITetheringStatsProvider}.
224      */
unregisterTetheringStatsProvider(ITetheringStatsProvider provider)225     void unregisterTetheringStatsProvider(ITetheringStatsProvider provider);
226 
227     /**
228      * Reports that a tethering provider has reached a data limit.
229      *
230      * Currently triggers a global alert, which causes NetworkStatsService to poll counters and
231      * re-evaluate data usage.
232      *
233      * This does not take an interface name because:
234      * 1. The tethering offload stats provider cannot reliably determine the interface on which the
235      *    limit was reached, because the HAL does not provide it.
236      * 2. Firing an interface-specific alert instead of a global alert isn't really useful since in
237      *    all cases of interest, the system responds to both in the same way - it polls stats, and
238      *    then notifies NetworkPolicyManagerService of the fact.
239      */
tetherLimitReached(ITetheringStatsProvider provider)240     void tetherLimitReached(ITetheringStatsProvider provider);
241 
242     /**
243      ** DATA USAGE RELATED
244      **/
245 
246     /**
247      * Return summary of network statistics all tethering interfaces.
248      */
getNetworkStatsTethering(int how)249     NetworkStats getNetworkStatsTethering(int how);
250 
251     /**
252      * Set quota for an interface.
253      */
setInterfaceQuota(String iface, long quotaBytes)254     void setInterfaceQuota(String iface, long quotaBytes);
255 
256     /**
257      * Remove quota for an interface.
258      */
removeInterfaceQuota(String iface)259     void removeInterfaceQuota(String iface);
260 
261     /**
262      * Set alert for an interface; requires that iface already has quota.
263      */
setInterfaceAlert(String iface, long alertBytes)264     void setInterfaceAlert(String iface, long alertBytes);
265 
266     /**
267      * Remove alert for an interface.
268      */
removeInterfaceAlert(String iface)269     void removeInterfaceAlert(String iface);
270 
271     /**
272      * Set alert across all interfaces.
273      */
setGlobalAlert(long alertBytes)274     void setGlobalAlert(long alertBytes);
275 
276     /**
277      * Control network activity of a UID over interfaces with a quota limit.
278      */
setUidOnMeteredNetworkDenylist(int uid, boolean enable)279     void setUidOnMeteredNetworkDenylist(int uid, boolean enable);
setUidOnMeteredNetworkAllowlist(int uid, boolean enable)280     void setUidOnMeteredNetworkAllowlist(int uid, boolean enable);
281     @EnforcePermission("NETWORK_SETTINGS")
setDataSaverModeEnabled(boolean enable)282     boolean setDataSaverModeEnabled(boolean enable);
283 
setUidCleartextNetworkPolicy(int uid, int policy)284     void setUidCleartextNetworkPolicy(int uid, int policy);
285 
286     /**
287      * Return status of bandwidth control module.
288      */
289     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
isBandwidthControlEnabled()290     boolean isBandwidthControlEnabled();
291 
setFirewallEnabled(boolean enabled)292     void setFirewallEnabled(boolean enabled);
isFirewallEnabled()293     boolean isFirewallEnabled();
setFirewallInterfaceRule(String iface, boolean allow)294     void setFirewallInterfaceRule(String iface, boolean allow);
setFirewallUidRule(int chain, int uid, int rule)295     void setFirewallUidRule(int chain, int uid, int rule);
setFirewallUidRules(int chain, in int[] uids, in int[] rules)296     void setFirewallUidRules(int chain, in int[] uids, in int[] rules);
setFirewallChainEnabled(int chain, boolean enable)297     void setFirewallChainEnabled(int chain, boolean enable);
298 
299     /**
300      * Allow UID to call protect().
301      */
allowProtect(int uid)302     void allowProtect(int uid);
303 
304     /**
305      * Deny UID from calling protect().
306      */
denyProtect(int uid)307     void denyProtect(int uid);
308 
addInterfaceToLocalNetwork(String iface, in List<RouteInfo> routes)309     void addInterfaceToLocalNetwork(String iface, in List<RouteInfo> routes);
removeInterfaceFromLocalNetwork(String iface)310     void removeInterfaceFromLocalNetwork(String iface);
removeRoutesFromLocalNetwork(in List<RouteInfo> routes)311     int removeRoutesFromLocalNetwork(in List<RouteInfo> routes);
312 
313     @EnforcePermission("OBSERVE_NETWORK_POLICY")
isNetworkRestricted(int uid)314     boolean isNetworkRestricted(int uid);
315 }
316