Commit graph android_packages_modules_Co.../tests/unit/java/com/android
Message SHA1
Mock Vpn.setUnderlyingNetworks()
Override Vpn.setUnderlyingNetworks() to do a direct call on the
network agent instead of relying on the Vpn class.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Ib7883f8a81a22317616cae79ce57a30afdd2bed4

Hansen Kurli   commited 2023-10-13 15:37:08 +08:00
233ac9463b
Mock Vpn.setLockdown()
Call setRequireVpnForUids directly to enable lockdown instead of
calling the real Vpn method.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I91ec59f7542d145e9250a7e7a414593db3d99424

Hansen Kurli   commited 2023-10-13 15:30:43 +08:00
39654c33cf
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
Add testLockdownVpn that mocks platform VPN.
Add a test for lockdown vpn that uses TYPE_IKEV2_IPSEC_PSK and
mocks platform VPN by override in startLegacyVpnPrivileged().
In the context of ConnectivityService, setVpnDefaultForUids()
is the main interaction.

Refactor testLegacyLockdownVpn to take a VpnProfile and assert
behaviors with and without setVpnDefaultForUids().
This includes:
    1. Updating callback asserts and assertActiveNetworkInfo to
       reflect setVpnDefaultForUids().
    2. Adding TODOs where mCm.getActiveNetworkInfo() returns
       unexpected values.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Ida4a4bc745af5ba2fc251795b2ffca56ead79b7f

Hansen Kurli   commited 2023-10-12 18:48:24 +08:00
48c14686a3
Make variables in testLegacyLockdownVpn() final.
Test: atest FrameworksNetTests
Change-Id: Ie852286275f0e377be582648f7766c077d9877e8

Hansen Kurli   commited 2023-10-04 16:50:05 +08:00
78b06ebe84
Update testLegacyLockdownVpn to mock VPN.
Override more VPN methods to mock the VPN interaction of
testLegacyLockdownVpn instead of relying on the Vpn class.
This includes:
    1. Overriding startLegacyVpnPrivileged() and avoid creating
       a VpnRunner.
    2. Removing expectStartLegacyVpnRunner() since it is not
       used when startLegacyVpnPrivileged() is overridden.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Id55d8d6cd03b84bca815cd331eb0f7d584eaed5f

Hansen Kurli   commited 2023-10-04 16:47:10 +08:00
b2764be9b6
Remove the fail case on IPv6 in testLockdownVpn
In testLegacyLockdownVpn, remove the fail check on IPv6 networks
and add coverage in VpnTest instead as this interaction relies
on the Vpn implementation, not ConnectivityService.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Ib24809ece2332c4c3d3e08c168e02ad859242eac

Hansen Kurli   commited 2023-10-04 16:45:45 +08:00
acb5205558
Remove LockdownVpnTracker from testLegacyLockdownVpn
The test coverage of LockdownVpnTracker has been moved to a
separate unit test file. testLegacyLockdownVpn now calls the Vpn
methods directly instead of creating a new LockdownVpnTracker.
Note this removes calls to expectStopVpnRunnerPrivileged since
stopVpnRunnerPrivileged is now directly called in the test so it
is already guaranteed to be called.

The expected calls/behavior of LockdownVpnTracker can be seen in
LockdownVpnTrackerTest.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Id9d26435bf62ffef954f6c7fa0558ce99540de1f

Hansen Kurli   commited 2023-10-04 16:44:09 +08:00
35f6fef389
Correct isLegacy metric data
The isLegacy field of Nsd metrics should indicate whether the
data was collected from the old backend or not. However, it is
currently only dependent on the ENABLE_PLATFORM_MDNS_BACKEND
compat change value, which is incorrect. This is because the
NsdService always uses the new backend since Android U,
regardless of the compat change value. Therefore, the isLegacy
data should be obtained from each transaction.

Bug: 287546772
Bug: 299880473
Test: atest FrameworksNetTestCases NsdManagerTest
Change-Id: I156abd656b90578d710696a69ccf7dfca97a2c9c

