Commit graph android_packages_modules_Co.../service/src/com/android/server/ConnectivityService.java
Message SHA1
Use netId as idleTimer label on V+
Following CL adds idleTimer for multiple networks and track activities
including non default network on V+
Current LegacyNetworkActivityTracker uses transport type as an idleTimer
label but this makes it difficult to have multiple idleTimers.
So, this CL updates LegacyNetworkActivityTracker to support using netId
as an idleTimer label.

Bug: 267870186
Bug: 279380356
Test: atest FrameworksNetTests
Change-Id: I0039f5624ae1d142dbacba53aa90ca9bf6d43599

Motomu Utsumi   commited 2023-11-14 13:43:45 +09:00
5fce43e548
Merge "Add test to make sure that unwanted local nets disconnect correctly" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-11-09 02:08:36 +00:00
7cf6e5a3b0
New firewall chain for default background restrictions
A new firewall chain is needed to configure background network
restrictions for apps.
This change only adds the API stubs and traffic controller constants to
make the chain work. Policy changes using this chain will follow in
the framework code.

Test: atest CtsNetTestCases:ConnectivityManagerTest
Test: atest ConnectivityServiceTest

NO_IFTTT=The Lint rule along with the relevant code in Common.h is
being deleted in aosp/2819759

Bug: 304347838
Change-Id: I33e2db6671431f7c576fc931d9f96e684fc1e78a

Suprabh Shukla   commited 2023-11-08 10:17:30 +00:00
2d893b68a9
Add test to make sure that unwanted local nets disconnect correctly
Also add some toString() methods that were useful in debugging.

Test: new test in CSLocalAgentTests
Change-Id: Ife95815e39d92bbef84b1c5ea75a151882590d09

Chalard Jean   commited 2023-11-07 22:28:25 +09:00
4fe2339f2c
Add LocalNetworkInfo and send callbacks when it changes
Test: CSLocalAgentTest
Change-Id: I8caca97b891081f9212a01d428a34ed1a08d5126

Chalard Jean   commited 2023-11-07 17:29:38 +09:00
22350c93b4
Set up forwarding rules for local network agents
Test: CSLocalAgentTests, new tests for this
Change-Id: I8994af350a1799ab5f6ebb2872f2abfaf174bd61

Chalard Jean   commited 2023-11-06 20:18:50 +09:00
1e4c218c28
Enforce structural NetworkAgent constraints
Avoid network agents trying to do things that the stack
does not support.

Test: new test in this change
Change-Id: I3ffa1c3ddbb0b648b06862dc0a44f8525d358acc

Chalard Jean   commited 2023-11-02 23:25:11 +09:00
78c9a381c9
Merge "[BR02] Implement isUidNetworkingBlocked" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-11-01 03:40:05 +00:00
2c8e96d599
Merge "Destroyed networks can't hope to beat champions" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-31 10:01:09 +00:00
de33ada087
[BR02] Implement isUidNetworkingBlocked
This is needed for data stall detection mechanism in NetworkStack
to get the information about whether the network is blocked for
a given uid and conditions. Because the API will be called
frequently from NetworkStack to resolve all status for all uids
on the device, the API cannot call into the service which
creates IPC. Instead, the API need to directly access bpf maps
in the user process to retrieve the status. In this case the
user process is the network stack, the access control is provided
by linux file permission and selinux.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.ConnectivityManagerTest
NO_IFTTT=Refactor only change for firewall chains definitions
Bug: 297836825

Change-Id: Iaf983b71ec98cbfe5152dcfade8a3120f938f135

Junyu Lai   commited 2023-10-31 16:33:41 +08:00
e003152e2c
Pass metered information to DNS resolver
Dns Resolver needs to know whether a network is metered when checking if
DNS requests will be blocked by Data Saver.

Bug: 288340533
Test: atest FrameworksNetTests
Change-Id: Ia5822dc522c766c7815680003c7ba275d15ccaff

