blob: 6bb8115d55f1545b46a156b4ac56809d037f5e12 [file] [log] [blame]
Wayne Ma0ea3bdc2022-01-12 01:12:11 +08001/*
2 * Copyright (C) 2022 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
17package com.android.server;
18
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000019import static android.net.ConnectivityManager.FIREWALL_CHAIN_DOZABLE;
20import static android.net.ConnectivityManager.FIREWALL_CHAIN_LOW_POWER_STANDBY;
21import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_1;
22import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_2;
23import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_3;
24import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE;
25import static android.net.ConnectivityManager.FIREWALL_CHAIN_RESTRICTED;
26import static android.net.ConnectivityManager.FIREWALL_CHAIN_STANDBY;
Motomu Utsumi40230be2022-07-05 03:27:35 +000027import static android.net.ConnectivityManager.FIREWALL_RULE_ALLOW;
28import static android.net.ConnectivityManager.FIREWALL_RULE_DENY;
Motomu Utsumi65271202022-07-05 08:21:41 +000029import static android.net.INetd.PERMISSION_INTERNET;
30import static android.net.INetd.PERMISSION_UNINSTALLED;
Motomu Utsumi18b287d2022-06-19 10:45:30 +000031import static android.system.OsConstants.EINVAL;
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +000032import static android.system.OsConstants.ENODEV;
Motomu Utsumi60ed3be2022-06-24 10:38:57 +000033import static android.system.OsConstants.ENOENT;
Ken Chene6d511f2022-01-25 11:10:42 +080034import static android.system.OsConstants.EOPNOTSUPP;
35
Motomu Utsumif688eeb2022-07-22 03:47:35 +000036import android.content.Context;
Wayne Ma2fde98c2022-01-17 18:04:05 +080037import android.net.INetd;
38import android.os.RemoteException;
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080039import android.os.ServiceSpecificException;
Motomu Utsumif688eeb2022-07-22 03:47:35 +000040import android.provider.DeviceConfig;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000041import android.system.ErrnoException;
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080042import android.system.Os;
Motomu Utsumi1a477b02022-08-23 15:14:56 +090043import android.util.ArraySet;
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080044import android.util.Log;
45
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000046import com.android.internal.annotations.VisibleForTesting;
Ken Chenf5f51332022-01-28 10:08:16 +080047import com.android.modules.utils.build.SdkLevel;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000048import com.android.net.module.util.BpfMap;
Motomu Utsumif688eeb2022-07-22 03:47:35 +000049import com.android.net.module.util.DeviceConfigUtils;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000050import com.android.net.module.util.Struct.U32;
Motomu Utsumi65271202022-07-05 08:21:41 +000051import com.android.net.module.util.Struct.U8;
Ken Chenf5f51332022-01-28 10:08:16 +080052
Ken Chene6d511f2022-01-25 11:10:42 +080053import java.io.FileDescriptor;
54import java.io.IOException;
Motomu Utsumi9be2ea02022-07-05 06:14:59 +000055import java.util.Set;
Ken Chene6d511f2022-01-25 11:10:42 +080056
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080057/**
58 * BpfNetMaps is responsible for providing traffic controller relevant functionality.
59 *
60 * {@hide}
61 */
62public class BpfNetMaps {
Motomu Utsumi305975f2022-06-27 09:24:32 +000063 private static final boolean PRE_T = !SdkLevel.isAtLeastT();
64 static {
65 if (!PRE_T) {
66 System.loadLibrary("service-connectivity");
67 }
68 }
69
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080070 private static final String TAG = "BpfNetMaps";
Wayne Ma2fde98c2022-01-17 18:04:05 +080071 private final INetd mNetd;
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +000072 private final Dependencies mDeps;
Ken Chenf5f51332022-01-28 10:08:16 +080073 // Use legacy netd for releases before T.
Ken Chenf5f51332022-01-28 10:08:16 +080074 private static boolean sInitialized = false;
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080075
Motomu Utsumif688eeb2022-07-22 03:47:35 +000076 private static Boolean sEnableJavaBpfMap = null;
77 private static final String BPF_NET_MAPS_ENABLE_JAVA_BPF_MAP =
78 "bpf_net_maps_enable_java_bpf_map";
79
Motomu Utsumi18b287d2022-06-19 10:45:30 +000080 // Lock for sConfigurationMap entry for UID_RULES_CONFIGURATION_KEY.
81 // This entry is not accessed by others.
82 // BpfNetMaps acquires this lock while sequence of read, modify, and write.
83 private static final Object sUidRulesConfigBpfMapLock = new Object();
84
Motomu Utsumi7abeaa42022-07-20 07:54:18 +000085 // Lock for sConfigurationMap entry for CURRENT_STATS_MAP_CONFIGURATION_KEY.
86 // BpfNetMaps acquires this lock while sequence of read, modify, and write.
87 // BpfNetMaps is an only writer of this entry.
88 private static final Object sCurrentStatsMapConfigLock = new Object();
89
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000090 private static final String CONFIGURATION_MAP_PATH =
91 "/sys/fs/bpf/netd_shared/map_netd_configuration_map";
Motomu Utsumi5a68a212022-06-24 10:14:31 +000092 private static final String UID_OWNER_MAP_PATH =
93 "/sys/fs/bpf/netd_shared/map_netd_uid_owner_map";
Motomu Utsumi65271202022-07-05 08:21:41 +000094 private static final String UID_PERMISSION_MAP_PATH =
95 "/sys/fs/bpf/netd_shared/map_netd_uid_permission_map";
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000096 private static final U32 UID_RULES_CONFIGURATION_KEY = new U32(0);
Motomu Utsumiba2fa152022-07-25 01:57:23 +000097 private static final U32 CURRENT_STATS_MAP_CONFIGURATION_KEY = new U32(1);
98 private static final long UID_RULES_DEFAULT_CONFIGURATION = 0;
99 private static final long STATS_SELECT_MAP_A = 0;
100 private static final long STATS_SELECT_MAP_B = 1;
101
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000102 private static BpfMap<U32, U32> sConfigurationMap = null;
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000103 // BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others.
104 private static BpfMap<U32, UidOwnerValue> sUidOwnerMap = null;
Motomu Utsumi65271202022-07-05 08:21:41 +0000105 private static BpfMap<U32, U8> sUidPermissionMap = null;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000106
107 // LINT.IfChange(match_type)
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000108 @VisibleForTesting public static final long NO_MATCH = 0;
109 @VisibleForTesting public static final long HAPPY_BOX_MATCH = (1 << 0);
110 @VisibleForTesting public static final long PENALTY_BOX_MATCH = (1 << 1);
111 @VisibleForTesting public static final long DOZABLE_MATCH = (1 << 2);
112 @VisibleForTesting public static final long STANDBY_MATCH = (1 << 3);
113 @VisibleForTesting public static final long POWERSAVE_MATCH = (1 << 4);
114 @VisibleForTesting public static final long RESTRICTED_MATCH = (1 << 5);
115 @VisibleForTesting public static final long LOW_POWER_STANDBY_MATCH = (1 << 6);
116 @VisibleForTesting public static final long IIF_MATCH = (1 << 7);
117 @VisibleForTesting public static final long LOCKDOWN_VPN_MATCH = (1 << 8);
118 @VisibleForTesting public static final long OEM_DENY_1_MATCH = (1 << 9);
119 @VisibleForTesting public static final long OEM_DENY_2_MATCH = (1 << 10);
120 @VisibleForTesting public static final long OEM_DENY_3_MATCH = (1 << 11);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000121 // LINT.ThenChange(packages/modules/Connectivity/bpf_progs/bpf_shared.h)
122
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000123 /**
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000124 * Set sEnableJavaBpfMap for test.
125 */
126 @VisibleForTesting
127 public static void setEnableJavaBpfMapForTest(boolean enable) {
128 sEnableJavaBpfMap = enable;
129 }
130
131 /**
Motomu Utsumi305975f2022-06-27 09:24:32 +0000132 * Set configurationMap for test.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000133 */
134 @VisibleForTesting
Motomu Utsumi305975f2022-06-27 09:24:32 +0000135 public static void setConfigurationMapForTest(BpfMap<U32, U32> configurationMap) {
136 sConfigurationMap = configurationMap;
137 }
138
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000139 /**
140 * Set uidOwnerMap for test.
141 */
142 @VisibleForTesting
143 public static void setUidOwnerMapForTest(BpfMap<U32, UidOwnerValue> uidOwnerMap) {
144 sUidOwnerMap = uidOwnerMap;
145 }
146
Motomu Utsumi65271202022-07-05 08:21:41 +0000147 /**
148 * Set uidPermissionMap for test.
149 */
150 @VisibleForTesting
151 public static void setUidPermissionMapForTest(BpfMap<U32, U8> uidPermissionMap) {
152 sUidPermissionMap = uidPermissionMap;
153 }
154
Motomu Utsumi305975f2022-06-27 09:24:32 +0000155 private static BpfMap<U32, U32> getConfigurationMap() {
156 try {
157 return new BpfMap<>(
158 CONFIGURATION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U32.class);
159 } catch (ErrnoException e) {
160 throw new IllegalStateException("Cannot open netd configuration map", e);
161 }
162 }
163
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000164 private static BpfMap<U32, UidOwnerValue> getUidOwnerMap() {
165 try {
166 return new BpfMap<>(
167 UID_OWNER_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, UidOwnerValue.class);
168 } catch (ErrnoException e) {
169 throw new IllegalStateException("Cannot open uid owner map", e);
170 }
171 }
172
Motomu Utsumi65271202022-07-05 08:21:41 +0000173 private static BpfMap<U32, U8> getUidPermissionMap() {
174 try {
175 return new BpfMap<>(
176 UID_PERMISSION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U8.class);
177 } catch (ErrnoException e) {
178 throw new IllegalStateException("Cannot open uid permission map", e);
179 }
180 }
181
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000182 private static void initBpfMaps() {
Motomu Utsumi305975f2022-06-27 09:24:32 +0000183 if (sConfigurationMap == null) {
184 sConfigurationMap = getConfigurationMap();
185 }
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000186 try {
187 sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY,
188 new U32(UID_RULES_DEFAULT_CONFIGURATION));
189 } catch (ErrnoException e) {
190 throw new IllegalStateException("Failed to initialize uid rules configuration", e);
191 }
192 try {
193 sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY,
194 new U32(STATS_SELECT_MAP_A));
195 } catch (ErrnoException e) {
196 throw new IllegalStateException("Failed to initialize current stats configuration", e);
197 }
198
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000199 if (sUidOwnerMap == null) {
200 sUidOwnerMap = getUidOwnerMap();
201 }
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000202 try {
203 sUidOwnerMap.clear();
204 } catch (ErrnoException e) {
205 throw new IllegalStateException("Failed to initialize uid owner map", e);
206 }
Motomu Utsumi65271202022-07-05 08:21:41 +0000207
208 if (sUidPermissionMap == null) {
209 sUidPermissionMap = getUidPermissionMap();
210 }
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000211 }
212
Ken Chenf5f51332022-01-28 10:08:16 +0800213 /**
214 * Initializes the class if it is not already initialized. This method will open maps but not
215 * cause any other effects. This method may be called multiple times on any thread.
216 */
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000217 private static synchronized void ensureInitialized(final Context context) {
Ken Chenf5f51332022-01-28 10:08:16 +0800218 if (sInitialized) return;
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000219 if (sEnableJavaBpfMap == null) {
220 sEnableJavaBpfMap = DeviceConfigUtils.isFeatureEnabled(context,
221 DeviceConfig.NAMESPACE_TETHERING, BPF_NET_MAPS_ENABLE_JAVA_BPF_MAP,
222 SdkLevel.isAtLeastU() /* defaultValue */);
223 }
224 Log.d(TAG, "BpfNetMaps is initialized with sEnableJavaBpfMap=" + sEnableJavaBpfMap);
225
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000226 initBpfMaps();
Motomu Utsumi305975f2022-06-27 09:24:32 +0000227 native_init();
Ken Chenf5f51332022-01-28 10:08:16 +0800228 sInitialized = true;
Wayne Ma2fde98c2022-01-17 18:04:05 +0800229 }
230
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000231 /**
232 * Dependencies of BpfNetMaps, for injection in tests.
233 */
234 @VisibleForTesting
235 public static class Dependencies {
236 /**
237 * Get interface index.
238 */
239 public int getIfIndex(final String ifName) {
240 return Os.if_nametoindex(ifName);
241 }
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000242
243 /**
244 * Call synchronize_rcu()
245 */
246 public int synchronizeKernelRCU() {
247 return native_synchronizeKernelRCU();
248 }
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000249 }
250
markchien49e944c2022-03-01 15:22:20 +0800251 /** Constructor used after T that doesn't need to use netd anymore. */
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000252 public BpfNetMaps(final Context context) {
253 this(context, null);
markchien49e944c2022-03-01 15:22:20 +0800254
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000255 if (PRE_T) throw new IllegalArgumentException("BpfNetMaps need to use netd before T");
markchien49e944c2022-03-01 15:22:20 +0800256 }
257
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000258 public BpfNetMaps(final Context context, final INetd netd) {
259 this(context, netd, new Dependencies());
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000260 }
261
262 @VisibleForTesting
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000263 public BpfNetMaps(final Context context, final INetd netd, final Dependencies deps) {
Motomu Utsumi305975f2022-06-27 09:24:32 +0000264 if (!PRE_T) {
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000265 ensureInitialized(context);
Motomu Utsumi305975f2022-06-27 09:24:32 +0000266 }
Wayne Ma2fde98c2022-01-17 18:04:05 +0800267 mNetd = netd;
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000268 mDeps = deps;
Wayne Ma790c83e2022-01-13 10:35:05 +0800269 }
270
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000271 /**
272 * Get corresponding match from firewall chain.
273 */
274 @VisibleForTesting
275 public long getMatchByFirewallChain(final int chain) {
Motomu Utsumi40230be2022-07-05 03:27:35 +0000276 switch (chain) {
277 case FIREWALL_CHAIN_DOZABLE:
278 return DOZABLE_MATCH;
279 case FIREWALL_CHAIN_STANDBY:
280 return STANDBY_MATCH;
281 case FIREWALL_CHAIN_POWERSAVE:
282 return POWERSAVE_MATCH;
283 case FIREWALL_CHAIN_RESTRICTED:
284 return RESTRICTED_MATCH;
285 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
286 return LOW_POWER_STANDBY_MATCH;
287 case FIREWALL_CHAIN_OEM_DENY_1:
288 return OEM_DENY_1_MATCH;
289 case FIREWALL_CHAIN_OEM_DENY_2:
290 return OEM_DENY_2_MATCH;
291 case FIREWALL_CHAIN_OEM_DENY_3:
292 return OEM_DENY_3_MATCH;
293 default:
294 throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000295 }
Motomu Utsumi40230be2022-07-05 03:27:35 +0000296 }
297
298 /**
299 * Get if the chain is allow list or not.
300 *
301 * ALLOWLIST means the firewall denies all by default, uids must be explicitly allowed
302 * DENYLIST means the firewall allows all by default, uids must be explicitly denyed
303 */
304 @VisibleForTesting
305 public boolean isFirewallAllowList(final int chain) {
306 switch (chain) {
307 case FIREWALL_CHAIN_DOZABLE:
308 case FIREWALL_CHAIN_POWERSAVE:
309 case FIREWALL_CHAIN_RESTRICTED:
310 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
311 return true;
312 case FIREWALL_CHAIN_STANDBY:
313 case FIREWALL_CHAIN_OEM_DENY_1:
314 case FIREWALL_CHAIN_OEM_DENY_2:
315 case FIREWALL_CHAIN_OEM_DENY_3:
316 return false;
317 default:
318 throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain);
319 }
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000320 }
321
Ken Chenf5f51332022-01-28 10:08:16 +0800322 private void maybeThrow(final int err, final String msg) {
323 if (err != 0) {
324 throw new ServiceSpecificException(err, msg + ": " + Os.strerror(err));
325 }
326 }
327
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000328 private void throwIfPreT(final String msg) {
329 if (PRE_T) {
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000330 throw new UnsupportedOperationException(msg);
331 }
332 }
333
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000334 private void removeRule(final int uid, final long match, final String caller) {
335 try {
336 synchronized (sUidOwnerMap) {
337 final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new U32(uid));
338
339 if (oldMatch == null) {
340 throw new ServiceSpecificException(ENOENT,
341 "sUidOwnerMap does not have entry for uid: " + uid);
342 }
343
344 final UidOwnerValue newMatch = new UidOwnerValue(
345 (match == IIF_MATCH) ? 0 : oldMatch.iif,
346 oldMatch.rule & ~match
347 );
348
349 if (newMatch.rule == 0) {
350 sUidOwnerMap.deleteEntry(new U32(uid));
351 } else {
352 sUidOwnerMap.updateEntry(new U32(uid), newMatch);
353 }
354 }
355 } catch (ErrnoException e) {
356 throw new ServiceSpecificException(e.errno,
357 caller + " failed to remove rule: " + Os.strerror(e.errno));
358 }
359 }
360
Motomu Utsumi389278e2022-06-28 07:05:05 +0000361 private void addRule(final int uid, final long match, final long iif, final String caller) {
362 if (match != IIF_MATCH && iif != 0) {
363 throw new ServiceSpecificException(EINVAL,
364 "Non-interface match must have zero interface index");
365 }
366
367 try {
368 synchronized (sUidOwnerMap) {
369 final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new U32(uid));
370
371 final UidOwnerValue newMatch;
372 if (oldMatch != null) {
373 newMatch = new UidOwnerValue(
374 (match == IIF_MATCH) ? iif : oldMatch.iif,
375 oldMatch.rule | match
376 );
377 } else {
378 newMatch = new UidOwnerValue(
379 iif,
380 match
381 );
382 }
383 sUidOwnerMap.updateEntry(new U32(uid), newMatch);
384 }
385 } catch (ErrnoException e) {
386 throw new ServiceSpecificException(e.errno,
387 caller + " failed to add rule: " + Os.strerror(e.errno));
388 }
389 }
390
391 private void addRule(final int uid, final long match, final String caller) {
392 addRule(uid, match, 0 /* iif */, caller);
393 }
394
Ken Chenf5f51332022-01-28 10:08:16 +0800395 /**
396 * Add naughty app bandwidth rule for specific app
397 *
398 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800399 * @throws ServiceSpecificException in case of failure, with an error code indicating the
400 * cause of the failure.
401 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900402 public void addNaughtyApp(final int uid) {
Motomu Utsumi389278e2022-06-28 07:05:05 +0000403 throwIfPreT("addNaughtyApp is not available on pre-T devices");
Motomu Utsumi55c282e2022-08-03 06:25:33 +0000404
405 if (sEnableJavaBpfMap) {
406 addRule(uid, PENALTY_BOX_MATCH, "addNaughtyApp");
407 } else {
408 final int err = native_addNaughtyApp(uid);
409 maybeThrow(err, "Unable to add naughty app");
410 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800411 }
412
Ken Chenf5f51332022-01-28 10:08:16 +0800413 /**
414 * Remove naughty app bandwidth rule for specific app
415 *
416 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800417 * @throws ServiceSpecificException in case of failure, with an error code indicating the
418 * cause of the failure.
419 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900420 public void removeNaughtyApp(final int uid) {
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000421 throwIfPreT("removeNaughtyApp is not available on pre-T devices");
Motomu Utsumi878ce0d2022-08-03 06:22:42 +0000422
423 if (sEnableJavaBpfMap) {
424 removeRule(uid, PENALTY_BOX_MATCH, "removeNaughtyApp");
425 } else {
426 final int err = native_removeNaughtyApp(uid);
427 maybeThrow(err, "Unable to remove naughty app");
428 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800429 }
430
Ken Chenf5f51332022-01-28 10:08:16 +0800431 /**
432 * Add nice app bandwidth rule for specific app
433 *
434 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800435 * @throws ServiceSpecificException in case of failure, with an error code indicating the
436 * cause of the failure.
437 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900438 public void addNiceApp(final int uid) {
Motomu Utsumi55630d02022-06-29 07:46:52 +0000439 throwIfPreT("addNiceApp is not available on pre-T devices");
Motomu Utsumi7f19df92022-08-03 06:29:59 +0000440
441 if (sEnableJavaBpfMap) {
442 addRule(uid, HAPPY_BOX_MATCH, "addNiceApp");
443 } else {
444 final int err = native_addNiceApp(uid);
445 maybeThrow(err, "Unable to add nice app");
446 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800447 }
448
Ken Chenf5f51332022-01-28 10:08:16 +0800449 /**
450 * Remove nice app bandwidth rule for specific app
451 *
452 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800453 * @throws ServiceSpecificException in case of failure, with an error code indicating the
454 * cause of the failure.
455 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900456 public void removeNiceApp(final int uid) {
Motomu Utsumi7392eb42022-06-29 03:53:03 +0000457 throwIfPreT("removeNiceApp is not available on pre-T devices");
Motomu Utsumi5f15f752022-08-03 06:27:51 +0000458
459 if (sEnableJavaBpfMap) {
460 removeRule(uid, HAPPY_BOX_MATCH, "removeNiceApp");
461 } else {
462 final int err = native_removeNiceApp(uid);
463 maybeThrow(err, "Unable to remove nice app");
464 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800465 }
466
Ken Chenf5f51332022-01-28 10:08:16 +0800467 /**
468 * Set target firewall child chain
469 *
470 * @param childChain target chain to enable
471 * @param enable whether to enable or disable child chain.
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000472 * @throws UnsupportedOperationException if called on pre-T devices.
Ken Chenf5f51332022-01-28 10:08:16 +0800473 * @throws ServiceSpecificException in case of failure, with an error code indicating the
474 * cause of the failure.
475 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900476 public void setChildChain(final int childChain, final boolean enable) {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000477 throwIfPreT("setChildChain is not available on pre-T devices");
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000478
Motomu Utsumie057dd42022-08-03 01:23:49 +0000479 if (sEnableJavaBpfMap) {
480 final long match = getMatchByFirewallChain(childChain);
481 try {
482 synchronized (sUidRulesConfigBpfMapLock) {
483 final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY);
484 final long newConfig = enable ? (config.val | match) : (config.val & ~match);
485 sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY, new U32(newConfig));
486 }
487 } catch (ErrnoException e) {
488 throw new ServiceSpecificException(e.errno,
489 "Unable to set child chain: " + Os.strerror(e.errno));
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000490 }
Motomu Utsumie057dd42022-08-03 01:23:49 +0000491 } else {
492 final int err = native_setChildChain(childChain, enable);
493 maybeThrow(err, "Unable to set child chain");
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000494 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800495 }
496
497 /**
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000498 * Get the specified firewall chain's status.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000499 *
500 * @param childChain target chain
501 * @return {@code true} if chain is enabled, {@code false} if chain is not enabled.
502 * @throws UnsupportedOperationException if called on pre-T devices.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000503 * @throws ServiceSpecificException in case of failure, with an error code indicating the
504 * cause of the failure.
505 */
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000506 public boolean isChainEnabled(final int childChain) {
507 throwIfPreT("isChainEnabled is not available on pre-T devices");
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000508
509 final long match = getMatchByFirewallChain(childChain);
510 try {
511 final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000512 return (config.val & match) != 0;
513 } catch (ErrnoException e) {
514 throw new ServiceSpecificException(e.errno,
515 "Unable to get firewall chain status: " + Os.strerror(e.errno));
516 }
517 }
518
Motomu Utsumi1a477b02022-08-23 15:14:56 +0900519 private Set<Integer> asSet(final int[] uids) {
520 final Set<Integer> uidSet = new ArraySet<>();
521 for (final int uid: uids) {
522 uidSet.add(uid);
523 }
524 return uidSet;
525 }
526
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000527 /**
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800528 * Replaces the contents of the specified UID-based firewall chain.
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000529 * Enables the chain for specified uids and disables the chain for non-specified uids.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800530 *
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000531 * @param chain Target chain.
Ken Chenf5f51332022-01-28 10:08:16 +0800532 * @param uids The list of UIDs to allow/deny.
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000533 * @throws UnsupportedOperationException if called on pre-T devices.
534 * @throws IllegalArgumentException if {@code chain} is not a valid chain.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800535 */
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000536 public void replaceUidChain(final int chain, final int[] uids) {
537 throwIfPreT("replaceUidChain is not available on pre-T devices");
538
Motomu Utsumic7c16852022-08-03 06:51:41 +0000539 if (sEnableJavaBpfMap) {
540 final long match;
541 try {
542 match = getMatchByFirewallChain(chain);
543 } catch (ServiceSpecificException e) {
544 // Throws IllegalArgumentException to keep the behavior of
545 // ConnectivityManager#replaceFirewallChain API
546 throw new IllegalArgumentException("Invalid firewall chain: " + chain);
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000547 }
Motomu Utsumi1a477b02022-08-23 15:14:56 +0900548 final Set<Integer> uidSet = asSet(uids);
549 final Set<Integer> uidSetToRemoveRule = new ArraySet<>();
Motomu Utsumic7c16852022-08-03 06:51:41 +0000550 try {
551 synchronized (sUidOwnerMap) {
552 sUidOwnerMap.forEach((uid, config) -> {
553 // config could be null if there is a concurrent entry deletion.
Motomu Utsumi8e420ea2022-08-24 18:03:30 +0900554 // http://b/220084230. But sUidOwnerMap update must be done while holding a
555 // lock, so this should not happen.
556 if (config == null) {
557 Log.wtf(TAG, "sUidOwnerMap entry was deleted while holding a lock");
558 } else if (!uidSet.contains((int) uid.val) && (config.rule & match) != 0) {
Motomu Utsumic7c16852022-08-03 06:51:41 +0000559 uidSetToRemoveRule.add((int) uid.val);
560 }
561 });
562
563 for (final int uid : uidSetToRemoveRule) {
564 removeRule(uid, match, "replaceUidChain");
565 }
566 for (final int uid : uids) {
567 addRule(uid, match, "replaceUidChain");
568 }
569 }
570 } catch (ErrnoException | ServiceSpecificException e) {
571 Log.e(TAG, "replaceUidChain failed: " + e);
572 }
573 } else {
574 final int err;
575 switch (chain) {
576 case FIREWALL_CHAIN_DOZABLE:
577 err = native_replaceUidChain("fw_dozable", true /* isAllowList */, uids);
578 break;
579 case FIREWALL_CHAIN_STANDBY:
580 err = native_replaceUidChain("fw_standby", false /* isAllowList */, uids);
581 break;
582 case FIREWALL_CHAIN_POWERSAVE:
583 err = native_replaceUidChain("fw_powersave", true /* isAllowList */, uids);
584 break;
585 case FIREWALL_CHAIN_RESTRICTED:
586 err = native_replaceUidChain("fw_restricted", true /* isAllowList */, uids);
587 break;
588 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
589 err = native_replaceUidChain(
590 "fw_low_power_standby", true /* isAllowList */, uids);
591 break;
592 case FIREWALL_CHAIN_OEM_DENY_1:
593 err = native_replaceUidChain("fw_oem_deny_1", false /* isAllowList */, uids);
594 break;
595 case FIREWALL_CHAIN_OEM_DENY_2:
596 err = native_replaceUidChain("fw_oem_deny_2", false /* isAllowList */, uids);
597 break;
598 case FIREWALL_CHAIN_OEM_DENY_3:
599 err = native_replaceUidChain("fw_oem_deny_3", false /* isAllowList */, uids);
600 break;
601 default:
602 throw new IllegalArgumentException("replaceFirewallChain with invalid chain: "
603 + chain);
604 }
605 if (err != 0) {
606 Log.e(TAG, "replaceUidChain failed: " + Os.strerror(-err));
607 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800608 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800609 }
610
Ken Chenf5f51332022-01-28 10:08:16 +0800611 /**
612 * Set firewall rule for uid
613 *
614 * @param childChain target chain
615 * @param uid uid to allow/deny
616 * @param firewallRule either FIREWALL_RULE_ALLOW or FIREWALL_RULE_DENY
Ken Chenf5f51332022-01-28 10:08:16 +0800617 * @throws ServiceSpecificException in case of failure, with an error code indicating the
618 * cause of the failure.
619 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900620 public void setUidRule(final int childChain, final int uid, final int firewallRule) {
Motomu Utsumi40230be2022-07-05 03:27:35 +0000621 throwIfPreT("setUidRule is not available on pre-T devices");
622
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000623 if (sEnableJavaBpfMap) {
624 final long match = getMatchByFirewallChain(childChain);
625 final boolean isAllowList = isFirewallAllowList(childChain);
626 final boolean add = (firewallRule == FIREWALL_RULE_ALLOW && isAllowList)
627 || (firewallRule == FIREWALL_RULE_DENY && !isAllowList);
Motomu Utsumi40230be2022-07-05 03:27:35 +0000628
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000629 if (add) {
630 addRule(uid, match, "setUidRule");
631 } else {
632 removeRule(uid, match, "setUidRule");
633 }
Motomu Utsumi40230be2022-07-05 03:27:35 +0000634 } else {
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000635 final int err = native_setUidRule(childChain, uid, firewallRule);
636 maybeThrow(err, "Unable to set uid rule");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000637 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800638 }
639
640 /**
641 * Add ingress interface filtering rules to a list of UIDs
642 *
643 * For a given uid, once a filtering rule is added, the kernel will only allow packets from the
644 * allowed interface and loopback to be sent to the list of UIDs.
645 *
646 * Calling this method on one or more UIDs with an existing filtering rule but a different
647 * interface name will result in the filtering rule being updated to allow the new interface
648 * instead. Otherwise calling this method will not affect existing rules set on other UIDs.
649 *
650 * @param ifName the name of the interface on which the filtering rules will allow packets to
Ken Chenf5f51332022-01-28 10:08:16 +0800651 * be received.
652 * @param uids an array of UIDs which the filtering rules will be set
653 * @throws RemoteException when netd has crashed.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800654 * @throws ServiceSpecificException in case of failure, with an error code indicating the
Ken Chenf5f51332022-01-28 10:08:16 +0800655 * cause of the failure.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800656 */
Ken Chenf5f51332022-01-28 10:08:16 +0800657 public void addUidInterfaceRules(final String ifName, final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000658 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800659 mNetd.firewallAddUidInterfaceRules(ifName, uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800660 return;
661 }
Motomu Utsumif794e7d2022-08-03 06:38:43 +0000662
663 if (sEnableJavaBpfMap) {
664 // Null ifName is a wildcard to allow apps to receive packets on all interfaces and
665 // ifIndex is set to 0.
666 final int ifIndex;
667 if (ifName == null) {
668 ifIndex = 0;
669 } else {
670 ifIndex = mDeps.getIfIndex(ifName);
671 if (ifIndex == 0) {
672 throw new ServiceSpecificException(ENODEV,
673 "Failed to get index of interface " + ifName);
674 }
675 }
676 for (final int uid : uids) {
677 try {
678 addRule(uid, IIF_MATCH, ifIndex, "addUidInterfaceRules");
679 } catch (ServiceSpecificException e) {
680 Log.e(TAG, "addRule failed uid=" + uid + " ifName=" + ifName + ", " + e);
681 }
682 }
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000683 } else {
Motomu Utsumif794e7d2022-08-03 06:38:43 +0000684 final int err = native_addUidInterfaceRules(ifName, uids);
685 maybeThrow(err, "Unable to add uid interface rules");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000686 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800687 }
688
689 /**
690 * Remove ingress interface filtering rules from a list of UIDs
691 *
692 * Clear the ingress interface filtering rules from the list of UIDs which were previously set
693 * by addUidInterfaceRules(). Ignore any uid which does not have filtering rule.
694 *
695 * @param uids an array of UIDs from which the filtering rules will be removed
Ken Chenf5f51332022-01-28 10:08:16 +0800696 * @throws RemoteException when netd has crashed.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800697 * @throws ServiceSpecificException in case of failure, with an error code indicating the
Ken Chenf5f51332022-01-28 10:08:16 +0800698 * cause of the failure.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800699 */
Ken Chenf5f51332022-01-28 10:08:16 +0800700 public void removeUidInterfaceRules(final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000701 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800702 mNetd.firewallRemoveUidInterfaceRules(uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800703 return;
704 }
Motomu Utsumi7dc657d2022-08-03 06:40:46 +0000705
706 if (sEnableJavaBpfMap) {
707 for (final int uid : uids) {
708 try {
709 removeRule(uid, IIF_MATCH, "removeUidInterfaceRules");
710 } catch (ServiceSpecificException e) {
711 Log.e(TAG, "removeRule failed uid=" + uid + ", " + e);
712 }
Motomu Utsumi599c4e52022-06-30 03:37:18 +0000713 }
Motomu Utsumi7dc657d2022-08-03 06:40:46 +0000714 } else {
715 final int err = native_removeUidInterfaceRules(uids);
716 maybeThrow(err, "Unable to remove uid interface rules");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000717 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800718 }
719
Ken Chenf5f51332022-01-28 10:08:16 +0800720 /**
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000721 * Update lockdown rule for uid
722 *
723 * @param uid target uid to add/remove the rule
724 * @param add {@code true} to add the rule, {@code false} to remove the rule.
725 * @throws ServiceSpecificException in case of failure, with an error code indicating the
726 * cause of the failure.
727 */
728 public void updateUidLockdownRule(final int uid, final boolean add) {
Motomu Utsumi697b2992022-06-30 02:25:29 +0000729 throwIfPreT("updateUidLockdownRule is not available on pre-T devices");
Motomu Utsumib2d32b72022-08-03 06:31:58 +0000730
731 if (sEnableJavaBpfMap) {
732 if (add) {
733 addRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule");
734 } else {
735 removeRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule");
736 }
Motomu Utsumi697b2992022-06-30 02:25:29 +0000737 } else {
Motomu Utsumib2d32b72022-08-03 06:31:58 +0000738 final int err = native_updateUidLockdownRule(uid, add);
739 maybeThrow(err, "Unable to update lockdown rule");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000740 }
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000741 }
742
743 /**
Ken Chenf5f51332022-01-28 10:08:16 +0800744 * Request netd to change the current active network stats map.
745 *
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000746 * @throws UnsupportedOperationException if called on pre-T devices.
Ken Chenf5f51332022-01-28 10:08:16 +0800747 * @throws ServiceSpecificException in case of failure, with an error code indicating the
748 * cause of the failure.
749 */
markchien49e944c2022-03-01 15:22:20 +0800750 public void swapActiveStatsMap() {
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000751 throwIfPreT("swapActiveStatsMap is not available on pre-T devices");
752
753 if (sEnableJavaBpfMap) {
754 try {
755 synchronized (sCurrentStatsMapConfigLock) {
756 final long config = sConfigurationMap.getValue(
757 CURRENT_STATS_MAP_CONFIGURATION_KEY).val;
758 final long newConfig = (config == STATS_SELECT_MAP_A)
759 ? STATS_SELECT_MAP_B : STATS_SELECT_MAP_A;
760 sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY,
761 new U32(newConfig));
762 }
763 } catch (ErrnoException e) {
764 throw new ServiceSpecificException(e.errno, "Failed to swap active stats map");
765 }
766
767 // After changing the config, it's needed to make sure all the current running eBPF
768 // programs are finished and all the CPUs are aware of this config change before the old
769 // map is modified. So special hack is needed here to wait for the kernel to do a
770 // synchronize_rcu(). Once the kernel called synchronize_rcu(), the updated config will
771 // be available to all cores and the next eBPF programs triggered inside the kernel will
772 // use the new map configuration. So once this function returns it is safe to modify the
773 // old stats map without concerning about race between the kernel and userspace.
774 final int err = mDeps.synchronizeKernelRCU();
775 maybeThrow(err, "synchronizeKernelRCU failed");
776 } else {
777 final int err = native_swapActiveStatsMap();
778 maybeThrow(err, "Unable to swap active stats map");
779 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800780 }
781
Ken Chenf5f51332022-01-28 10:08:16 +0800782 /**
783 * Assigns android.permission.INTERNET and/or android.permission.UPDATE_DEVICE_STATS to the uids
784 * specified. Or remove all permissions from the uids.
785 *
786 * @param permissions The permission to grant, it could be either PERMISSION_INTERNET and/or
787 * PERMISSION_UPDATE_DEVICE_STATS. If the permission is NO_PERMISSIONS, then
788 * revoke all permissions for the uids.
789 * @param uids uid of users to grant permission
790 * @throws RemoteException when netd has crashed.
791 */
792 public void setNetPermForUids(final int permissions, final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000793 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800794 mNetd.trafficSetNetPermForUids(permissions, uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800795 return;
796 }
Motomu Utsumi65271202022-07-05 08:21:41 +0000797
798 if (sEnableJavaBpfMap) {
799 // Remove the entry if package is uninstalled or uid has only INTERNET permission.
800 if (permissions == PERMISSION_UNINSTALLED || permissions == PERMISSION_INTERNET) {
801 for (final int uid : uids) {
802 try {
803 sUidPermissionMap.deleteEntry(new U32(uid));
804 } catch (ErrnoException e) {
805 Log.e(TAG, "Failed to remove uid " + uid + " from permission map: " + e);
806 }
807 }
808 return;
809 }
810
811 for (final int uid : uids) {
812 try {
813 sUidPermissionMap.updateEntry(new U32(uid), new U8((short) permissions));
814 } catch (ErrnoException e) {
815 Log.e(TAG, "Failed to set permission "
816 + permissions + " to uid " + uid + ": " + e);
817 }
818 }
819 } else {
820 native_setPermissionForUids(permissions, uids);
821 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800822 }
823
Ken Chene6d511f2022-01-25 11:10:42 +0800824 /**
825 * Dump BPF maps
826 *
827 * @param fd file descriptor to output
828 * @throws IOException when file descriptor is invalid.
829 * @throws ServiceSpecificException when the method is called on an unsupported device.
830 */
831 public void dump(final FileDescriptor fd, boolean verbose)
832 throws IOException, ServiceSpecificException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000833 if (PRE_T) {
Ken Chene6d511f2022-01-25 11:10:42 +0800834 throw new ServiceSpecificException(
835 EOPNOTSUPP, "dumpsys connectivity trafficcontroller dump not available on pre-T"
836 + " devices, use dumpsys netd trafficcontroller instead.");
837 }
838 native_dump(fd, verbose);
839 }
840
Wayne Ma790c83e2022-01-13 10:35:05 +0800841 private static native void native_init();
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800842 private native int native_addNaughtyApp(int uid);
843 private native int native_removeNaughtyApp(int uid);
844 private native int native_addNiceApp(int uid);
845 private native int native_removeNiceApp(int uid);
Motomu Utsumi114cd9c2022-08-01 02:08:35 +0000846 private native int native_setChildChain(int childChain, boolean enable);
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800847 private native int native_replaceUidChain(String name, boolean isAllowlist, int[] uids);
848 private native int native_setUidRule(int childChain, int uid, int firewallRule);
849 private native int native_addUidInterfaceRules(String ifName, int[] uids);
850 private native int native_removeUidInterfaceRules(int[] uids);
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000851 private native int native_updateUidLockdownRule(int uid, boolean add);
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800852 private native int native_swapActiveStatsMap();
Wayne Ma2fde98c2022-01-17 18:04:05 +0800853 private native void native_setPermissionForUids(int permissions, int[] uids);
Ken Chene6d511f2022-01-25 11:10:42 +0800854 private native void native_dump(FileDescriptor fd, boolean verbose);
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000855 private static native int native_synchronizeKernelRCU();
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800856}