Paul Hu   commited 2023-09-12 01:20:00 +00:00
508a012b2e
Implement ConnectivityStateMetrics sample
Test: ConnectivitySampleMetricsTest
Change-Id: I0afdda023208c3f8620cb5b89add66448af596d7

Chalard Jean   commited 2023-09-11 17:12:46 +09:00
f95e2de35a
Add base classes for common ConnectivityService tests.
This sets up what is necessary for an instrumented
ConnectivityService to run. Users of this class are
meant to inherit CSTest.

This is still relatively basic and does not have all the
instrumentation in ConnectivityServiceTest. Developers
looking to extend CSTest may find some instrumentation
missing ; when they add the missing instrumentation,
they should consider whether it should be generic for all
CSTests (and put it in base/), or whether it's local to
their own test suite. This should enable faster testing
as each CSTest children will only need to set up the
instrumentation it actually needs.

This patch also migrates a basic test to have a first user.

Bug: 272685721
Test: ConnectivityServiceTest
      CSBasicMethodsTest
Change-Id: I1c47f616af90629c9cb2a6ae89d992b19863e704

Chalard Jean   commited 2023-09-11 16:46:27 +09:00
0f5c4fe9cb
Merge "Add Chicken bit for the mDNS offload feature" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2023-09-08 13:25:53 +00:00
169de9c8a1
Merge "Disable cache flush bit in existing announcement" into main
Paul Hu   authored and   Gerrit Code Review   commited 2023-09-08 12:48:05 +00:00
af511b5abe
Add Chicken bit for the mDNS offload feature
Bug: 297482971
Test: TH
Change-Id: I6f2cdd066d9047b113ff80211cf6d4c6fa605104

Yuyang Huang   commited 2023-09-08 17:42:26 +09:00
b96a071f51
Verify that VPN name is set in VPN networks
Verify that the extra info for validation logs in the
NetworkInfo is set.

Bug: 297790570
Test: atest FrameworksNetTests
Change-Id: I5b77b3bab30154b7979cda003274cde0d834a5fb

Chiachang Wang   commited 2023-09-07 09:22:24 +00:00
5ee9dedb0f
Report more advertising metrics data
Report more advertising metrics data below when the service is
unregistered.
- Replied request count (sum across interfaces)
- Sent packet count (including announcements and probes)
- Number of conflicts during probing
- Nubmer of conflicts after probing

Bug: 287546772
Test: atest FrameworksNetTestCases NsdManagerTest
Merged-In: I50c54a35dc523422e3a7302c059bbbc38eac5631
Change-Id: I50c54a35dc523422e3a7302c059bbbc38eac5631

Paul Hu   commited 2023-09-06 11:26:53 +08:00
043bcd4537
Merge "Send rawOffloadPacket to OffloadEngine" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2023-09-06 00:04:00 +00:00
a337d95cc4
Disable cache flush bit in existing announcement
Per RFC6762#10.1, the cache flush bit should be false for
existing announcement. Otherwise, the record will be deleted
immediately when receiving this response.

Bug: 299054783
Test: atest FrameworksNetTestCases NsdManagerTest
Change-Id: I8bf1a5b1914b49720862836abb543b232185f5f5

Paul Hu   commited 2023-09-05 17:54:55 +08:00
88239ccb0a
Merge "Delay frozen app sockets close until the cellular modem wakes up" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-09-05 09:11:01 +00:00
4e95ea0740
Send rawOffloadPacket to OffloadEngine
Add the missing logic to send the rawOffloadPacket to OffloadEngine.

Bug: 297314970
Test: atest CtsNetTestCases FrameworksNetTestCases
Change-Id: I06d7a9bb84df72808eff4f0c9df60f7e60aa2a2c

Yuyang Huang   commited 2023-09-05 08:51:04 +00:00
31f6e2eccb
Merge "Update permission check for offloadEngine registration" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2023-09-05 08:45:39 +00:00
65f96123a2
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

Yuyang Huang   commited 2023-09-05 14:53:51 +09:00
8e6fbc8c1a
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

Motomu Utsumi   commited 2023-09-04 18:04:31 +09:00
188bfd36da
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

