Commit Graph

1467 Commits

Author SHA1 Message Date
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
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
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
Chalard Jean
816f0af86a Remove expectLinkPropertiesThat
expect() is simply better

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: I5bf109ccf34f1fa5ce2f4ed78300d5a126778e30
2023-02-10 14:32:14 +09:00
Jean Chalard
9f3857754d Merge changes from topics "remove_expectblocked", "rename_reason"
* changes:
  Rename BlockedStatusInt.blocked to .reason
  Remove expectBlockedStatusCallback
2023-02-10 05:26:50 +00:00
Yuyang Huang
90a2cbdd8d Moves all compatibility flags to ConnectivityCompatChanges.java
ConnectivityCompatChanges.java becomes the centralized place for all the
CompatChanges used in the Connectivity module. By putting all the
CompatChanges here, we are able to manage them under a single
platform_compat_config.

Bug: 268440216
Test: atest FrameworksNetTests
Change-Id: I3e17af545718073d7d1c96e27298e7790563fd33
2023-02-09 19:51:37 +09:00
Chalard Jean
9d8397a87a Rename BlockedStatusInt.blocked to .reason
It's a reason, so it's a lot clearer this way

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: I1cfcdb291f46205141d5d40322d5a8e3b178db20
2023-02-09 16:19:14 +09:00
Chalard Jean
6486ca58fc Remove expectBlockedStatusCallback
expect() is simpler to do the same thing

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: I4d992fd7ea57d36a38afc33eaebcf2f7ce05aa80
2023-02-09 16:19:14 +09:00
Jean Chalard
2a6c2e0160 Merge "Remove expectCapabilitiesWith and Without" 2023-02-09 02:20:20 +00:00
Lorenzo Colitti
5d8c3b1428 Merge changes from topic "experimental-udp-encap"
* changes:
  Experimental support for IPv6 UDP encap.
  Remove unused assignment.
  Refactor testCreateTransform and add IPv6 and encap coverage.
2023-02-08 06:06:17 +00:00
Lorenzo Colitti
b38fef8333 Experimental support for IPv6 UDP encap.
This is a back-pocket solution only, to ensure that VpnManager
privileged clients can temporarily rely on IPv6 UDP encap if on
certain carriers IPv4 UDP and IPv6 ESP cannot provide acceptable
performance and battery life.

For these reasons IPv6 UDP encap is not a public or system API
and is triggered by passing a port greater than 65535 to the
existing openUdpEncapsulationSocket API.

Bug: 259001350
Test: new CTS tests
Change-Id: I02e0566ba910a300dda6a589cd265a3360add40c
2023-02-08 15:05:07 +09:00
Chalard Jean
99cab4a44c Remove expectCapabilitiesWith and Without
The base method is capable of doing this in a clearer manner,
so this redundant method is no longer needed.

Test: ConnectivityServiceTest FrameworksNetIntegrationTests
Bug: 157405399
Change-Id: I5f801d3c66374096fe7be7be21ee8d80264cd693
2023-02-07 18:17:33 +09:00
Jean Chalard
f1aeb1051e Merge "Remove expectCapabilitiesThat" 2023-02-07 03:20:05 +00:00
Aaron Huang
40eb6abb07 Merge "Combine two register broadcast receiver methods into one method" 2023-02-07 03:06:37 +00:00
Paul Hu
e3e9f5622b Merge "Rename onResolveStopped to onResolutionStopped" 2023-02-06 11:16:48 +00:00
Aaron Huang
9e04018e8c Combine two register broadcast receiver methods into one method
Combine registerPacProxBroadcastThat and registerConnectiviyBroadcastThat
into one method since they are highly similar.

