Commit graph android_packages_modules_Co.../tests/unit/java/com/android/server
Message SHA1
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
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
Merge "Migrate CSAgentWrapper to TestableCallback." into main
Jean Chalard   authored and   Android (Google) Code Review   commited 2025-06-22 18:43:23 -07:00
3cbf1e3b94
Merge "Check service meta-data for satellite opt-in" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-20 02:25:16 -07:00
bc19379378
Check service meta-data for satellite opt-in
Previously, the approach for apps to declare themselves
satellite-optimized was problematic. Relying solely on the
<application> tag for opt-in could significantly increase app
size. This was particularly an issue on older devices, where
the duplication of <meta-data> directly under the
<application> tag into each ProviderInfo could drastically
swell its size. A prime example of this negative impact was
crashes on Android 5.0 (API 21) and older devices, where
PackageManager.queryContentProviders would exceed the 1MB
Binder transaction limit due to the bloated ProviderInfo size.

The `isSatelliteDataOptimizedApp` method is updated to iterate
through a package's services if the application-level meta-data
is not found.

Flag: EXEMPT controlled by kill switch
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest
Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideSatelliteDataOptInTest
Bug: 424290966

Change-Id: I36b6a0093bc74de470443f6553b26b09d070ed9d

Junyu Lai   commited 2025-06-20 16:35:28 +08:00
441ce68713
Migrate CSAgentWrapper to TestableCallback.
This makes it much more powerful as well as consistent with
other use cases of this paradigm.

Test: TH
Flag: EXEMPT test-only
Change-Id: I4f5b86bfdd16d8bfe21b79235444817a13bc3c49

Chalard Jean   authored and   Jean Chalard   commited 2025-06-20 01:08:25 -07:00
6fe5d13b3a
Merge changes from topic "avoid-bad-wifi-api-update" into main
* changes:
  Enable per-subId 'avoid bad Wi-Fi' setting storage
  Use ConnectivitySettingsManager API for avoid bad Wi-Fi updates

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-20 00:42:48 -07:00
553054fcee
Merge "Use handler thread to retrieve carrier config directly" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-19 06:06:08 -07:00
4ee72294c0
Use ConnectivitySettingsManager API for avoid bad Wi-Fi updates
This change replaces the internal cache with the `ConnectivitySettingsManager` API
to manage "avoid bad Wi-Fi" settings. It reduces code duplication and improves
readability.

Flag: EXEMPT mainline
Bug: 422063047
Test: atest ConnectivityCoverageTests
Change-Id: I82d9e1afb7c318d584e708da6ad5c10f298f057b

Jimi Chen   commited 2025-06-19 11:30:02 +00:00
dd73a350f9
Merge changes I97b4cf85,I33134502,I43beb0d3,I1b681708 into main
* changes:
  Add EthernetPort#matches(interfaceName)
  Ignore NLMSG_DONE messages
  Only consider interfaces tracked by regex in EthernetManager#isAvailable
  Ensure provisioning is never started with Mode.NONE

Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-06-18 17:08:04 -07:00
f2b5e4a9a0
Add EthernetPort#matches(interfaceName)
Interface matching in the ethernet module is still done by interface
name. Add an explicit #matches() function to avoid accidentally
comparing against the wrong object. Comparing a String to an
EthernetPort (or vice versa) is a valid java expression.

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I97b4cf856160195f44e4cebd13d8ce2fdeeb220c

Patrick Rohr   commited 2025-06-18 14:49:41 -07:00
8b390a5cca
Merge "Fix flaky testHandleUdpSocketDestroy" into main
Motomu Utsumi   authored and   Android (Google) Code Review   commited 2025-06-18 03:16:33 -07:00
67f4f44402
Fix flaky testHandleUdpSocketDestroy
The SkDestroyListenerCallback posts a message to a handler thread.
This can cause a race condition when sendQuicConnectionClosePayload call
is verified.

This CL sets a timeout for verifying sendQuicConnectionClosePayload
call.
Additionally, a short timeout is used to assert that destroyUdpSocket is
not called.

Test: QuicConnectionCloserTest
Bug: 407226131
Flag: EXEMPT test only change
Change-Id: I62522fcafb91bef12e2781afbd090af8d0350f1e

