Commit Graph

1854 Commits

Author SHA1 Message Date
Yuyang Huang
8e6fbc8c1a Update permission check for offloadEngine registration
For an app to register itself as an offloadEngine, it must have either
of the following permissions: NETWORK_STACK,
PERMISSION_MAINLINE_NETWORK_STACK, NETWORK_SETTINGS,
REGISTER_NSD_OFFLOAD_ENGINE.

Bug: 294777050
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: I19fe9b996a02b1ae23116c02a1b8406d93b3ecf1
2023-09-05 14:53:51 +09:00
Junyu Lai
35c69c7986 Address review followup comments for NetworkStats
This change includes:
1. Mark groupedBy*() deprecated and throw after android U.
2. Modify map() to mapKeysNotNull().
3. rename clearInterfaces to withoutInterfaces and refactoring.
4. Modify tests accordingly.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.NetworkStatsTest
Fix: 296149902
Fix: 296150018
Change-Id: I5d97422ba957a212c0c5fbc1eee3f8b174343348
2023-09-04 18:01:14 +08:00
Motomu Utsumi
188bfd36da Delay frozen app sockets close until the cellular modem wakes up
Closing TCP sockets sends RST packets. If the cellular modem is idle,
sending RST packets will wake the modem up and consume battery.

This CL adds delay_destroy_frozen_sockets_version flag.
When this flag and destroy_frozen_sockets_version is enabled,
ConnectivityService delays closing socket until the cellular modem wakes up.
Pending frozen sockets are closed also when cellular network becomes no
longer the default network.

This CL also adds flag status and pending uids to the dump.

Bug: 284900338
Test: FrameworksNetTests
Change-Id: I2562568390dda36d02f72afb3a96f824788964c0
2023-09-04 18:04:31 +09:00
Chalard Jean
2eb2f7998d Address flake in testNetworkCallbackMaximum
These flake occasionally because registering a request increases
the current request count synchronously while unregistering
decreases it asynchronously, meaning if the test has time to
call register 100 times before unregister can run it will
wrongfully flake.
This could be addressed in production code but as comments in
the change explain, this isn't worth the complexity. Hence
just have a pinpoint fix in the test. See aosp/2707373 for
what a fix in the production code would look like.

Test: manual
Bug: 289530922
Change-Id: Iad9a725eda91406f820abe4706bca0a4756352a4
2023-08-30 15:19:50 +09:00
Chiachang Wang
29178c8906 Merge "Verify reevaluation triggered when VPN validation fails" into main 2023-08-30 03:12:42 +00:00
Chiachang Wang
3e1edc231f Verify reevaluation triggered when VPN validation fails
Update tests to verify that the underlying network reevaluation
is triggered when VPN validation status switches to unvalidated.

Bug: 296183603
Test: atest FrameworksNetTests
Change-Id: I80934cce6e7f2d56039bdd6ad63c6f7173a597cb
2023-08-30 03:08:56 +00:00
Junyu Lai
50a7ecccf1 Merge "Split BpfNetMaps constants and utilities into standalone classes" into main 2023-08-29 10:44:51 +00:00
Junyu Lai
29b7b6385a Split BpfNetMaps constants and utilities into standalone classes
This is a no-op refactoring that splits constants and utility
methods into standalone classes which will be shared with
a bpf reader class in subsequent CLs.

NO_IFTTT=No-op refactoring

Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.StructTest

Bug: 297836825
Change-Id: I6d7ea044e43180ae001573009a166be74ebe6a5d
2023-08-29 08:20:10 +00:00
Chiachang Wang
69cd0aa5a0 Merge "Verify VPN underlying network is set as soon as it tries to use it" into main 2023-08-28 10:18:23 +00:00
Jean Chalard
940e330f5d Merge "Request enterprise networks" into main 2023-08-28 09:20:34 +00:00
Chiachang Wang
845a91cc31 Verify VPN underlying network is set as soon as it tries to use it
Bug: 289606688
Test: atest FrameworksNetTests
Change-Id: Ib35a63ac5f68599c646afad5cad68c1753fb732f
2023-08-28 08:00:20 +00:00
Paul Hu
1b5d601d0c Merge changes I47b91c0c,I630c0e49 into main
* changes:
  Report sent query count
  Report service info callback metrics data
