Commit graph android_packages_modules_Co.../tests/unit/java
Message SHA1
Clean up the LinkProperties when stop monitoring sockets
The active network LinkProperties are not cleaned up after stop
socket monitoring. Then the apps will have duplicate sockets
to discover on one interface if the interface has been toggled,
because requestSocket will return both the old socket (for the
old netId that is actually gone) and a new socket on the same
interface, for the new netId. Thus, clean up the LinkProperties
when stop monitoring sockets.

Bug: 274063187
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: I3d600169b069a1534bd740e711bc21db107b1201

Paul Hu   commited 2023-03-20 15:06:05 +08:00
13921b2cdc
Merge "Remove unused augmentWithStackedInterfaces"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-03-09 06:55:24 +00:00
e9df7ca57f
Merge "Update system APIs based on feedback."
Jeff Sharkey   authored and   Gerrit Code Review   commited 2023-03-09 02:47:49 +00:00
31b6c65f51
Merge changes from topic "PerNetworkServiceTypeClient"
* changes:
  Create MdnsServiceTypeClient per network
  Wait for a socket to be created before sending packets

Paul Hu   authored and   Gerrit Code Review   commited 2023-03-08 11:14:57 +00:00
71c006bd14
Merge "Migrate reigster service callback backend"
Paul Hu   authored and   Gerrit Code Review   commited 2023-03-08 10:27:57 +00:00
ee0e6cd701
Remove unused augmentWithStackedInterfaces
after the commit aosp/1948496, both mMobileIfaces and mWifiIfaces
already contain the stacked interfaces. Hence, the method is not
really useful.

Test: TH
Fix: 215633405
Change-Id: Id132a166e9cf94cab711f417a4f7ffc84eab6185

Junyu Lai   commited 2023-03-08 13:49:00 +08:00
615610c3d1
Create MdnsServiceTypeClient per network
The running task in MdnsServiceTypeClient would be cancel if the
requests using other networks for the same service type start a
new discovery. Besides, the instanceNameToResponse cache would
be incorrect too. The service attributes may be different on
different networks, so there needs to be a different instance
of the cache. Thus, the MdnsServiceTypeClient needs to be
Network-specific.

Bug: 265787401
Test: atest FrameworksNetTests
Change-Id: Id5ac42f3522a774fe9789c0de4d5357501b63868

Paul Hu   commited 2023-03-08 10:01:50 +08:00
da3c0fe857
Wait for a socket to be created before sending packets
The required sockets may not have been created yet when
MdnsServiceTypeClient#startSendAndReceive is called on
MdnsDiscoveryManager#registerListener, so the first send would go
nowhere, and only later retries would be sent. Ideally the code
would wait for some sockets to be created before calling
startSendAndReceive.

Bug: 265787401
Bug: 264634275
Test: atest FrameworksNetTests
Change-Id: Id789d564d125c0192e742d7dd246367afdb93413

Paul Hu   commited 2023-03-07 19:21:24 +08:00
bf9d2a0ea0
Update system APIs based on feedback.
API council has requested that the recently added BroadcastOptions
APIs be modified to better match API guidelines.

Bug: 267646347
Test: treehugger
Change-Id: Ia701ae31079476d0cc05079d62cd90ba81279cdd

Jeff Sharkey   commited 2023-03-06 14:10:34 -07:00
4ffd34cc42
Merge "Keep case in MdnsServiceInfo attributes"
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2023-03-06 13:03:46 +00:00
2172a5a370
Keep case in MdnsServiceInfo attributes
Although case should not matter when comparing attributes,
converting all keys to lowercase breaks NsdServiceInfo APIs which
provide the original case to the caller.

Use a TreeMap with a case-insensitive comparator to ignore case when
querying keys, while keeping case information in the map.

Bug: 270885892
Test: atest MdnsServiceInfoTest
Change-Id: Id15947b1e8650eb6b59126c5d2dc8624ae4f8100

Remi NGUYEN VAN   commited 2023-03-06 19:52:53 +09:00
0e929ddfcd
Fill in all resolved addresses into NsdServiceInfo
Now, the multiple addresses is supported in resolution service
with the new java backend. Thus, fill in all resolved addresses
into NsdServiceInfo.

