Commit Graph

1501 Commits

Author SHA1 Message Date
Jeff Sharkey
4ffd34cc42 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
2023-03-06 14:10:34 -07:00
Remi NGUYEN VAN
2172a5a370 Merge "Keep case in MdnsServiceInfo attributes" 2023-03-06 13:03:46 +00:00
Remi NGUYEN VAN
0e929ddfcd 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
2023-03-06 19:52:53 +09:00
Paul Hu
2b86591d39 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
2023-03-06 14:27:53 +08:00
Paul Hu
6477d7b697 Merge "Support multiple IPv4 / IPv6 addresses in MdnsResponse" 2023-03-06 03:47:09 +00:00
Paul Hu
3a632aeb6b 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
2023-03-03 21:40:47 +08:00
Paul Hu
e4407fb469 Merge changes I987ab866,I73fa9ca7
* changes:
  Drop dot at the end of service type
  Implement the stop resolution with MdnsDiscoveryManager
2023-03-03 12:56:38 +00:00
Remi NGUYEN VAN
151d0a5528 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
2023-03-03 18:00:59 +09:00
Paul Hu
7445e3dc78 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
2023-03-03 16:18:32 +08:00
Remi NGUYEN VAN
de5adc4f1f 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
2023-03-03 07:45:24 +00:00
Paul Hu
e4f5f258d6 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
2023-03-03 14:20:11 +08:00
Remi NGUYEN VAN
448100884e 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
2023-03-03 12:51:40 +09:00
Remi NGUYEN VAN
bb62b1de50 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
2023-03-03 11:58:21 +09:00
Remi NGUYEN VAN
42b1042f36 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
2023-03-03 11:58:21 +09:00
Remi NGUYEN VAN
36981e2352 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
2023-03-03 11:58:20 +09:00
Remi NGUYEN VAN
af4ea5826b 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
2023-03-03 11:43:03 +09:00
Yuyang Huang
09cad2bc2d Merge "Uses identical hostName across all interface" 2023-03-02 23:40:29 +00:00
Ahmad Khalil
8d45846632 Merge "Revert "Implement the stop resolution with MdnsDiscoveryManager"" 2023-03-02 11:58:28 +00:00
Ahmad Khalil
4b8d45a4c1 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
2023-03-02 11:43:25 +00:00
Paul Hu
1246c7243b Merge "Implement the stop resolution with MdnsDiscoveryManager" 2023-03-02 10:31:30 +00:00
Paul Hu
6772a31c5a Merge "Stop monitoring sockets until all sockets are unrequested" 2023-03-02 10:21:05 +00:00
Yuyang Huang
7311c42b94 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
2023-03-02 16:33:17 +09:00
Paul Hu
6d77c41f2a 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
2023-03-02 14:57:25 +08:00
Remi NGUYEN VAN
9e54059c5d Merge changes I8157c373,I495db18d
* changes:
  Build MdnsResponse in ServiceTypeClient
  Support follow-up queries for missing records
2023-03-02 03:53:29 +00:00
Paul Hu
58f2060614 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
2023-03-02 10:56:35 +08:00
Remi NGUYEN VAN
016aad904d 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
2023-03-01 16:17:43 +09:00
Yuyang Huang
a908d816de Merge "Check network slicing declaration for network request" 2023-03-01 02:13:31 +00:00
Suprabh Shukla
1e31203fcc 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
2023-02-28 19:18:44 +00:00
Yuyang Huang
96e8bfee5f 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
2023-02-28 17:38:30 +09:00
Kangping Dong
7dc4459d33 Merge "add TRANSPORT_THREAD to NetworkCapabilities" 2023-02-28 07:16:16 +00:00
Treehugger Robot
ea5e220c90 Merge "Address comments at aosp/2361702" 2023-02-23 11:07:03 +00:00
Junyu Lai
c53a169a90 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
2023-02-23 15:21:29 +08:00
Chiachang Wang
bf8b243978 Merge "Add test for using ESP_IP_VERSION and ESP_ENCAP_TYPE in Vpn" 2023-02-22 05:58:02 +00:00
Treehugger Robot
3bee8c9afa Merge "Fix a bug where alarms are deduplicated" 2023-02-22 04:08:47 +00:00
Chalard Jean
f4eb1ae6b9 Fix a bug where alarms are deduplicated
Test: new test in this patch
Bug: 269719647
Change-Id: I32e8d35f1751e2fd81a0007ae6cb308b6bcbb463
2023-02-22 03:00:46 +09:00
chiachangwang
84ea53691c Add test for using ESP_IP_VERSION and ESP_ENCAP_TYPE in Vpn
Bug: 269714344
Test: atest FrameworksNetTests
Change-Id: Ia9c47967a1b96204a6a739d133f2b8455229af52
2023-02-21 11:31:28 +00:00
Chalard Jean
e4341f0933 Update VpnTests for adding ESP arguments
Test: VpnTest
Bug: 269714344
Change-Id: I0d8a2818ea0b67ebb5da7dbac9cd6aea9bede386
2023-02-21 05:59:52 +00:00
Lucas Lin
1e9120a863 Merge "Fix flaky test testRestrictedProfileAffectsVpnUidRanges" 2023-02-18 06:19:26 +00:00
lucaslin
881daf084f 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
2023-02-18 02:59:05 +00:00
Treehugger Robot
4e1695f711 Merge "Enable automatic keepalives by default." 2023-02-17 23:53:00 +00:00
Chalard Jean
759fbc7f3d Enable automatic keepalives by default.
This can still be flagged off.

