Commit Graph

766 Commits

Author SHA1 Message Date
Paul Hu
37c6b51e4e Add a handler thread check to all public methods am: d5b24b4855
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2593665

Change-Id: I4c5da9d97fc55954c65f06bb59c5d659c7a62a01
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-05 11:15:01 +00:00
Paul Hu
bd5359529d Use SocketKey in MdnsServiceCache am: 775840e1b4
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2648319

Change-Id: Ie72151c0d878eab35c76b4d52b32f2c0653971a5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-05 10:12:12 +00:00
Paul Hu
d5b24b4855 Add a handler thread check to all public methods
To ensure that all access to the MdnsServiceTypeClient is done on
the handler thread, a handler thread check must be added to all
public methods in the MdnsServiceTypeClient. This will allow the
synchronized lock to be removed in future changes, and it will
also ensure that MdnsServiceTypeClient can access MdsServiceCache
properly.

Bug: 265787401
Test: atest FrameworksNetTests
Change-Id: I0206874eb0acdf0272b8ad23d29f3e764bfdec38
2023-07-05 07:46:36 +00:00
Treehugger Robot
682ff9559b Merge "Adjust query frequency based on remaining TTL" am: e59d30bc2a
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2632294

Change-Id: I1f245f7d21172d7492c2d942ff30b0c809cda3ef
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-05 07:02:55 +00:00
Paul Hu
775840e1b4 Use SocketKey in MdnsServiceCache
The MdnsServiceTypeClient is now created using a SocketKey, so
the MdnsServiceCache should also use the SocketKey to deal with
the caching services.

Bug: 265787401
Test: atest FrameworksNetTests
Change-Id: I6165ffd420a39e750c06778b4851142a3ba3cf44
2023-07-05 06:38:41 +00:00
Yuyang Huang
f56c92f3ff Adjust query frequency based on remaining TTL
After numOfQueriesBeforeBackoff query, the mDNS discovery logic will
enter backoff mode. In backoff mode,  the query frequency will be
updated to max(20, 0.8 * shortest remaining TTL) seconds. It will help
to reduce mDNS query frequency in certain use cases.

Bug: 284480315
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Iac8baaaf58cf9b3b8e67e1cd80402fdecde1d3d4
2023-07-05 13:01:19 +09:00
Paul Hu
8f84940454 Merge "Rename some variables in NsdService" am: 2388643f92
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2627851

Change-Id: I5edc2dbb68e198fe2ff6e8c2413a8a04d451bc63
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-04 02:00:01 +00:00
Paul Hu
d44e1b721d Rename some variables in NsdService
- This is a no-op change change that only unify the naming of
  transaction IDs. Because there are currently different naming
  conventions for transaction IDs, which can cause confusion and
  lead to errors.
- Also renaming the "client ID" to "client request ID" because
  this more accurately reflects how the ID is used.

Bug: 287546772
Test: m
Change-Id: I4fb7255f23754aa720a83a5df282700c59140207
2023-06-28 17:49:25 +08:00
Paul Hu
628b644e72 Merge "Address leftover comments" am: 0068ec2765
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2629431

Change-Id: Ia3713ac1097ab933e797edf11a1a91820fcaddef
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-27 11:34:54 +00:00
Paul Hu
0068ec2765 Merge "Address leftover comments" 2023-06-27 10:57:54 +00:00
Paul Hu
5b855bcbab Merge "Send packets on the specific socket" am: 03aabc0d78
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2606783

Change-Id: I4c0b0388e4e869fd67b1f941bd388421e612dcde
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-27 05:47:18 +00:00
Paul Hu
03aabc0d78 Merge "Send packets on the specific socket" 2023-06-27 05:40:38 +00:00
Paul Hu
9be28bda10 Merge "Add more logs for debugging" am: f5843be9d4
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2618621

Change-Id: Ic8796caa93e3f46bbae7a7e90d5dc0ea344defc9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-27 01:26:27 +00:00
Paul Hu
f5843be9d4 Merge "Add more logs for debugging" 2023-06-27 00:55:43 +00:00
Paul Hu
070007164c Address leftover comments
Address leftover comments on aosp/2596565 & aosp/2593907 includes
- Rename onAllSocketsDestroyed to onSocketDestroyed
- Move SocketKey into SocketInfo
- Remove getInterfaceIndex dependency.