Ken Chen   commited 2023-10-31 07:38:40 +00:00
5a35cf9086
Write Data Saver setting to BPF map
The information is needed by modules who want to know whether a
specific UID is blocked by Data Saver feature.

1. Add a one-element map data_saver_enabled_map.
2. Update current data saver setting to the map.

Bug: 288340533
Test: atest FrameworksNetTests:android.net.connectivity.com.android.serv
er.BpfNetMapsTest
Test: atest bpf_existence_test

Change-Id: I981da4b569247c33cba2d365cb6f2691f673474e

Ken Chen   commited 2023-10-31 01:36:03 +00:00
243301748e
Destroyed networks can't hope to beat champions
In particular, this fixes a bug where a non-validated destroyed
network can't get disconnected after it's replaced by another
non-validated network because CS thinks it should keep it in
case it validates and beats the replacement network.

Test: new test for this : CSDestroyedNetworkTests
Change-Id: I5d7e413624d6fca28b06484e5369cd17e4a599a4

Chalard Jean   commited 2023-10-30 23:26:43 +09:00
80685f42c3
Pass NetworkCapabilities into DnsManager
1. At present, the transportTypes in NetworkCapabilities have been
passed into DnsManager::updateTransportsForNetwork() as a parameter. In
the following CL, we also need to pass the 'metered' (also in
NetworkCapabilities) as a parameter to the function. Instead of passing
the members of NetworkCapabilities one by one, it is better to pass the
entire NetworkCapabilities.

2. Rename updateTransportsForNetwork() to
updateCapabilitiesForNetwork().

Bug: 288340533
Test: presubmit
Change-Id: I0966124f87b12c1d5a2eaee681885c3d5c7f74dc

Ken Chen   commited 2023-10-30 08:29:58 +00:00
6b134f18f4
remove dead portions of BpfUtils.java
(mostly to improve code coverage)

We can always revert if it ever turns out this is useful,
but I'd prefer for cgroup attach to be a once-at-boot
thing and handled either from bpfloader or the netd updatable
which are both directly C++ code.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I79b5ca8a47388cb6b9189234942e74ab6056aab9

Maciej Å»enczykowski   commited 2023-10-25 17:40:35 +00:00
de9d367ab2
Merge "Add a routing coordinator class" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-25 09:13:16 +00:00
4e47533688
Merge "Revert "Revert "[BR07.1] Expose setDataSaverEnabled from Connect..."" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-10-25 01:59:12 +00:00
0cfaea8d98
Add a routing coordinator class
Test: In followup changes : RoutingCoordinatorManagerTest
Change-Id: Ia6811d614e02123a072c7638291828745abae051

Chalard Jean   commited 2023-10-24 22:12:26 +09:00
2fb66f1b28
Revert "Revert "[BR07.1] Expose setDataSaverEnabled from Connect..."
Revert submission 2799494-revert-2745215-npmsbpf-OBOPDXREUI

Reason for revert: Need to 1. Merge API first. 2. Wait for prebuilt. 3. Merge the caller.

Reverted changes: /q/submissionid:2799494-revert-2745215-npmsbpf-OBOPDXREUI

Change-Id: Icd5f3d40595a0d2a221b016cec70568bf3597c16

Junyu Lai   commited 2023-10-24 07:30:23 +00:00
df210365fe
Merge "Revert "[BR07.1] Expose setDataSaverEnabled from ConnectivityManager"" into main
Jordan Silva   authored and   Gerrit Code Review   commited 2023-10-23 15:12:50 +00:00
118c2646f3
Revert "[BR07.1] Expose setDataSaverEnabled from ConnectivityManager"
Revert submission 2745215-npmsbpf

DroidMonitor: Potential culprit for Bug 307256512 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.


Reason for revert: 307256512

Reverted changes: /q/submissionid:2745215-npmsbpf

Change-Id: I27119a7484453d1369bbdf71ad2479edec7d664f