2023-08-25 14:46:39 +00:00
Motomu Utsumi
5324475f6e Add some tests back which were removed for fixing kotlin nullable errors
Followup CL for aosp/2700076

Bug: 296972712
Test: build with aosp/2688146
Change-Id: I617b330c42a99e4c839adac2ea614756b5955ce9
2023-08-24 11:25:21 +09:00
Paul Hu
bad6fe9835 Report sent query count
Report the sent query count when the discovery is stopped.

Bug: 287546772
Test: atest FrameworksNetTestCases NsdManagerTest
Change-Id: I47b91c0c530eee2f00920ee5ea99e8d7b6e2e9ee
2023-08-22 17:26:27 +08:00
Paul Hu
ddce5919af Report service info callback metrics data
Bug: 287546772
Test: atest FrameworksNetTestCases
Change-Id: I630c0e4921f7acf42bf29812d9790ee5a894d60b
2023-08-22 15:25:37 +08:00
Colin Cross
d5038a042c Merge "Fix kotlin nullable errors in Connectivity tests" into main 2023-08-22 04:13:01 +00:00
Treehugger Robot
aa4db9753b Merge "Report resolution stop" into main 2023-08-18 09:30:26 +00:00
Paul Hu
6014905672 Report resolution stop
Report the nsd metrics event of resolution stop.

Bug: 287546772
Test: atest FrameworksNetTestCases
Change-Id: I2e6de22c946d58a3410f16b2f2689fd3ffc635a4
2023-08-18 11:59:06 +08:00
Paul Hu
a436faf92d Merge "Stop the created handler threads on the tests" into main 2023-08-18 02:40:45 +00:00
Chiachang Wang
033ca4c8cf Merge "Stop the created handler threads" into main 2023-08-17 09:40:05 +00:00
Paul Hu
f6e1867963 Stop the created handler threads on the tests
The created handler thread will stay there for a while until
all the tests are finished. This is considered as a leakage
which will take the resource from the devices. In low end
devices, this may possibly impact the performance. The created
threads should be closed explicitly.

Test: atest FrameworksNetTests
Change-Id: Id5faceec341578f1c9757194c91a433fbb3f657f
2023-08-17 06:53:16 +00:00
chiachangwang
8d336eb1a3 Stop the created handler threads
The created handler thread will stay there for a while until
all the tests are finished. This is considered as a leakage
which will take the resource from the devices. In low end
devices, this may possibly impact the performance. The created
threads should be closed explicitly.

Test: atest FrameworksNetTests
Change-Id: I332d55d8effdb975fd9a8953b19910a7fb25e426
2023-08-17 06:18:46 +00:00
Motomu Utsumi
23b0bab6b1 Merge "Use isTetheringFeatureNotChickenedOut for kill switch" into main 2023-08-17 06:13:21 +00:00
Motomu Utsumi
0a50c65f75 Use isTetheringFeatureNotChickenedOut for kill switch
Following CLs remove the default value from isFeatureEnabled since the
default value was difficult to use correctly.
For example, there was a code that use isAtLeastT() as default value and
expect feature is always enabled on T+ devices.
However, default value is used only when the device does not have the
flag value or flag value is 0.
So the expectation that the feature is always enabled on T+ devices is
not correct if flag is pushed to the device by mistake or the device is
upgraded from S to T but the flag value is not cleared.
If the feature should be always enabled on T+ devices, `isAtleastT() ||
isFeatureEnabled()` should be used instead of `isFeatureEnabled(
isAtleastT() /* defaultValue*/ )`

After the default value argument is removed from isFeatureEnabled,
isFeatureEnabled is used for default false flag and
isTetheringFeatureNotChickenedOut is used for default true kill switch flag.

automatic_on_off_keepalive_version flag is not configured and devices
don't have this flag value.
So updating to use isTetheringFeatureNotChickenedOut should not have any
behavior change.

Test: m
Bug: 279108992
Change-Id: I43ceab6cc5234bd5a43af3acbd7bd7344844c5a6
2023-08-16 20:15:52 +09:00
Paul Hu
a6bc463155 Report resolution metrics data
Collect information on resolution success and failure events,
then use this data to build metrics and report them.

