Commit Graph

1673 Commits

Author SHA1 Message Date
Hansen Kurli
c48d856976 Register OnSubscriptionsChangedListener and cache results.
Register a listener to get notified of SubscriptionInfo changes and
store all carrierIds of active subscriptions in a cache. The executor
for the listener callback runs on a different thread to the connectivity
thread but posts the SubscriptionInfo list to the connectivity thread
for caching.

Bug: 273451360
Test: atest FrameworksNetTests
Change-Id: I889d4da725ccda713367309c257622a0bf9939f3
2023-06-12 05:42:46 +00:00
Hansen Kurli
ad03b887e6 Track and build KeepaliveLifetimePerCarrier.
Create a nested class KeepaliveStats to store and track the carrier info
and lifetime metrics for each keepalive where a keepalive is identified
by its network and slot number. Then aggregate the metrics using
(carrierId, transportTypes, intervalMs) as the key before writing the
metrics into the KeepaliveLifetimePerCarrier proto. Also aggregates the
metrics whenever a keepalive is stopped to free up the (network, slot).

Bug: 273451360
Test: atest FrameworksNetTests
Change-Id: I113ec68053710a7f41f64a9d6fa4dd83bd924225
2023-06-12 05:41:19 +00:00
Hansen Kurli
7e343d58ce Merge "Ensure public methods are running on handler thread" 2023-06-09 04:54:58 +00:00
Chiachang Wang
646715e787 Merge "Stop TCP keepalive from CS for fd initiated stop events" 2023-06-09 01:05:46 +00:00
chiachangwang
739f0960f3 Stop TCP keepalive from CS for fd initiated stop events
When a TCP keepalive start request is sent from ConnectivityService
to KeepaliveTracker, the keepalive is tracked on both
AutomaticOnOffKeepaliveTracker and KeepaliveTracker. The existing
design stops the keepalive inside KeepaliveTracker without
notifying AutomaticOnOffKeepaliveTracker for fd initiated stops.
This causes AutomaticOnOffKeepaliveTracker to lose track of these
fd initiated stops and cause a leak on the object.

The updated design sends the event to ConnectivityService handler
to handle the event down from ConnectivityService. This ensures
that each stakeholder class will get the stop event.

Bug: 283885097
Test: atest FrameworksNetTests
Test: atest CtsNetTestCases
Change-Id: I3c40d80694cd2c046f3a19ddb8f437878c98ab43
2023-06-08 15:31:42 +00:00
Yuyang Huang
01b988255f Merge "Enable useSessionIdToScheduleMdnsTask" 2023-06-08 10:41:58 +00:00
Yuyang Huang
e0f07a9dc1 Merge "Fix cache flush always causing response change" 2023-06-08 09:17:59 +00:00
Yuyang Huang
c505844d8a Enable useSessionIdToScheduleMdnsTask
In case that the task is not canceled successfully, use session ID to
check if this task should continue to schedule more.

Bug: 285260665
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Ic953ae781449a7ebf943999c8c8d3040a97641d9
2023-06-08 17:38:52 +09:00
Remi NGUYEN VAN
98a44bcb29 Fix cache flush always causing response change
When the cache flush bit is set on host address records in a response,
known records are cleared and replaced with the contents of the packet.
However even if the response contains the same records as before, this
caused it to be marked as modified, and response modified callbacks are
sent for every incoming packet.

Instead, ensure that the response is only marked as modified if a
previously unknown address record is added, or if a previously known
address record is removed.

The issue wasn't found by the existing testDecodeWithNoChange test,
because it used a service record for testhost2 instead of testhost1, so
the address records were ignored.

Bug: 285997766
Bug: 285084489
Test: atest CtsNetTest FrameworksNetTests