Jordan Silva   authored and   Gerrit Code Review   commited 2023-10-23 13:23:01 +00:00
457ae0f00f
Merge "[BR07.1] Expose setDataSaverEnabled from ConnectivityManager" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-10-23 11:21:53 +00:00
d88205a1ae
Merge "Reapply "Add LocalNetworkConfig"" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-20 06:25:14 +00:00
e32bf36be8
Merge "Support shell command to get bpf program id" into main
Maciej Å»enczykowski   authored and   Gerrit Code Review   commited 2023-10-19 22:35:04 +00:00
5c2b517d6a
[BR07.1] Expose setDataSaverEnabled from ConnectivityManager
Currently, data saver switch is controlled in NPMS, which
calls into NetworkManagementService and netd when switching
status. In netd, BandwidthController manipulates the
bw_data_saver chain to control the overall behavior.

However, this code are all platform implementation, which
are not updatable. In order to migrate data saver switch
from iptables to bpf, this API is needed for Connectivity to
change the implementation to directly write bpf in later
patches.

Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Test: atest FrameworksServicesTests:NetworkManagementServiceTest
Bug: 297836825
Change-Id: I71fa41ca739fef8e191fba91b02758ad5f732d5c

Junyu Lai   commited 2023-10-19 17:43:44 +08:00
c279f1830e
Merge "Dump bpf program status in dumpsys" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-10-19 09:33:27 +00:00
eb75416136
Support shell command to get bpf program id
Test: atest NetworkStatsIntegrationTest#testBpfProgramAttachStatus
Bug: 292156770

Change-Id: I815be0f3f3592442939872f98e3ad9d224a6aeb6

Junyu Lai   commited 2023-10-18 16:06:15 +08:00
452e464ee9
Dump bpf program status in dumpsys
Sample output:
Bpf Program Status:
  CGROUP_INET_INGRESS: 21
  CGROUP_INET_EGRESS: 22
  CGROUP_INET_SOCK_CREATE: 28
  CGROUP_INET4_BIND: 30
  CGROUP_INET6_BIND: 31

Test: adb shell dumpsys connectivity
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testDumpDoesNotCrash
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testDumpDoesNotCrash
Bug: 292156770
Change-Id: I312c90c524af12d093536156d6d5c6febd64305a

Junyu Lai   commited 2023-10-18 16:05:55 +08:00
155760b57b
Reapply "Add LocalNetworkConfig"
This reverts commit 6eea22b18c.

Change-Id: I0a2cef4ee992577674c92ecd384dc6f4361afa02

Chalard Jean   commited 2023-10-18 15:50:02 +09:00
f9d0e3e94f
Merge "Reapply "Tell netd about local networks"" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-17 13:00:46 +00:00
de0f4e5b87
Move dumpsys to handler thread
I0afdda023208c3f8620cb5b89add66448af596d7 added some assertions
to ensure NetworkAgentInfo can only be accessed from the handler
thread. This is good to eliminate any potential concurrent
accessing problem. Howver, dumpsys runs on binder thread, this
change breaks dumpsys functionality.

Thus, this change:
  1. Copy Handler#runWithScissors() and related class
     locally since they are @hide methods.
  2. Run doDump on the handler thread and waits for return.

Test: adb shell dumpsys connectivity
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.HandlerUtilsTest
Fix: 303348620
Change-Id: Ic3a22f5d370bbf8c18b1972e86d695b6ad61bd0d

Junyu Lai   commited 2023-10-17 17:16:04 +08:00
f8dba342f1
Reapply "Tell netd about local networks"
This reverts commit cc409153b4.

Change-Id: Ied6bdb9b94e08e2bfe1092765d0f4591e603c3eb

Chalard Jean   commited 2023-10-17 17:39:23 +09:00
e0aaca5ac6
Revert "Tell netd about local networks"
Revert submission 2777667

Reason for revert: DroidMonitor-triggered revert due to breakage, bug b/305187495