Bug: 287546772
Test: atest FrameworksNetTestCases NsdManagerTest
Change-Id: I373ce91fea9d5a278f53fc0c505be90dd39b2d5b
2023-08-16 15:53:06 +08:00
Paul Hu
812e9217b9 Report discovery metrics data
Collect information on discovery start, failure, and stop events,
then use this data to build metrics and report them.

Bug: 287546772
Test: atest FrameworksNetTestCases NsdManagerTest
Change-Id: I2f6a718024870f9658cfeabe8995624a3ad81f05
2023-08-16 15:09:17 +08:00
Chalard Jean
c33eafb464 Request enterprise networks
...so they don't disconnect in the middle of the test

Test: strategically add a sleep to reproduce the failure
      apply the patch, observe the test passing with the sleep
Bug: 293844884
Change-Id: I4388e151d886461ca44185639e292ccd9795c50e
2023-08-15 15:14:57 +09:00
Paul Hu
d45bf5499f Merge "Fix NullPointerException on NsdService" into main 2023-08-10 09:03:41 +00:00
Paul Hu
101dbf5262 Fix NullPointerException on NsdService
The NsdService will throw a NPE if a new client is registered
with a null INsdManagerCallback object. To avoid this, perform
a null check before registering a new client and throw an
IllegalArgumentException if the callback is null.

Bug: 293285797
Test: atest FrameworksNetTests
Change-Id: Id61e27873591031c3fe383879aee0d40eebc08b3
2023-08-10 14:19:01 +08:00
Colin Cross
4e5a061f26 Fix kotlin nullable errors in Connectivity tests
Fix kotlin nullable errors that were exposed by setting the retention
of android.annotation.NonNull and android.annotation.Nullable to
class retention.

Bug: 294110802
Test: builds
Change-Id: Id49e4a2ee0b7b463d99bce6eb22919b84c21443a
2023-08-09 10:57:35 -07:00
Junyu Lai
ef0afdef0e Merge "Fix flaky test: testDataMigration_differentFromFallback" into main 2023-08-09 08:53:46 +00:00
Treehugger Robot
b15f7d1e68 Merge "Allow VPN lockdown UID ranges to stack properly" into main 2023-08-09 08:05:20 +00:00
Junyu Lai
353ec97c64 Fix flaky test: testDataMigration_differentFromFallback
Test main thread mocked settings object but use that on the handler
thread as well, which is not thread-safe.
Create a real object instead of mocking it instead.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest#testDataMigration_differentFromFallback \
      --rerun-until-failure 500
Fix: 289705810
Change-Id: Ibfb722818467fdf2b69a4b8fa87b4ac04a713573
2023-08-09 14:44:23 +08:00
Treehugger Robot
b7d3f3fd77 Merge "Use destroyLiveTcpSocketsByOwnerUids for frozen apps" into main 2023-08-09 05:17:14 +00:00
Chiachang Wang
f574524c0b Merge "Add VpnTest back to presubmut" into main 2023-08-08 08:39:21 +00:00
chiachangwang
1a72396be6 Add VpnTest back to presubmut
These tests were disabled from presubmit because of flaky test.
It's no longer flaky now, so add these tests back to presubmit.

Bug: 293233390
Test: atest FrameworksNetTests
Change-Id: I7f1f36385d2ca6ed210e1d9b7399b6509fd26519
2023-08-07 08:47:34 +00:00
Treehugger Robot
8ba50ae30f Merge "Fix flake : testVpnSetUnderlyingNetworks" into main 2023-08-07 05:22:20 +00:00
Chalard Jean
9033477aa7 Fix flake : testVpnSetUnderlyingNetworks
When the device is very slow to run this test, cell might end
its lingering period in the middle of the test while wifi is
the default. VPN will then ignore it as an underlying network,
causing the test to fail.

Test: testVpnSetUnderlyingNetworks
      Added sleep in a strategic place to make sure the problem
      was correctly identified, and observed the test failing.
      After the fix, the test passes with the sleep.
Fixes: 280627836
Fixes: 293844384
Change-Id: Iaf56de963eb17845c1d76a0310b55f7f9321f7e4
2023-08-07 14:20:13 +09:00
Yuyang Huang
7ddf2935f9 Replace usage of android.util.Log to SharedLog
Bug: 294326360
Test: atest FrameworksNetTests
Change-Id: I9a3a84f907362260bdcf6be19e2c4d5345788d2e
2023-08-06 17:34:50 +09:00
Yuyang Huang
33fa4d268c Add callbacks for service offload
Components that can provide offload like IpClient (packet
filter offloading) can use the API to register a callback to be notified
when offload is necessary.

