Commit graph android_packages_modules_Co.../tests/unit/java/com/android
Message SHA1
Mdns: Skip networks with NET_CAPABILITY_LOCAL_NETWORK
MdnsSocketProvider expects no overlap between NetworkCallbacks,
Tethering, and Wifi P2P. However, local NetworkAgents can cause
overlap, leading to duplicate sockets. This commit fixes the issue by
skipping networks with NET_CAPABILITY_LOCAL_NETWORK.

Alternatively, the NetworkRequest should addForbiddenCapability
for local networks. However, since this is a module API, it is
not visible to standalone applications.

Flag: EXEMPT bug fix
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.mdns.MdnsSocketProviderTest \
      --update-device
Test: m service-connectivity-mdns-standalone-build-test
Test: atest CtsNetTestCases:android.net.cts.NsdManagerTest \
      CtsNetTestCases:android.net.cts.NsdManagerDownstreamTetheringTest
Bug: 437038495
Change-Id: I78dd7d98ad80147ca26ec6130b6081ef4efb2ecc

Junyu Lai   commited 2025-08-14 20:44:36 +08:00
eb80e8ad9f
Merge "Use mainline beta flag for NetworkAgent event queueing" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-08-14 01:19:15 -07:00
0c6b14587b
Merge changes I69ad789f,I5954b196 into main
* changes:
  Fix mobile data preferred on multi-user devices.
  Support multi-user SettingsObservers in ConnectivityService

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-14 00:33:06 -07:00
4c516ffd67
Use mainline beta flag for NetworkAgent event queueing
Add `queue_network_agent_events_in_system_server` as a mainline beta
flag. This flag replaces the previous check for
`mQueueNetworkAgentEventsInSystemServer`, allowing the feature to be
controlled and enabled on all Android versions via mainline beta program.

Flag: com.android.tethering.mainline.beta.queue_network_agent_events_in_system_server
Test: atest ConnectivityCoverageTests --update-device \
      --test-filter '.*NetworkAgent.*'
Test: atest ConnectivityCoverageTests --update-device \
      --test-filter '.*Connectivity.*'
Fix: 428098184
Change-Id: I96b0443bd4c55c28d482349738bbdc4798f0c7f9

Junyu Lai   commited 2025-08-14 14:53:06 +08:00
c9890408bf
Support multi-user SettingsObservers in ConnectivityService
ConnectivityService uses SettingsObservers to detect when
settings change. These are all set on user zero. This is fine
for most settings, which are in Settings.Global, but some
settings are per-user, such as MOBILE_DATA_PREFERRED_UIDS, which
is in Settings.Secure.

This CL adds the ability to register SettingsObservers on all
users. These observers will fire any time the setting changes
for any current user, and any time a user is added or removed.

This CL does not add or change any SettingsObservers and should
cause no behaviour changes.

Bug: 404186833
Flag: EXEMPT refactor
Test: covered by existing tests
Change-Id: I5954b196eea776414098f1ce4441eb02065438ef

Lorenzo Colitti   commited 2025-08-08 15:36:54 +09:00
aad9267493
replace CookieTagMapKey with S64
(mostly autogenerated, with minor tweaks to make it build)

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2065c3fc6d4d37663a0a52281deb7624fd5c801d

Maciej Żenczykowski   commited 2025-08-07 15:52:35 -07:00
9ef3916ba4
replace UidStatsMapKey with S32
(mostly autogenerated, with minor tweaks to make it build)

Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id2ffe0df6526a6377806464e902b8e8f87a43c62

Maciej Żenczykowski   commited 2025-08-07 15:50:48 -07:00
b28b0c70b9
Merge "Change proto message name for NetworkConfigStoreProto" into main
Chuwei He   authored and   Android (Google) Code Review   commited 2025-08-06 22:28:10 -07:00
7dc6767005
Change proto message name for NetworkConfigStoreProto
This patch add *Proto suffix for some proto message in
NetworkConfigStoreProto to avoid name conflicts with names in
android.net package.