Bug: 278018903
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: Ia37804f18d8e9abbd12d4b929b71dce5fa19d4f0
2023-06-26 14:19:05 +00:00
Paul Hu
721f9b28bf Send packets on the specific socket
In the previous design, the network could be null for some
MdnsServiceTypeClient (tethering interfaces). However, the
MdnsMultinetworkSocketClient is designed to send packets on
specific networks. This means that if there are multiple
tethering interfaces, packets will be sent to unnecessary
sockets. Now, the MdnsServiceTypeClient is created by the socket,
which can identify which socket is the target for sending
packets. Therefore, the design should be updated to send packets
only on the specific socket.

Bug: 278018903
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: Id87e6d202599c57620281a6761d3c56acd2c929c
2023-06-26 13:27:47 +00:00
Ryan Zuklie
49a7757cb5 Fix deadlock while stopping network trace poller am: f5326be5dd
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2636969

Change-Id: I9fb05b86604612489bc046d15ed8d58b5662e295
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-23 22:26:24 +00:00
Ryan Zuklie
f5326be5dd Fix deadlock while stopping network trace poller
Calling reset on mTaskRunner waits for any in progress tasks to finish.
Since Stop takes mMutex, it's possible that in-progress task is waiting
for mMutex in order to finish, resulting in a deadlock.

This breaks the loop by using try_lock to remove the blocking dependency
on the mutex. Since we _always_ want to re-schedule ourselves, the poll
duration and runner are taken as arguments (if rescheduling is also in
the try_lock, any class interactions could stop the polling sequence).

Test: local start/stop stress test and atest libnetworkstats_test
Bug: 285411033
Change-Id: I4b8bea9c5474a37e8c081bcfe542d4fe57f5206c
2023-06-22 23:43:30 -07:00
Treehugger Robot
afffdd6f9a Merge "Adds option to control whethert to send IPv6 packet on IPv6 only network" am: 454c06e956
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2613049

Change-Id: I9ee6271e8e3e07f87da83e55d144b11f90f62c03
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-17 10:16:27 +00:00
Treehugger Robot
454c06e956 Merge "Adds option to control whethert to send IPv6 packet on IPv6 only network" 2023-06-17 09:34:57 +00:00
Yuyang Huang
9637e84eed Adds option to control whethert to send IPv6 packet on IPv6 only network
Add options to control whether only send IPv6 packet on IPv6 only
network. In some use case, IPv6 query should not be sent on a dual
network.

Added a small improvement to send an ANY query if both SRV & PTR
records are needed.

Bug: 284480254
Test: atest CtsNetTest FrameworksNetTests
Change-Id: I8f55db6f5e8ae606ac167fb363bc9b2fb9b5fc14
2023-06-17 16:27:43 +09:00
Treehugger Robot
a00f68c287 Merge "ethernet: delete superfluous helper function" am: a6f0bf9c93
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2626729

Change-Id: I9121f24f39b9e560d666bd3afd9fb112f0f4feb5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-15 09:52:36 +00:00
Treehugger Robot
a6f0bf9c93 Merge "ethernet: delete superfluous helper function" 2023-06-15 08:34:18 +00:00
Paul Hu
4d388384ae Merge "Create an MdnsServiceTypeClient using a SocketKey" am: 7c60aaa851
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2593907

Change-Id: Ia53e16fd27640bace3974744a656806201699c21
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-15 01:40:18 +00:00
Paul Hu
745ff5dbda Merge "Notify socket changes using a SoketKey" am: a8d1cabcd7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2596565

Change-Id: I955cf21e53a039b04a9fb09fce1997af638c1c7d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-15 01:40:04 +00:00
Paul Hu
7c60aaa851 Merge "Create an MdnsServiceTypeClient using a SocketKey" 2023-06-15 01:01:46 +00:00
Paul Hu
a8d1cabcd7 Merge "Notify socket changes using a SoketKey" 2023-06-15 01:01:24 +00:00
Patrick Rohr
be65f24705 ethernet: delete superfluous helper function
isCurrentCallback() is a trivial one liner that is more readable
inlined.
This change also renames handleIpEvent() to safelyPostOnHandler() to be
more descriptive.

Test: TH
Change-Id: I9224c9555f0b2ed22ff1cec5ae1c6e870c16820b
2023-06-14 19:20:03 +00:00
Treehugger Robot
62ba05ff71 Merge "Improve logging and shutdown executor properly" am: a87b6027fb
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2624811