Motomu Utsumi   commited 2025-06-18 15:56:56 +09:00
54a621a248
Merge "Allow VCN network to beat a physical cell in network ranking" into main
Yan Yan   authored and   Android (Google) Code Review   commited 2025-06-17 11:09:54 -07:00
7b1145e6b4
Only consider interfaces tracked by regex in EthernetManager#isAvailable
There is an argument that the API is @UnsupportedAppUsage since R and
this code only ships to T. In any case, just to be on the safe side, the
code should ignore NCM interfaces which are not part of the regex. (It
already ignores interfaces which are in tethering/server mode today).

This CL also marks a couple of related functions properly as public.
These functions are not @VisibleForTesting; they belong to the public
interface of the class.

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I43beb0d3a17d403b7f6bcbadd7089110ad28684e

Patrick Rohr   commited 2025-06-17 09:12:37 -07:00
fb8c780b6f
Do not try to send updated allowed ranges for destroyed networks
Test: TH
Bug: 420229020
Flag: EXEMPT bugfix
Change-Id: Ibc1c4cf2d94afe86f22b515ac0b91c85f6506f8e

Chalard Jean   commited 2025-06-17 13:53:42 +09:00
4d2887b593
Allow VCN network to beat a physical cell in network ranking
This patch adds a new POLICY to identify a VCN network offer, and
updates NetworkRanker to allow a VCN network to win over a physical
cell network. This is to fix the issue where VCN cannot exit safe
mode when there is already a phsical cell

Bug: 391977557
Test: NetworkRankerTest(new test)
Flag: EXEMPT bugfix
Change-Id: I00ebeb3eeb30ca8b46d25bbde1b6fd3dfee53993

Yan Yan   commited 2025-06-17 01:30:07 +00:00
6eab1d0af3
Merge "Introduce interface name field to SocketKey" into main
Paul Hu   authored and   Android (Google) Code Review   commited 2025-06-16 18:28:55 -07:00
fff6a3fdcd
Introduce interface name field to SocketKey
This commit adds a new interfaceName field to the SocketKey
class, which allows us to uniquely identify sockets based on
their interface name in addition to their network and interface
index. This information is used for subsequent changes to
identify the target ServiceTypeClient by the interface name.

Bug: 410734687
Test: atest ConnectivityCoverageTests NsdManagerTest
Flag: EXEMPT refactor
Change-Id: Ic312b26ca572d12b7c3177b84aced9d487636003

Paul Hu   commited 2025-06-16 16:10:01 +00:00
ef6f92b903
Pass TrackingReason to NetworkInterfaceState
Because changing the tethering mode invokes addInterface(), the
tracking mode for the tethering interface needs to be persisted
separately.

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: Ifb8371a55a582bf2133a59bdbedcce95c94626cc

Patrick Rohr   commited 2025-06-13 16:14:08 -07:00
a2d1cb97fa
Use handler thread to retrieve carrier config directly
Binder calls to the `CarrierConfigManager` API have a P99 latency of 25ms.
This latency is acceptable for direct execution on the handler thread,
eliminating the need for a separate background thread.

This change reduces complexity and improves code readability.

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

Jimi Chen   commited 2025-06-13 11:32:16 +00:00
fbdc438e7a
Merge "Enhance global settings for carrier-specific "avoid bad WiFi" behavior" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-06-12 22:37:20 -07:00
b5cd28aec9
Merge "Add kill switch for storing transport types" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-10 16:52:20 -07:00
4be13fb54d
Merge "Make a base class for testable callbacks" into main
Jean Chalard   authored and   Android (Google) Code Review   commited 2025-06-10 16:48:00 -07:00
7f7c597328
Enhance global settings for carrier-specific "avoid bad WiFi" behavior
Previously, the "avoid bad WiFi" global setting was limited to a single boolean value (0 or 1),
preventing granular control for multiple carriers.
This commit introduces support for carrier-aware "avoid bad WiFi" configurations using a new,
extensible format: "subId1,value1;subId2,value2;...".
This allows different `subId`s (carriers) to have their own specific "avoid bad WiFi" settings.

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

Jimi Chen   commited 2025-06-10 12:20:07 +00:00
cbdfd9f54b
Add kill switch for storing transport types
In case there is a bug after rolling out transport
types support in the NetworkIdentity. Add a kill switch
to stop writing transport types to mitigate the
impact if any.

Flag: EXEMPT the change is the kill switch
Test: atest ConnectivityCoverageTests --test-filter \
  'NetworkIdentity*' --update-device
Test: atest ConnectivityCoverageTests --test-filter \
  'NetworkStats*' --update-device
Test: atest ConnectivityBenchmarkTests
Test: atest FrameworksNetIntegrationTests:com.android.server.net.integrationtests.NetworkStatsIntegrationTest
Test: Manual:
  1. Download files
  2. adb shell device_config put tethering store_transport_types -1
  3. reboot and check Data Usage Settings page.