Bug: 268586836
Test: atest FrameworksNetTests
Change-Id: I499a749255429df9fe9fbad678074ad383159240

Paul Hu   commited 2023-03-06 14:27:53 +08:00
2b86591d39
Migrate reigster service callback backend
registerServiceInfoCallback currently only sends updates for
addresses added, but does not handle removes (expiration) and
TXT/SRV record updates. Thus, migrate its backend to
MdnsDiscoveryManager which can support the expiration update.

Bug: 266030646
Test: atest FrameworksNetTests CteNetTestCases
Change-Id: I72add213935dc1beacb6277007868ad30bd89c00

Paul Hu   commited 2023-03-06 13:49:19 +08:00
30bd70d168
Merge "Support multiple IPv4 / IPv6 addresses in MdnsResponse"
Paul Hu   authored and   Gerrit Code Review   commited 2023-03-06 03:47:09 +00:00
6477d7b697
Support multiple IPv4 / IPv6 addresses in MdnsResponse
If the mDNS service has multiple IPv4 / IPv6 addresses, only the
last added address will be present on the response. Since the
NsdServiceInfo supports multiple host addresses in Android U, the
MdnsResponse should also support multiple IPv4 / IPv6 addresses
in favor of providing accurate service info to clients.

Check cache flush flag on the response when adding a new address
record. Per RFC6762 10.2, clear all address records if the
cache-flush bit set.

Bug: 268586836
Test: atest FrameworksNetTests
Change-Id: I04548a3f16837939f3131b84c1033377ff81d521

Paul Hu   commited 2023-03-03 21:40:47 +08:00
3a632aeb6b
Merge changes I987ab866,I73fa9ca7
* changes:
  Drop dot at the end of service type
  Implement the stop resolution with MdnsDiscoveryManager

Paul Hu   authored and   Gerrit Code Review   commited 2023-03-03 12:56:38 +00:00
e4407fb469
Add flags for allowlisting types for new NSD impl
The flags allow enabling MdnsDiscoveryManager or MdnsAdvertiser for
specific service types only. For example:

  mdns_type_allowlist_flags = "_type1._tcp:flag1,_type2._tcp:flag2"
  mdns_discovery_manager_allowlist_flag1_version = 1234
  mdns_advertiser_allowlist_flag2_version = 2345

will enable MdnsDiscoveryManager when discovering/resolving services of
type _type1._tcp, and MdnsAdvertiser when advertising services of type
_type2._tcp.

Test: atest NsdServiceTest
Bug: 270885892
Change-Id: I75c31a28472210bf8777409ea7aff1e3d8bf0a0d

Remi NGUYEN VAN   commited 2023-03-03 18:00:59 +09:00
151d0a5528
Drop dot at the end of service type
The service type that found from NsdManager#discoverServices()
with old backend(mDnsResponder) has an extra dot at the end. And
the previous API accepted both formats, so we need to keep
backwards compatibility with both formats. Thus, drop that extra
dot when constructing the service type for the new backend.

Bug: 266030646
Test: atest FrameoworksNetTests
Change-Id: I987ab866f6a3a7cff654f96978057fdd93b859d6

Paul Hu   commited 2023-03-03 16:18:32 +08:00
7445e3dc78
Merge changes I488cc768,Icb9ed7ae,Ib18c3afb,Iba293b47,Ied55829c, ...
* changes:
  Return ERROR_NO_ANSWERS for replies with no answer
  Allow resolving previously undiscovered services
  Use resolveInstanceName in NsdService
  Add missing SRV/TXT/address records to responses
  Update record TTL in set/add methods
  Clear inetaddress fields when removing the record

Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2023-03-03 07:45:24 +00:00
de5adc4f1f
Implement the stop resolution with MdnsDiscoveryManager
The resolveService() uses new mdns backend if the
MdnsDiscoveryManager feature is enabled. So the new API
stopServiceResolution() should have new mdns backend
implementation as well.

Test: atest FrameworksNetTests
Change-Id: I73fa9ca71c0afc5db99db9252f4c030d4f2b8066