Test: FrameworksNetTests:ConnectivityServiceTest
Change-Id: If0605a94208478399375a43c1ef92782d26cb805
2023-02-06 19:04:01 +08:00
Aaron Huang
c6d0770afc Merge "Make sure device is awake to verify the launcher is shown" 2023-02-06 06:47:23 +00:00
Aaron Huang
361e617b93 Make sure device is awake to verify the launcher is shown
If the screen is off while running the test, it will
cause test fail because the test cannot verify the
launcher is shown. Thus, wake up the device first to
verify if the launcher is shown or not.

Bug: 261860642
Test: this
Change-Id: Icda8a2c6fdc97caf1986bb812ca366d9c9fde03f
2023-02-06 12:13:26 +08:00
Chalard Jean
c030aebe86 Remove expectCapabilitiesThat
expect() does the job better.

Test: FrameworksNetTests
Bug: 157405399
Change-Id: Ibb8fa432318cd2c37b23947a33c0e806111d099f
2023-02-03 23:40:25 +09:00
Remi NGUYEN VAN
e32490944b Merge "Allow Advertiser, DiscoveryManager runtime toggle" 2023-02-02 02:53:47 +00:00
Motomu Utsumi
56c412a9c8 Add getUidRule method to BpfNetMaps
Upcoming CLs use this method to add chain status to failure log of
ConnectivityManagerTest#testFirewallBlocking which is a flaky test

Test: atest BpfNetMapsTest
Bug: 262141231
Change-Id: Ib130a28c708f675c79b889bf293dfe6b0f8d7f60
2023-02-01 17:05:36 +09:00
Paul Hu
b2c0f3407f Rename onResolveStopped to onResolutionStopped
Rename the method onResolveStopped(NsdServiceInfo) to
onResolutionStopped(NsdServiceInfo) for consistency as API
review feedback.

Bug: 266811051
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I788b5903ecaf78a9aa960dd3b7413a22f171c72f
2023-01-30 08:53:15 +00:00
Motomu Utsumi
9a9c11e33e Remove getVpnLockdownUidRanges test api
getVpnLockdownUidRanges acquire lock and access internal state of a
Handler-based class (PermissionMonitor), which is bad practice in
general.

getVpnLockdownUidRanges returns keySet of mVpnLockdownUidRanges.
PermissionMonitor call updateUidLockdownRule and update the bpf map
based on mVpnLockdownUidRanges.
PermissionMonitorTest verifies the args of updateUidLockdownRule call.

So, It's not necessary to verify the mVpnLockdownUidRanges which
is internal states of PermissionMonitor.

Test: atest PermissionMonitorTest
Bug: 262199762
Change-Id: I85b39ab2aff44dcbe809b39560d6bb87fbb0c084
2023-01-30 17:41:39 +09:00
Motomu Utsumi
ff12d34445 Remove getVpnInterfaceUidRanges test api
getVpnInterfaceUidRanges acquire lock and access internal state of a
Handler-based class (PermissionMonitor), which is bad practice in
general.

getVpnInterfaceUidRanges returns mVpnInterfaceUidRanges.
PermissionMonitor call add/removeUidInterfaceRules and update the bpf
map based on mVpnInterfaceUidRanges.
PermissionMonitorTest/ConnectivityServiceTest verifies the args of
add/removeUidInterfaceRules call.

So, It's not necessary to verify the mVpnInterfaceUidRanges which
is internal states of PermissionMonitor.

Test: atest ConnectivityServiceTest PermissionMonitorTest
Bug: 262199762
Change-Id: I31cbb9b1dd43eaf0354799a81c9df292fb5f6445
2023-01-30 17:41:34 +09:00
Remi NGUYEN VAN
a8a777bbbd Allow Advertiser, DiscoveryManager runtime toggle
Allow toggling MdnsAdvertiser and MdnsDiscoveryManager at runtime, by
always creating them in NsdService constructor, but only using them when
the flag is on when starting discovery, resolve or registration.

When stopping, based on the type of the stored request, stop the
corresponding backend.

