Commit graph android_packages_modules_Co.../tests
Message SHA1
[mdns] service implementation for public key
Bug: 317946010
Bug: 333232582

Change-Id: Iab66bf0a1af14878c7b18a7a3015c2de7a6514c8

Handa Wang   commited 2024-04-24 07:17:00 +00:00
52497d66cc
[mdns] add hidden API for public key
This commit adds support of registering a public key for a host/service.
This is required to enable Advertising Proxy feature for Thread devices.

For example:
```
NsdServiceInfo info = new NsdServiceInfo();

info.setServiceName("My Service");
info.setServiceType("_test._tcp");
info.setHostname("MyHost");
info.setHostAddresses(List.of(address1, address2));
info.setPublicKey(/* KEY RDATA */);

nsdManager.registerService(info, PROTOCOL_DNS_SD, listener);
```

Bug: 317946010

Change-Id: I367ebff8119d5c1dff0410c85e6fb86dca6c66b8

Handa Wang   commited 2024-04-24 07:02:42 +00:00
364aa570e2
Merge "Test whether APF program actually runs" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-04-24 04:17:31 +00:00
1b7c5e097c
Merge "Add firewall chains for HAPPY_BOX and user/admin PENALTY_BOX" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-04-24 03:51:09 +00:00
c04493234e
Test whether APF program actually runs
Adds a test that sends a ping packet, asserts its reply, then installs a
filter and asserts that the second ping packet is dropped.

Test: test only
Change-Id: I832ea1b3cc35a44c98fbf8c86c16bf753f183c92

Patrick Rohr   commited 2024-04-23 09:01:04 -07:00
22e571353f
Only listen to echo replies
This discards anything that is not an echo reply. Technically, length
cannot be 0, since zero-length packets close the PacketReader (because
FdEventsReader#shoudlProcessZeroLengthPacket has not been overridden
(yet?)).

Test: atest ApfIntegrationTest
Change-Id: Ib7cd9bf819614e66c8b6b7fc15622be5c344a208

Patrick Rohr   commited 2024-04-23 08:24:44 -07:00
bd50241d03
Move turnScreenOff to BeforeClass setUp
A Thread.sleep() is needed after turnScreenOff() to ensure APF has
started running. This means it makes sense to move turnScreenOff to
a @BeforeClass setup to avoid slowing down the tests.

Test: atest ApfIntegrationTest
Change-Id: Ie1d9335fb1ad2ac3c51a48269b28f66f212f993c

Patrick Rohr   commited 2024-04-23 08:24:44 -07:00
2ec433dd58
Reapply "Send ICMPv6 ping to support IPv6-only network"
This reverts commit 98219a4e8a.

Moved the revert past "Only run APF tests on physical devices".
This broke on cuttlefish, as CF does not support IPv6.

Test: TH
Change-Id: I04d1adb4538e6c413a1325432e1c014ca78b41e3

Patrick Rohr   commited 2024-04-23 08:24:00 -07:00
c83731b8d9
Only run APF tests on physical devices
Cuttlefish does not actually implement APF, and there is no point in
general to test APF integration on virtual devices.

Test: atest ApfIntegrationTest
Change-Id: I1f0e25255d1ebcc5a6a50a42968ea1e14b5755db

Patrick Rohr   commited 2024-04-23 08:22:42 -07:00
5ec06b7a65
Merge "Use helper function getIndexForValue in MulticastRoutingCoordinator." into main
Yang Sun   authored and   Gerrit Code Review   commited 2024-04-23 12:58:39 +00:00
173ffb9278
Use helper function getIndexForValue in MulticastRoutingCoordinator.
The SparseArray.indexOfValue() uses == to compare values,
MulticastRoutingCoordinator uses SparseArray with String type values,
and the indexOfValue function would sometimes return -1 when looking for
a value in the SparseArray.

Added a helper function getIndexForValue in CollectionUtils to get index
by comparing values with equals, and used this function in MulticastRoutingCoordinator.

Updated
MulticastRoutingCoordinatorServiceTest#testMulticastRouting_applyConfigNone_removesMfc
test case to use copies of interface names when updating the multicast
configs, so the test would fail without this fix.

Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.CollectionUtilsTest#testGetIndexForValue
atest android.net.connectivity.com.android.server.connectivity.MulticastRoutingCoordinatorServiceTest#testMulticastRouting_applyConfigNone_removesMfc

Change-Id: I862242d6be01b8552cdd6af6c9691948a9f0bfe0

Yang Sun   commited 2024-04-23 17:22:15 +08:00
4e7baadc71
Merge "Revert "Send ICMPv6 ping to support IPv6-only network"" into main
Daniel Hsieh   authored and   Gerrit Code Review   commited 2024-04-23 07:14:36 +00:00
0fc03c7c31
Revert "Send ICMPv6 ping to support IPv6-only network"
This reverts commit 03e958226e.