Change-Id: Ic0f19adf5d9bde7cdab766e49cf677b319a2219b
2023-06-08 16:30:31 +09:00
Paul Hu
bad235f4f9 Merge "Adjust the notifyNetworkUnrequested on handleRegisterListener" 2023-06-08 06:34:25 +00:00
Paul Hu
c54aa729c9 Adjust the notifyNetworkUnrequested on handleRegisterListener
If the MdnsServiceTypeClient was removed when the
SocketCreationCallback#onAllSocketsDestroyed() was called, the
MdnsSocketClientBase#notifyNetworkUnrequested() will not be
called when a listener is unregistered from the
MdnsDiscoveryManager. This is because the serviceTypeClients will
be cleared after the socket is destroyed. However, these dead
listeners will be re-added to the MdnsServiceTypeClient when a
new socket is created. They will then continue to send callbacks
to the NsdService. Therefore, the notifyNetworkUnrequested()
should be moved to the beginning of the handleRegisterListener()
to ensure that the socket unregistration is properly notified.

Bug: 285997766
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: I31c766305018889f50a7c12c836174c340d01d7f
2023-06-08 10:29:07 +08:00
Jean Chalard
f2b38772ac Merge "Fix a bug where the PAC proxy port is not set correctly." 2023-06-06 12:22:21 +00:00
Treehugger Robot
1667bfea04 Merge "Update record receipt time on records updated" 2023-06-06 08:34:39 +00:00
Yuyang Huang
86f674187f Update record receipt time on records updated
The receipt time in the MdnsResponse need to be updated every time new
packet is received. And then the record refreshing logic could calculate
remaining TTL correctly.

Bug: 285260665
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Ib7a290ea0ea8e552c71c657696397e8114fcee52
2023-06-06 12:55:27 +09:00
Remi NGUYEN VAN
a8efbe0e32 Take the multicast lock on mDNS usage
When an mDNS request (discovery, advertising, resolving...) is
registered and gets assigned a socket on a wifi network, take the
multicast lock to ensure that it can reliably receive mDNS responses.

This is limited to when the application has importance
FOREGROUND_SERVICE or higher.
NsdManager is not documented to require usage of the multicast lock,
which has caused various reports about its reliability. Taking the lock
while the app is in the foreground should address the large majority of
cases, while limiting battery impact.

Going forward this should allow developers on U+ to not take the
lock themselves, allowing optimizations on devices supporting APF,
where instead of taking the lock APF would let through only select
mDNS packets.

Bug: 284389438
Test: atest
Change-Id: I1ce85220eac4a1529b6716d50727c1c462356846
2023-06-06 11:13:34 +09:00
Aaron Huang
9fe47bee09 Fix a bug where the PAC proxy port is not set correctly.
Test: new test for this behavior in the preliminary change
Test: FrameworksNetTests NetworkStackTests
Fixes: 138810051
Fixes: 140610528
Change-Id: I95a979d232fb60ece2e33e972bf5d66d20357a1f
2023-06-05 20:24:59 +09:00
Treehugger Robot
c133f6e29c Merge "On U+ require config_networkWakeupPacketMark/Mask to be 0x80000000" 2023-06-05 09:34:47 +00:00
Maciej Żenczykowski
cf41fc877a On U+ require config_networkWakeupPacketMark/Mask to be 0x80000000
See system/netd/include/Fwmark.h which reserves the bottom 21 bits
of skb->mark for netid, etc... so out of necessity these have to be
in the top 11 bits.

In practice the only values that really make sense are either:
  mark == mask == 0 (disabled)
or (mark == mask) being one of the top 11 available bits, for example:
  mark == mask == 0x80000000 (enabled, using top-most bit)
(only a single bit makes sense, as this is really just a boolean signal,
 and only the topmost is known to be used on any real devices)

Let's just force the use of 0x80000000 for ecosystem consistency.

