Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server; |
| 18 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 19 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_DOZABLE; |
| 20 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_LOW_POWER_STANDBY; |
| 21 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_1; |
| 22 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_2; |
| 23 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_OEM_DENY_3; |
| 24 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE; |
| 25 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_RESTRICTED; |
| 26 | import static android.net.ConnectivityManager.FIREWALL_CHAIN_STANDBY; |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 27 | import static android.net.ConnectivityManager.FIREWALL_RULE_ALLOW; |
| 28 | import static android.net.ConnectivityManager.FIREWALL_RULE_DENY; |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 29 | import static android.system.OsConstants.EINVAL; |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 30 | import static android.system.OsConstants.ENODEV; |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 31 | import static android.system.OsConstants.ENOENT; |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 32 | import static android.system.OsConstants.EOPNOTSUPP; |
| 33 | |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 34 | import android.net.INetd; |
| 35 | import android.os.RemoteException; |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 36 | import android.os.ServiceSpecificException; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 37 | import android.system.ErrnoException; |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 38 | import android.system.Os; |
| 39 | import android.util.Log; |
| 40 | |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 41 | import com.android.internal.annotations.GuardedBy; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 42 | import com.android.internal.annotations.VisibleForTesting; |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 43 | import com.android.modules.utils.build.SdkLevel; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 44 | import com.android.net.module.util.BpfMap; |
| 45 | import com.android.net.module.util.Struct.U32; |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 46 | |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 47 | import java.io.FileDescriptor; |
| 48 | import java.io.IOException; |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame^] | 49 | import java.util.Arrays; |
| 50 | import java.util.HashSet; |
| 51 | import java.util.Set; |
| 52 | import java.util.stream.Collectors; |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 53 | |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 54 | /** |
| 55 | * BpfNetMaps is responsible for providing traffic controller relevant functionality. |
| 56 | * |
| 57 | * {@hide} |
| 58 | */ |
| 59 | public class BpfNetMaps { |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 60 | private static final boolean PRE_T = !SdkLevel.isAtLeastT(); |
| 61 | static { |
| 62 | if (!PRE_T) { |
| 63 | System.loadLibrary("service-connectivity"); |
| 64 | } |
| 65 | } |
| 66 | |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 67 | private static final String TAG = "BpfNetMaps"; |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 68 | private final INetd mNetd; |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 69 | private final Dependencies mDeps; |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 70 | // Use legacy netd for releases before T. |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 71 | private static boolean sInitialized = false; |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 72 | |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 73 | // Lock for sConfigurationMap entry for UID_RULES_CONFIGURATION_KEY. |
| 74 | // This entry is not accessed by others. |
| 75 | // BpfNetMaps acquires this lock while sequence of read, modify, and write. |
| 76 | private static final Object sUidRulesConfigBpfMapLock = new Object(); |
| 77 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 78 | private static final String CONFIGURATION_MAP_PATH = |
| 79 | "/sys/fs/bpf/netd_shared/map_netd_configuration_map"; |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 80 | private static final String UID_OWNER_MAP_PATH = |
| 81 | "/sys/fs/bpf/netd_shared/map_netd_uid_owner_map"; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 82 | private static final U32 UID_RULES_CONFIGURATION_KEY = new U32(0); |
| 83 | private static BpfMap<U32, U32> sConfigurationMap = null; |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 84 | // BpfMap for UID_OWNER_MAP_PATH. This map is not accessed by others. |
| 85 | private static BpfMap<U32, UidOwnerValue> sUidOwnerMap = null; |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 86 | |
| 87 | // LINT.IfChange(match_type) |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 88 | @VisibleForTesting public static final long NO_MATCH = 0; |
| 89 | @VisibleForTesting public static final long HAPPY_BOX_MATCH = (1 << 0); |
| 90 | @VisibleForTesting public static final long PENALTY_BOX_MATCH = (1 << 1); |
| 91 | @VisibleForTesting public static final long DOZABLE_MATCH = (1 << 2); |
| 92 | @VisibleForTesting public static final long STANDBY_MATCH = (1 << 3); |
| 93 | @VisibleForTesting public static final long POWERSAVE_MATCH = (1 << 4); |
| 94 | @VisibleForTesting public static final long RESTRICTED_MATCH = (1 << 5); |
| 95 | @VisibleForTesting public static final long LOW_POWER_STANDBY_MATCH = (1 << 6); |
| 96 | @VisibleForTesting public static final long IIF_MATCH = (1 << 7); |
| 97 | @VisibleForTesting public static final long LOCKDOWN_VPN_MATCH = (1 << 8); |
| 98 | @VisibleForTesting public static final long OEM_DENY_1_MATCH = (1 << 9); |
| 99 | @VisibleForTesting public static final long OEM_DENY_2_MATCH = (1 << 10); |
| 100 | @VisibleForTesting public static final long OEM_DENY_3_MATCH = (1 << 11); |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 101 | // LINT.ThenChange(packages/modules/Connectivity/bpf_progs/bpf_shared.h) |
| 102 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 103 | /** |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 104 | * Set configurationMap for test. |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 105 | */ |
| 106 | @VisibleForTesting |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 107 | public static void setConfigurationMapForTest(BpfMap<U32, U32> configurationMap) { |
| 108 | sConfigurationMap = configurationMap; |
| 109 | } |
| 110 | |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 111 | /** |
| 112 | * Set uidOwnerMap for test. |
| 113 | */ |
| 114 | @VisibleForTesting |
| 115 | public static void setUidOwnerMapForTest(BpfMap<U32, UidOwnerValue> uidOwnerMap) { |
| 116 | sUidOwnerMap = uidOwnerMap; |
| 117 | } |
| 118 | |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 119 | private static BpfMap<U32, U32> getConfigurationMap() { |
| 120 | try { |
| 121 | return new BpfMap<>( |
| 122 | CONFIGURATION_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, U32.class); |
| 123 | } catch (ErrnoException e) { |
| 124 | throw new IllegalStateException("Cannot open netd configuration map", e); |
| 125 | } |
| 126 | } |
| 127 | |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 128 | private static BpfMap<U32, UidOwnerValue> getUidOwnerMap() { |
| 129 | try { |
| 130 | return new BpfMap<>( |
| 131 | UID_OWNER_MAP_PATH, BpfMap.BPF_F_RDWR, U32.class, UidOwnerValue.class); |
| 132 | } catch (ErrnoException e) { |
| 133 | throw new IllegalStateException("Cannot open uid owner map", e); |
| 134 | } |
| 135 | } |
| 136 | |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 137 | private static void setBpfMaps() { |
| 138 | if (sConfigurationMap == null) { |
| 139 | sConfigurationMap = getConfigurationMap(); |
| 140 | } |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 141 | if (sUidOwnerMap == null) { |
| 142 | sUidOwnerMap = getUidOwnerMap(); |
| 143 | } |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 146 | /** |
| 147 | * Initializes the class if it is not already initialized. This method will open maps but not |
| 148 | * cause any other effects. This method may be called multiple times on any thread. |
| 149 | */ |
| 150 | private static synchronized void ensureInitialized() { |
| 151 | if (sInitialized) return; |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 152 | setBpfMaps(); |
| 153 | native_init(); |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 154 | sInitialized = true; |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 155 | } |
| 156 | |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 157 | /** |
| 158 | * Dependencies of BpfNetMaps, for injection in tests. |
| 159 | */ |
| 160 | @VisibleForTesting |
| 161 | public static class Dependencies { |
| 162 | /** |
| 163 | * Get interface index. |
| 164 | */ |
| 165 | public int getIfIndex(final String ifName) { |
| 166 | return Os.if_nametoindex(ifName); |
| 167 | } |
| 168 | } |
| 169 | |
markchien | 49e944c | 2022-03-01 15:22:20 +0800 | [diff] [blame] | 170 | /** Constructor used after T that doesn't need to use netd anymore. */ |
| 171 | public BpfNetMaps() { |
| 172 | this(null); |
| 173 | |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 174 | if (PRE_T) throw new IllegalArgumentException("BpfNetMaps need to use netd before T"); |
markchien | 49e944c | 2022-03-01 15:22:20 +0800 | [diff] [blame] | 175 | } |
| 176 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 177 | public BpfNetMaps(final INetd netd) { |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 178 | this(netd, new Dependencies()); |
| 179 | } |
| 180 | |
| 181 | @VisibleForTesting |
| 182 | public BpfNetMaps(final INetd netd, final Dependencies deps) { |
Motomu Utsumi | 305975f | 2022-06-27 09:24:32 +0000 | [diff] [blame] | 183 | if (!PRE_T) { |
| 184 | ensureInitialized(); |
| 185 | } |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 186 | mNetd = netd; |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 187 | mDeps = deps; |
Wayne Ma | 790c83e | 2022-01-13 10:35:05 +0800 | [diff] [blame] | 188 | } |
| 189 | |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 190 | /** |
| 191 | * Get corresponding match from firewall chain. |
| 192 | */ |
| 193 | @VisibleForTesting |
| 194 | public long getMatchByFirewallChain(final int chain) { |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 195 | switch (chain) { |
| 196 | case FIREWALL_CHAIN_DOZABLE: |
| 197 | return DOZABLE_MATCH; |
| 198 | case FIREWALL_CHAIN_STANDBY: |
| 199 | return STANDBY_MATCH; |
| 200 | case FIREWALL_CHAIN_POWERSAVE: |
| 201 | return POWERSAVE_MATCH; |
| 202 | case FIREWALL_CHAIN_RESTRICTED: |
| 203 | return RESTRICTED_MATCH; |
| 204 | case FIREWALL_CHAIN_LOW_POWER_STANDBY: |
| 205 | return LOW_POWER_STANDBY_MATCH; |
| 206 | case FIREWALL_CHAIN_OEM_DENY_1: |
| 207 | return OEM_DENY_1_MATCH; |
| 208 | case FIREWALL_CHAIN_OEM_DENY_2: |
| 209 | return OEM_DENY_2_MATCH; |
| 210 | case FIREWALL_CHAIN_OEM_DENY_3: |
| 211 | return OEM_DENY_3_MATCH; |
| 212 | default: |
| 213 | throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain); |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 214 | } |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Get if the chain is allow list or not. |
| 219 | * |
| 220 | * ALLOWLIST means the firewall denies all by default, uids must be explicitly allowed |
| 221 | * DENYLIST means the firewall allows all by default, uids must be explicitly denyed |
| 222 | */ |
| 223 | @VisibleForTesting |
| 224 | public boolean isFirewallAllowList(final int chain) { |
| 225 | switch (chain) { |
| 226 | case FIREWALL_CHAIN_DOZABLE: |
| 227 | case FIREWALL_CHAIN_POWERSAVE: |
| 228 | case FIREWALL_CHAIN_RESTRICTED: |
| 229 | case FIREWALL_CHAIN_LOW_POWER_STANDBY: |
| 230 | return true; |
| 231 | case FIREWALL_CHAIN_STANDBY: |
| 232 | case FIREWALL_CHAIN_OEM_DENY_1: |
| 233 | case FIREWALL_CHAIN_OEM_DENY_2: |
| 234 | case FIREWALL_CHAIN_OEM_DENY_3: |
| 235 | return false; |
| 236 | default: |
| 237 | throw new ServiceSpecificException(EINVAL, "Invalid firewall chain: " + chain); |
| 238 | } |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 241 | private void maybeThrow(final int err, final String msg) { |
| 242 | if (err != 0) { |
| 243 | throw new ServiceSpecificException(err, msg + ": " + Os.strerror(err)); |
| 244 | } |
| 245 | } |
| 246 | |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 247 | private void throwIfPreT(final String msg) { |
| 248 | if (PRE_T) { |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 249 | throw new UnsupportedOperationException(msg); |
| 250 | } |
| 251 | } |
| 252 | |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 253 | private void removeRule(final int uid, final long match, final String caller) { |
| 254 | try { |
| 255 | synchronized (sUidOwnerMap) { |
| 256 | final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new U32(uid)); |
| 257 | |
| 258 | if (oldMatch == null) { |
| 259 | throw new ServiceSpecificException(ENOENT, |
| 260 | "sUidOwnerMap does not have entry for uid: " + uid); |
| 261 | } |
| 262 | |
| 263 | final UidOwnerValue newMatch = new UidOwnerValue( |
| 264 | (match == IIF_MATCH) ? 0 : oldMatch.iif, |
| 265 | oldMatch.rule & ~match |
| 266 | ); |
| 267 | |
| 268 | if (newMatch.rule == 0) { |
| 269 | sUidOwnerMap.deleteEntry(new U32(uid)); |
| 270 | } else { |
| 271 | sUidOwnerMap.updateEntry(new U32(uid), newMatch); |
| 272 | } |
| 273 | } |
| 274 | } catch (ErrnoException e) { |
| 275 | throw new ServiceSpecificException(e.errno, |
| 276 | caller + " failed to remove rule: " + Os.strerror(e.errno)); |
| 277 | } |
| 278 | } |
| 279 | |
Motomu Utsumi | 389278e | 2022-06-28 07:05:05 +0000 | [diff] [blame] | 280 | private void addRule(final int uid, final long match, final long iif, final String caller) { |
| 281 | if (match != IIF_MATCH && iif != 0) { |
| 282 | throw new ServiceSpecificException(EINVAL, |
| 283 | "Non-interface match must have zero interface index"); |
| 284 | } |
| 285 | |
| 286 | try { |
| 287 | synchronized (sUidOwnerMap) { |
| 288 | final UidOwnerValue oldMatch = sUidOwnerMap.getValue(new U32(uid)); |
| 289 | |
| 290 | final UidOwnerValue newMatch; |
| 291 | if (oldMatch != null) { |
| 292 | newMatch = new UidOwnerValue( |
| 293 | (match == IIF_MATCH) ? iif : oldMatch.iif, |
| 294 | oldMatch.rule | match |
| 295 | ); |
| 296 | } else { |
| 297 | newMatch = new UidOwnerValue( |
| 298 | iif, |
| 299 | match |
| 300 | ); |
| 301 | } |
| 302 | sUidOwnerMap.updateEntry(new U32(uid), newMatch); |
| 303 | } |
| 304 | } catch (ErrnoException e) { |
| 305 | throw new ServiceSpecificException(e.errno, |
| 306 | caller + " failed to add rule: " + Os.strerror(e.errno)); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | private void addRule(final int uid, final long match, final String caller) { |
| 311 | addRule(uid, match, 0 /* iif */, caller); |
| 312 | } |
| 313 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 314 | /** |
| 315 | * Add naughty app bandwidth rule for specific app |
| 316 | * |
| 317 | * @param uid uid of target app |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 318 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 319 | * cause of the failure. |
| 320 | */ |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 321 | public void addNaughtyApp(final int uid) { |
Motomu Utsumi | 389278e | 2022-06-28 07:05:05 +0000 | [diff] [blame] | 322 | throwIfPreT("addNaughtyApp is not available on pre-T devices"); |
| 323 | addRule(uid, PENALTY_BOX_MATCH, "addNaughtyApp"); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 324 | } |
| 325 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 326 | /** |
| 327 | * Remove naughty app bandwidth rule for specific app |
| 328 | * |
| 329 | * @param uid uid of target app |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 330 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 331 | * cause of the failure. |
| 332 | */ |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 333 | public void removeNaughtyApp(final int uid) { |
Motomu Utsumi | 60ed3be | 2022-06-24 10:38:57 +0000 | [diff] [blame] | 334 | throwIfPreT("removeNaughtyApp is not available on pre-T devices"); |
| 335 | removeRule(uid, PENALTY_BOX_MATCH, "removeNaughtyApp"); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 336 | } |
| 337 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 338 | /** |
| 339 | * Add nice app bandwidth rule for specific app |
| 340 | * |
| 341 | * @param uid uid of target app |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 342 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 343 | * cause of the failure. |
| 344 | */ |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 345 | public void addNiceApp(final int uid) { |
Motomu Utsumi | 55630d0 | 2022-06-29 07:46:52 +0000 | [diff] [blame] | 346 | throwIfPreT("addNiceApp is not available on pre-T devices"); |
| 347 | addRule(uid, HAPPY_BOX_MATCH, "addNiceApp"); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 348 | } |
| 349 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 350 | /** |
| 351 | * Remove nice app bandwidth rule for specific app |
| 352 | * |
| 353 | * @param uid uid of target app |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 354 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 355 | * cause of the failure. |
| 356 | */ |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 357 | public void removeNiceApp(final int uid) { |
Motomu Utsumi | 7392eb4 | 2022-06-29 03:53:03 +0000 | [diff] [blame] | 358 | throwIfPreT("removeNiceApp is not available on pre-T devices"); |
| 359 | removeRule(uid, HAPPY_BOX_MATCH, "removeNiceApp"); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 360 | } |
| 361 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 362 | /** |
| 363 | * Set target firewall child chain |
| 364 | * |
| 365 | * @param childChain target chain to enable |
| 366 | * @param enable whether to enable or disable child chain. |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 367 | * @throws UnsupportedOperationException if called on pre-T devices. |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 368 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 369 | * cause of the failure. |
| 370 | */ |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 371 | public void setChildChain(final int childChain, final boolean enable) { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 372 | throwIfPreT("setChildChain is not available on pre-T devices"); |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 373 | |
| 374 | final long match = getMatchByFirewallChain(childChain); |
| 375 | try { |
| 376 | synchronized (sUidRulesConfigBpfMapLock) { |
| 377 | final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY); |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 378 | final long newConfig = enable ? (config.val | match) : (config.val & ~match); |
Motomu Utsumi | 18b287d | 2022-06-19 10:45:30 +0000 | [diff] [blame] | 379 | sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY, new U32(newConfig)); |
| 380 | } |
| 381 | } catch (ErrnoException e) { |
| 382 | throw new ServiceSpecificException(e.errno, |
| 383 | "Unable to set child chain: " + Os.strerror(e.errno)); |
| 384 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /** |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 388 | * Get the specified firewall chain's status. |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 389 | * |
| 390 | * @param childChain target chain |
| 391 | * @return {@code true} if chain is enabled, {@code false} if chain is not enabled. |
| 392 | * @throws UnsupportedOperationException if called on pre-T devices. |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 393 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 394 | * cause of the failure. |
| 395 | */ |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 396 | public boolean isChainEnabled(final int childChain) { |
| 397 | throwIfPreT("isChainEnabled is not available on pre-T devices"); |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 398 | |
| 399 | final long match = getMatchByFirewallChain(childChain); |
| 400 | try { |
| 401 | final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY); |
Motomu Utsumi | be3ff1e | 2022-06-08 10:05:07 +0000 | [diff] [blame] | 402 | return (config.val & match) != 0; |
| 403 | } catch (ErrnoException e) { |
| 404 | throw new ServiceSpecificException(e.errno, |
| 405 | "Unable to get firewall chain status: " + Os.strerror(e.errno)); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 410 | * Replaces the contents of the specified UID-based firewall chain. |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame^] | 411 | * Enables the chain for specified uids and disables the chain for non-specified uids. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 412 | * |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame^] | 413 | * @param chain Target chain. |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 414 | * @param uids The list of UIDs to allow/deny. |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame^] | 415 | * @throws UnsupportedOperationException if called on pre-T devices. |
| 416 | * @throws IllegalArgumentException if {@code chain} is not a valid chain. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 417 | */ |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame^] | 418 | public void replaceUidChain(final int chain, final int[] uids) { |
| 419 | throwIfPreT("replaceUidChain is not available on pre-T devices"); |
| 420 | |
| 421 | final long match; |
| 422 | try { |
| 423 | match = getMatchByFirewallChain(chain); |
| 424 | } catch (ServiceSpecificException e) { |
| 425 | // Throws IllegalArgumentException to keep the behavior of |
| 426 | // ConnectivityManager#replaceFirewallChain API |
| 427 | throw new IllegalArgumentException("Invalid firewall chain: " + chain); |
| 428 | } |
| 429 | final Set<Integer> uidSet = Arrays.stream(uids).boxed().collect(Collectors.toSet()); |
| 430 | final Set<Integer> uidSetToRemoveRule = new HashSet<>(); |
| 431 | try { |
| 432 | synchronized (sUidOwnerMap) { |
| 433 | sUidOwnerMap.forEach((uid, config) -> { |
| 434 | // config could be null if there is a concurrent entry deletion. |
| 435 | // http://b/220084230. |
| 436 | if (config != null |
| 437 | && !uidSet.contains((int) uid.val) && (config.rule & match) != 0) { |
| 438 | uidSetToRemoveRule.add((int) uid.val); |
| 439 | } |
| 440 | }); |
| 441 | |
| 442 | for (final int uid : uidSetToRemoveRule) { |
| 443 | removeRule(uid, match, "replaceUidChain"); |
| 444 | } |
| 445 | for (final int uid : uids) { |
| 446 | addRule(uid, match, "replaceUidChain"); |
| 447 | } |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 448 | } |
Motomu Utsumi | 9be2ea0 | 2022-07-05 06:14:59 +0000 | [diff] [blame^] | 449 | } catch (ErrnoException | ServiceSpecificException e) { |
| 450 | Log.e(TAG, "replaceUidChain failed: " + e); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 451 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 452 | } |
| 453 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 454 | /** |
| 455 | * Set firewall rule for uid |
| 456 | * |
| 457 | * @param childChain target chain |
| 458 | * @param uid uid to allow/deny |
| 459 | * @param firewallRule either FIREWALL_RULE_ALLOW or FIREWALL_RULE_DENY |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 460 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 461 | * cause of the failure. |
| 462 | */ |
Lorenzo Colitti | 82244fd | 2022-03-04 23:15:00 +0900 | [diff] [blame] | 463 | public void setUidRule(final int childChain, final int uid, final int firewallRule) { |
Motomu Utsumi | 40230be | 2022-07-05 03:27:35 +0000 | [diff] [blame] | 464 | throwIfPreT("setUidRule is not available on pre-T devices"); |
| 465 | |
| 466 | final long match = getMatchByFirewallChain(childChain); |
| 467 | final boolean isAllowList = isFirewallAllowList(childChain); |
| 468 | final boolean add = (firewallRule == FIREWALL_RULE_ALLOW && isAllowList) |
| 469 | || (firewallRule == FIREWALL_RULE_DENY && !isAllowList); |
| 470 | |
| 471 | if (add) { |
| 472 | addRule(uid, match, "setUidRule"); |
| 473 | } else { |
| 474 | removeRule(uid, match, "setUidRule"); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 475 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Add ingress interface filtering rules to a list of UIDs |
| 480 | * |
| 481 | * For a given uid, once a filtering rule is added, the kernel will only allow packets from the |
| 482 | * allowed interface and loopback to be sent to the list of UIDs. |
| 483 | * |
| 484 | * Calling this method on one or more UIDs with an existing filtering rule but a different |
| 485 | * interface name will result in the filtering rule being updated to allow the new interface |
| 486 | * instead. Otherwise calling this method will not affect existing rules set on other UIDs. |
| 487 | * |
| 488 | * @param ifName the name of the interface on which the filtering rules will allow packets to |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 489 | * be received. |
| 490 | * @param uids an array of UIDs which the filtering rules will be set |
| 491 | * @throws RemoteException when netd has crashed. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 492 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 493 | * cause of the failure. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 494 | */ |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 495 | public void addUidInterfaceRules(final String ifName, final int[] uids) throws RemoteException { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 496 | if (PRE_T) { |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 497 | mNetd.firewallAddUidInterfaceRules(ifName, uids); |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 498 | return; |
| 499 | } |
Motomu Utsumi | 5f52f4f | 2022-06-30 03:31:09 +0000 | [diff] [blame] | 500 | // Null ifName is a wildcard to allow apps to receive packets on all interfaces and ifIndex |
| 501 | // is set to 0. |
| 502 | final int ifIndex; |
| 503 | if (ifName == null) { |
| 504 | ifIndex = 0; |
| 505 | } else { |
| 506 | ifIndex = mDeps.getIfIndex(ifName); |
| 507 | if (ifIndex == 0) { |
| 508 | throw new ServiceSpecificException(ENODEV, |
| 509 | "Failed to get index of interface " + ifName); |
| 510 | } |
| 511 | } |
| 512 | for (final int uid: uids) { |
| 513 | try { |
| 514 | addRule(uid, IIF_MATCH, ifIndex, "addUidInterfaceRules"); |
| 515 | } catch (ServiceSpecificException e) { |
| 516 | Log.e(TAG, "addRule failed uid=" + uid + " ifName=" + ifName + ", " + e); |
| 517 | } |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 518 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Remove ingress interface filtering rules from a list of UIDs |
| 523 | * |
| 524 | * Clear the ingress interface filtering rules from the list of UIDs which were previously set |
| 525 | * by addUidInterfaceRules(). Ignore any uid which does not have filtering rule. |
| 526 | * |
| 527 | * @param uids an array of UIDs from which the filtering rules will be removed |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 528 | * @throws RemoteException when netd has crashed. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 529 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 530 | * cause of the failure. |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 531 | */ |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 532 | public void removeUidInterfaceRules(final int[] uids) throws RemoteException { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 533 | if (PRE_T) { |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 534 | mNetd.firewallRemoveUidInterfaceRules(uids); |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 535 | return; |
| 536 | } |
Motomu Utsumi | 599c4e5 | 2022-06-30 03:37:18 +0000 | [diff] [blame] | 537 | for (final int uid: uids) { |
| 538 | try { |
| 539 | removeRule(uid, IIF_MATCH, "removeUidInterfaceRules"); |
| 540 | } catch (ServiceSpecificException e) { |
| 541 | Log.e(TAG, "removeRule failed uid=" + uid + ", " + e); |
| 542 | } |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 543 | } |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 544 | } |
| 545 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 546 | /** |
Motomu Utsumi | 8b42e6d | 2022-05-19 06:23:40 +0000 | [diff] [blame] | 547 | * Update lockdown rule for uid |
| 548 | * |
| 549 | * @param uid target uid to add/remove the rule |
| 550 | * @param add {@code true} to add the rule, {@code false} to remove the rule. |
| 551 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 552 | * cause of the failure. |
| 553 | */ |
| 554 | public void updateUidLockdownRule(final int uid, final boolean add) { |
Motomu Utsumi | 697b299 | 2022-06-30 02:25:29 +0000 | [diff] [blame] | 555 | throwIfPreT("updateUidLockdownRule is not available on pre-T devices"); |
| 556 | if (add) { |
| 557 | addRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule"); |
| 558 | } else { |
| 559 | removeRule(uid, LOCKDOWN_VPN_MATCH, "updateUidLockdownRule"); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 560 | } |
Motomu Utsumi | 8b42e6d | 2022-05-19 06:23:40 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /** |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 564 | * Request netd to change the current active network stats map. |
| 565 | * |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 566 | * @throws ServiceSpecificException in case of failure, with an error code indicating the |
| 567 | * cause of the failure. |
| 568 | */ |
markchien | 49e944c | 2022-03-01 15:22:20 +0800 | [diff] [blame] | 569 | public void swapActiveStatsMap() { |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 570 | final int err = native_swapActiveStatsMap(); |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 571 | maybeThrow(err, "Unable to swap active stats map"); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 572 | } |
| 573 | |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 574 | /** |
| 575 | * Assigns android.permission.INTERNET and/or android.permission.UPDATE_DEVICE_STATS to the uids |
| 576 | * specified. Or remove all permissions from the uids. |
| 577 | * |
| 578 | * @param permissions The permission to grant, it could be either PERMISSION_INTERNET and/or |
| 579 | * PERMISSION_UPDATE_DEVICE_STATS. If the permission is NO_PERMISSIONS, then |
| 580 | * revoke all permissions for the uids. |
| 581 | * @param uids uid of users to grant permission |
| 582 | * @throws RemoteException when netd has crashed. |
| 583 | */ |
| 584 | public void setNetPermForUids(final int permissions, final int[] uids) throws RemoteException { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 585 | if (PRE_T) { |
Ken Chen | f5f5133 | 2022-01-28 10:08:16 +0800 | [diff] [blame] | 586 | mNetd.trafficSetNetPermForUids(permissions, uids); |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 587 | return; |
| 588 | } |
| 589 | native_setPermissionForUids(permissions, uids); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 590 | } |
| 591 | |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 592 | /** |
| 593 | * Dump BPF maps |
| 594 | * |
| 595 | * @param fd file descriptor to output |
| 596 | * @throws IOException when file descriptor is invalid. |
| 597 | * @throws ServiceSpecificException when the method is called on an unsupported device. |
| 598 | */ |
| 599 | public void dump(final FileDescriptor fd, boolean verbose) |
| 600 | throws IOException, ServiceSpecificException { |
Motomu Utsumi | 25cf86f | 2022-06-27 08:50:19 +0000 | [diff] [blame] | 601 | if (PRE_T) { |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 602 | throw new ServiceSpecificException( |
| 603 | EOPNOTSUPP, "dumpsys connectivity trafficcontroller dump not available on pre-T" |
| 604 | + " devices, use dumpsys netd trafficcontroller instead."); |
| 605 | } |
| 606 | native_dump(fd, verbose); |
| 607 | } |
| 608 | |
Wayne Ma | 790c83e | 2022-01-13 10:35:05 +0800 | [diff] [blame] | 609 | private static native void native_init(); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 610 | @GuardedBy("sUidOwnerMap") |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 611 | private native int native_addNaughtyApp(int uid); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 612 | @GuardedBy("sUidOwnerMap") |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 613 | private native int native_removeNaughtyApp(int uid); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 614 | @GuardedBy("sUidOwnerMap") |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 615 | private native int native_addNiceApp(int uid); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 616 | @GuardedBy("sUidOwnerMap") |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 617 | private native int native_removeNiceApp(int uid); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 618 | @GuardedBy("sUidOwnerMap") |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 619 | private native int native_replaceUidChain(String name, boolean isAllowlist, int[] uids); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 620 | @GuardedBy("sUidOwnerMap") |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 621 | private native int native_setUidRule(int childChain, int uid, int firewallRule); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 622 | @GuardedBy("sUidOwnerMap") |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 623 | private native int native_addUidInterfaceRules(String ifName, int[] uids); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 624 | @GuardedBy("sUidOwnerMap") |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 625 | private native int native_removeUidInterfaceRules(int[] uids); |
Motomu Utsumi | 5a68a21 | 2022-06-24 10:14:31 +0000 | [diff] [blame] | 626 | @GuardedBy("sUidOwnerMap") |
Motomu Utsumi | 8b42e6d | 2022-05-19 06:23:40 +0000 | [diff] [blame] | 627 | private native int native_updateUidLockdownRule(int uid, boolean add); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 628 | private native int native_swapActiveStatsMap(); |
Wayne Ma | 2fde98c | 2022-01-17 18:04:05 +0800 | [diff] [blame] | 629 | private native void native_setPermissionForUids(int permissions, int[] uids); |
Ken Chen | e6d511f | 2022-01-25 11:10:42 +0800 | [diff] [blame] | 630 | private native void native_dump(FileDescriptor fd, boolean verbose); |
Wayne Ma | 0ea3bdc | 2022-01-12 01:12:11 +0800 | [diff] [blame] | 631 | } |