Reason for revert: This cl causes b/336432192.

Change-Id: Id103cbce07466213eb325fc99fe37f02aa72c786

Daniel Hsieh   authored and   Gerrit Code Review   commited 2024-04-23 06:05:09 +00:00
98219a4e8a
Add firewall chains for HAPPY_BOX and user/admin PENALTY_BOX
Follow up CLs will update CS to generate blocked reason from bpf map
instead of asking NPMS.

However, one issue is NPMS set PENALTY_BOX for
BLOCKED_METERED_REASON_USER_RESTRICTED and
BLOCKED_METERED_REASON_ADMIN_DISABLED without telling the reason.
So, CS can not know the reason of PENALTY_BOX.

This CL add new firewall chain and match to distinguish reasons.
NPMS must call setUidFirewallRule with
FIREWALL_CHAIN_METERED_DENY_USER or FIREWALL_CHAIN_METERED_DENY_ADMIN
based on the reason so that CS can know the reason of restriction.

Bug: 332628891
Test: atest com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Change-Id: Ia4ad4bdb345abc22c782630e828edfad2452db36

Motomu Utsumi   commited 2024-04-23 15:04:28 +09:00
11d3345daa
Merge "Assert fixed test method count in ConnectivityServiceTest" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-23 03:38:41 +00:00
0168ae22f6
Merge "Send ICMPv6 ping to support IPv6-only network" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-04-23 03:18:51 +00:00
d601d1156c
Merge "[mdns] add elapsedRealTime() to Dependencies for MdnsRecordRepository" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-04-23 01:59:30 +00:00
23a6d34788
Send ICMPv6 ping to support IPv6-only network
When using IPv4 ping, the APF filter has to take clat into account. In
order to prevent this complexity, just send an ICMPv6 ping instead.

Test: atest ApfIntegrationTest
Change-Id: I7938366ea26295bb3b3b1077d7d31395bc493770

Patrick Rohr   commited 2024-04-22 11:29:02 -07:00
03e958226e
CompletableFuture can only be completed once
Also, it throws a TimeoutException instead of an ExecutionException if
get() times out. (ExecutionExceptions are thrown if the future completes
exceptionally, which is not the case here.)

Test: TH
Change-Id: If1bc359e8fefb819089e4f2885fb45ee7e3a996c

Patrick Rohr   commited 2024-04-22 11:29:02 -07:00
522d5c7e7a
Log ping packet and reply and use ByteArray.toHexString
ByteArray.toHexString is experimental stdlib API, so it requires a
special annotation to be used. If there is a good reason not to use the
experimental API, an extension function "asHexString()" could be added
to.
Unfortunately, ByteArray does not have a companion object, so it is not
possible to add a fun ByteArray.Companion.fromHexString().

Test: TH
Change-Id: Ifedc998e95d6a1e4cdeb5bd9982b9456e64e649c

Patrick Rohr   commited 2024-04-22 11:29:02 -07:00
2eb48f0265
[mdns] add elapsedRealTime() to Dependencies for MdnsRecordRepository
This CL adds elapsedRealTime() to Dependencies so that in the unit test
we can simulate the elapse of time.

Bug: 336268432
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.connectivity.mdns.MdnsRecordRepositoryTest
Change-Id: I64cf0ac1772f54edf187cf9ca6351a75b81fd859

Handa Wang   commited 2024-04-22 16:06:38 +00:00
a1a80ad9c3
Merge "[mdns] separate the multicast reply quota for IPv4 and IPv6" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-04-22 13:50:18 +00:00
c03867b757
Assert fixed test method count in ConnectivityServiceTest
ConnectivityServiceTest is deprecated but people sometimes still
add new test methods to it, and getting review feedback to rewrite
tests in CSTest. This wastes resources.
Thus, assert fixed test method count to make it fails locally for
people to aware of it.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testTestMethodCount
Bug: N/A
Change-Id: I0a98a0e3fcd97484f372737e7c6fe24743c21834

Junyu Lai   commited 2024-04-22 17:11:50 +08:00
08f5b59482
[mdns] separate the multicast reply quota for IPv4 and IPv6
This CL separates the multicast reply quota for IPv4 and IPv6. Before
this change, when an IPv4 mDNS query and an IPv6 mdns query arrives at
the same time for the same record (which is a common behavior for DNS-SD
resolvers), MdnsRecordRepository will only respond to one of them. The
other response will be throttled silently.

It's especially problematic when the IPv4 query and IPv6 query are sent
by different hosts. One of the hosts will get no reply.