Test: FrameworksNetTests
Change-Id: Ic69911d21da380662a65f1c482ccee107f851a23
2023-02-17 15:37:57 +09:00
Motomu Utsumi
6c01bd30af Merge "Add getUidRule method to BpfNetMaps" 2023-02-17 01:52:52 +00:00
Benedict Wong
78dea027ff Merge "Add unit tests for new VpnProfile fields" 2023-02-15 23:42:51 +00:00
Quang Luong
0f6a2e69cd Merge "Allow SUW to access registerSystemDefaultNetworkCallback" 2023-02-15 20:22:10 +00:00
chiachangwang
015b68b192 Add unit tests for new VpnProfile fields
Add and update tests for automaticNattKeepaliveTimerEnabled
and automaticIpVersionSelectionEnabled fields.

Test: atest Ikev2VpnProfileTest VpnProfileTest
Change-Id: I4e424abd2197d9099a2efe0bd8c4b9120bfcfe3a
2023-02-15 15:01:28 +00:00
chiachangwang
7c17c283ea [DK5]Add debugging information for automaticOnOff keepalive
Print state and keepalive information in the dump.

Also update ConnectivityService and the corresponding test to
create AutomaticOnOffKeepaliveTracker from a Dependencies class.
ConnectivityService#dump() will require READ_DEVICE_CONFIG
permission because of the new dump() in AutomaticOnOffKeepaliveTreacker.
ConnectivityServiceTest should focus on verifying design in
ConnectivityService, so skipping the DeviceConfig check via a fake
Dependencies class in the unit test.

Sample dump:

AutomaticOnOff enabled: true
  AutomaticOnOffKeepalive [KeepaliveInfo [ type=1 network=100 startedS ... ], state=STATE_ENABLED ]

Bug: 259000745
Test: m ; atest FrameworksNetTests CtsNetTestCases
Change-Id: I9ac725bcef7daec1d1a12bad592b7fa6856a1707
2023-02-13 09:54:36 +00:00
Jean Chalard
d500f20f90 Merge "Remove expectLinkPropertiesThat" 2023-02-11 02:09:38 +00:00
Quang Luong
98858d6b27 Allow SUW to access registerSystemDefaultNetworkCallback
registerSystemDefaultNetworkCallback is required by WifiTrackerLib to
detect the system default network for UI purposes. Currently this API is
allowed for holders of the NETWORK_SETTINGS permission, but not
NETWORK_SETUP_WIZARD. Since SUW also uses WifiTrackerLib, we should
allow this API for NETWORK_SETUP_WIZARD as well.

Bug: 230643853
Test: atest ConnectivityServiceTest
Change-Id: Ic01a186f91ed67b4603b6b8964921be7473a483a
2023-02-11 00:31:59 +00:00
Aaron Huang
2a69e41772 Merge "Tempates with different subscriber ID should be not equal" 2023-02-10 08:06:07 +00:00
Aaron Huang
c9371d05fe Tempates with different subscriber ID should be not equal
mSubscriberId was removed from NetworkTemplate and equals/hashCode
does not check the mMatchSubscriberIds. This will cause tempates
with different subscriber ID matching that are equal now. Thus
adding the check for mMatchSubscriberIds to fix it.

Bug: 267968247
Test: FrameworksNetTests:NetworkTemplateTest
Change-Id: I2956bf4c8cf2c4d73ebe102d53e755fbcc5d7642
2023-02-10 08:04:53 +00:00