Paul Hu   commited 2023-03-03 14:20:11 +08:00
e4f5f258d6
Allow resolving previously undiscovered services
Previously resolve queries for SRV/TXT/A/AAAA were only sent when there
was a known but incomplete MdnsResponse for the service.

Allow sending the resolve queries when there is no known MdnsResponse,
so no known PTR record, but the client specified the resolveInstanceName
in the MdnsSearchOptions. This is achieved by adding the serviceName as
an additional field in MdnsResponse, as it is always known when
constructing the MdnsResponse. The serviceName can either be set from a
discovered PTR record, or from the client-specified resolveInstanceName.

Bug: 267570781
Test: atest NsdManagerTest#testResolveWhenServerSendsNoAdditionalRecord
      (see separate change).
Change-Id: Icb9ed7ae44179a5df5b69a1e6a0486ffc2d8e42c

Remi NGUYEN VAN   commited 2023-03-03 12:51:40 +09:00
448100884e
Use resolveInstanceName in NsdService
For resolve requests, specify the resolveInstanceName in
MdnsSearchOptions.

This will cause discovery to send followup queries when TXT/SRV/A/AAAA
records are missing; for example if only a PTR record is returned
following the discovery probes, or if no discovery probe is sent at all.

Test: atest NsdServiceTest
Bug: 267570781
Change-Id: Ib18c3afbd1533ada7a78dd8ccac993adb439d014

Remi NGUYEN VAN   commited 2023-03-03 11:58:21 +09:00
bb62b1de50
Add missing SRV/TXT/address records to responses
MdnsResponses were only updated through
MdnsResponse.mergeRecordsFrom(MndsResponse), meaning that MdnsResponse
cannot be updated unless a MdnsResponse can be built from the update
packet.

Because a PTR record is required to build a MdnsResponse, this means
that it was not possible to add records to a MdnsResponse unless the
update packet contains a PTR record.

Fix this by having MdnsServiceTypeClient augment its current known
responses in addition to creating new responses from incoming
MdnsPackets.

Bug: 267570781
Test: atest NsdManagerTest#testPtrOnlyResponse with
      mdns_discovery_manager_version set to 1.
Change-Id: Iba293b4772fcd79e94ee6412c9af8225a3349f12

Remi NGUYEN VAN   commited 2023-03-03 11:58:21 +09:00
42b1042f36
Update record TTL in set/add methods
MdnsResponse would not replace records if the TTL changed, but this is
necessary in particular in case of exit announcements (RFC6762 10.1)
where the TTL is updated to zero.

Update MdnsResponse to update records if the TTL changed. The
receiptTimeMillis is still not considered to update records, but doing
so would generate service change notifications every time a reply is
received, so this is not covered here.

Bug: 267570781
Test: atest MdnsResponseTests
Change-Id: Ied55829cba6b043d13603a8230bda457c07de42f

Remi NGUYEN VAN   commited 2023-03-03 11:58:20 +09:00
36981e2352
Clear inetaddress fields when removing the record
When calling MdnsResponse.setInet4AddressRecord with null, the record
was removed from the records list, but not from the inet4AddressRecord /
inet6AddressRecord fields.

Fix that, and update the MdnsResponseDecoder test that missed the bug
because it modified the same incomplete MdnsResponse multiple times
(so isComplete keeps returning false), instead of using a copy of
a complete MdnsResponse.

This requires using a copy constructor, which will be useful for future
changes, so add it with a test.

Bug: 267570781
Test: atest
Change-Id: I199a8e4bc9a54a142c1fec1acee2ab6b1baa7efb

Remi NGUYEN VAN   commited 2023-03-03 11:43:03 +09:00
af4ea5826b
Merge "Uses identical hostName across all interface"
Yuyang Huang   authored and   Gerrit Code Review   commited 2023-03-02 23:40:29 +00:00
09cad2bc2d
Merge "Revert "Implement the stop resolution with MdnsDiscoveryManager""
Ahmad Khalil   authored and   Gerrit Code Review   commited 2023-03-02 11:58:28 +00:00
8d45846632
Revert "Implement the stop resolution with MdnsDiscoveryManager"
This reverts commit 6d77c41f2a.