Bug: 335096961
Test: Unit test and verified on a local device.

Change-Id: I0d7a9fad2b43bbfb8b042828295cdf08bf4ae5c8

Handa Wang   commited 2024-04-22 07:37:22 +00:00
c8de4cb79f
Merge "Wait for start() to finish" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-20 02:11:34 +00:00
503a25c8f0
Wait for start() to finish
Since start() triggers createFd(), it does need to wait for it to
complete. Otherwise, sendPing() might run before a socket has been
allocated.

Bug: 335824575
Test: TH
Change-Id: Ic65b691ea039c3cbbe99c792144f491c46c486b7

Patrick Rohr   commited 2024-04-19 10:50:33 -07:00
1588303666
Merge "Add a placeholder test to test IcmpPacketReader and sendPing" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-04-19 02:12:40 +00:00
a114c93950
Merge changes I1d0b73ef,I753dac68,Id3fb329b,I7037bee1 into main
* changes:
  Add support for sendPing
  Add support to expect ping reply or dropped ping
  Bind socket to WiFi network
  Add IcmpPacketReader to ApfIntegrationTest

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-04-19 02:12:32 +00:00
c0863c003e
Add a placeholder test to test IcmpPacketReader and sendPing
This will soon become an actual APF test.

Test: atest ApfIntegrationTest
Change-Id: I5c78b557177c96e3460a1057527f67de78290338

Patrick Rohr   commited 2024-04-18 13:12:48 -07:00
c2c667ba43
Add support for sendPing
This hard-codes the destination as 8.8.8.8.

Test: mm
Change-Id: I1d0b73ef5bfa20bf094d5ca81de6a2bbe443f30a

Patrick Rohr   commited 2024-04-18 13:12:21 -07:00
977573efd0
Add support to expect ping reply or dropped ping
Test: mm
Change-Id: I753dac687c5521b45bd99a6d57c7be60e25bb1ce

Patrick Rohr   commited 2024-04-18 13:03:22 -07:00
a89976d5f9
Bind socket to WiFi network
APF is only supported on WiFi, so make sure that the socket is bound to
the right network.

Test: TH
Change-Id: Id3fb329b0bb3125c9dfe64cc22f3e04bd586f70a

Patrick Rohr   commited 2024-04-18 12:46:23 -07:00
125deb970a
Add IcmpPacketReader to ApfIntegrationTest
This does not currently do anything as no one is sending packets yet.

Test: builds
Change-Id: I7037bee1997dda8ed2a706a8178dec9be995fcf1

Patrick Rohr   commited 2024-04-18 12:44:51 -07:00
824a659921
Merge "Return current testable networks directly in instant mode" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-18 12:02:42 +00:00
53babdfee5
Return current testable networks directly in instant mode
Some MultinetworkApiTest tests require a testable network and
attempt to request cell or Wi-Fi connections. This involves
calling ConnectivityManager#requestNetwork, which requires the
CHANGE_NETWORK_STATE permission. Since instant apps cannot be
granted this permission, return currently available testable
networks directly in instant mode instead of attempting to
request new ones.

Fix: 335103621
Test: atest CtsNetTestCases:android.net.cts.MultinetworkApiTest \
      --instant
Change-Id: I51dbd33e0dab12856e1c0f387e45e6286feefe20

Paul Hu   commited 2024-04-18 05:57:04 +00:00
82e396394b
Add safeguard against previous ethernet interfaces existing
The test EthernetManagerTest#testEnableDisableInterface_callbacks
captures the interface state changes of ethernet
interfaces that already exist instead of the test one created. Changes
the expectCallback to eventuallyExpect to account for this.

Test: atest EthernetManagerTest
Flag: TEST_ONLY
Bug: 333338569
Change-Id: Ic08444c87f93b3832c4fae1ce2f8382bbb71cb28

Chris Desir   commited 2024-04-17 15:00:00 -07:00
7e6f10ce0a
Merge "[mdns] allow hostnames beginning with a digit" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-04-16 08:25:38 +00:00
f41e6019dd
[mdns] allow hostnames beginning with a digit
A Matter device uses a hex as the hostname so it may begin with a digit
which wasn't allowed in NsdService. This CL looses this check to allow
Matter devices to register their services at Android Thread Border
Router.

Bug: 334828525
Test: CI
Change-Id: Ia779791e214158a08c2ec06adf8d5630ec8ea616

Handa Wang   commited 2024-04-16 05:52:01 +00:00
8310a5e2d4
Merge "Revert "Use bpf map based isUidNetworkingBlocked on V+"" into main
Patrick Rohr   authored and   Gerrit Code Review   commited 2024-04-11 19:37:46 +00:00
c6678bbd71
Revert "Use bpf map based isUidNetworkingBlocked on V+"
This reverts commit 9b272fa53a.