Bug: 284334830
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I199e9b00de845b3747940426ea6644426ab72e87
2023-06-05 07:41:00 +00:00
Hansen Kurli
48e61a4520 Merge changes I8fcaa1f0,I8925fbe4,I78394645,Iadf9f060
* changes:
  FinalizePausedKeepalive in handleStopAllKeepalives.
  Add tests for pause, resume and stop keepalives.
  Ensure autoKi is not stored when keepalive stops or is not started.
  Add tests for NATT keepalives stopped internally in KeepaliveTracker.
2023-06-05 04:56:16 +00:00
Motomu Utsumi
d8b852fc06 Merge "Use netd socketDestroy for VPN in T-" 2023-06-05 03:04:19 +00:00
Motomu Utsumi
1d13726710 Use netd socketDestroy for VPN in T-
aosp/2490881 updated to use InetDiagMessage.destroyLiveTcpSocket for all
devices.
But it is possible that netd socketDestory is modified in T- devices.
So this CL revert changes to keep using netd socketDestroy in T-
devices.

Test: atest FrameworksNetTests
Bug: 284253763
Change-Id: I9b61f10e975d2e38e9829a8c01d3af706e2518ef
2023-06-04 23:12:58 +09:00
Paul Hu
83bd5a5927 Merge changes If830eb53,If03514f1
* changes:
  Update tethered/local only interfaces when no all networks request
  Use wifi p2p interfaces for mDNS
2023-06-02 13:10:51 +00:00
Paul Hu
bb69412f5b Update tethered/local only interfaces when no all networks request
If there is no request for all networks, the tethered/local only
interface changes will be ignored. However, these available
interfaces are not used for mDNS when a user requests a socket
with a null network because the interfaces are lost due to the
previous ignore. Therefore, the interface changes should be
retained and will be used for socket creations afterwards.

Bug: 284939720
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: If830eb53af26f21f497314477b131ce28468a971
2023-06-02 08:54:41 +00:00
Paul Hu
fbba5e8307 Use wifi p2p interfaces for mDNS
mDNS is used by wifi p2p in many places. However,
MdnsSocketProvider does not monitor changes to the wifi p2p
connection to get the names of the available wifi p2p interfaces.
This prevents mDNS from registering or discovering services on
the wifi p2p interfaces. Therefore, listen to the wifi p2p change
intent to know the available interfaces and status changes that
can be used by mDNS.

Bug: 284263838
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: If03514f1286c0507e5862372272234dd07eb084d
2023-06-02 08:54:41 +00:00
Yuyang Huang
c823dc2259 Merge changes from topic "refresh-record"
* changes:
  Renew the SRV/TXT records if half of TTL passed
  Turn on removeExpiredService feature
2023-06-02 08:10:52 +00:00
Yuyang Huang
f2cc01dc12 Renew the SRV/TXT records if half of TTL passed
As mentioned in RFC6762 7.1. The records only needed to be renewed if
at least half of the TTL passed. Usually A/AAAA records are included in
the response to the SRV record query, they are not refreshed individually.

Bug: 285261577
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Ifd7140de0d733191256184c5481412e1822d279b
2023-06-02 15:36:09 +09:00
Yuyang Huang
ff96322c4f Turn on removeExpiredService feature
Turn on removeExpiredService feature by: 1) Remove the unnecessary
allowSearchOptionsToRemoveExpiredService flag. 2) Turn on the
removeExpiredService flag in the MdnsSearchOptions.

Bug: 285260665
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Ib115b40e70b0f81a7877deb73af7d61e2e0c385f
2023-06-02 12:33:55 +09:00
Hansen Kurli
1b71e38673 Ensure public methods are running on handler thread
Store the handler that should be running all the public methods and
use it by comparing its thread with the current thread.

Also refactor the tests to use and run on a test handler thread.