Reason for revert: DroidMonitor-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?branch=aosp-master&target=aosp_cf_x86_64_phone-userdebug&lkgb=9678930&lkbb=9678975&fkbb=9678975, bug b/271400306

Change-Id: I8bfd2b8117ea401df7441116b983f5fe19f63d5d
BUG: 271400306

Ahmad Khalil   authored and   Gerrit Code Review   commited 2023-03-02 11:43:25 +00:00
4b8d45a4c1
Merge "Implement the stop resolution with MdnsDiscoveryManager"
Paul Hu   authored and   Gerrit Code Review   commited 2023-03-02 10:31:30 +00:00
1246c7243b
Merge "Stop monitoring sockets until all sockets are unrequested"
Paul Hu   authored and   Gerrit Code Review   commited 2023-03-02 10:21:05 +00:00
6772a31c5a
Uses identical hostName across all interface
In case a host has two interfaces (e.g. wifi and ethernet) that are
bridged on the router side, hosts on the network would receive service
advertisements for both interfaces. If each interface uses a different
hostname, this creates a problem where service SRV records would point
to two different hostnames. Generating a hostname for all interfaces can
fix this problem. The hostname will be regenerated if all the clients
for NsdService are disconnected.

Test: atest FrameworksNetTests CtsNetTestCases
Bug: 268153179
Change-Id: Icdd2991233729b7f90e65984ca0381e32ab4ce93

Yuyang Huang   commited 2023-03-02 16:33:17 +09:00
7311c42b94
Implement the stop resolution with MdnsDiscoveryManager
The resolveService() uses new mdns backend if the
MdnsDiscoveryManager feature is enabled. So the new API
stopServiceResolution() should have new mdns backend
implementation as well.

Test: atest FrameworksNetTests
Change-Id: I591e78180f530daa701e0970860f7471f5f5fb9a

Paul Hu   commited 2023-03-02 14:57:25 +08:00
6d77c41f2a
Merge changes I8157c373,I495db18d
* changes:
  Build MdnsResponse in ServiceTypeClient
  Support follow-up queries for missing records

Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2023-03-02 03:53:29 +00:00
9e54059c5d
Stop monitoring sockets until all sockets are unrequested
Now MdnsSocketProvider is stopped when there is no client request
left in NsdService, but this does not trigger
SocketCallback.onInterfaceDestroyed callbacks. If the network of
the socket is then lost while MdnsSocketProvider is not
monitoring, no callback will be fired. Users of the socket
(MdnsDiscoveryManager and MdnsAdvertiser) may keep using it
without ever getting notified. So ignore the stop and wait until
all sockets are unrequested. Then the socket destroy should be
notified to all users.

Bug: 267978487
Test: atest FrameworksNetTests
Change-Id: I7a8bb0550262fe397b91f1236a8dbca1cf2c7518

Paul Hu   commited 2023-03-02 10:56:35 +08:00
58f2060614
Build MdnsResponse in ServiceTypeClient
Instead of building MdnsResponse lists in MdnsSocketClient and sending
each one to ServiceTypeClient, only parse packets in MdnsSocketClient,
and let each ServiceTypeClient build the MdnsResponse from them.

MdnsResponseDecoder already implements the same filtering that
MdnsDiscoveryManager#onResponseReceived did on the service types so this
is a no-op.

This will be useful to allow MdnsServiceTypeClient to update its
responses using records that are not necessarily part of a full
MdnsResponse; for example if a reply packet only contains address
records, or only SRV/TXT records without a PTR record.

Bug: 267570781
Test: atest
Change-Id: I8157c3732c425aae497d44c44c64b640859c13dc

Remi NGUYEN VAN   commited 2023-03-01 16:17:43 +09:00
016aad904d
Merge "Check network slicing declaration for network request"
Yuyang Huang   authored and   Gerrit Code Review   commited 2023-03-01 02:13:31 +00:00
a908d816de
Add network handle to the nflog prefix for wakeups
This is useful in the system server for better attribution of wakeup
events.
The logic for encoding the data in the prefix is still maintained ad-hoc
and should be standardized in the future.