Reason for revert: possible root cause of b/333340911.

Change-Id: Ic4923fd19db7e4704a3ef02d79644b47c271e18e

Patrick Rohr   authored and   Gerrit Code Review   commited 2024-04-11 16:54:04 +00:00
a658220234
Merge "Report sent query count in resolution stop metrics" into main
Paul Hu   authored and   Gerrit Code Review   commited 2024-04-11 08:42:54 +00:00
cede6542da
Merge changes from topic "rate-limit-trafficstats" into main
* changes:
  Make cache duration and max entries configurable
  Create TestRule: SetFeatureFlagsRule
  Rate-limit on TrafficStats#get*[Bytes|Packets] API calls
  Clear TrafficStats cache before getting readings from TrafficStats

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-11 07:26:14 +00:00
47c819640d
Merge "Migrate ConnectivityManagerTest to callback rule" into main
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2024-04-11 02:32:13 +00:00
2d23887beb
Report sent query count in resolution stop metrics
In the reportServiceResolutionStop function, the sent query count
is not set. This means it's impossible to track how many queries
are sent when a service is not resolved successfully. To track
this information, add the sent query count to
reportServiceResolutionStop.

Fix: 333302084
Test: atest FrameworksNetTets NsdManagerTest
Change-Id: Ida2a33ea35e9bb7393fe860245eb5ad8578d5ff6

Paul Hu   commited 2024-04-10 09:21:29 +00:00
edaeecda7b
Migrate ConnectivityManagerTest to callback rule
ConnectivityManagerTest has existing logic that is functionally
identical to AutoReleaseNetworkCallbackRule. Migrate it to use the rule
instead.

This just migrates callbacks to their Rule equivalents, except for
waitForActiveNetworkMetered which relied on the NetworkStack
ConnectivityManager shim for registerSystemDefaultNetworkCallback on R
to use a fallback implementation. Use the same NetworkRequest as
ConnectivityManagerShim as a direct fallback in this case.

Test: atest
Change-Id: I06501a5b7c05071667344bedb08e9b824c03b27c

Remi NGUYEN VAN   commited 2024-04-10 15:27:08 +09:00
93b08e202e
Add DevSdkIgnoreRule to ApfIntegrationTest
testReadWriteProgram is annotated with IgnoreUpTo(U), but because the
class does not use the rule, that has no effect.

Fix that by adding the rule.

Note that DevSdkIgnoreRunner only affects running the whole class
(having IgnoreUpTo at the class level), not annotated individual tests.

Test: atest
Bug: 333208995
Change-Id: I56b9c0775c3f39bb0f133705e57a41717a7d777b

Remi NGUYEN VAN   commited 2024-04-09 15:26:19 +09:00
7780b674b6
Make cache duration and max entries configurable
Field trials could be used to find ideal values.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Bug: N/A
Change-Id: Ia1304d041a19a81f54b7fdfbbbf1871c7c58a57f

Junyu Lai   commited 2024-04-08 10:43:48 +08:00
233362bf28
Create TestRule: SetFeatureFlagsRule
This rule works by reading the annotation and dynamically
invoking a user-specified method before evaluation to handle the feature flag configuration.

Usage:
class MyTestClass {
  @get:Rule
  val setFeatureFlagsRule = SetFeatureFlagsRule(setFlagsMethod = (name, enabled) -> {
    // Custom handling code.
  })

  // ... test methods with @FeatureFlag annotations
  @FeatureFlag("FooBar1", true)
  @FeatureFlag("FooBar2", false)
  @Test
  fun testFooBar() {}
}

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Bug: N/A
Change-Id: I439e8ee40b8e81b6eb3857925912a3b843e8dfa1

Junyu Lai   commited 2024-04-08 10:43:42 +08:00
5ed8003915
Merge "Deflaking network access checks in CtsHostsideNetworkTests" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-06 05:48:36 +00:00
1d73c6bea5
Suppress ktlint:standard:comment-wrapping warning
standard:comment-wrapping does not allow annotating function argument
literals inline (since block comments must not be surrounded by code).
So the following annotations are not allowed in ktlint:

foo(1 /* bar */)

Unfortunately, there are not good alternatives. Named arguments can only
be used to call Kotlin functions and are not a general solution.
Instead, disable this linter rule for the entire file.

This also adds a suppress annotation further down in the file, since
ktlint does not like the extra space required to make the comments line
up horizontally...

Test: repo upload --dry-run
Change-Id: I62fdb0347965ee3fc43783eb07af47e95af882a5

Patrick Rohr   commited 2024-04-05 11:57:42 -07:00
9c3cbe5dd2