Bug: 419123367
Change-Id: I52791f6fe5207021748641cf0719055533b5d511

Junyu Lai   commited 2025-06-10 17:57:11 +08:00
1c5f5b5270
Make a base class for testable callbacks
Have TestableNetworkCallback adopt it, as a first client. It's also by
far the most complex.

Test: TH
Flag: EXEMPT test-only
Change-Id: Ie58d051b4478c901b7f0f54e89a67d22f1ee2ce2

Chalard Jean   commited 2025-06-10 17:22:01 +09:00
2db96977db
Add NetworkTemplate get/set transport type methods
This is needed for counter-part modules to query data usage
with specified transport type.
This is kept hidden and will be exposed in follow-up
CLs.

Flag: EXEMPT controlled in the counter-part CL
Test: atest ConnectivityCoverageTests --test-filter \
'NetworkTemplate*' --update-device
Bug: 419123367
Bug: 420531377

Change-Id: I503b4d7307d008a64a14aa713d9714428e399809

Junyu Lai   commited 2025-06-09 14:09:46 +08:00
dc7bfba12e
Merge changes I7e78be87,Id0c9cc4f,I2fb00abf,Iba1dfdba,I4fd6658e, ... into main
* changes:
  Pass EthernetPort to EthernetNetworkFactory#updateInterfaceLinkState
  Pass EthernetPort to updateInterfaceState
  Remove spurious VisibleForTesting and change visibility to public
  Pass EthernetPort to EthernetNetworkFactory#removeInterface
  Pass EthernetPort to removeInterface
  Pass EthernetPort to stopTrackingInterface
  Add getEthernetPorts and use it in getAllInterfaces

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-06 14:31:58 -07:00
e2fe8648d4
Merge changes Id33fb720,Ic1a6e60d,If1b88754,I290ee07d into main
* changes:
  Rename getClientModeInterfaces to getClientModeInterfacesSorted
  Rename getAvailableInterfaces to getInterfacesSorted
  Pass EthernetPort into NetworkInterfaceState
  Pass EthernetPort into EthernetNetworkFactory#addInterface

Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-06-06 12:17:33 -07:00
eec49e4bb6
Pass EthernetPort to EthernetNetworkFactory#updateInterfaceLinkState
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I7e78be87824e29eab90074b1a2263e0cbd779021

Patrick Rohr   commited 2025-06-06 12:14:51 -07:00
db32c1bbdc
Pass EthernetPort to EthernetNetworkFactory#removeInterface
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: Iba1dfdba7f249013da0946bfe9738f110f95391e

Patrick Rohr   commited 2025-06-06 12:14:51 -07:00
345876e119
Rename getAvailableInterfaces to getInterfacesSorted
The next change will add a getInterfaces() method which returns the
interfaces in any order.

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: Ic1a6e60d8a7e74a6d46e569f0d9045849fd0f8ed

Patrick Rohr   commited 2025-06-06 11:29:38 -07:00
30b9d14780
Pass EthernetPort into EthernetNetworkFactory#addInterface
Also removes @NonNull annotations (implied) and unnecessary final
specifier.

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I290ee07d63e224d45d744f1f00671e0ca4f57a1e

Patrick Rohr   commited 2025-06-06 11:29:38 -07:00
f19ff514be
Merge changes I3c73b445,If707b96b into main
* changes:
  Test refactoring of DefaultNetworkRematchMetrics
  Fix SatisfiedTime initialization

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-06 03:22:40 -07:00
c60c225e73
Test refactoring of DefaultNetworkRematchMetrics
This change includes:
 1. addEvent Parameter Update: Added satisfied duration to
    addEvent, making duration testable in CSTest.
 2. CSDefaultNetworkRematchMetricsTest Refactor: Tests now use
    expectAddEvent with argThat and InOrder for more deterministic
    verification.
 3. New Unit Test: Added a test to demonstrate a metrics reporting
    issue during per-app default network request updates.

Test: atest ConnectivityCoverageTests --test-filter 'DefaultNetworkRematch*' \
      --update-device
Flag: EXEMPT Test only refactoring
Bug: 419123367
Change-Id: I3c73b445674991f85e37b3f980fa80fb918713ac

Junyu Lai   commited 2025-06-06 16:45:51 +08:00
d4c521ab43
Fix SatisfiedTime initialization
mSatisfiedTime now initializes with the current time upon NRI
creation, or copied when the copy constructor is called.