Test: Builds, boots. Manually triggering a wifi wakeup doesn't result
in anything unexpected.
Test: atest FrameworksNetTests

Bug: 265742148
Change-Id: I7ef8a606459bb9f0630f629c01d3b34643ae5319

Suprabh Shukla   commited 2023-02-28 19:18:44 +00:00
1e31203fcc
Check network slicing declaration for network request
When the application wants to request network with
NET_CAPABILITY_PRIORITIZE_BANDWIDTH or
NET_CAPABILITY_PRIORITIZE_LATENCY, it has to declare
PackageManager.PROPERTY_NETWORK_SLICE_DECLARATIONS property and also
adds the declaration in a separate XML files. Otherwise, the request
will fail with a SecurityException being thrown.

Test: atest FrameworksNetTests CtsNetTestCases
Bug: 266524688
Change-Id: I6affc857b803211517368da288e1b2fdc06a955b

Yuyang Huang   commited 2023-02-28 17:38:30 +09:00
96e8bfee5f
Merge "add TRANSPORT_THREAD to NetworkCapabilities"
Kangping Dong   authored and   Gerrit Code Review   commited 2023-02-28 07:16:16 +00:00
7dc4459d33
Merge "Address comments at aosp/2361702"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-02-23 11:07:03 +00:00
ea5e220c90
Address comments at aosp/2361702
Test: 1. Patch local built module on T device
      2. atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest
Fix: 267968887
Change-Id: I86e5be9a0cee0621ff9ef0996d56a51fc5f408c2

Junyu Lai   commited 2023-02-23 15:21:29 +08:00
c53a169a90
Merge "Add test for using ESP_IP_VERSION and ESP_ENCAP_TYPE in Vpn"
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-02-22 05:58:02 +00:00
bf8b243978
Merge "Fix a bug where alarms are deduplicated"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-02-22 04:08:47 +00:00
3bee8c9afa
Fix a bug where alarms are deduplicated
Test: new test in this patch
Bug: 269719647
Change-Id: I32e8d35f1751e2fd81a0007ae6cb308b6bcbb463

Chalard Jean   commited 2023-02-22 03:00:46 +09:00
f4eb1ae6b9
Add test for using ESP_IP_VERSION and ESP_ENCAP_TYPE in Vpn
Bug: 269714344
Test: atest FrameworksNetTests
Change-Id: Ia9c47967a1b96204a6a739d133f2b8455229af52

chiachangwang   commited 2023-02-21 11:31:28 +00:00
84ea53691c
Update VpnTests for adding ESP arguments
Test: VpnTest
Bug: 269714344
Change-Id: I0d8a2818ea0b67ebb5da7dbac9cd6aea9bede386

Chalard Jean   authored and   chiachangwang   commited 2023-02-21 05:59:52 +00:00
e4341f0933
Merge "Fix flaky test testRestrictedProfileAffectsVpnUidRanges"
Lucas Lin   authored and   Gerrit Code Review   commited 2023-02-18 06:19:26 +00:00
1e9120a863
Fix flaky test testRestrictedProfileAffectsVpnUidRanges
File a VPN request to prevent the VPN network being lingered.

The VPN network will be lingered and onCapabilitiesChanged()
will be fired when the linger timer is expired, which will
cause the test receiving an unexpected onCapabilitiesChnaged()
and make the test failed eventually.

Bug: 265396507
Bug: 265510523
Test: atest FrameworksNetTests
Change-Id: Id9ad810d46cb2bbb13fa5c602520635ae8e73e31

lucaslin   authored and   Lucas Lin   commited 2023-02-18 02:59:05 +00:00
881daf084f
Merge "Enable automatic keepalives by default."
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-02-17 23:53:00 +00:00
4e1695f711
Enable automatic keepalives by default.
This can still be flagged off.

Test: FrameworksNetTests
Change-Id: Ic69911d21da380662a65f1c482ccee107f851a23

Chalard Jean   commited 2023-02-17 15:37:57 +09:00
759fbc7f3d