Commit Graph

10733 Commits

Author SHA1 Message Date
Motomu Utsumi
5fce43e548 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
2023-11-14 13:43:45 +09:00
Jean Chalard
7cf6e5a3b0 Merge "Add test to make sure that unwanted local nets disconnect correctly" into main 2023-11-09 02:08:36 +00:00
Suprabh Shukla
2d893b68a9 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
2023-11-08 10:17:30 +00:00
Maciej Żenczykowski
87f7f27ad0 Merge changes Ie1a36c3c,Id727cf7b,Ifba198d9 into main
* changes:
  Remove unnecessary check for skDestroyListener
  Remove TrafficController
  Remove native code path in BpfNetMaps.java
2023-11-07 19:32:51 +00:00
Jean Chalard
e28740f79b Merge changes I301bf032,I8caca97b into main
* changes:
  Rename TiramisuConnectivityInternalApiUtil
  Add LocalNetworkInfo and send callbacks when it changes
2023-11-07 13:29:00 +00:00
Chalard Jean
4fe2339f2c 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
2023-11-07 22:28:25 +09:00
Motomu Utsumi
96b6c39229 Remove native code path in BpfNetMaps.java
BpfNetMaps uses java library for updating bpf map as the default code
path.
This is already released to 100% production without any issues.
So this CL removes the old code path from BpfNetMaps.

Note that native_init only opens the bpf maps if sEnableJavaBpfMap is
true.
But if sEnableJavaBpfMap is true, no native code in TrafficController
access the bpf map.
So this CL can remove native_init.

Following CL will remove the nativce codes for old code path.

Bug: 217624062
Test: NetworkStaticLibsTests
Change-Id: Ifba198d9e6f93b53fd1dbf3b2aafb644da0b147d
2023-11-07 17:45:32 +09:00
Chalard Jean
22350c93b4 Add LocalNetworkInfo and send callbacks when it changes
Test: CSLocalAgentTest
Change-Id: I8caca97b891081f9212a01d428a34ed1a08d5126
2023-11-07 17:29:38 +09:00
Chiachang Wang
9846b924b8 Merge "Remove @IgnoreUpTo(Q) annotation and isAtLeastR() check" into main 2023-11-07 05:21:12 +00:00
Jean Chalard
85fce4f871 Merge "Set up forwarding rules for local network agents" into main 2023-11-07 02:50:50 +00:00
Chalard Jean
1e4c218c28 Set up forwarding rules for local network agents
Test: CSLocalAgentTests, new tests for this
Change-Id: I8994af350a1799ab5f6ebb2872f2abfaf174bd61
2023-11-06 20:18:50 +09:00
Motomu Utsumi
d872c3c960 Merge "Add methods for updating ingressDiscardRule bpf map to BpfNetMaps" into main 2023-11-06 10:41:53 +00:00
Chiachang Wang
a8efe40865 Remove @IgnoreUpTo(Q) annotation and isAtLeastR() check
Remove the Q test annotation/check since mainline updates does
not push to Q anymore. This annotation is unnecessary now.

Test: atest FrameworksNetTests
Change-Id: Iba4f38731db9f369f99ba12a3ab7ef3f3b1630b8
2023-11-06 09:35:28 +00:00
Junyu Lai
bb59480733 [BR03.1] Expose isUidNetworkingBlocked
Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideNetworkCallbackTests
Bug: 297836825
Change-Id: I70b2351b9cd1c3c6fa34258397e0bf22cb8150b2
2023-11-06 13:26:19 +08:00
Ken Chen
90e009be6c [Test] Fix DNS resolver MTS failures
In MTS, test infra installs only the DNS resolver module without
installing tethering module. The test utils should not assume the BPF
maps defined in tethering will be in the device.

Bug: 309164580
Test: atest
resolv_integration_test:ResolverTest#BlockDnsQueryWithUidRule

Change-Id: I2c7349a11c9b413c129c93d236c8280588097cf7
2023-11-04 16:10:34 +08:00
Chalard Jean
820ce9df2d Add forwarding methods to RoutingCoordinator
Test: RoutingCoordinatorServiceTest
      TetheringTest
Change-Id: I2fa6250875d517c3452c85a3678d3feb0c0354d8
2023-11-02 23:25:32 +09:00
Chalard Jean
842a914dff Rename KEEP_CONNECTED_DOWNSTREAM_NETWORK to K_C_LOCAL_NETWORK
...following feedback