Test: atest ConnectivityCoverageTests
Bug: 397536853
Flag: EXEMPT mainline

Change-Id: I4f826511bcab0fcd3b154bbc349a062fd4841321

Chuwei He   commited 2025-08-06 20:58:53 -07:00
88d424c3b8
Merge "Add EthernetConfigHolderProto to NetworkConfigStoreProto" into main
Chuwei He   authored and   Android (Google) Code Review   commited 2025-08-06 20:37:00 -07:00
dc421c895e
Add EthernetConfigHolderProto to NetworkConfigStoreProto
This patch Adds EthernetConfigHolderProto to NetworkConfigStoreProto for storing
collective ethernet configurations state.

Test: atest ConnectivityCoverageTests
Bug: 397536853
Flag: EXEMPT mainline
Change-Id: I420c0775163b5608cb6defb35e217b2c2c867df1

Chuwei He   commited 2025-08-07 10:11:16 +09:00
18a67028d2
Merge "Use reported satellite suspended and roaming state" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-08-06 00:29:17 -07:00
2d94e180e7
Merge "Include NET_CAPABILITY_NOT_VCN_MANAGED for tethering local network agent" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-08-05 23:07:49 -07:00
1986dec249
Include NET_CAPABILITY_NOT_VCN_MANAGED for tethering local network agent
Currently, NET_CAPABILITY_NOT_VCN_MANAGED is implicited added for
NetworkRequest built by normal apps.
However, the tethering network agent doesn't have this capability,
which makes the agent being exposed to VcnManager and cannot be
seen by normal apps.

Add NET_CAPABILITY_NOT_VCN_MANAGED to tethering NetworkAgent. Include
NET_CAPABILITY_NOT_VCN_MANAGED in local network capabilities for
metrics and API utilities to ensure correct evaluation of local
network connectivity. Update unit tests to reflect the new capability.

Flag: EXEMPT bug fix
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSSatisfiedByLocalNetworkMetricsTest \
      ConnectivityCoverageTests:android.net.connectivity.com.android.metrics.SatisfiedByLocalNetworkMetricsTest \
      --update-device
Test: manual generate request by CTS and statsd_testdrive -e 10247
Bug: 428098173
Change-Id: Ifa9ce0827abd22d887a0e8a2ab6f4d7391b2b8ed

Junyu Lai   commited 2025-08-06 11:24:33 +08:00
fbf102a88b
Use reported satellite suspended and roaming state
Bug: 431296970
Test: TH
Flag: EXEMPT mainline
Change-Id: I4d828bad6419aa2d12bff6f1855314c0060af3f7

Motomu Utsumi   commited 2025-08-06 09:53:30 +09:00
f9065b8898
Use FakeSettingsProvider callbacks to simplify CS tests.
Because FakeSettingsProvider and other test infrastructure did
not support settings observers, the tests called internal
ConnectivityService methods to cause the settings to be re-read.
Now that FakeSettingsProvider supports callbacks, use
ContentResolverWithFakeSettingsProvider in the CS tests and just
use the callbacks.

Bug: 397521796
Flag: TEST_ONLY
Test: test-only change
Change-Id: I26d8e98706fec99aa423721bf1474af2f9b60099

Lorenzo Colitti   commited 2025-08-05 18:02:02 +09:00
6e3afc7dc6
Merge "Add logging for onPermissionsChanged latency." into main
Hao Liu   authored and   Android (Google) Code Review   commited 2025-07-31 06:47:43 -07:00
85415edca0
Add logging for onPermissionsChanged latency.
Flag: com.android.tethering.mainline.beta.lnp_developer_opt_in
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.PermissionMonitorTest
Bug: 424558169

Change-Id: Ifb621149130212a2903a7c31eebd4126e7d9924a

Hao Liu   commited 2025-07-31 03:02:08 +00:00
55614983a6
Fix UnfinishedStubbingException when running testAutomotiveEthernetAllowedUids
Mocking the PackageManager while ConnectivityService is running
could throw an UnfinishedStubbingException. This change splits
the test into two distinct tests that don't need to change the
mocking value for PackageManager during testing.

