blob: 52db7403a188f17a03386a174bd8edad983ded0b [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.
554 // http://b/220084230.
555 if (config != null
556 && !uidSet.contains((int) uid.val) && (config.rule & match) != 0) {
557 uidSetToRemoveRule.add((int) uid.val);
558 }
559 });
560
561 for (final int uid : uidSetToRemoveRule) {
562 removeRule(uid, match, "replaceUidChain");
563 }
564 for (final int uid : uids) {
565 addRule(uid, match, "replaceUidChain");
566 }
567 }
568 } catch (ErrnoException | ServiceSpecificException e) {
569 Log.e(TAG, "replaceUidChain failed: " + e);
570 }
571 } else {
572 final int err;
573 switch (chain) {
574 case FIREWALL_CHAIN_DOZABLE:
575 err = native_replaceUidChain("fw_dozable", true /* isAllowList */, uids);
576 break;
577 case FIREWALL_CHAIN_STANDBY:
578 err = native_replaceUidChain("fw_standby", false /* isAllowList */, uids);
579 break;
580 case FIREWALL_CHAIN_POWERSAVE:
581 err = native_replaceUidChain("fw_powersave", true /* isAllowList */, uids);
582 break;
583 case FIREWALL_CHAIN_RESTRICTED:
584 err = native_replaceUidChain("fw_restricted", true /* isAllowList */, uids);
585 break;
586 case FIREWALL_CHAIN_LOW_POWER_STANDBY:
587 err = native_replaceUidChain(
588 "fw_low_power_standby", true /* isAllowList */, uids);
589 break;
590 case FIREWALL_CHAIN_OEM_DENY_1:
591 err = native_replaceUidChain("fw_oem_deny_1", false /* isAllowList */, uids);
592 break;
593 case FIREWALL_CHAIN_OEM_DENY_2:
594 err = native_replaceUidChain("fw_oem_deny_2", false /* isAllowList */, uids);
595 break;
596 case FIREWALL_CHAIN_OEM_DENY_3:
597 err = native_replaceUidChain("fw_oem_deny_3", false /* isAllowList */, uids);
598 break;
599 default:
600 throw new IllegalArgumentException("replaceFirewallChain with invalid chain: "
601 + chain);
602 }
603 if (err != 0) {
604 Log.e(TAG, "replaceUidChain failed: " + Os.strerror(-err));
605 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800606 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800607 }
608
Ken Chenf5f51332022-01-28 10:08:16 +0800609 /**
610 * Set firewall rule for uid
611 *
612 * @param childChain target chain
613 * @param uid uid to allow/deny
614 * @param firewallRule either FIREWALL_RULE_ALLOW or FIREWALL_RULE_DENY
Ken Chenf5f51332022-01-28 10:08:16 +0800615 * @throws ServiceSpecificException in case of failure, with an error code indicating the
616 * cause of the failure.
617 */
Lorenzo Colitti82244fd2022-03-04 23:15:00 +0900618 public void setUidRule(final int childChain, final int uid, final int firewallRule) {
Motomu Utsumi40230be2022-07-05 03:27:35 +0000619 throwIfPreT("setUidRule is not available on pre-T devices");
620
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000621 if (sEnableJavaBpfMap) {
622 final long match = getMatchByFirewallChain(childChain);
623 final boolean isAllowList = isFirewallAllowList(childChain);
624 final boolean add = (firewallRule == FIREWALL_RULE_ALLOW && isAllowList)
625 || (firewallRule == FIREWALL_RULE_DENY && !isAllowList);
Motomu Utsumi40230be2022-07-05 03:27:35 +0000626
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000627 if (add) {
628 addRule(uid, match, "setUidRule");
629 } else {
630 removeRule(uid, match, "setUidRule");
631 }
Motomu Utsumi40230be2022-07-05 03:27:35 +0000632 } else {
Motomu Utsumi381ad9e2022-08-03 06:42:47 +0000633 final int err = native_setUidRule(childChain, uid, firewallRule);
634 maybeThrow(err, "Unable to set uid rule");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000635 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800636 }
637
638 /**
639 * Add ingress interface filtering rules to a list of UIDs
640 *
641 * For a given uid, once a filtering rule is added, the kernel will only allow packets from the
642 * allowed interface and loopback to be sent to the list of UIDs.
643 *
644 * Calling this method on one or more UIDs with an existing filtering rule but a different
645 * interface name will result in the filtering rule being updated to allow the new interface
646 * instead. Otherwise calling this method will not affect existing rules set on other UIDs.
647 *
648 * @param ifName the name of the interface on which the filtering rules will allow packets to
Ken Chenf5f51332022-01-28 10:08:16 +0800649 * be received.
650 * @param uids an array of UIDs which the filtering rules will be set
651 * @throws RemoteException when netd has crashed.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800652 * @throws ServiceSpecificException in case of failure, with an error code indicating the
Ken Chenf5f51332022-01-28 10:08:16 +0800653 * cause of the failure.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800654 */
Ken Chenf5f51332022-01-28 10:08:16 +0800655 public void addUidInterfaceRules(final String ifName, final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000656 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800657 mNetd.firewallAddUidInterfaceRules(ifName, uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800658 return;
659 }
Motomu Utsumif794e7d2022-08-03 06:38:43 +0000660
661 if (sEnableJavaBpfMap) {
662 // Null ifName is a wildcard to allow apps to receive packets on all interfaces and
663 // ifIndex is set to 0.
664 final int ifIndex;
665 if (ifName == null) {
666 ifIndex = 0;
667 } else {
668 ifIndex = mDeps.getIfIndex(ifName);
669 if (ifIndex == 0) {
670 throw new ServiceSpecificException(ENODEV,
671 "Failed to get index of interface " + ifName);
672 }
673 }
674 for (final int uid : uids) {
675 try {
676 addRule(uid, IIF_MATCH, ifIndex, "addUidInterfaceRules");
677 } catch (ServiceSpecificException e) {
678 Log.e(TAG, "addRule failed uid=" + uid + " ifName=" + ifName + ", " + e);
679 }
680 }
Motomu Utsumi5f52f4f2022-06-30 03:31:09 +0000681 } else {
Motomu Utsumif794e7d2022-08-03 06:38:43 +0000682 final int err = native_addUidInterfaceRules(ifName, uids);
683 maybeThrow(err, "Unable to add uid interface rules");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000684 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800685 }
686
687 /**
688 * Remove ingress interface filtering rules from a list of UIDs
689 *
690 * Clear the ingress interface filtering rules from the list of UIDs which were previously set
691 * by addUidInterfaceRules(). Ignore any uid which does not have filtering rule.
692 *
693 * @param uids an array of UIDs from which the filtering rules will be removed
Ken Chenf5f51332022-01-28 10:08:16 +0800694 * @throws RemoteException when netd has crashed.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800695 * @throws ServiceSpecificException in case of failure, with an error code indicating the
Ken Chenf5f51332022-01-28 10:08:16 +0800696 * cause of the failure.
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800697 */
Ken Chenf5f51332022-01-28 10:08:16 +0800698 public void removeUidInterfaceRules(final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000699 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800700 mNetd.firewallRemoveUidInterfaceRules(uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800701 return;
702 }
Motomu Utsumi7dc657d2022-08-03 06:40:46 +0000703
704 if (sEnableJavaBpfMap) {
705 for (final int uid : uids) {
706 try {
707 removeRule(uid, IIF_MATCH, "removeUidInterfaceRules");
708 } catch (ServiceSpecificException e) {
709 Log.e(TAG, "removeRule failed uid=" + uid + ", " + e);
710 }
Motomu Utsumi599c4e52022-06-30 03:37:18 +0000711 }
Motomu Utsumi7dc657d2022-08-03 06:40:46 +0000712 } else {
713 final int err = native_removeUidInterfaceRules(uids);
714 maybeThrow(err, "Unable to remove uid interface rules");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000715 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800716 }
717
Ken Chenf5f51332022-01-28 10:08:16 +0800718 /**
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000719 * Update lockdown rule for uid
720 *
721 * @param uid target uid to add/remove the rule
722 * @param add {@code true} to add the rule, {@code false} to remove the rule.
723 * @throws ServiceSpecificException in case of failure, with an error code indicating the
724 * cause of the failure.
725 */
726 public void updateUidLockdownRule(final int uid, final boolean add) {
Motomu Utsumi697b2992022-06-30 02:25:29 +0000727 throwIfPreT("updateUidLockdownRule is not available on pre-T devices");
Motomu Utsumib2d32b72022-08-03 06:31:58 +0000728
729 if (sEnableJavaBpfMap) {
730 if (add) {
731 addRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule");
732 } else {
733 removeRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule");
734 }
Motomu Utsumi697b2992022-06-30 02:25:29 +0000735 } else {
Motomu Utsumib2d32b72022-08-03 06:31:58 +0000736 final int err = native_updateUidLockdownRule(uid, add);
737 maybeThrow(err, "Unable to update lockdown rule");
Motomu Utsumi5a68a212022-06-24 10:14:31 +0000738 }
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000739 }
740
741 /**
Ken Chenf5f51332022-01-28 10:08:16 +0800742 * Request netd to change the current active network stats map.
743 *
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000744 * @throws UnsupportedOperationException if called on pre-T devices.
Ken Chenf5f51332022-01-28 10:08:16 +0800745 * @throws ServiceSpecificException in case of failure, with an error code indicating the
746 * cause of the failure.
747 */
markchien49e944c2022-03-01 15:22:20 +0800748 public void swapActiveStatsMap() {
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000749 throwIfPreT("swapActiveStatsMap is not available on pre-T devices");
750
751 if (sEnableJavaBpfMap) {
752 try {
753 synchronized (sCurrentStatsMapConfigLock) {
754 final long config = sConfigurationMap.getValue(
755 CURRENT_STATS_MAP_CONFIGURATION_KEY).val;
756 final long newConfig = (config == STATS_SELECT_MAP_A)
757 ? STATS_SELECT_MAP_B : STATS_SELECT_MAP_A;
758 sConfigurationMap.updateEntry(CURRENT_STATS_MAP_CONFIGURATION_KEY,
759 new U32(newConfig));
760 }
761 } catch (ErrnoException e) {
762 throw new ServiceSpecificException(e.errno, "Failed to swap active stats map");
763 }
764
765 // After changing the config, it's needed to make sure all the current running eBPF
766 // programs are finished and all the CPUs are aware of this config change before the old
767 // map is modified. So special hack is needed here to wait for the kernel to do a
768 // synchronize_rcu(). Once the kernel called synchronize_rcu(), the updated config will
769 // be available to all cores and the next eBPF programs triggered inside the kernel will
770 // use the new map configuration. So once this function returns it is safe to modify the
771 // old stats map without concerning about race between the kernel and userspace.
772 final int err = mDeps.synchronizeKernelRCU();
773 maybeThrow(err, "synchronizeKernelRCU failed");
774 } else {
775 final int err = native_swapActiveStatsMap();
776 maybeThrow(err, "Unable to swap active stats map");
777 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800778 }
779
Ken Chenf5f51332022-01-28 10:08:16 +0800780 /**
781 * Assigns android.permission.INTERNET and/or android.permission.UPDATE_DEVICE_STATS to the uids
782 * specified. Or remove all permissions from the uids.
783 *
784 * @param permissions The permission to grant, it could be either PERMISSION_INTERNET and/or
785 * PERMISSION_UPDATE_DEVICE_STATS. If the permission is NO_PERMISSIONS, then
786 * revoke all permissions for the uids.
787 * @param uids uid of users to grant permission
788 * @throws RemoteException when netd has crashed.
789 */
790 public void setNetPermForUids(final int permissions, final int[] uids) throws RemoteException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000791 if (PRE_T) {
Ken Chenf5f51332022-01-28 10:08:16 +0800792 mNetd.trafficSetNetPermForUids(permissions, uids);
Wayne Ma2fde98c2022-01-17 18:04:05 +0800793 return;
794 }
Motomu Utsumi65271202022-07-05 08:21:41 +0000795
796 if (sEnableJavaBpfMap) {
797 // Remove the entry if package is uninstalled or uid has only INTERNET permission.
798 if (permissions == PERMISSION_UNINSTALLED || permissions == PERMISSION_INTERNET) {
799 for (final int uid : uids) {
800 try {
801 sUidPermissionMap.deleteEntry(new U32(uid));
802 } catch (ErrnoException e) {
803 Log.e(TAG, "Failed to remove uid " + uid + " from permission map: " + e);
804 }
805 }
806 return;
807 }
808
809 for (final int uid : uids) {
810 try {
811 sUidPermissionMap.updateEntry(new U32(uid), new U8((short) permissions));
812 } catch (ErrnoException e) {
813 Log.e(TAG, "Failed to set permission "
814 + permissions + " to uid " + uid + ": " + e);
815 }
816 }
817 } else {
818 native_setPermissionForUids(permissions, uids);
819 }
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800820 }
821
Ken Chene6d511f2022-01-25 11:10:42 +0800822 /**
823 * Dump BPF maps
824 *
825 * @param fd file descriptor to output
826 * @throws IOException when file descriptor is invalid.
827 * @throws ServiceSpecificException when the method is called on an unsupported device.
828 */
829 public void dump(final FileDescriptor fd, boolean verbose)
830 throws IOException, ServiceSpecificException {
Motomu Utsumi25cf86f2022-06-27 08:50:19 +0000831 if (PRE_T) {
Ken Chene6d511f2022-01-25 11:10:42 +0800832 throw new ServiceSpecificException(
833 EOPNOTSUPP, "dumpsys connectivity trafficcontroller dump not available on pre-T"
834 + " devices, use dumpsys netd trafficcontroller instead.");
835 }
836 native_dump(fd, verbose);
837 }
838
Wayne Ma790c83e2022-01-13 10:35:05 +0800839 private static native void native_init();
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800840 private native int native_addNaughtyApp(int uid);
841 private native int native_removeNaughtyApp(int uid);
842 private native int native_addNiceApp(int uid);
843 private native int native_removeNiceApp(int uid);
Motomu Utsumi114cd9c2022-08-01 02:08:35 +0000844 private native int native_setChildChain(int childChain, boolean enable);
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800845 private native int native_replaceUidChain(String name, boolean isAllowlist, int[] uids);
846 private native int native_setUidRule(int childChain, int uid, int firewallRule);
847 private native int native_addUidInterfaceRules(String ifName, int[] uids);
848 private native int native_removeUidInterfaceRules(int[] uids);
Motomu Utsumi8b42e6d2022-05-19 06:23:40 +0000849 private native int native_updateUidLockdownRule(int uid, boolean add);
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800850 private native int native_swapActiveStatsMap();
Wayne Ma2fde98c2022-01-17 18:04:05 +0800851 private native void native_setPermissionForUids(int permissions, int[] uids);
Ken Chene6d511f2022-01-25 11:10:42 +0800852 private native void native_dump(FileDescriptor fd, boolean verbose);
Motomu Utsumi7abeaa42022-07-20 07:54:18 +0000853 private static native int native_synchronizeKernelRCU();
Wayne Ma0ea3bdc2022-01-12 01:12:11 +0800854}