Commit graph android_packages_modules_Co.../tests/unit/java/com/android/server
Message SHA1
Use a delayed message to schedule the query task
To reduce the multi-thread access to MdnsServiceTypeClient, the
query task scheduling should be replaced with a delayed message.
This will allow the synchronized lock to be removed in future
changes.

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

Paul Hu   commited 2023-07-10 05:45:37 +00:00
cd39d81fe1
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

Paul Hu   commited 2023-07-05 07:46:36 +00:00
d5b24b4855
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

Paul Hu   commited 2023-07-05 06:38:41 +00:00
775840e1b4
Merge "Adjust query frequency based on remaining TTL"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-07-05 06:19:38 +00:00
e59d30bc2a
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

Yuyang Huang   commited 2023-07-05 13:01:19 +09:00
f56c92f3ff
Update tests to reflect the time unit change in Vpn
Test: atest FrameworksNetTests
Change-Id: I84a3f75bb527136bd0319f5af1bc43d2575495dd

chiachangwang   authored and   Chiachang Wang   commited 2023-07-04 08:27:44 +00:00
d34aac4123
Update tests for VPN data stall recovery
Data stall recovery in VPN does not rely on the data stall
event now. Update the tests accordingly.

Bug: 289746779
Test: atest FrameworksNetTests
Change-Id: I4d2d96fe2f76706512325b6653b3e7cced10f207

chiachangwang   authored and   Chiachang Wang   commited 2023-07-04 05:49:49 +00:00
42ba18ca1e
Skip writing the metrics before T.
Repeated fields are only supported on T+ and the metrics in
KeepaliveStatsTracker contains repeated fields. Hence, guard the write
with a T+ check.

Bug: 289344384
Test: Manual test
Change-Id: If3be75292b5a79aa753bddb772fe2c52c9dde994

Hansen Kurli   commited 2023-07-03 10:43:28 +00:00
ab85de69b1
Merge "Translate v4 keepalive packet on clat started network to v6"
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-07-03 09:14:09 +00:00
7e1076e174
Translate v4 keepalive packet on clat started network to v6
This commit translates the address of keepalive packet to v6
in order to make NATT keepalive work on v6 only network.

Sending a v4 NATT keepalive on a v6 only network is bogus if
hardware does not translate the packet automatically. Network
may drop the packet or reject the attempt by hardware. This
results in ERROR_INVALID_IP_ADDRESS and stop the keepalive
request.

Bug: 196453719
Test: atest FrameworksNetTests
Test: Manually connect to v6 only network and check if the
      keepalive packets are sent
Change-Id: I798c5d48661d8151b19902435732f465b5aa725b

chiachangwang   commited 2023-06-29 12:43:59 +00:00
c5c5c84f4c
Merge "Revert "Always disconnect agents immediately.""
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-06-27 12:06:45 +00:00
fd7fa4ede9
Merge "Address leftover comments"
Paul Hu   authored and   Gerrit Code Review   commited 2023-06-27 10:57:54 +00:00
0068ec2765
Revert "Always disconnect agents immediately."
This reverts commit 4bc9fa6b8c.

Reason for revert: b/288450518

Some iterations over mNetworkAgentInfos result in networks being
disconnected, which removes them from mNetworkAgentInfos during
iteration. This crashes with NPE or OOB exceptions.

Bug: 286649301
Bug: 288149251
Bug: 288450518
Change-Id: I6e0b5b614d9e88267db77cb807ae4bf09f88c0f6

Jean Chalard   authored and   Chalard Jean   commited 2023-06-27 19:19:11 +09:00
3160bc0825
Merge "Send packets on the specific socket"
Paul Hu   authored and   Gerrit Code Review   commited 2023-06-27 05:40:38 +00:00
03aabc0d78
Merge "Evaluation delay = 8 secs for explicitly selected networks"
Jean Chalard   authored and   Gerrit Code Review   commited 2023-06-27 05:15:16 +00:00
56d484c6e5
Merge "Allow firing the LOST_INTERNET intent immediately in config"
Jean Chalard   authored and   Gerrit Code Review   commited 2023-06-27 05:14:44 +00:00
1acb331613
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

Paul Hu   commited 2023-06-26 14:19:05 +00:00
070007164c
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

Paul Hu   commited 2023-06-26 13:27:47 +00:00
721f9b28bf
Allow firing the LOST_INTERNET intent immediately in config
When config_notifyNoInternetAsDialogWhenHighPriority is on, the
LOST_INTERNET notification intent should be fired immediately
rather than as a pending intent.

Bug: 281970908
Test: Improve test for this in NetworkNotificationManagerTest
Change-Id: I88565839a12a1ab4b096f763250944ebaf6c5349

Chalard Jean   commited 2023-06-22 15:03:10 +09:00
e13b833b21
Reset the generated v6 clat address when stop
The v6 address is generated from the prefix when clat is started.
The address should be reset when clat is stop.

Test: atest FrameworksNetTests
Change-Id: I943d4efba85dda556dd1ec852322caaf9470e87b