Bug: 273451360
Test: atest FrameworksNetTests
Change-Id: I053f1043a3b518728c4b30b94eec1d33fbfe39c0
2023-06-01 06:58:18 +00:00
Hansen Kurli
9656e23d91 FinalizePausedKeepalive in handleStopAllKeepalives.
In the case that a keepalive is paused and handleStopAllKeepalives is
called, there is no KeepaliveInfo for the paused keepalive and so no
onError callback will be called. The autoKi will also be cleaned up so
no callback will ever called that notifies the keepalive is stopped.

Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: I8fcaa1f07746235326c7ae05d97e20fd27927fea
2023-06-01 06:45:07 +00:00
Hansen Kurli
01d0ef1636 Add tests for pause, resume and stop keepalives.
The tests added verify the following:
1. Stopping the keepalive will cleanup the autoKi.
2. Pausing the keepalive does not cleanup the autoKi and stopping
   a paused keepalive will still call the onStopped callback.
3. A starting error by resuming the keepalive will cleanup the
   autoKi.
4. handleStopAllKeepalives also does the appropriate callback for paused
   keepalives.
5. Stopping a resumed keepalive stops the correct slot when a second
   keepalive is started while the first is paused.

Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: I8925fbe40323dc4584a111d0cf31de016525ef41
2023-06-01 06:44:52 +00:00
Hansen Kurli
0d179a3ff0 Ensure autoKi is not stored when keepalive stops or is not started.
In the cases below, the keepalive is already cleaned up internally in
KeepaliveTracker, but are not be cleaned up in
AutomaticOnOffKeepaliveTracker. This means the mAutomaticOnOffKeepalives
list is storing stopped keepalives and the metrics will still conisder
the keepalive as active.

1. In KeepaliveInfo.start, return whether the keepalive is successfully
   starting(i.e. mStartedState == STARTING). Check for this in
   handleStartKeepalive and return early on failure, without storing the
   autoKi. Also check in handleResumeKeepalive.
2. In handleEventSocketKeepalive, return whether the handleStopKeepalive
   is called, indicating the keepalive is forced to stop and was not
   already STOPPING. This should happen when the state is STARTING but
   the network agent returned an unsuccessful event.
3. In handleCheckKeepalivesStillValid, move the checking logic to
   AutomaticOnOffKeepaliveTracker so the handleStopKeepalive is called.

Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: I7839464534baed43abbd40b321287132da25b978
2023-06-01 06:02:16 +00:00
Jean Chalard
5e76b40973 Merge "Add tests for PAC proxies." 2023-06-01 05:20:37 +00:00
Yuyang Huang
d72daab448 Matches all MdnsServiceTypeClient if using MdnsSocketClient
MdnsSocketClient doesn't support requesting specific network. As a
result, when processing the response, all the MdnsServiceTypeClient
should be called.

Bug: 285064577
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: Id95f1e78d60063ccee7f5855a21fa6b5a48fbd3e
2023-05-31 15:39:08 +09:00
Hansen Kurli
76adfacd84 Add tests for NATT keepalives stopped internally in KeepaliveTracker.
Add tests where NATT keepalives are stopped and cleaned up within
KeepaliveTracker in these scenarios:
1. startNattKeepalive is called with an invalid interval.
2. The state is STARTING and the network agent returns an error event.
3. The keepalive started successfully but becomes invalid and
   handleCheckKeepalivesStillValid is called on the network.

Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: Iadf9f06030cae20f36d950f520c8dcc4181924ad
2023-05-30 11:27:11 +00:00
Treehugger Robot
ae9b229b7e Merge "Add MdnsDiscoveryManager constructor without looper" 2023-05-30 10:24:27 +00:00
Yuyang Huang
243d1a5de4 Add MdnsDiscoveryManager constructor without looper
In some use cases for the MdnsDiscoveryManager, providing looper as an
argument to the MdnsDiscoveryManager constructor is not feasible. Adding
a constructor without looper can help to match those use cases. If
constructor without looper is used. The shutDown() must be called as a
part of cleanup process.