Fix: 433600031
Test: atest ConnectivityServiceTest
Flag: TEST_ONLY
Change-Id: Ibcff2082d1e50e89c272573b4c719a7325c959fd

Paul Hu   commited 2025-07-30 08:36:26 +00:00
e4e65d7b48
Merge "Add proto to store network configuration" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-07-25 16:48:31 -07:00
3e3e18b2f1
Merge "Notify offload engine with discovery service information" into main
Paul Hu   authored and   Android (Google) Code Review   commited 2025-07-25 01:48:41 -07:00
f98e4c2f7b
Notify offload engine with discovery service information
Updated the NsdService to send all OffloadServiceInfo from the
MdnsDiscoveryManager to the OffloadEngine upon the OffloadEngine
is registered.

Bug: 410734687
Test: atest ConnectivityCoverageTests
Flag: EXEMPT legacy flag nsd_force_disable_mdns_offload
Change-Id: I833d244dd59e98818985c69edd2012a2aa4dc8e6

Paul Hu   commited 2025-07-24 07:43:32 +00:00
2fa3227110
Add proto to store network configuration
This patch adds proto which will be used to store network
configuration. This will be used in IpConfigStore.

Test: atest ConnectivityCoverageTests
Bug: 397536853
Flag: EXEMPT mainline

Change-Id: I83032ebc78c60cbf2fc8f9119471fc13ae7f09e1

Chuwei He   commited 2025-07-24 16:41:00 +09:00
5adb3c56aa
Use beta flag for bluetoothTetheringRandomizedAddress
Bug: 287177081
Test: TH
Flag: com.android.tethering.mainline.beta.bluetooth_tethering_randomized_address
Change-Id: I1de9f4bb15c8423f09381a0c7513f0d7ebf80856

Motomu Utsumi   authored and   Hao Liu   commited 2025-07-17 21:30:07 +00:00
4b4f3018a5
Merge "Add metrics for QUIC connection close" into main
Motomu Utsumi   authored and   Android (Google) Code Review   commited 2025-07-15 20:32:42 -07:00
e5d4a0fca3
Disconnect a network if it's suspended for 5 minutes for wear
The suspension state is designed to be a transient state. Implement an
enforcement to disconnect the network after staying at this state for 5
minutes. This can avoid apps unnecessarily waking up the device for
network activities even when there's no network actually connected.

Test: unit tests. Locally tested with a signal blocking bag.
Bug: 404570281
Flag: EXEMPT mainline
Change-Id: I1427a72402f7ec64eda537a89c86768466a72328

Hongyi Zhang   commited 2025-07-15 09:39:37 -07:00
3dcb3c5890
Add metrics for QUIC connection close
Test: QuicConnectionCloserTest
Flag: EXEMPT mainline
Bug: 311792075
Change-Id: I2bd9108c1f8af89824bf48767fcca9a1e1d57831

Motomu Utsumi   commited 2025-07-15 17:10:56 +09:00
504fe27b86
Merge "Search for the satellite opt-in flag in disabled services" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-07-14 20:41:48 -07:00
c5cda84789
Revert^2 "Fix onActiveDataSubscriptionIdChanged is not received in multi SIM mode"
This reverts commit 1bcbb88955.

Reason for revert: fix TelephonyCallback in multi SIM mode

Bug: 430233890
Change-Id: Ibfdc5546083132c504ac129256f321dd000b890c

Jimi Chen   commited 2025-07-13 20:05:43 -07:00
b588948892
Search for the satellite opt-in flag in disabled services
As it might be necessary to discover the metadata in services
for technical reasons, a good way to file that data is to make a
phony, disabled service for the purposes of containing this
metadata.

Unfortunately, the disabled components are not returned by
PackageManager unless you pass MATCH_DISABLED_COMPONENTS
as a flag, and we didn't know that at the time.

Do match disabled components so a disabled service can be used
as a holder for this.

Bug: 427846736
Test: manual
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest
Flag: EXEMPT bugfix
Change-Id: Id32c32ab8cfb93a4270795a5bdf75edb4cb7a1f6