Test: FrameworksNetTests
Change-Id: I9c25f0b066a58980bf071d2b958223ed609f0d8e
2023-11-02 23:25:31 +09:00
Chalard Jean
78c9a381c9 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
2023-11-02 23:25:11 +09:00
Jean Chalard
4fd9451cdb Merge "Run CSDestroyedNetworkTests starting in R" into main 2023-11-02 10:23:50 +00:00
Junyu Lai
31ab762e42 Merge "[BR06] Support check whether network is blocked by data saver" into main 2023-11-02 07:09:50 +00:00
Chalard Jean
0a0be176d2 Run CSDestroyedNetworkTests starting in R
This can only run where the connectivity module is updated

Bug: 308601625
Test: TH
Change-Id: Icc5df3013e90070502a805abe89725591470b464
2023-11-02 14:00:16 +09:00
Ken Chen
90428539d6 Merge "Add Data Saver utils in Firewall test helper class" into main 2023-11-02 02:35:44 +00:00
Junyu Lai
2deeef4f5e Merge "Fix NetworkStatsObersers thread leak in the NetworkStatsServiceTest" into main 2023-11-01 10:18:50 +00:00
Junyu Lai
8b5ebfc342 Fix NetworkStatsObersers thread leak in the NetworkStatsServiceTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
     (with debug code that dump all threads at the end of tests)
Fix: 308544001
Change-Id: I597054633bbb008ffd0edebe34dcf6935958aa5d
2023-11-01 17:11:17 +08:00
Hansen Kurli
8f329c2e97 Merge changes I5fffc137,Ifc076a8d into main
* changes:
  Add Log.wtf when keepalive metrics are unexpected.
  Add dump of KeepaliveStatsTracker
2023-11-01 08:50:39 +00:00
Hansen Kurli
a746c1a4da Add Log.wtf when keepalive metrics are unexpected.
To debug unexpected keepalive metrics values, print the built
metrics in a Log.wtf before writing it to statsd.

Bug: 297292877
Test: atest FrameworksNetTests
Change-Id: I5fffc13721e50e28f24b0da12a961364f3f77e21
2023-11-01 14:41:35 +08:00
Hansen Kurli
723c273be3 Add dump of KeepaliveStatsTracker
To debug unexpected metrics values, print the built metrics into
the connectivity dump.

Sample of the added log dump:
KeepaliveStatsTracker enabled: true
   # android.net.connectivity.com.android.metrics.Dailykeepalive
InfoReported@3293424e
   automatic_keepalive_requests: 2
   distinct_user_count: 1
   duration_per_num_of_keepalive {
     duration_for_num_of_keepalive {
       keepalive_active_durations_msec: 36
       keepalive_registered_durations_msec: 36
       num_of_keepalive: 0
     }
     duration_for_num_of_keepalive {
       keepalive_active_durations_msec: 9
       keepalive_registered_durations_msec: 6
       num_of_keepalive: 1
     }
     duration_for_num_of_keepalive {
       keepalive_active_durations_msec: 7
       keepalive_registered_durations_msec: 10
       num_of_keepalive: 2
     }
   }
   keepalive_lifetime_per_carrier {
     keepalive_lifetime_for_carrier {
       active_lifetime_msec: 23
       carrier_id: -1
       intervals_msec: 10000
       lifetime_msec: 26
       transport_types: 1
     }
   }
   keepalive_requests: 2
   uid: 10097

Bug: 297292877
Test: adb shell dumpsys connectivity
Test: New test testDumpDoesNotCrash()
Change-Id: Ifc076a8dce734e9c175f1b1f28e1c448b9a792e5
2023-11-01 14:41:24 +08:00
Chiachang Wang
006f9d2998 Merge "Quit handler threads at the end of the tests" into main 2023-11-01 06:29:33 +00:00
Junyu Lai
2c8e96d599 Merge "[BR02] Implement isUidNetworkingBlocked" into main 2023-11-01 03:40:05 +00:00
Junyu Lai
c3dc5b6222 [BR06] Support check whether network is blocked by data saver
This change adds a DataSaverStatusTracker, which is a helper
class to continuously track data saver status through NPMS
public API and intents. ConnectivityManager#isUidNetworkingBlocked
would use this cached information along with bpf maps to decide
whether networking of an uid is blocked.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.android.net.ConnectivityManagerTest
Bug: 297836825
Change-Id: I7e13191759430f3ea1f4dec7facc02f16be7146d
2023-11-01 11:10:01 +08:00
Chiachang Wang
2973cf4363 Quit handler threads at the end of the tests
The created handler threads should be quit after the tests to
prevent memory leakage. Also, this commit updates the method
used to close the created HandlerThread to do it correctly.

