blob: 2dde0db85722e77d244473d7066e645b57877832 [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;
43import android.util.Log;
44
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000045import com.android.internal.annotations.VisibleForTesting;
Ken Chenf5f51332022-01-28 10:08:16 +080046import com.android.modules.utils.build.SdkLevel;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000047import com.android.net.module.util.BpfMap;
Motomu Utsumif688eeb2022-07-22 03:47:35 +000048import com.android.net.module.util.DeviceConfigUtils;
Motomu Utsumi73599a52022-08-24 11:59:21 +090049import com.android.net.module.util.IBpfMap;
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.Arrays;
56import java.util.HashSet;
57import java.util.Set;
58import java.util.stream.Collectors;
Ken Chene6d511f2022-01-25 11:10:42 +080059
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080060/**
61 * BpfNetMaps is responsible for providing traffic controller relevant functionality.
62 *
63 * {@hide}
64 */
65public class BpfNetMaps {
Motomu Utsumi305975f2022-06-27 09:24:32 +000066 private static final boolean PRE_T = !SdkLevel.isAtLeastT();
67 static {
68 if (!PRE_T) {
69 System.loadLibrary("service-connectivity");
70 }
71 }
72
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080073 private static final String TAG = "BpfNetMaps";
Wayne Ma2fde98c2022-01-17 18:04:05 +080074 private final INetd mNetd;
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +000075 private final Dependencies mDeps;
Ken Chenf5f51332022-01-28 10:08:16 +080076 // Use legacy netd for releases before T.
Ken Chenf5f51332022-01-28 10:08:16 +080077 private static boolean sInitialized = false;
Wayne Ma0ea3bdc2022-01-12 01:12:11 +080078
Motomu Utsumif688eeb2022-07-22 03:47:35 +000079 private static Boolean sEnableJavaBpfMap = null;
80 private static final String BPF_NET_MAPS_ENABLE_JAVA_BPF_MAP =
81 "bpf_net_maps_enable_java_bpf_map";
82
Motomu Utsumi18b287d2022-06-19 10:45:30 +000083 // Lock for sConfigurationMap entry for UID_RULES_CONFIGURATION_KEY.
84 // This entry is not accessed by others.
85 // BpfNetMaps acquires this lock while sequence of read, modify, and write.
86 private static final Object sUidRulesConfigBpfMapLock = new Object();
87
Motomu Utsumi7abeaa42022-07-20 07:54:18 +000088 // Lock for sConfigurationMap entry for CURRENT_STATS_MAP_CONFIGURATION_KEY.
89 // BpfNetMaps acquires this lock while sequence of read, modify, and write.
90 // BpfNetMaps is an only writer of this entry.
91 private static final Object sCurrentStatsMapConfigLock = new Object();
92
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000093 private static final String CONFIGURATION_MAP_PATH =
94 "/sys/fs/bpf/netd_shared/map_netd_configuration_map";
Motomu Utsumi5a68a212022-06-24 10:14:31 +000095 private static final String UID_OWNER_MAP_PATH =
96 "/sys/fs/bpf/netd_shared/map_netd_uid_owner_map";
Motomu Utsumi65271202022-07-05 08:21:41 +000097 private static final String UID_PERMISSION_MAP_PATH =
98 "/sys/fs/bpf/netd_shared/map_netd_uid_permission_map";
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +000099 private static final U32 UID_RULES_CONFIGURATION_KEY = new U32(0);
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000100 private static final U32 CURRENT_STATS_MAP_CONFIGURATION_KEY = new U32(1);
101 private static final long UID_RULES_DEFAULT_CONFIGURATION = 0;
102 private static final long STATS_SELECT_MAP_A = 0;
103 private static final long STATS_SELECT_MAP_B = 1;
104
Motomu Utsumi73599a52022-08-24 11:59:21 +0900105 private static IBpfMap<U32, U32> sConfigurationMap = null;
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000106 // BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others.
Motomu Utsumi73599a52022-08-24 11:59:21 +0900107 private static IBpfMap<U32, UidOwnerValue> sUidOwnerMap = null;
108 private static IBpfMap<U32, U8> sUidPermissionMap = null;
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000109
110 // LINT.IfChange(match_type)
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000111 @VisibleForTesting public static final long NO_MATCH = 0;
112 @VisibleForTesting public static final long HAPPY_BOX_MATCH = (1 << 0);
113 @VisibleForTesting public static final long PENALTY_BOX_MATCH = (1 << 1);
114 @VisibleForTesting public static final long DOZABLE_MATCH = (1 << 2);
115 @VisibleForTesting public static final long STANDBY_MATCH = (1 << 3);
116 @VisibleForTesting public static final long POWERSAVE_MATCH = (1 << 4);
117 @VisibleForTesting public static final long RESTRICTED_MATCH = (1 << 5);
118 @VisibleForTesting public static final long LOW_POWER_STANDBY_MATCH = (1 << 6);
119 @VisibleForTesting public static final long IIF_MATCH = (1 << 7);
120 @VisibleForTesting public static final long LOCKDOWN_VPN_MATCH = (1 << 8);
121 @VisibleForTesting public static final long OEM_DENY_1_MATCH = (1 << 9);
122 @VisibleForTesting public static final long OEM_DENY_2_MATCH = (1 << 10);
123 @VisibleForTesting public static final long OEM_DENY_3_MATCH = (1 << 11);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000124 // LINT.ThenChange(packages/modules/Connectivity/bpf_progs/bpf_shared.h)
125
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000126 /**
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000127 * Set sEnableJavaBpfMap for test.
128 */
129 @VisibleForTesting
130 public static void setEnableJavaBpfMapForTest(boolean enable) {
131 sEnableJavaBpfMap = enable;
132 }
133
134 /**
Motomu Utsumi305975f2022-06-27 09:24:32 +0000135 * Set configurationMap for test.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000136 */
137 @VisibleForTesting
Motomu Utsumi73599a52022-08-24 11:59:21 +0900138 public static void setConfigurationMapForTest(IBpfMap<U32, U32> configurationMap) {
Motomu Utsumi305975f2022-06-27 09:24:32 +0000139 sConfigurationMap = configurationMap;
140 }
141
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000142 /**
143 * Set uidOwnerMap for test.
144 */
145 @VisibleForTesting
Motomu Utsumi73599a52022-08-24 11:59:21 +0900146 public static void setUidOwnerMapForTest(IBpfMap<U32, UidOwnerValue> uidOwnerMap) {
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000147 sUidOwnerMap = uidOwnerMap;
148 }
149
Motomu Utsumi65271202022-07-05 08:21:41 +0000150 /**
151 * Set uidPermissionMap for test.
152 */
153 @VisibleForTesting
Motomu Utsumi73599a52022-08-24 11:59:21 +0900154 public static void setUidPermissionMapForTest(IBpfMap<U32, U8> uidPermissionMap) {
Motomu Utsumi65271202022-07-05 08:21:41 +0000155 sUidPermissionMap = uidPermissionMap;
156 }
157
Motomu Utsumi73599a52022-08-24 11:59:21 +0900158 private static IBpfMap<U32, U32> getConfigurationMap() {
Motomu Utsumi305975f2022-06-27 09:24:32 +0000159 try {
160 return new BpfMap<>(
161 CONFIGURATION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U32.class);
162 } catch (ErrnoException e) {
163 throw new IllegalStateException("Cannot open netd configuration map", e);
164 }
165 }
166
Motomu Utsumi73599a52022-08-24 11:59:21 +0900167 private static IBpfMap<U32, UidOwnerValue> getUidOwnerMap() {
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000168 try {
169 return new BpfMap<>(
170 UID_OWNER_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, UidOwnerValue.class);
171 } catch (ErrnoException e) {
172 throw new IllegalStateException("Cannot open uid owner map", e);
173 }
174 }
175
Motomu Utsumi73599a52022-08-24 11:59:21 +0900176 private static IBpfMap<U32, U8> getUidPermissionMap() {
Motomu Utsumi65271202022-07-05 08:21:41 +0000177 try {
178 return new BpfMap<>(
179 UID_PERMISSION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U8.class);
180 } catch (ErrnoException e) {
181 throw new IllegalStateException("Cannot open uid permission map", e);
182 }
183 }
184
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000185 private static void initBpfMaps() {
Motomu Utsumi305975f2022-06-27 09:24:32 +0000186 if (sConfigurationMap == null) {
187 sConfigurationMap = getConfigurationMap();
188 }
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000189 try {
190 sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY,
191 new U32(UID_RULES_DEFAULT_CONFIGURATION));
192 } catch (ErrnoException e) {
193 throw new IllegalStateException("Failed to initialize uid rules configuration", e);
194 }
195 try {
196 sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY,
197 new U32(STATS_SELECT_MAP_A));
198 } catch (ErrnoException e) {
199 throw new IllegalStateException("Failed to initialize current stats configuration", e);
200 }
201
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000202 if (sUidOwnerMap == null) {
203 sUidOwnerMap = getUidOwnerMap();
204 }
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000205 try {
206 sUidOwnerMap.clear();
207 } catch (ErrnoException e) {
208 throw new IllegalStateException("Failed to initialize uid owner map", e);
209 }
Motomu Utsumi65271202022-07-05 08:21:41 +0000210
211 if (sUidPermissionMap == null) {
212 sUidPermissionMap = getUidPermissionMap();
213 }
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000214 }
215
Ken Chenf5f51332022-01-28 10:08:16 +0800216 /**
217 * Initializes the class if it is not already initialized. This method will open maps but not
218 * cause any other effects. This method may be called multiple times on any thread.
219 */
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000220 private static synchronized void ensureInitialized(final Context context) {
Ken Chenf5f51332022-01-28 10:08:16 +0800221 if (sInitialized) return;
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000222 if (sEnableJavaBpfMap == null) {
223 sEnableJavaBpfMap = DeviceConfigUtils.isFeatureEnabled(context,
224 DeviceConfig.NAMESPACE_TETHERING, BPF_NET_MAPS_ENABLE_JAVA_BPF_MAP,
225 SdkLevel.isAtLeastU() /* defaultValue */);
226 }
227 Log.d(TAG, "BpfNetMaps is initialized with sEnableJavaBpfMap=" + sEnableJavaBpfMap);
228
Motomu Utsumiba2fa152022-07-25 01:57:23 +0000229 initBpfMaps();
Motomu Utsumi305975f2022-06-27 09:24:32 +0000230 native_init();
Ken Chenf5f51332022-01-28 10:08:16 +0800231 sInitialized = true;
Wayne Ma2fde98c2022-01-17 18:04:05 +0800232 }
233
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000234 /**
235 * Dependencies of BpfNetMaps, for injection in tests.
236 */
237 @VisibleForTesting
238 public static class Dependencies {
239 /**
240 * Get interface index.
241 */
242 public int getIfIndex(final String ifName) {
243 return Os.if_nametoindex(ifName);
244 }
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000245
246 /**
247 * Call synchronize_rcu()
248 */
249 public int synchronizeKernelRCU() {
250 return native_synchronizeKernelRCU();
251 }
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000252 }
253
markchien49e944c2022-03-01 15:22:20 +0800254 /** Constructor used after T that doesn't need to use netd anymore. */
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000255 public BpfNetMaps(final Context context) {
256 this(context, null);
markchien49e944c2022-03-01 15:22:20 +0800257
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000258 if (PRE_T) throw new IllegalArgumentException("BpfNetMaps need to use netd before T");
markchien49e944c2022-03-01 15:22:20 +0800259 }
260
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000261 public BpfNetMaps(final Context context, final INetd netd) {
262 this(context, netd, new Dependencies());
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000263 }
264
265 @VisibleForTesting
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000266 public BpfNetMaps(final Context context, final INetd netd, final Dependencies deps) {
Motomu Utsumi305975f2022-06-27 09:24:32 +0000267 if (!PRE_T) {
Motomu Utsumif688eeb2022-07-22 03:47:35 +0000268 ensureInitialized(context);
Motomu Utsumi305975f2022-06-27 09:24:32 +0000269 }
Wayne Ma2fde98c2022-01-17 18:04:05 +0800270 mNetd = netd;
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000271 mDeps = deps;
Wayne Ma790c83e2022-01-13 10:35:05 +0800272 }
273
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000274 /**
275 * Get corresponding match from firewall chain.
276 */
277 @VisibleForTesting
278 public long getMatchByFirewallChain(final int chain) {
Motomu Utsumi40230be2022-07-05 03:27:35 +0000279 switch (chain) {
280 case FIREWALL_CHAIN_DOZABLE:
281 return DOZABLE_MATCH;
282 case FIREWALL_CHAIN_STANDBY:
283 return STANDBY_MATCH;
284 case FIREWALL_CHAIN_POWERSAVE:
285 return POWERSAVE_MATCH;
286 case FIREWALL_CHAIN_RESTRICTED:
287 return RESTRICTED_MATCH;
288 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
289 return LOW_POWER_STANDBY_MATCH;
290 case FIREWALL_CHAIN_OEM_DENY_1:
291 return OEM_DENY_1_MATCH;
292 case FIREWALL_CHAIN_OEM_DENY_2:
293 return OEM_DENY_2_MATCH;
294 case FIREWALL_CHAIN_OEM_DENY_3:
295 return OEM_DENY_3_MATCH;
296 default:
297 throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000298 }
Motomu Utsumi40230be2022-07-05 03:27:35 +0000299 }
300
301 /**
302 * Get if the chain is allow list or not.
303 *
304 * ALLOWLIST means the firewall denies all by default, uids must be explicitly allowed
305 * DENYLIST means the firewall allows all by default, uids must be explicitly denyed
306 */
307 @VisibleForTesting
308 public boolean isFirewallAllowList(final int chain) {
309 switch (chain) {
310 case FIREWALL_CHAIN_DOZABLE:
311 case FIREWALL_CHAIN_POWERSAVE:
312 case FIREWALL_CHAIN_RESTRICTED:
313 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
314 return true;
315 case FIREWALL_CHAIN_STANDBY:
316 case FIREWALL_CHAIN_OEM_DENY_1:
317 case FIREWALL_CHAIN_OEM_DENY_2:
318 case FIREWALL_CHAIN_OEM_DENY_3:
319 return false;
320 default:
321 throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain);
322 }
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000323 }
324
Ken Chenf5f51332022-01-28 10:08:16 +0800325 private void maybeThrow(final int err, final String msg) {
326 if (err != 0) {
327 throw new ServiceSpecificException(err, msg + ": " + Os.strerror(err));
328 }
329 }
330
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000331 private void throwIfPreT(final String msg) {
332 if (PRE_T) {
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000333 throw new UnsupportedOperationException(msg);
334 }
335 }
336
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000337 private void removeRule(final int uid, final long match, final String caller) {
338 try {
339 synchronized (sUidOwnerMap) {
340 final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new U32(uid));
341
342 if (oldMatch == null) {
343 throw new ServiceSpecificException(ENOENT,
344 "sUidOwnerMap does not have entry for uid: " + uid);
345 }
346
347 final UidOwnerValue newMatch = new UidOwnerValue(
348 (match == IIF_MATCH) ? 0 : oldMatch.iif,
349 oldMatch.rule & ~match
350 );
351
352 if (newMatch.rule == 0) {
353 sUidOwnerMap.deleteEntry(new U32(uid));
354 } else {
355 sUidOwnerMap.updateEntry(new U32(uid), newMatch);
356 }
357 }
358 } catch (ErrnoException e) {
359 throw new ServiceSpecificException(e.errno,
360 caller + " failed to remove rule: " + Os.strerror(e.errno));
361 }
362 }
363
Motomu Utsumi389278e2022-06-28 07:05:05 +0000364 private void addRule(final int uid, final long match, final long iif, final String caller) {
365 if (match != IIF_MATCH && iif != 0) {
366 throw new ServiceSpecificException(EINVAL,
367 "Non-interface match must have zero interface index");
368 }
369
370 try {
371 synchronized (sUidOwnerMap) {
372 final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new U32(uid));
373
374 final UidOwnerValue newMatch;
375 if (oldMatch != null) {
376 newMatch = new UidOwnerValue(
377 (match == IIF_MATCH) ? iif : oldMatch.iif,
378 oldMatch.rule | match
379 );
380 } else {
381 newMatch = new UidOwnerValue(
382 iif,
383 match
384 );
385 }
386 sUidOwnerMap.updateEntry(new U32(uid), newMatch);
387 }
388 } catch (ErrnoException e) {
389 throw new ServiceSpecificException(e.errno,
390 caller + " failed to add rule: " + Os.strerror(e.errno));
391 }
392 }
393
394 private void addRule(final int uid, final long match, final String caller) {
395 addRule(uid, match, 0 /* iif */, caller);
396 }
397
Ken Chenf5f51332022-01-28 10:08:16 +0800398 /**
399 * Add naughty app bandwidth rule for specific app
400 *
401 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800402 * @throws ServiceSpecificException in case of failure, with an error code indicating the
403 * cause of the failure.
404 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900405 public void addNaughtyApp(final int uid) {
Motomu Utsumi389278e2022-06-28 07:05:05 +0000406 throwIfPreT("addNaughtyApp is not available on pre-T devices");
Motomu Utsumi55c282e2022-08-03 06:25:33 +0000407
408 if (sEnableJavaBpfMap) {
409 addRule(uid, PENALTY_BOX_MATCH, "addNaughtyApp");
410 } else {
411 final int err = native_addNaughtyApp(uid);
412 maybeThrow(err, "Unable to add naughty app");
413 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800414 }
415
Ken Chenf5f51332022-01-28 10:08:16 +0800416 /**
417 * Remove naughty app bandwidth rule for specific app
418 *
419 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800420 * @throws ServiceSpecificException in case of failure, with an error code indicating the
421 * cause of the failure.
422 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900423 public void removeNaughtyApp(final int uid) {
Motomu Utsumi60ed3be2022-06-24 10:38:57 +0000424 throwIfPreT("removeNaughtyApp is not available on pre-T devices");
Motomu Utsumi878ce0d2022-08-03 06:22:42 +0000425
426 if (sEnableJavaBpfMap) {
427 removeRule(uid, PENALTY_BOX_MATCH, "removeNaughtyApp");
428 } else {
429 final int err = native_removeNaughtyApp(uid);
430 maybeThrow(err, "Unable to remove naughty app");
431 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800432 }
433
Ken Chenf5f51332022-01-28 10:08:16 +0800434 /**
435 * Add nice app bandwidth rule for specific app
436 *
437 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800438 * @throws ServiceSpecificException in case of failure, with an error code indicating the
439 * cause of the failure.
440 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900441 public void addNiceApp(final int uid) {
Motomu Utsumi55630d02022-06-29 07:46:52 +0000442 throwIfPreT("addNiceApp is not available on pre-T devices");
Motomu Utsumi7f19df92022-08-03 06:29:59 +0000443
444 if (sEnableJavaBpfMap) {
445 addRule(uid, HAPPY_BOX_MATCH, "addNiceApp");
446 } else {
447 final int err = native_addNiceApp(uid);
448 maybeThrow(err, "Unable to add nice app");
449 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800450 }
451
Ken Chenf5f51332022-01-28 10:08:16 +0800452 /**
453 * Remove nice app bandwidth rule for specific app
454 *
455 * @param uid uid of target app
Ken Chenf5f51332022-01-28 10:08:16 +0800456 * @throws ServiceSpecificException in case of failure, with an error code indicating the
457 * cause of the failure.
458 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900459 public void removeNiceApp(final int uid) {
Motomu Utsumi7392eb42022-06-29 03:53:03 +0000460 throwIfPreT("removeNiceApp is not available on pre-T devices");
Motomu Utsumi5f15f752022-08-03 06:27:51 +0000461
462 if (sEnableJavaBpfMap) {
463 removeRule(uid, HAPPY_BOX_MATCH, "removeNiceApp");
464 } else {
465 final int err = native_removeNiceApp(uid);
466 maybeThrow(err, "Unable to remove nice app");
467 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800468 }
469
Ken Chenf5f51332022-01-28 10:08:16 +0800470 /**
471 * Set target firewall child chain
472 *
473 * @param childChain target chain to enable
474 * @param enable whether to enable or disable child chain.
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000475 * @throws UnsupportedOperationException if called on pre-T devices.
Ken Chenf5f51332022-01-28 10:08:16 +0800476 * @throws ServiceSpecificException in case of failure, with an error code indicating the
477 * cause of the failure.
478 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900479 public void setChildChain(final int childChain, final boolean enable) {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000480 throwIfPreT("setChildChain is not available on pre-T devices");
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000481
Motomu Utsumie057dd42022-08-03 01:23:49 +0000482 if (sEnableJavaBpfMap) {
483 final long match = getMatchByFirewallChain(childChain);
484 try {
485 synchronized (sUidRulesConfigBpfMapLock) {
486 final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY);
487 final long newConfig = enable ? (config.val | match) : (config.val & ~match);
488 sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY, new U32(newConfig));
489 }
490 } catch (ErrnoException e) {
491 throw new ServiceSpecificException(e.errno,
492 "Unable to set child chain: " + Os.strerror(e.errno));
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000493 }
Motomu Utsumie057dd42022-08-03 01:23:49 +0000494 } else {
495 final int err = native_setChildChain(childChain, enable);
496 maybeThrow(err, "Unable to set child chain");
Motomu Utsumi18b287d2022-06-19 10:45:30 +0000497 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800498 }
499
500 /**
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000501 * Get the specified firewall chain's status.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000502 *
503 * @param childChain target chain
504 * @return {@code true} if chain is enabled, {@code false} if chain is not enabled.
505 * @throws UnsupportedOperationException if called on pre-T devices.
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000506 * @throws ServiceSpecificException in case of failure, with an error code indicating the
507 * cause of the failure.
508 */
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000509 public boolean isChainEnabled(final int childChain) {
510 throwIfPreT("isChainEnabled is not available on pre-T devices");
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000511
512 final long match = getMatchByFirewallChain(childChain);
513 try {
514 final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY);
Motomu Utsumibe3ff1e2022-06-08 10:05:07 +0000515 return (config.val & match) != 0;
516 } catch (ErrnoException e) {
517 throw new ServiceSpecificException(e.errno,
518 "Unable to get firewall chain status: " + Os.strerror(e.errno));
519 }
520 }
521
522 /**
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800523 * Replaces the contents of the specified UID-based firewall chain.
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000524 * Enables the chain for specified uids and disables the chain for non-specified uids.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800525 *
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000526 * @param chain Target chain.
Ken Chenf5f51332022-01-28 10:08:16 +0800527 * @param uids The list of UIDs to allow/deny.
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000528 * @throws UnsupportedOperationException if called on pre-T devices.
529 * @throws IllegalArgumentException if {@code chain} is not a valid chain.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800530 */
Motomu Utsumi9be2ea02022-07-05 06:14:59 +0000531 public void replaceUidChain(final int chain, final int[] uids) {
532 throwIfPreT("replaceUidChain is not available on pre-T devices");
533
Motomu Utsumic7c16852022-08-03 06:51:41 +0000534 if (sEnableJavaBpfMap) {
535 final long match;
536 try {
537 match = getMatchByFirewallChain(chain);
538 } catch (ServiceSpecificException e) {
539 // Throws IllegalArgumentException to keep the behavior of
540 // ConnectivityManager#replaceFirewallChain API
541 throw new IllegalArgumentException("Invalid firewall chain: " + chain);
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000542 }
Motomu Utsumic7c16852022-08-03 06:51:41 +0000543 final Set<Integer> uidSet = Arrays.stream(uids).boxed().collect(Collectors.toSet());
544 final Set<Integer> uidSetToRemoveRule = new HashSet<>();
545 try {
546 synchronized (sUidOwnerMap) {
547 sUidOwnerMap.forEach((uid, config) -> {
548 // config could be null if there is a concurrent entry deletion.
549 // http://b/220084230.
550 if (config != null
551 && !uidSet.contains((int) uid.val) && (config.rule & match) != 0) {
552 uidSetToRemoveRule.add((int) uid.val);
553 }
554 });
555
556 for (final int uid : uidSetToRemoveRule) {
557 removeRule(uid, match, "replaceUidChain");
558 }
559 for (final int uid : uids) {
560 addRule(uid, match, "replaceUidChain");
561 }
562 }
563 } catch (ErrnoException | ServiceSpecificException e) {
564 Log.e(TAG, "replaceUidChain failed: " + e);
565 }
566 } else {
567 final int err;
568 switch (chain) {
569 case FIREWALL_CHAIN_DOZABLE:
570 err = native_replaceUidChain("fw_dozable", true /* isAllowList */, uids);
571 break;
572 case FIREWALL_CHAIN_STANDBY:
573 err = native_replaceUidChain("fw_standby", false /* isAllowList */, uids);
574 break;
575 case FIREWALL_CHAIN_POWERSAVE:
576 err = native_replaceUidChain("fw_powersave", true /* isAllowList */, uids);
577 break;
578 case FIREWALL_CHAIN_RESTRICTED:
579 err = native_replaceUidChain("fw_restricted", true /* isAllowList */, uids);
580 break;
581 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
582 err = native_replaceUidChain(
583 "fw_low_power_standby", true /* isAllowList */, uids);
584 break;
585 case FIREWALL_CHAIN_OEM_DENY_1:
586 err = native_replaceUidChain("fw_oem_deny_1", false /* isAllowList */, uids);
587 break;
588 case FIREWALL_CHAIN_OEM_DENY_2:
589 err = native_replaceUidChain("fw_oem_deny_2", false /* isAllowList */, uids);
590 break;
591 case FIREWALL_CHAIN_OEM_DENY_3:
592 err = native_replaceUidChain("fw_oem_deny_3", false /* isAllowList */, uids);
593 break;
594 default:
595 throw new IllegalArgumentException("replaceFirewallChain with invalid chain: "
596 + chain);
597 }
598 if (err != 0) {
599 Log.e(TAG, "replaceUidChain failed: " + Os.strerror(-err));
600 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800601 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800602 }
603
Ken Chenf5f51332022-01-28 10:08:16 +0800604 /**
605 * Set firewall rule for uid
606 *
607 * @param childChain target chain
608 * @param uid uid to allow/deny
609 * @param firewallRule either FIREWALL_RULE_ALLOW or FIREWALL_RULE_DENY
Ken Chenf5f51332022-01-28 10:08:16 +0800610 * @throws ServiceSpecificException in case of failure, with an error code indicating the
611 * cause of the failure.
612 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900613 public void setUidRule(final int childChain, final int uid, final int firewallRule) {
Motomu Utsumi40230be2022-07-05 03:27:35 +0000614 throwIfPreT("setUidRule is not available on pre-T devices");
615
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000616 if (sEnableJavaBpfMap) {
617 final long match = getMatchByFirewallChain(childChain);
618 final boolean isAllowList = isFirewallAllowList(childChain);
619 final boolean add = (firewallRule == FIREWALL_RULE_ALLOW && isAllowList)
620 || (firewallRule == FIREWALL_RULE_DENY && !isAllowList);
Motomu Utsumi40230be2022-07-05 03:27:35 +0000621
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000622 if (add) {
623 addRule(uid, match, "setUidRule");
624 } else {
625 removeRule(uid, match, "setUidRule");
626 }
Motomu Utsumi40230be2022-07-05 03:27:35 +0000627 } else {
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000628 final int err = native_setUidRule(childChain, uid, firewallRule);
629 maybeThrow(err, "Unable to set uid rule");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000630 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800631 }
632
633 /**
634 * Add ingress interface filtering rules to a list of UIDs
635 *
636 * For a given uid, once a filtering rule is added, the kernel will only allow packets from the
637 * allowed interface and loopback to be sent to the list of UIDs.
638 *
639 * Calling this method on one or more UIDs with an existing filtering rule but a different
640 * interface name will result in the filtering rule being updated to allow the new interface
641 * instead. Otherwise calling this method will not affect existing rules set on other UIDs.
642 *
643 * @param ifName the name of the interface on which the filtering rules will allow packets to
Ken Chenf5f51332022-01-28 10:08:16 +0800644 * be received.
645 * @param uids an array of UIDs which the filtering rules will be set
646 * @throws RemoteException when netd has crashed.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800647 * @throws ServiceSpecificException in case of failure, with an error code indicating the
Ken Chenf5f51332022-01-28 10:08:16 +0800648 * cause of the failure.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800649 */
Ken Chenf5f51332022-01-28 10:08:16 +0800650 public void addUidInterfaceRules(final String ifName, final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000651 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800652 mNetd.firewallAddUidInterfaceRules(ifName, uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800653 return;
654 }
Motomu Utsumif794e7d2022-08-03 06:38:43 +0000655
656 if (sEnableJavaBpfMap) {
657 // Null ifName is a wildcard to allow apps to receive packets on all interfaces and
658 // ifIndex is set to 0.
659 final int ifIndex;
660 if (ifName == null) {
661 ifIndex = 0;
662 } else {
663 ifIndex = mDeps.getIfIndex(ifName);
664 if (ifIndex == 0) {
665 throw new ServiceSpecificException(ENODEV,
666 "Failed to get index of interface " + ifName);
667 }
668 }
669 for (final int uid : uids) {
670 try {
671 addRule(uid, IIF_MATCH, ifIndex, "addUidInterfaceRules");
672 } catch (ServiceSpecificException e) {
673 Log.e(TAG, "addRule failed uid=" + uid + " ifName=" + ifName + ", " + e);
674 }
675 }
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000676 } else {
Motomu Utsumif794e7d2022-08-03 06:38:43 +0000677 final int err = native_addUidInterfaceRules(ifName, uids);
678 maybeThrow(err, "Unable to add uid interface rules");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000679 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800680 }
681
682 /**
683 * Remove ingress interface filtering rules from a list of UIDs
684 *
685 * Clear the ingress interface filtering rules from the list of UIDs which were previously set
686 * by addUidInterfaceRules(). Ignore any uid which does not have filtering rule.
687 *
688 * @param uids an array of UIDs from which the filtering rules will be removed
Ken Chenf5f51332022-01-28 10:08:16 +0800689 * @throws RemoteException when netd has crashed.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800690 * @throws ServiceSpecificException in case of failure, with an error code indicating the
Ken Chenf5f51332022-01-28 10:08:16 +0800691 * cause of the failure.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800692 */
Ken Chenf5f51332022-01-28 10:08:16 +0800693 public void removeUidInterfaceRules(final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000694 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800695 mNetd.firewallRemoveUidInterfaceRules(uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800696 return;
697 }
Motomu Utsumi7dc657d2022-08-03 06:40:46 +0000698
699 if (sEnableJavaBpfMap) {
700 for (final int uid : uids) {
701 try {
702 removeRule(uid, IIF_MATCH, "removeUidInterfaceRules");
703 } catch (ServiceSpecificException e) {
704 Log.e(TAG, "removeRule failed uid=" + uid + ", " + e);
705 }
Motomu Utsumi599c4e52022-06-30 03:37:18 +0000706 }
Motomu Utsumi7dc657d2022-08-03 06:40:46 +0000707 } else {
708 final int err = native_removeUidInterfaceRules(uids);
709 maybeThrow(err, "Unable to remove uid interface rules");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000710 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800711 }
712
Ken Chenf5f51332022-01-28 10:08:16 +0800713 /**
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000714 * Update lockdown rule for uid
715 *
716 * @param uid target uid to add/remove the rule
717 * @param add {@code true} to add the rule, {@code false} to remove the rule.
718 * @throws ServiceSpecificException in case of failure, with an error code indicating the
719 * cause of the failure.
720 */
721 public void updateUidLockdownRule(final int uid, final boolean add) {
Motomu Utsumi697b2992022-06-30 02:25:29 +0000722 throwIfPreT("updateUidLockdownRule is not available on pre-T devices");
Motomu Utsumib2d32b72022-08-03 06:31:58 +0000723
724 if (sEnableJavaBpfMap) {
725 if (add) {
726 addRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule");
727 } else {
728 removeRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule");
729 }
Motomu Utsumi697b2992022-06-30 02:25:29 +0000730 } else {
Motomu Utsumib2d32b72022-08-03 06:31:58 +0000731 final int err = native_updateUidLockdownRule(uid, add);
732 maybeThrow(err, "Unable to update lockdown rule");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000733 }
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000734 }
735
736 /**
Ken Chenf5f51332022-01-28 10:08:16 +0800737 * Request netd to change the current active network stats map.
738 *
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000739 * @throws UnsupportedOperationException if called on pre-T devices.
Ken Chenf5f51332022-01-28 10:08:16 +0800740 * @throws ServiceSpecificException in case of failure, with an error code indicating the
741 * cause of the failure.
742 */
markchien49e944c2022-03-01 15:22:20 +0800743 public void swapActiveStatsMap() {
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000744 throwIfPreT("swapActiveStatsMap is not available on pre-T devices");
745
746 if (sEnableJavaBpfMap) {
747 try {
748 synchronized (sCurrentStatsMapConfigLock) {
749 final long config = sConfigurationMap.getValue(
750 CURRENT_STATS_MAP_CONFIGURATION_KEY).val;
751 final long newConfig = (config == STATS_SELECT_MAP_A)
752 ? STATS_SELECT_MAP_B : STATS_SELECT_MAP_A;
753 sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY,
754 new U32(newConfig));
755 }
756 } catch (ErrnoException e) {
757 throw new ServiceSpecificException(e.errno, "Failed to swap active stats map");
758 }
759
760 // After changing the config, it's needed to make sure all the current running eBPF
761 // programs are finished and all the CPUs are aware of this config change before the old
762 // map is modified. So special hack is needed here to wait for the kernel to do a
763 // synchronize_rcu(). Once the kernel called synchronize_rcu(), the updated config will
764 // be available to all cores and the next eBPF programs triggered inside the kernel will
765 // use the new map configuration. So once this function returns it is safe to modify the
766 // old stats map without concerning about race between the kernel and userspace.
767 final int err = mDeps.synchronizeKernelRCU();
768 maybeThrow(err, "synchronizeKernelRCU failed");
769 } else {
770 final int err = native_swapActiveStatsMap();
771 maybeThrow(err, "Unable to swap active stats map");
772 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800773 }
774
Ken Chenf5f51332022-01-28 10:08:16 +0800775 /**
776 * Assigns android.permission.INTERNET and/or android.permission.UPDATE_DEVICE_STATS to the uids
777 * specified. Or remove all permissions from the uids.
778 *
779 * @param permissions The permission to grant, it could be either PERMISSION_INTERNET and/or
780 * PERMISSION_UPDATE_DEVICE_STATS. If the permission is NO_PERMISSIONS, then
781 * revoke all permissions for the uids.
782 * @param uids uid of users to grant permission
783 * @throws RemoteException when netd has crashed.
784 */
785 public void setNetPermForUids(final int permissions, final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000786 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800787 mNetd.trafficSetNetPermForUids(permissions, uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800788 return;
789 }
Motomu Utsumi65271202022-07-05 08:21:41 +0000790
791 if (sEnableJavaBpfMap) {
792 // Remove the entry if package is uninstalled or uid has only INTERNET permission.
793 if (permissions == PERMISSION_UNINSTALLED || permissions == PERMISSION_INTERNET) {
794 for (final int uid : uids) {
795 try {
796 sUidPermissionMap.deleteEntry(new U32(uid));
797 } catch (ErrnoException e) {
798 Log.e(TAG, "Failed to remove uid " + uid + " from permission map: " + e);
799 }
800 }
801 return;
802 }
803
804 for (final int uid : uids) {
805 try {
806 sUidPermissionMap.updateEntry(new U32(uid), new U8((short) permissions));
807 } catch (ErrnoException e) {
808 Log.e(TAG, "Failed to set permission "
809 + permissions + " to uid " + uid + ": " + e);
810 }
811 }
812 } else {
813 native_setPermissionForUids(permissions, uids);
814 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800815 }
816
Ken Chene6d511f2022-01-25 11:10:42 +0800817 /**
818 * Dump BPF maps
819 *
820 * @param fd file descriptor to output
821 * @throws IOException when file descriptor is invalid.
822 * @throws ServiceSpecificException when the method is called on an unsupported device.
823 */
824 public void dump(final FileDescriptor fd, boolean verbose)
825 throws IOException, ServiceSpecificException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000826 if (PRE_T) {
Ken Chene6d511f2022-01-25 11:10:42 +0800827 throw new ServiceSpecificException(
828 EOPNOTSUPP, "dumpsys connectivity trafficcontroller dump not available on pre-T"
829 + " devices, use dumpsys netd trafficcontroller instead.");
830 }
831 native_dump(fd, verbose);
832 }
833
Wayne Ma790c83e2022-01-13 10:35:05 +0800834 private static native void native_init();
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800835 private native int native_addNaughtyApp(int uid);
836 private native int native_removeNaughtyApp(int uid);
837 private native int native_addNiceApp(int uid);
838 private native int native_removeNiceApp(int uid);
Motomu Utsumi114cd9c2022-08-01 02:08:35 +0000839 private native int native_setChildChain(int childChain, boolean enable);
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800840 private native int native_replaceUidChain(String name, boolean isAllowlist, int[] uids);
841 private native int native_setUidRule(int childChain, int uid, int firewallRule);
842 private native int native_addUidInterfaceRules(String ifName, int[] uids);
843 private native int native_removeUidInterfaceRules(int[] uids);
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000844 private native int native_updateUidLockdownRule(int uid, boolean add);
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800845 private native int native_swapActiveStatsMap();
Wayne Ma2fde98c2022-01-17 18:04:05 +0800846 private native void native_setPermissionForUids(int permissions, int[] uids);
Ken Chene6d511f2022-01-25 11:10:42 +0800847 private native void native_dump(FileDescriptor fd, boolean verbose);
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000848 private static native int native_synchronizeKernelRCU();
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800849}