Bug: 283914408
Test: atest FrameworksNetTests
Change-Id: I0ab04d67bae127628c6d67c4b8c109201612a54b
2023-05-30 17:14:54 +09:00
Aaron Huang
40b524448c Add tests for PAC proxies.
Test: this is a change that adds a test
Bug: 138810051
Bug: 140610528
Change-Id: I6e7b77320f6baf32ac2f98634fa2e3231d1bf12f
2023-05-30 15:53:11 +09:00
Jean Chalard
5cc9676d4c Merge "Instrument SDK level and change IDs to help testing" 2023-05-30 02:10:05 +00:00
Chalard Jean
df29a85ee7 Instrument SDK level and change IDs to help testing
This patch mocks the SDK level and/or change IDs to help
developing functionality that depends on these without
having to flash a new device every time.

Test: TH
Change-Id: I1011193c99e123a0e5501ed313c9cecbceebdae6
2023-05-29 18:42:31 +09:00
Remi NGUYEN VAN
f4cf2707e7 Merge "Do not process null network packets on all clients" 2023-05-29 03:56:26 +00:00
Remi NGUYEN VAN
5a1c614e42 Merge "Only send to downstream ifaces for null network" 2023-05-29 03:56:20 +00:00
Remi NGUYEN VAN
401ab44c36 Merge "Use the ServiceTypeClient network for queries" 2023-05-29 03:56:12 +00:00
Remi NGUYEN VAN
0ba206cbd1 Do not process null network packets on all clients
Packets received from the "null" networks are packets received from
tethering downstream interfaces. They should not be processed by all
MdnsServiceTypeClients; instead they should be processed by
the MdnsServiceTypeClient for the null network.

Bug: 283708537
Test: atest
Change-Id: Ifef59eca7a24bdfe3650067445d2565869dfa852
2023-05-24 16:37:13 +09:00
Remi NGUYEN VAN
87c374a37a Only send to downstream ifaces for null network
When sendMulticastPacket or sendUnicastPacket is called with the null
network, only send the packets to interfaces indexed with null, instead
of all interfaces.

When using MdnsMultinetworkSocketClient sending packets on the null
network means sending on tethered downstream interfaces. When
MdnsSocketClient is used (not used in the Android tree), sending on the
null network sends on all interfaces as MdnsSocketClient does not
support specific networks. This is clarified by explicitly throwing
when a non-null Network is attempted to be used with MdnsSocketClient
(but MdnsSocketClient is only used for tests in the Android tree).

Bug: 283708537
Test: atest
Change-Id: Ia0186bf8aa2e0fc5878d6071fd23599df8488616
2023-05-24 14:30:14 +09:00
Chiachang Wang
3fabc1b0e0 Merge "Cleanup VpnTest for unused methods/annotations" 2023-05-24 01:41:01 +00:00
Chiachang Wang
b1f3dd9dd1 Merge "Test for not logging meaningless caps changes" 2023-05-24 01:40:34 +00:00
Chalard Jean
74732ba43d Cleanup VpnTest for unused methods/annotations
• Remove unused private methods
• Build files have this test in FrameworksNetTests, which
  by TEST_MAPPING is not run on T and below. It is not in
  the targets that do run on T and below like
  ConnectivityCoverageTest.

Test: VpnTest
Change-Id: I198e5b3571e34e41611f71d351501d3f98f78caa
2023-05-23 18:30:05 +09:00
Chalard Jean
16e41d130c Test for not logging meaningless caps changes
Test: this
Change-Id: Ife6500daae58b7f85a7f4c76cd89ce91def5e78c
2023-05-23 18:30:04 +09:00
Treehugger Robot
7be7f06fc4 Merge "Use "don't actively prefer" timeout when avoiding bad wifi" 2023-05-23 06:47:18 +00:00
Chalard Jean
6f6c353baf Use "don't actively prefer" timeout when avoiding bad wifi
Test: ConnectivityServiceTest
Change-Id: I6e99aff77c55805630d878e472f466bd31bba360
2023-05-23 13:47:15 +09:00