Chalard Jean   authored and   Junyu Lai   commited 2025-07-10 14:27:43 +08:00
21575cf8dd
Add UID to NSD metrics
This commit introduces the UID to the NetworkNsdReportedMetrics,
allowing for the association of NSD metrics with the specific
application or process that initiated the NSD operation.

Bug: 427689120
Test: atest ConnectivityCoverageTests NsdManagerTest
Flag: EXEMPT refactor
Change-Id: I780cd6ba74d2ef7e23200f83f497691dd4702919

Paul Hu   commited 2025-07-10 03:47:50 +00:00
924f535b56
Merge "Fix onActiveDataSubscriptionIdChanged is not received in multi SIM mode" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-07-07 21:57:41 -07:00
7e816d5d07
Fix onActiveDataSubscriptionIdChanged is not received in multi SIM mode
Flag: EXEMPT mainline
Bug: 428673855
Test: manually
Change-Id: I0d7c2538ec33402dba64949c3fb34519605d843e

Jimi Chen   commited 2025-07-08 02:14:21 +00:00
aecb2b65ba
Merge "Fix mDNS offload by skipping probing and preventing race." into main
Yuyang Huang   authored and   Android (Google) Code Review   commited 2025-07-04 03:27:31 -07:00
e46c997be3
Merge "Address review comment at ag/34147135" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-07-03 23:56:09 -07:00
fd334b90f7
Fix mDNS offload by skipping probing and preventing race.
In the mDNS advertising offload-only path, skip both the probing and
announcement stages.

Test: TH
Flag: EXEMPT bugfix only
Change-Id: I644a4c0d72de4ae521f048ca4d33e3ae69a66499

Yuyang Huang   commited 2025-07-04 15:27:36 +09:00
c3709c211f
Merge "Implement the private DNS bypass logic for captive portal over CCT." into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-07-03 18:10:05 -07:00
43252b41bf
Address review comment at ag/34147135
This includes:
1. Fix Race Condition: The call to `logRequest` is moved before
   `trackUidAndRegisterNetworkRequest`. This prevents a race condition
   where the `NetworkRequest` object could be modified on the handler
   thread before its initial state was logged.

2. Clear Metrics on Pull: The metrics map is now cleared after the
   data is pulled. This changes the atom from a cumulative
   counter to a periodic one, simplifying server-side aggregation.

Bug: 406172997
Flag: EXEMPT controlled by the `satisfied_by_local_network_metrics`
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSSatisfiedByLocalNetworkMetricsTest \
  ConnectivityCoverageTests:android.net.connectivity.com.android.metrics.SatisfiedByLocalNetworkMetricsTest \
  --update-device
Change-Id: Ia3b74088183c95173ab07a4f72393065bca2bafe

Junyu Lai   commited 2025-07-03 17:18:47 +08:00
cf8688deab
Implement the private DNS bypass logic for captive portal over CCT.
Flag: EXEMPT the API caller is guarded by a legacy experiment flag
Bug: 368416967
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSNetdBypassRulesTests
Change-Id: I0e24bf37c412e6f5676924269ca98db1f9dfd6df

Xiao Ma   commited 2025-07-02 15:13:20 +09:00
5fd76d347d
Merge "Use NETWORK_STACK permission for broadcast receivers" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-07-01 22:58:04 -07:00
18e2c70d3b
Merge "Refactor: Stop caching PackageManager in SatelliteAccessController" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-07-01 18:54:09 -07:00
d0869b0b08
Add metrics for requests satisfied by local networks
This change introduces `SatisfiedByLocalNetworkMetrics` to count the
number of `NetworkRequest`s per UID that can be satisfied by a
local-only network.

The purpose is to gather data on how many applications register callbacks
that would match non-thread local network connectivity.
This data helps in understanding app behavior and can inform
future development of local-only network features particularly
for the backward compatibility of existing NetworkRequests.

- A new class `SatisfiedByLocalNetworkMetrics` handles the counting and
  logging logic.