Change-Id: I14fc51a2a8cc9642a2f354a78d71163f14aa86c1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-14 13:41:27 +00:00
Yuyang Huang
76b66b672d Merge "Revert "Importing the following changes from gmscore"" am: 018758595d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2624810

Change-Id: I36394b97604330b937dec290ab2146750f308812
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-14 06:25:15 +00:00
Yuyang Huang
521f162149 Merge "Importing the following changes from gmscore" am: 049263eb74
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2620913

Change-Id: I191833a960bfda70db87a0200dee43d93a0d7e2b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-14 06:24:59 +00:00
Yuyang Huang
0e1977e01f Improve logging and shutdown executor properly
* Added logging to track mDNS service type client registrations and
  response handling.
* Only shutdown the executor when it is not shutdown.

Bug: 285508143
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Ic6fc0e1e6aef92bf3ee1a7990c4904a06e6db34a
2023-06-14 14:55:04 +09:00
Yuyang Huang
f50cbffe8f Revert "Importing the following changes from gmscore"
This reverts commit bff1cf7132.

Reason for revert: Accidentially submitted

Change-Id: I8ebca56e908a9d790f1251b15ce7e3628bc2038c
2023-06-14 05:34:10 +00:00
Paul Hu
62b6439f96 Create an MdnsServiceTypeClient using a SocketKey
Now, MdnsServiceTypeClient is created using a network. However,
all tether interfaces use the same network (null), which
means they use the same client for the same service type. This is
not the intended behavior, as each interface should have its own
client. Therefore, MdnsServiceTypeClient creation should be
changed to use SocketKey, which includes both the network and
interface index. This will allow each interface to have its own
client.

Bug: 278018903
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: I34b7d983f00b67198befb5bf71fc511cf0dabae6
2023-06-14 10:36:50 +08:00
Paul Hu
2f236e9ca4 Notify socket changes using a SoketKey
Currently, all socket changes are identified using a Network
object. However, the Network object is null for all tethering
interface sockets, which means that the socket cannot be
identified in some places. Therefore, the Network object should
be replaced with a SocketKey object, which includes both the
network and interface index.

Bug: 278018903
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: Ib49981a4071ecab18c7cf3a8827d1459529492a9
2023-06-13 18:41:28 +08:00
Yuyang Huang
bff1cf7132 Importing the following changes from gmscore
* Only shutdown the executor when it is not shutdown
* Added logging to trace mDNS service type client registrations and
  response handling.

Bug: 285508143
Test: atest CtsNetTest FrameworksNetTests
Change-Id: I9350941e63b0c6917f69aa588aaa0f234f93aa08
2023-06-12 14:50:06 +09:00
Yuyang Huang
7db258d02f Merge "Enable useSessionIdToScheduleMdnsTask" am: 01b988255f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2619296

Change-Id: I71ead9ae123744c6d31028d5c2421421a4d8861b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-08 11:19:58 +00:00
Yuyang Huang
01b988255f Merge "Enable useSessionIdToScheduleMdnsTask" 2023-06-08 10:41:58 +00:00
Yuyang Huang
7032ddb87c Merge "Fix cache flush always causing response change" am: e0f07a9dc1
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2619297

Change-Id: I5d259e1ba1d3c066d1081a6ff173cb467a8c946e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-08 09:57:16 +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
54ef1040e5 Merge "Adjust the notifyNetworkUnrequested on handleRegisterListener" am: bad235f4f9
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2618620

Change-Id: I6f7b4cbf17bbc1bc8f5e2dcc79f3985d0f5764af
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-08 07:22:27 +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
Paul Hu
83ec7f4cae Add more logs for debugging
There is no log to show whether the callbacks have been sent to
user. So add some logs on NsdService to at least know whether
the callback was sent to NsdService.

Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: I1940d501ac3f9f56ce440366d0b5214a97d6f6f7
2023-06-07 18:04:09 +08:00
Treehugger Robot
30218cb80c Merge "Update record receipt time on records updated" am: 1667bfea04
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2614892

Change-Id: I9efac571b1dd086912942f9af2c2b476e6914cd9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-06 08:46:16 +00:00
Remi NGUYEN VAN
1b5c5f72f9 Merge "Take the multicast lock on mDNS usage" am: 5f921c4292
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2606585

Change-Id: Iecc8f43613314301a81d883d91351a1223893469
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-06 08:46:02 +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