Commit graph android_packages_modules_Co.../tests/unit/java
Message SHA1
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
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
Add golden sample test for storing transport types kill switch support
This test uses a golden sample to verify that the file reading
results are as expected when the storing transport types feature
is either enabled or disabled. This is to ensure compatibility
when the feature is remotely disabled.

The golden sample is taken from a test device after manually
performing a file download.

Flag: EXEMPT test only
Test: atest ConnectivityCoverageTests:android.net.connectivity.android.net.NetworkStatsCollectionTest \
      --update-device
Test: Manually:
      1. adb shell device_config put tethering store_transport_types 1
      2. Download files
      3. adb shell dumpsys netstats --poll
      4. adb pull /data/misc/apexdata/com.android.tethering/netstats .
      5. Check-in the active netstats_uid* file.

Bug: 419123367
Change-Id: I266d07703f3ad47239d9c6721cdcd417ae4f179f

Junyu Lai   commited 2025-06-12 13:31:38 +08:00
76a774c21a
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
Merge "Refactor: Pass parameterized argument via test constructor" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-01 21:09:55 -07:00
7b633c65ef
Update start timestamp for querying data usage
The previous implementation used a fixed start timestamp for
querying network usage statistics, initialized based on the
device's boot time. This caused the query window to grow
indefinitely as the device uptime increased, leading to
inefficient queries that fetched and processed a large
ever-expanding amount of historical data.

This change refactors the logic to use a rolling start
timestamp. The `mStartTime` is now updated after each
usage report is generated (in `onLost`). By resetting
the start time to a more recent point (current time
minus one bucket duration), we ensure that subsequent
queries for usage snapshots are performed over a small,
manageable time window.

This optimization prevents fetching excessive data
from the NetworkStatsManager, improving the efficiency
of the metrics collector. Dependencies for time and
duration have also been abstracted for better testability.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.metrics.SatelliteCoarseUsageMetricsCollectorTest \
  --update-device
Flag: EXEMPT controlled with kill switch
Bug: 419123367
Change-Id: I49d3b044f0a038093060f5541ea263d2d0d253a2

Junyu Lai   commited 2025-05-31 16:37:59 +08:00
48c3c2bf10
Report satellite coarse usage
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.metrics.SatelliteCoarseUsageMetricsCollectorTest \
      --update-device
Test: atest ConnectivityCoverageTests --test-filter 'CSTest*' --update-device
Test: atest ConnectivityCoverageTests --test-filter 'ConnectivityService*' --update-device
Test: Manual:
  1. Change code to use TRANSPORT_CELLULAR
  2. m statsd_testdrive && statsd_testdrive -e 1102
  3. Turn off mobile data.
Flag: EXEMPT controlled with kill switch
Bug: 419123367
Change-Id: I264efa6802612809fdbff22901f31447f370bbe5

Junyu Lai   commited 2025-05-31 16:37:59 +08:00
bb589cf33c
Merge changes from topic "destroy_socket_at_cs" into main
* changes:
  Destroy sockets lacking permission at CS.
  Destroy sockets with nlmsg RTM_DELADDR
  Destroy sockets with NetworkAgent update event
  Add a Map to NetworkAgent list for IP address
  Add socket destroying methods to InetDiagMessage.

Sewook Seo   authored and   Android (Google) Code Review   commited 2025-05-30 16:00:11 -07:00
13e6742742
Make EthernetPort#toString more legible
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I6abf322a57412edf97b20d6b96ca5747938fd1ea

Patrick Rohr   commited 2025-05-30 13:30:53 -07:00
1185d242a6
Destroy sockets lacking permission at CS.
Move destroying socket logic for lacking permission to CS from netd

Bug: 373280981
Bug: 331139818
Flag: android.net.platform.flags.connectivity_service_destroy_socket
Test: atest ConnectivityCoverageTests
Test: device test

Change-Id: Id933d51d6175958a1b78443360858db577319622

Sewook Seo   commited 2025-05-29 20:15:47 -07:00
34ef7dbd1b
Destroy sockets with nlmsg RTM_DELADDR
Destroy sockets that matched to netId less than MIN_NET_ID for the non
link local address in RTM_DELADDR.
Destroy sockets on link local address with the corresponding interface
ID.

Bug: 373280981
Bug: 331139818
Flag: android.net.platform.flags.connectivity_service_destroy_socket
Test: atest ConnectivityCoverageTests
Test: device test
Change-Id: I4d8127fc693f8b32f815c5cddbae0b64deeb23e5

Sewook Seo   commited 2025-05-29 20:14:13 -07:00
fe1f5cbf32
Destroy sockets with NetworkAgent update event
Destroy platform managed sockets on the removed IP address based on NetworkAgent update.

Bug: 373280981
Bug: 331139818
Flag: android.net.platform.flags.connectivity_service_destroy_socket
Test: atest ConnectivityCoverageTests
Test: device test
Change-Id: I6a1d2d0c25c130c2747d66bee203b0408e2fa0da

