Commit graph android_packages_modules_Co.../tests/unit/java/com/android/server
Message SHA1
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
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
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
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

chiachangwang   commited 2023-06-08 15:31:42 +00:00
739f0960f3
Merge "Enable useSessionIdToScheduleMdnsTask"
Yuyang Huang   authored and   Gerrit Code Review   commited 2023-06-08 10:41:58 +00:00
01b988255f
Merge "Fix cache flush always causing response change"
Yuyang Huang   authored and   Gerrit Code Review   commited 2023-06-08 09:17:59 +00:00
e0f07a9dc1
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

Yuyang Huang   commited 2023-06-08 17:38:52 +09:00
c505844d8a
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

Remi NGUYEN VAN   authored and   Yuyang Huang   commited 2023-06-08 16:30:31 +09:00
98a44bcb29
Merge "Adjust the notifyNetworkUnrequested on handleRegisterListener"
Paul Hu   authored and   Gerrit Code Review   commited 2023-06-08 06:34:25 +00:00
bad235f4f9
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

Paul Hu   commited 2023-06-08 10:29:07 +08:00
c54aa729c9
Merge "Fix a bug where the PAC proxy port is not set correctly."
Jean Chalard   authored and   Gerrit Code Review   commited 2023-06-06 12:22:21 +00:00
f2b38772ac
Merge "Update record receipt time on records updated"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-06-06 08:34:39 +00:00
1667bfea04
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

Yuyang Huang   commited 2023-06-06 12:55:27 +09:00
86f674187f
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

Remi NGUYEN VAN   commited 2023-06-06 11:13:34 +09:00
a8efbe0e32
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

Aaron Huang   authored and   Chalard Jean   commited 2023-06-05 20:24:59 +09:00
9fe47bee09
Merge "On U+ require config_networkWakeupPacketMark/Mask to be 0x80000000"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-06-05 09:34:47 +00:00
c133f6e29c
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

Maciej Żenczykowski   commited 2023-06-05 07:41:00 +00:00
cf41fc877a
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.

Hansen Kurli   authored and   Gerrit Code Review   commited 2023-06-05 04:56:16 +00:00
48e61a4520
Merge "Use netd socketDestroy for VPN in T-"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-05 03:04:19 +00:00
d8b852fc06
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

Motomu Utsumi   commited 2023-06-04 23:12:58 +09:00
1d13726710
Merge changes If830eb53,If03514f1
* changes:
  Update tethered/local only interfaces when no all networks request
  Use wifi p2p interfaces for mDNS

Paul Hu   authored and   Gerrit Code Review   commited 2023-06-02 13:10:51 +00:00
83bd5a5927