Bug: 308537727
Test: atest ConnectivityCoverageTests
Change-Id: I3715a73a9142418c05f98bc95e275f97161ab3cd
2023-11-01 01:24:07 +00:00
Ken Chen
5b144a1061 Add Data Saver utils in Firewall test helper class
Resolv_integration_test needs the function to toggle Data Saver settings
in BPF map.

Bug: 288340533
Test: atest resolv_integration_test
Change-Id: I1725d3c8c6fc641b855c935d7289a99f78dd5933
2023-11-01 06:23:09 +08:00
Sudheer Shanka
3130de88f3 Merge "Use 'set-standby-bucket' instead of 'set-inactive' command." into main 2023-10-31 21:04:49 +00:00
Sudheer Shanka
c6240e9cfd Use 'set-standby-bucket' instead of 'set-inactive' command.
When 'set-inactive' command is used, it is possible for the
test app to get into the NEVER bucket as it wouldn't be
recorded as used by the user in some cases.

Bug: 298816567
Test: atest tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
Change-Id: If2667a07629b38395d0fed99771488d0900caf18
2023-10-31 19:50:51 +00:00
Jean Chalard
de33ada087 Merge "Destroyed networks can't hope to beat champions" into main 2023-10-31 10:01:09 +00:00
Jean Chalard
a394bcf24a Merge changes I9109cd9d,Ie7cec6fe,I215e915d into main
* changes:
  Stop MockVpn from extending Vpn class.
  Remove unused method calls of MockVpn
  Create local NetworkCapabilites for MockVpn.
2023-10-31 09:01:50 +00:00
Junyu Lai
e003152e2c [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
2023-10-31 16:33:41 +08:00
Motomu Utsumi
77b49996d2 Add methods for updating ingressDiscardRule bpf map to BpfNetMaps
Bug 295800201
Test: NetworkStaticLibsTests

Change-Id: I42bc0adc22c3018480029d624053f758d815e526
2023-10-31 17:07:46 +09:00
Ken Chen
5a35cf9086 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
2023-10-31 07:38:40 +00:00
Ken Chen
792a7cd1a1 Merge "Write Data Saver setting to BPF map" into main 2023-10-31 07:09:47 +00:00
Hansen Kurli
a9b72ba71b Merge "Fill ConnectivityService in testDumpDoesNotCrash()" into main 2023-10-31 05:52:02 +00:00
Ken Chen
243301748e 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
2023-10-31 01:36:03 +00:00
Chalard Jean
80685f42c3 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
2023-10-30 23:26:43 +09:00
Ken Chen
6b134f18f4 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
2023-10-30 08:29:58 +00:00
Maciej Żenczykowski
e26f93318c Merge "Revert "Add forwarding methods to RoutingCoordinator"" into main 2023-10-28 06:34:26 +00:00
Maciej Żenczykowski
543d0d32e4 Revert "Add forwarding methods to RoutingCoordinator"
This reverts commit 55ccfe19e2.

Reason for revert: this must be introducing some sort of race
it appears to cause
  atest EthernetTetheringTest 'NetdBinderTest#TetherForwardAddRemove'
to no longer reliably pass.

Change-Id: I5281ab3f42c5ce268d97a12db24a6768db3f4354
2023-10-28 02:10:52 +00:00
Hansen Kurli
f7a8e9928f Stop MockVpn from extending Vpn class.
Make MockVpn stop extending Vpn in order to stop depending on
Vpn code. This includes:

1. Remove @Override and synchronized for all MockVpn methods.
2. Remove the constructor.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I9109cd9d3e17717cffa6c89c6a9e4330ed9af3cf
2023-10-27 15:30:46 +08:00
Hansen Kurli
03faec6ea0 Remove unused method calls of MockVpn
The following are removed:
1. mUnderlyingNetworkInfo and the related get and set.
2. Calls to setEnableTeardown() since this has no
   interaction with ConnectivityService.
3. Calls to updateState().
4. Usage of mInterface.
5. Usage of mConfig.
6. Usage of mNetworkAgent.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Ie7cec6fed25f841de995059deba1c1df67377e70
2023-10-27 15:30:46 +08:00
Jean Chalard
23376e6fe7 Merge "Add forwarding methods to RoutingCoordinator" into main 2023-10-27 05:12:07 +00:00
Hansen Kurli
20b5a99f88 Create local NetworkCapabilites for MockVpn.
Store the mNetworkCapabilities locally in MockVpn to stop
depending on the Vpn class.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I215e915dcafb6700950bc8a500bc16f839d0e13e
2023-10-27 10:18:08 +08:00