Bug: 265891278
Test: atest NsdServiceTest
Change-Id: I7cb2f9fe9e1ed3dc77616689a8e3ffa00f5bc269
2023-01-27 19:37:04 +09:00
Sudheer Shanka
74fe7178af Add defer-until-active policy to CONNECTIVITY_ACTION.
This allows deferring the broadcast delivery to apps in
the Cached state.

Bug: 255545931
Test: TH
Change-Id: Idd94ad5f9dbabf88f6070108bdfc8e60f34304a6
2023-01-24 19:33:06 +00:00
Remi NGUYEN VAN
5fc52a4b2f Merge "Do not return found services on dummy0" 2023-01-24 04:10:58 +00:00
Remi NGUYEN VAN
643edb6715 Do not return found services on dummy0
When registering and advertising a service on the same device, it is
possible for NsdService to find the service on the dummy0 interface. It
is however unusable and not resolveable.

Skip callbacks on the dummy0 interface as they would confuse apps and
tests.

Bug: 266176036
Test: atest NsdServiceTest
Change-Id: I98cca0135e0f6936187d45707cbdad7a7f263ff1
2023-01-23 19:14:57 +09:00
Chalard Jean
e0abd52557 Fix a bug where adding a user doesn't update network allow lists
Even if there are no preferences, the allow list needs
to be updated upon adding a new user, because it's set
unconditionally when the network connects.

Adding all existing UIDs would address this issue too
and we probably want to do it, but immediately this
seems simpler.

Bug: 266136779
Test: new test for this
Change-Id: I77091a6c3d3ccf2b80ab0aaa01d09ef0df922501
2023-01-23 17:40:01 +09:00
Treehugger Robot
c795473a80 Merge "[DK2-2]Add flag to control dynamic keepalive mode" 2023-01-20 11:59:26 +00:00
chiachangwang
a38b723fb9 [DK2-2]Add flag to control dynamic keepalive mode
Add a flag to control dynamic keepalive mode so that this
feature could be dynamically enabled via flag push. Default
is enabled in KeepaliveTracker.

Bug: 259000745
Test: atest FrameworksNetTests
Change-Id: I438de9aefd22229669a9ae4da5fd109fdfa73b10
2023-01-20 17:47:11 +09:00
Remi NGUYEN VAN
3c42e517ac Merge "Implement conflict detection" 2023-01-20 06:00:54 +00:00
Remi NGUYEN VAN
c8db64bdb1 Implement conflict detection
On each received packet, query MdnsRecordRepository to detect any
conflicting service, and report it though onServiceConflict.

Implement restartProbingForConflict and renameServiceForConflict which
may be called when that callback is dispatched.

Bug: 266151066
Test: atest MndsInterfaceAdvertiserTest MdnsRecordRepositoryTest
Change-Id: I5434b00879e0c8f7fc1e4769455b688c3bd7a9b5
2023-01-20 12:53:32 +09:00
Remi NGUYEN VAN
93587f609b Merge "New API to listen service update" 2023-01-19 15:25:23 +00:00
Paul Hu
18aecccc9d New API to listen service update
Currently, the resolution is a one shot query, it only notifies
the first finding service information. There is no way to listen
the service update. Thus, add a new API that can register a
callback to listen to the service updates continuously.

Bug: 245369943
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I0e9d92b9028375feb3e344ab6c4acb515c5b2be9
2023-01-19 20:16:03 +09:00
chiachangwang
3d60bacfa0 [DK2-0]Create AutomaticOnOffKeepaliveTracker
Add a new AutomaticOnOffKeepaliveTracker class between
ConnectivityService and KeepaliveTracker to handle the automatic
on/off keepalive. This commit only creates this new class and
move the TCP polling code to the new class as a preparation for
the following commit.

The original test file was created for testing the TCP polling
mechanism, so rename it to match the new class.

Bug: 259000745
Test: m ; atest FrameworksNetTests
Change-Id: I1b229f906283c0f5ef7a3efdb0572fcbfc5df72b
2023-01-19 13:17:54 +09:00