chiachangwang   commited 2023-06-21 06:43:28 +00:00
b3eccf7b8a
Evaluation delay = 8 secs for explicitly selected networks
When a network was explicitly selected, the user just tapped it and
is likely waiting for it to connect. A shorter timeout is therefore
more appropriate for these.

Bug: 281970908
Test: New test in ConnectivityServiceTest
Change-Id: I99a263960cbc9292868fc4bb46a4f3b2f3c71541

Chalard Jean   commited 2023-06-20 18:48:39 +09:00
0f1413395d
Merge "Fixes isDefaultNetworkActive and onNetworkActive unreasonable behavior"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-20 01:00:24 +00:00
e0365d45ca
Fixes isDefaultNetworkActive and onNetworkActive unreasonable behavior
This CL changes the behavior as follows.

Before this CL, isDefaultNetworkActive returns true if there is no
default network.
After this CL, isDefaultNetworkActive returns false if there is no
default network on all releases.

Before this CL, LegacyNetworkActivityTracker does not call
onNetworkActive callback for networks that tracker does not add the idle
timer to (e.g.  ethernet, cell network configured with activity tracking
disabled).
After this CL,
On T-, onNetworkActive keeps the current behavior.
On U+, onNetworkActive is called regardless of the idle timer existence. This behavior is consistent with ConnectivityManager#isDefaultNetworkActive, which always returns true for a network that has no activity tracking.

Bug: 267870186
Bug: 279380356
Test: atest FrameworksNetTests
Change-Id: I7b1d493fea0ab028b53a3d640a58a00ebbdcc143

Motomu Utsumi   commited 2023-06-20 00:59:46 +00:00
6225d57b18
Merge "Add test for default network activity APIs"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-20 00:44:01 +00:00
0d56157186
Merge "Add checks around CONTROL_VPN permission during prepare()"
Cassie Wang   authored and   Gerrit Code Review   commited 2023-06-19 11:38:23 +00:00
04f3dc871d
Merge "Have paused keepalives keep their hardware slot"
Hansen Kurli   authored and   Gerrit Code Review   commited 2023-06-19 08:30:35 +00:00
95386feff1
Add checks around CONTROL_VPN permission during prepare()
Bug: 284803285
Test: atest
FrameworksNetTests: android.net.connectivity.com.android.server.connectivity.VpnTest
Change-Id: I0a277f6b4e7cd25aff7edad9dd0e89a44dfbf3fe

Cassie Wang   commited 2023-06-19 17:26:15 +09:00
eecfb86aa9
Merge changes I9bbff5be,I270b751d,Ibf1bd267
* changes:
  Remove unused import and reorder the import
  Add debug logs for error cases
  Add KeepaliveTracker.Dependencies class for testing purpose

Chiachang Wang   authored and   Gerrit Code Review   commited 2023-06-19 01:17:59 +00:00
fbcd08a28d
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

Yuyang Huang   commited 2023-06-17 16:27:43 +09:00
9637e84eed
Add KeepaliveTracker.Dependencies class for testing purpose
This is a part of preliminary work for adding tests in the
follow up commit.

Bug: 196453719
Test: atest FrameworksNetTests
Change-Id: Ibf1bd267c4c144f533380eeafc6a6144f64da483

chiachangwang   commited 2023-06-17 03:24:09 +00:00
4f52de0bdc
Have paused keepalives keep their hardware slot
When a keepalive is paused, it should sit on its hardware
slot for this network to make sure that it is possible to
resume later, even if it means other keepalives can't be
started at the same time.

Test: update AutomaticOnOffKeepaliveTrackerTest for this
Fixes: 268149573
Fixes: 283886067
Change-Id: Ida325bdea198d751483a83ee5d9ec26e39812137

Chalard Jean   authored and   Hansen Kurli   commited 2023-06-16 09:19:42 +00:00
ebb0747af3
Merge "Always disconnect agents immediately."
Lorenzo Colitti   authored and   Gerrit Code Review   commited 2023-06-15 03:49:05 +00:00
d925df8aa6
Merge "Create an MdnsServiceTypeClient using a SocketKey"
Paul Hu   authored and   Gerrit Code Review   commited 2023-06-15 01:01:46 +00:00
7c60aaa851
Merge "Notify socket changes using a SoketKey"
Paul Hu   authored and   Gerrit Code Review   commited 2023-06-15 01:01:24 +00:00
a8d1cabcd7
Always disconnect agents immediately.
Currently, various codepaths in ConnectivityService disconnect
networks using NetworkAgentInfo#disconnect. This posts a message
to the NetworkAgent to disconnect and also posts a message to
ConnectivityService to call disconnectAndDestroyNetwork, which
performs all cleanup in ConnectivityService. These two messages
race and the order is non-deterministic.

Instead, always disconnect using disconnectAndDestroyNetwork,
and have disconnectAndDestroyNetwork post the message to the
agent to disconnect.