Test: atest ConnectivityCoverageTests --test-filter 'NetworkRequestInfo*' --update-device
Flag: EXEMPT controlled by kill switch
Bug: 419123367
Change-Id: If707b96bf6ce5c6cb0287d5c2d6056591dd6769f

Junyu Lai   commited 2025-06-06 16:04:03 +08:00
1ff0c98745
Merge "Revert "Make a base class for testable callbacks"" into main
Priyanka Advani (xWF)   authored and   Android (Google) Code Review   commited 2025-06-05 13:02:09 -07:00
130e55e17e
Revert "Make a base class for testable callbacks"
This reverts commit a77d5ac126.

Reason for revert: Droidmonitor created revert due to b/422782308. Will be verifying through ABTD before submission.

Fix: 422782308
Change-Id: I00825e0f17a9a9e0d152ac8ebe767da3f267fbb1

Priyanka Advani (xWF)   authored and   Android (Google) Code Review   commited 2025-06-05 11:35:49 -07:00
827aa58224
Merge "Make a base class for testable callbacks" into main
Jean Chalard   authored and   Android (Google) Code Review   commited 2025-06-05 05:12:50 -07:00
595ab39d06
Merge "Report DefaultNetworkRematch for satellite network" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-06-05 02:33:56 -07:00
2ebde067f4
Make a base class for testable callbacks
Have TestableNetworkCallback adopt it, as a first client. It's also by
far the most complex.

Test: TH
Flag: EXEMPT test-only
Change-Id: Ifd636a09d0695f04b17330c4987f2b7b742508fa

Chalard Jean   commited 2025-06-05 16:13:34 +09:00
a77d5ac126
Report DefaultNetworkRematch for satellite network
This change introduces the `DefaultNetworkRematchMetrics`
class to collect and log data about default network reassignments.

The primary motivation is to monitor the behavior of satellite
networks when they act as a default network fallback. This class
records an event whenever a default network request with the
`PREFERENCE_ORDER_SATELLITE_FALLBACK` preference is moved from
one network to another.

For each reassignment, a `DEFAULT_NETWORK_REMATCH` atom is logged
to ConnectivityStatsLog. This atom includes detailed `NetworkDescription`
protos for the old and new networks, capturing their transport
types, capabilities, and metered/validated states. It also logs
the duration the device spent on the previous network.

Sample metrics:
event_metrics {
  data {
    aggregated_atom_info {
      atom {
        default_network_rematch {
          session_id: 1099094483789245667
          rematch_reason: RMR_UNKNOWN
          default_network_rematch_info_list {
            default_network_rematch_info {
              old_network {
                transport_types: 1
                metered_state: METERED_YES
                validated_state: VS_VALID
                score_policies: -4575657221408423932
                capabilities: 137711448064
                enterprise_id: 0
              }
              time_duration_on_old_network_sec: 9
              uid_ranges {
                uid_range {
                  begin: 10137
                  end: 10137
                }
              }
            }
          }
        }
      }
      elapsed_timestamp_nanos: 73821951490
    }
  }
}

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.metrics.DefaultNetworkRematchMetricsTest  \
      --update-device
Test: Manual:
   1. Change code to use TRANSPORT_CELLULAR
   2. m statsd_testdrive && statsd_testdrive -e 525
   3. Turn off mobile data.
Flag: EXEMPT controlled by kill switch
Bug: 419123367
Change-Id: I40ba78d81cd30b2dc783e855aa76e776f76ace98

Junyu Lai   commited 2025-06-05 02:22:03 +08:00
7516d81c87
Remove tests which are covered by EthernetManagerTest
Test interface tracking is already covered by EthernetManagerTest (in
fact, that test relies heavily on this functionality), so it does not
need to be part of EthernetTrackerTest. Additionally, both
isValidTestInterface() and setIncludeTestInterfaces() are trivial
functions that do not improve coverage significantly. Long-term, the
ethernet unit tests should be reimagined as more of a module-wide unit
test, rather than testing individual classes. This will make the tests
much more valuable and could allow testing scenarios that are not
possible in a end-to-end integration test.

Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I94540b6e7b94b1de00965f4e54393d573788c59a

Patrick Rohr   commited 2025-06-04 10:50:17 -07:00
50d7eee5a4
Merge "Make EthernetPort#toString more legible" into main
Maciej Żenczykowski   authored and   Android (Google) Code Review   commited 2025-06-03 12:25:00 -07:00
d6541b8daa