Chalard Jean   commited 2023-08-30 15:19:50 +09:00
2eb2f7998d
Merge "Verify reevaluation triggered when VPN validation fails" into main
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-08-30 03:12:42 +00:00
29178c8906
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

Chiachang Wang   commited 2023-08-30 03:08:56 +00:00
3e1edc231f
Merge "Split BpfNetMaps constants and utilities into standalone classes" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-08-29 10:44:51 +00:00
50a7ecccf1
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

Junyu Lai   commited 2023-08-29 08:20:10 +00:00
29b7b6385a
Merge "Verify VPN underlying network is set as soon as it tries to use it" into main
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-08-28 10:18:23 +00:00
69cd0aa5a0
Merge "Request enterprise networks" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-08-28 09:20:34 +00:00
940e330f5d
Verify VPN underlying network is set as soon as it tries to use it
Bug: 289606688
Test: atest FrameworksNetTests
Change-Id: Ib35a63ac5f68599c646afad5cad68c1753fb732f

Chiachang Wang   commited 2023-08-28 08:00:20 +00:00
845a91cc31
Merge changes I47b91c0c,I630c0e49 into main
* changes:
  Report sent query count
  Report service info callback metrics data

Paul Hu   authored and   Gerrit Code Review   commited 2023-08-25 14:46:39 +00:00
1b5d601d0c
Report sent query count
Report the sent query count when the discovery is stopped.

Bug: 287546772
Test: atest FrameworksNetTestCases NsdManagerTest
Change-Id: I47b91c0c530eee2f00920ee5ea99e8d7b6e2e9ee

Paul Hu   commited 2023-08-22 17:26:27 +08:00
bad6fe9835
Report service info callback metrics data
Bug: 287546772
Test: atest FrameworksNetTestCases
Change-Id: I630c0e4921f7acf42bf29812d9790ee5a894d60b

Paul Hu   commited 2023-08-22 15:25:37 +08:00
ddce5919af
Merge "Fix kotlin nullable errors in Connectivity tests" into main
Colin Cross   authored and   Gerrit Code Review   commited 2023-08-22 04:13:01 +00:00
d5038a042c
Merge "Report resolution stop" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-08-18 09:30:26 +00:00
aa4db9753b
Report resolution stop
Report the nsd metrics event of resolution stop.

Bug: 287546772
Test: atest FrameworksNetTestCases
Change-Id: I2e6de22c946d58a3410f16b2f2689fd3ffc635a4

Paul Hu   commited 2023-08-18 11:59:06 +08:00
6014905672
Merge "Stop the created handler threads on the tests" into main
Paul Hu   authored and   Gerrit Code Review   commited 2023-08-18 02:40:45 +00:00
a436faf92d
Merge "Stop the created handler threads" into main
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-08-17 09:40:05 +00:00
033ca4c8cf
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

Paul Hu   commited 2023-08-17 06:53:16 +00:00
f6e1867963
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

chiachangwang   commited 2023-08-17 06:18:46 +00:00
8d336eb1a3
Merge "Use isTetheringFeatureNotChickenedOut for kill switch" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-08-17 06:13:21 +00:00
23b0bab6b1
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

Motomu Utsumi   commited 2023-08-16 20:15:52 +09:00
0a50c65f75
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

Paul Hu   commited 2023-08-16 15:53:06 +08:00
a6bc463155
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

Paul Hu   commited 2023-08-16 15:09:17 +08:00
812e9217b9
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

Chalard Jean   commited 2023-08-15 15:14:57 +09:00
c33eafb464
Merge "Fix NullPointerException on NsdService" into main
Paul Hu   authored and   Gerrit Code Review   commited 2023-08-10 09:03:41 +00:00
d45bf5499f
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

Paul Hu   commited 2023-08-10 14:19:01 +08:00
101dbf5262
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

Colin Cross   commited 2023-08-09 10:57:35 -07:00
4e5a061f26
Merge "Fix flaky test: testDataMigration_differentFromFallback" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-08-09 08:53:46 +00:00
ef0afdef0e