Sewook Seo   commited 2025-05-30 03:10:38 +00:00
1af98cb493
Add a Map to NetworkAgent list for IP address
Keeping a map from IP addresses to the list of NetworkAgentInfos that have
that IP address in their LinkProperties.

Bug: 373280981
Bug: 331139818i
Flag: android.net.platform.flags.connectivity_service_destroy_socket
Test: atest ConnectivityCoverageTests
Test: device test
Change-Id: I1e39ce00d8bc49252df8088efc768804ae9ee0a8

Sewook Seo   commited 2025-05-27 22:59:43 +00:00
720ccd2b32
Support matches transport types in NetworkTemplate
Flag: EXEMPT implemented in the counter-part CL
Test: atest CtsNetTestCases --test-filter \
      'NetworkStats*' --update-device
Test: atest ConnectivityCoverageTests --test-filter \
      'NetworkStats*' --update-device
Test: atest ConnectivityCoverageTests --test-filter \
      'NetworkTemplate*' --update-device
Bug: 419123367
Change-Id: I0c8bf2e24502befd810081f519ff915491b0a905

Junyu Lai   commited 2025-05-27 20:35:40 +08:00
3fd36e5f93
Merge "Fill Opt-in uid count in ConnetivityStateSample" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-27 04:28:58 -07:00
3e75b9025d
Fill Opt-in uid count in ConnetivityStateSample
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.metrics.ConnectivitySampleMetricsTest \
  --update-device
Flag: EXEMPT controlled with kill switch
Bug: 419123367
Change-Id: I95376e30e160b4db00d018a0919be98b37d44e5e

Junyu Lai   commited 2025-05-27 17:41:47 +08:00
5b061066c9
Merge "Add NetworkCapabilities transport types into NetworkIdentity." into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-27 00:41:35 -07:00
2a4acb194c
Refactor: Pass parameterized argument via test constructor
Moves the parameterized variable into the test class constructor for cleaner initialization
and improved test flexibility.

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

Jimi Chen   commited 2025-05-26 06:52:12 +00:00
20be055148
Merge "Use lisOf in parameterized test parameters" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-05-25 20:47:08 -07:00
147d357fe1
Add NetworkCapabilities transport types into NetworkIdentity.
This change updates NetworkIdentity to have NetworkCapabilities
transport types for improved network identification, and updates
NetworkIdentitySet for backward compatibility with older data.

Flag: EXEMPT implemented in the counter-part CL
Test: atest ConnectivityCoverageTests --test-filter \
      'NetworkIdentity*' --update-device
Test: atest ConnectivityCoverageTests --test-filter \
      'NetworkStats*' --update-device
Bug: 419123367
Change-Id: I26cc770d90b4687d832dd029d9a11db03404db39

Junyu Lai   commited 2025-05-24 00:30:41 +08:00
bebd4090ae
Merge "Fix kotlin lint errors in NetworkTemplateTests" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-23 03:25:06 -07:00
74b2e40e52
Merge "Truncate the additional records if the packet is too large" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-05-23 01:01:05 -07:00
f79d1bd53d
Fix kotlin lint errors in NetworkTemplateTests
Flag: EXEMPT Test only refactor
Test: atest ConnectivityCoverageTests --test-filter \
  'NetworkTemplate*' --update-device
Bug: 419123367
Change-Id: I7f87c4a9f4f3e40c0274bf6539ccff4e42967cc8

Junyu Lai   commited 2025-05-23 15:34:53 +08:00
ab696ccc1b
Truncate the additional records if the packet is too large
When the packet is too large to be sent it may cause the socket to throw
an error. This commit truncates the additional records in this case.

Bug: 407609792
Test: CI
Flag: EXEMPT bugfix

Change-Id: I77a979d7f8799f05cbcb14857061a18aecfef657

Handa Wang   commited 2025-05-22 21:38:55 -07:00
8f8c78d56f
Use lisOf in parameterized test parameters
Flag: EXEMPT mainline
Bug: 410976315
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.MultinetworkPolicyTrackerTest
Change-Id: Ib3fef2982b50ac0642da9bca46123651f8e0a228

Jimi Chen   commited 2025-05-22 08:04:04 +00:00
99bf60dee5
Revert^2 "Check whether CarrierConfigManager is null"
This reverts commit 7b7cfa45a6.

Reason for revert: prevents crash with no carrierConfigManager support
Test: atest ConnectivityCoverageTests

Change-Id: I9e91d2d25d16c0c2a39388f08a49bef7b17fda42

Jimi Chen   commited 2025-05-21 07:24:00 +00:00
232c944de3
Merge "Revert "Check whether CarrierConfigManager is null"" into main
Priyanka Advani (xWF)   authored and   Android (Google) Code Review   commited 2025-05-20 14:22:25 -07:00
730bb0bfe9
Revert "Check whether CarrierConfigManager is null"
This reverts commit b936f0c5fd.

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

Fix: 418898788
Change-Id: Ia47f0cc9a33ed33f9d53064878992081a792f1ad

Priyanka Advani (xWF)   authored and   Android (Google) Code Review   commited 2025-05-20 11:19:03 -07:00
7b7cfa45a6