Bug: 269240366
Test: atest CtsNetTestCases
Change-Id: I8080702f5b530001b88e79e504f4722ac01bc576
2023-08-04 19:22:15 +09:00
Chiachang Wang
89b25779e3 Merge "Add version control for packet address translation design" into main 2023-08-03 06:58:28 +00:00
chiachangwang
144dd51761 Add version control for packet address translation design
This commit adds the version control for keepalive packet address
translation design to prevent device crash if the network stack
is not updated to a newer version. This commit also adds a
DeviceConfig to control the design in newer module version.

Bug: 291870956
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: Id4efbf51dae9154d2bc3a1ee405e2139d5c91e36
2023-08-02 12:16:31 +00:00
Treehugger Robot
865bfacab7 Merge "Deduplicate items after clear interface in NetworkStats" into main 2023-08-01 07:40:57 +00:00
Motomu Utsumi
dc9cb1da23 Merge "Revert isDefaultNetworkActive behavior when there is no default network" into main 2023-08-01 05:49:47 +00:00
Junyu Lai
23d89c0bbf Deduplicate items after clear interface in NetworkStats
Follow-up from commit Ie60829a65d0d9b5b63ad353695a820c0586e3665,
the interface field was cleared before returning the result to
the caller. However, this can cause problems in the
NetworkStats#subtract method. If the interface field is cleared,
the findIndexHinted method can match to a wrong entry.
This is because the keys of multiple entries will now be the
same. This can cause the subtract result to be unexpectedly
large and the return value of getUidStatsForTransport to be
mismatched with the values retrieved from other APIs.

Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest \
      FrameworksNetTests:android.net.connectivity.android.net.NetworkStatsTest
Bug: 290728278
Change-Id: I891ab29b8a2902663febc7c32b04417caf510926
2023-08-01 13:38:26 +08:00
Motomu Utsumi
51e7a60359 Revert isDefaultNetworkActive behavior when there is no default network
aosp/2605757 updated isDefaultNetworkActive returns false when there is
no default network.
But this change was not merged to U release branch and this change was
not well tested by dogfooding.
So this CL reverts the isDefaultNetworkActivity behavior change.

Bug: 279380356
Bug: 291870075
Test: atest FrameworksNetTests
Change-Id: Id88662faea9eeaba93d59ab2729f6204a3631ab1
2023-08-01 12:50:00 +09:00
Motomu Utsumi
3f35bb2fce Merge "Revert onNetworkActive callback behavior on U+" into main 2023-07-31 10:34:41 +00:00
Motomu Utsumi
1e51a64988 Revert onNetworkActive callback behavior on U+
aosp/2605757 changed onNetworkActive callback behavior on U+ but this
change was not merged to U release branch.
This CL reverts the behavior change and keep the current behavior on U+.

Bug: 279380356
Bug: 291870075
Test: atest FrameworksNetTests
Change-Id: I91ccc7ee93f0827986401f316997b4a2df11318f
2023-07-31 19:33:24 +09:00
Chiachang Wang
52f3e8f29e Merge "Deflake doTestPlatformVpnWithException related tests" into main 2023-07-31 08:54:14 +00:00
chiachangwang
9f9a4dc69c Deflake doTestPlatformVpnWithException related tests
This commit updates test to
- Execute IkeSessionCallback inside executor. The callback should
  be called from executor in production code but test trigger the
  callback from test main thread which will result in unexpected
  code interaction.
- Verify the timer directly. The origin design verifies
  interactions with Captor with uncertain interaction. Test
  should be able to verify the schedule() calls with the expected
  timeout value. Also, in lower performance device, device may
  still process previous interaction. Add longer timeout to reduce
  flakes.

Bug: 293233390
Test: atest FrameworksNetTests
Test: atest VpnTest#testStartPlatformVpnFailedWithRecoverableError
      --rerun-until-failure 100
Change-Id: Ie42a2597a382800d6484a086b6d808490dfbdd32
2023-07-31 04:59:58 +00:00