Reverted changes: /q/submissionid:2777667

Bug: 305187495

Change-Id: Icb46558d17b56f9f6fd402f1489de9ed2b8f7644

Anton Kulakov   commited 2023-10-13 15:23:59 +00:00
cc409153b4
Revert "Add LocalNetworkConfig"
Revert submission 2777667

Reason for revert: DroidMonitor-triggered revert due to breakage, bug b/305187495

Reverted changes: /q/submissionid:2777667

Bug: 305187495

Change-Id: Iae4ef936a4c111ae5668e539ce4cdbbb14c811f4

Anton Kulakov   commited 2023-10-13 15:18:55 +00:00
6eea22b18c
Merge changes I3b6ee1db,I70e13303,I6fb7dfe4 into main
* changes:
  Simplify addRoutesToLocalNetwork calls
  Add LocalNetworkConfig
  Tell netd about local networks

Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-13 09:57:18 +00:00
a6190bd658
Add LocalNetworkConfig
This doesn't do anything at this patchset, but the whole
pipe from the agent to ConnectivityService is built.

LocalNetworkInfo will be the name of the public information
sent in callbacks to clients.

Test: CSLocalAgentTests
Change-Id: I70e133031ef3b0aaf6c3e59ccc2ad895c66d339c

Chalard Jean   commited 2023-10-13 14:40:45 +09:00
fa21cafc1c
Tell netd about local networks
This patch does the following :
• When a network is local but the system doesn't support it,
  throw in registerNetworkAgent.
• When a network is local, tell netd about it.
• Add tests for the above, as well as a test for callbacks
  being sent correctly when the caps are set and not when
  they aren't and that the new keep connected flag is
  respected.

Telling netd about the network being local has it add two
routes that do not exist if the network is not local :
• One at PRIORITY_LOCAL_NETWORK matching unmarked sockets
  and looking up the table for the interface.
20000: from all fwmark 0x0/0x10000 lookup xxxx
• One at PRIORITY_EXPLICIT_NETWORK matching explicitly on
  network 99, so that dnsmasq traffic and any OEM traffic
  marked for network 99 flowing there.
16000: from all fwmark 0x10063/0x1ffff iif lo lookup xxxx
IMPLICIT_NETWORK and EXPLICIT_NETWORK rules are installed
by connectivity service as a matter of course whether the
network is local or not.

See commit If8729fc6f3716a580c936584b851bc38000b5de5 for
implementation details of this mechanic.

There is no need to implement anything in particular for the
new connected reason, as the current implementation will
already keep it connected. A new test makes sure of that.

Test: FrameworksNetTests
      CtsNetTestCases
      FrameworksNetIntegrationTests
      NetworkStackTests
      NetworkStaticLibTests
      TetheringTests
      MtsTetheringTestLatestSdk
      TetheringIntegrationTests
Change-Id: I6fb7dfe4c232eea8cac9ac268897ddb36bb794d1

Chalard Jean   commited 2023-10-13 14:40:38 +09:00
774dc3cd51
Merge changes I22d67a7e,Ida4a4bc7,Ie8522862,Id55d8d6c into main
* changes:
  Ensure nri is satisfied before returning.
  Add testLockdownVpn that mocks platform VPN.
  Make variables in testLegacyLockdownVpn() final.
  Update testLegacyLockdownVpn to mock VPN.

Hansen Kurli   authored and   Gerrit Code Review   commited 2023-10-13 05:00:29 +00:00
ccfc52145b
Ensure nri is satisfied before returning.
When a network preference is set, the highest priority nri will
be a managed default request that disallows default networking.
In the case where there is no satisfying network,
mNoServiceNetwork is used as the satisfier instead of null.
(see computeNetworkReassignment)

mNoServiceNetwork should not be returned in any public API.
Check for the nri being satisfied before returning the satisfier
to ensure mNoServiceNetwork is not returned.