This fixes a bug where if wifi uses unregisterAfterReplacement
twice in quick succession, when the third agent connects it
doesn't work because the interface is still being used by the
second network.

Also remove the import of IllegalArgumentException to keep the
linter happy (java.lang.* never needs to be imported).

Bug: 286649301
Test: covered by existing tests
Change-Id: Ie01f5589d6839ac6db25f0ba98fc929fbb5b0a96

Lorenzo Colitti   commited 2023-06-14 18:03:02 +09:00
4bc9fa6b8c
Merge "Add helper method to generate a v6 NAT-T keepalive packet"
Maciej Å»enczykowski   authored and   Gerrit Code Review   commited 2023-06-14 02:55:29 +00:00
977fa60f5d
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

Paul Hu   commited 2023-06-14 10:36:50 +08:00
62b6439f96
Merge "Update VPN tests to mock out createAttributionContext"
Yan Yan   authored and   Gerrit Code Review   commited 2023-06-13 17:34:57 +00:00
4f68ecf4ed
Add helper method to generate a v6 NAT-T keepalive packet
This is a part of preliminary work for sending a v6 NAT-T
keepalive packet in a v6 only network. This commit
release the constraint on constructing a v6 NAT-T keepalive
packet.

Bug: 196453719
Test: Manually connect to v6 only network and check if the
      keepalive packets are sent with subsequent commit
Test: atest FrameworksNetTests with the updated test
Change-Id: I9dc96e840265c5dee6b9e3ef2b3901a0aeb4ff9e

chiachangwang   commited 2023-06-13 11:50:13 +00:00
c18f0bbbb3
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

Paul Hu   commited 2023-06-13 18:41:28 +08:00
2f236e9ca4
Register BroadcastReceiver for default subId.
Register a receiver of ACTION_DEFAULT_SUBSCRIPTION_CHANGED to update
the cached default subId.

Bug: 273451360
Test: atest FrameworksNetTests
Change-Id: I3a38af7615fde2811449585d4e659ffaf29c5670

Hansen Kurli   commited 2023-06-13 05:46:51 +00:00
7b36f2322b
Write keepalive metrics periodically using alarms.
Use AlarmManger ELAPSED_REALTIME_WAKEUP to trigger writing the metrics
to statsd on an interval of 24 hours.

Bug: 273451360
Test: statsd_testdrive
Test: atest FrameworksNetTests
Change-Id: I5e21de058336819189532beffe2b3239a3c69599

Hansen Kurli   commited 2023-06-13 05:45:52 +00:00
19ea150271
Update VPN tests to mock out createAttributionContext
This allows VpnManagerServiceTest continues to work after
adding an attribution tag to VpnManagerService

Bug: 278943609
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.VpnManagerServiceTest
Change-Id: I4228a7fb308b8d01aee53f0734f4c5753908473a
Merged-In: I4228a7fb308b8d01aee53f0734f4c5753908473a

Yan Yan   commited 2023-06-12 18:06:47 +00:00
8e9f045d8d
Replace upTimeMillis with elapsedRealTime
upTimeMillis does not include time spent in deep sleep. Use
elapsedRealtime instead.

The time spent in deep sleep is important to include since the
keepalives may still be ongoing during deep sleep and so that time
should be included in duration calculations.

Bug: 273451360
Fixes: 281639289
Test: atest FrameworksNetTests
Change-Id: I54350d49bdfec58cc00dea6d82cba01f5d387bb0

Hansen Kurli   commited 2023-06-12 05:43:21 +00:00
d5ca3f1f69
Fill the other values for DailyKeepaliveInfoReported
Store the number of requests and app uids on start keepalives. The
values are also stored in KeepaliveStats and can be recalculated from
KeepaliveStats when reset. Fill the DailyKeepaliveInfoReported proto
with these values.

Bug: 273451360
Test: atest FrameworksNetTests
Change-Id: Ifb9a0048896d31c8ea897cf14768e94dcfd3b010

Hansen Kurli   commited 2023-06-12 05:43:05 +00:00
91adc204d8
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

Hansen Kurli   commited 2023-06-12 05:42:46 +00:00
c48d856976
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

Hansen Kurli   commited 2023-06-12 05:41:19 +00:00
ad03b887e6
Add test for default network activity APIs
Following CLs update LegacyNetworkActivityTracker to support multiple
network activities including non default network.
To avoid breaking default network activity APIs, this CL adds tests.
Following CL fix known issues of LegacyNetworkActivityTracker so this
CL also adds test for known issue behavior.

Bug: 279380356
Test: FrameworksNetTests
Change-Id: Ic180efe690807e940d0b412a38ebc5e6d22691c4

Motomu Utsumi   commited 2023-06-09 17:28:44 +09:00
2738f4fd4d
Merge "Ensure public methods are running on handler thread"
Hansen Kurli   authored and   Gerrit Code Review   commited 2023-06-09 04:54:58 +00:00
7e343d58ce
Merge "Stop TCP keepalive from CS for fd initiated stop events"
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-06-09 01:05:46 +00:00
646715e787