- `ConnectivityService` calls into this class upon `NetworkRequest`
  registration.
- Counts are logged to statsd.

Sample dumpsys output:
  SatisfiedByLocalNetworkMetrics: {LISTEN={10217=2}}

Bug: 406172997
Flag: EXEMPT controlled by the `satisfied_by_local_network_metrics`
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSSatisfiedByLocalNetworkMetricsTest \
      ConnectivityCoverageTests:android.net.connectivity.com.android.metrics.SatisfiedByLocalNetworkMetricsTest \
      --update-device
Test: m statsd_testdrive && statsd_testdrive -e 10247
Test: Manual: atest dumpsys connectivity

Change-Id: I62f6299a1c726537b373e3e80d41a494323f3cf2

Junyu Lai   commited 2025-07-01 16:01:28 +08:00
c00cf63e8a
Use NETWORK_STACK permission for broadcast receivers
Use the NETWORK_STACK permission instead of null when registering
broadcast receivers in ConnectivityService, PermissionMonitor and
BroadcastReceiveHelper.
This ensures that only components with the NETWORK_STACK permission
can send these protected broadcasts, improving system security.
Tests were updated to reflect the new permission requirement.

Flag: EXEMPT trivial change
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.BroadcastReceiveHelperTest \
      ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.PermissionMonitorTest \
      --update-device
Fix: 425828059
Change-Id: I9761f9f454751761b346e255aac0d1c7d7a7e30c

Junyu Lai   commited 2025-06-28 06:40:14 +08:00
ca5a062321
Refactor: Stop caching PackageManager in SatelliteAccessController
Stop caching per-user PackageManager instances to avoid potential race
conditions.
The previous implementation relied on the ordering of ACTION_USER_*
and ACTION_PACKAGE_* broadcasts, which is not guaranteed across
Android releases.
This change refactors the code to fetch the PackageManager on demand,
ensuring correctness and robustness. Corresponding tests have been
updated.

Flag: EXEMPT bug fix
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest \
      --update-device
Fix: 422064138
Change-Id: I09db0be542a1ce9746174f4b8e816ac0def7c833

Junyu Lai   commited 2025-06-28 06:40:14 +08:00
fea137ae76
Merge changes If5f9b5e8,I2ae559df into main
* changes:
  Remove delayed messages from handler queue correctly
  Exclude more files from mDNS standalone library

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-26 17:47:59 -07:00
830b2bc40e
Remove delayed messages from handler queue correctly
This change replaces removeMessages() with removeEqualMessages().
The latter uses the equals() method to correctly compare the
content of interface name strings, ensuring previously delayed
messages are properly removed.

Bug: 427426427
Test: Manual testing with some modifications.
Test: atest ConnectivityCoverageTests NsdManagerTest
Flag: EXEMPT bug fix
Change-Id: If5f9b5e8425fc9bb235431edd78c3f3a28a037d8

Paul Hu   commited 2025-06-26 07:30:40 +00:00
4d22c15b0a
Merge "Format MdnsReplySenderTest" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-25 08:34:13 -07:00
7e90162275
Format MdnsReplySenderTest
Use the ktlint.py script to correct Kotlin code formatting errors.

Test: m
Flag: EXEMPT corret format
Change-Id: I1c184ce89e4e511340b8a32cb5dd3253191a8bbd

Paul Hu   commited 2025-06-25 10:18:15 +00:00
e823669fb7
Merge "Register network_carrier_aware_avoid_bad_wifi setting change callback" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-06-23 19:59:08 -07:00
1895b07c81
Register network_carrier_aware_avoid_bad_wifi setting change callback
This commit registers the "network_carrier_aware_avoid_bad_wifi" URI
with the ContentResolver to allow for monitoring changes to this
specific Global.Settings entry.

Flag: EXEMPT mainline
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.MultinetworkPolicyTrackerTest
Change-Id: I0e9161c5390b71e5c3ecac89613aa042f40ab695

Jimi Chen   commited 2025-06-23 14:01:56 +00:00
1095a3486f