Fixes: 301222648
Test: atest FrameworksNetTests
Change-Id: I22d67a7e8d0274d8ad4f6123fbedf6d37eed18e7

Hansen Kurli   commited 2023-10-12 18:48:57 +08:00
ed972a6fd2
Merge "Update mActiveIdleTimers to use netId as a key" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-10-12 09:10:22 +00:00
9b6420bc13
Allow for mocking an SDK in the tests
Test: in followup patches
Change-Id: I540ce2a455c92be52eb94fbd4b54a2081d04d25e

Chalard Jean   commited 2023-10-10 14:57:22 +09:00
eb66389d6a
Update mActiveIdleTimers to use netId as a key
Following CL update +U devices to use netId as an idle timer label.
Using netId as key for mActiveIdleTimers makes it easier to handle
network activity change event in U+ devices.

Bug: 267870186
Bug: 279380356
Test: atest FrameworksNetTests
Change-Id: I4cba6fa546ab403b9a462cc7b77393ac0227f690

Motomu Utsumi   commited 2023-10-06 18:45:54 +09:00
473c38d1aa
Merge changes Ifd7abd8a,I39cab8ff,I6b3270d6,Ia28c6abc,If47d7e23 into main am: 1d600f4300
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2405726

Change-Id: I9867b0c48537dd0164a3858328c865c667847289
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>

Jean Chalard   authored and   Automerger Merge Worker   commited 2023-09-29 07:07:23 +00:00
6d5e0ad07e
Merge changes Ifd7abd8a,I39cab8ff,I6b3270d6,Ia28c6abc,If47d7e23 into main
* changes:
  Move the MULTI_SIM_ACTION receiver inline
  Inline registerForCarrierChanges
  Make mThread a local
  Introduce a flag for using the carrier service changed callbacks.
  Have DevSdkIgnoreRunner support @Parameterized parameters

Jean Chalard   authored and   Gerrit Code Review   commited 2023-09-29 06:46:08 +00:00
1d600f4300
Introduce a flag for using the carrier service changed callbacks.
Test: CarrierPrivilegeAuthenticatorTest
Change-Id: Ia28c6abca67866c1de953cb61953a0d2882cd7e2

Chalard Jean   commited 2023-09-28 21:37:32 +09:00
84dfa9f104
Merge "wear proxy behind portal" into main am: 6aec2583cd
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2762234

Change-Id: Ib5c5489b6abdf3427ccfa2112908b6d42ffd9961
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>

Andriy Naborskyy   authored and   Automerger Merge Worker   commited 2023-09-27 17:54:22 +00:00
f891a01eb5
wear proxy behind portal
Do not avoid captive portal on wear proxy network; keep network agent
after detecting portal.

Bug: 291112432
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.ConnectivityServiceTest
Change-Id: I8f6669da62ebd76b6a46d2aec9b3ea563a08cb5e

Andriy Naborskyy   commited 2023-09-27 07:28:05 +00:00
d032dd42ea
Merge "Nat464Xlat: rely on netd events being called on handler thread." into main am: d196fab898
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2763405

Change-Id: Ice4d84ec6ff98098475e21e8ae96052d1827903a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>

Remi NGUYEN VAN   authored and   Automerger Merge Worker   commited 2023-09-27 03:03:52 +00:00
04085fd688
Merge "Nat464Xlat: rely on netd events being called on handler thread." into main
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2023-09-27 02:01:58 +00:00
d196fab898
Nat464Xlat: rely on netd events being called on handler thread.
aosp/2724918 moved processing netd events for 464xlat to the
handler thread.

This CL makes 464xlat run the code that processes those events
inline. This simplifies the code and makes the ordering of events
more similar to what it was before.

Bug: 293965195
Fix: 302071735
Test: existing unit tests
Change-Id: I18b0d491aff94646b878a3d3488b5519fd42783c

Lorenzo Colitti   commited 2023-09-26 11:00:37 +00:00
3b817cbad3