Commit graph

111,367 commits

Message SHA1
Introduce carrier-aware avoid bad Wi-Fi APIs
This commit introduces new system APIs to manage "avoid bad Wi-Fi" settings,
leveraging both global system settings and carrier configurations. This
enhancement allows for more granular control and visibility into how Wi-Fi
networks are managed, especially in multi-SIM environments.

The new `setNetworkAvoidBadWifi(Context, int subId)` method provides
the ability to programmatically control this setting based on carrier-specific
policies or user preferences. This complements `getNetworkAvoidBadWifi(Context, int subId)`,
which allows querying the setting for a specific subscription ID, ensuring the
system can accurately determine the avoid bad Wi-Fi status.

Additionally, `shouldShowAvoidBadWifiToggle(Context, int subId)` is introduced.
This method determines whether the 'Avoid Bad Wi-Fi' user interface toggle
should be displayed. It considers both global settings and carrier configurations,
allowing for dynamic UI adjustments based on carrier requirements or user preferences.

These changes provide greater flexibility for managing Wi-Fi network selection
and improve the user experience by offering more context-aware control over
cellular behavior.

Deprecated APIs:
- `setNetworkAvoidBadWifi(Context, int value)`
- `getNetworkAvoidBadWifi(Context)`
New APIs:
- `setNetworkAvoidBadWifi(Context, int subId, int value)`
- `getNetworkAvoidBadWifi(Context, int subId)`
- `shouldShowAvoidBadWifiToggle(Context, int subId)`

Flag: com.android.net.flags.carrier_aware_avoid_bad_wifi
Bug: 410976315
Test: atest ConnectivityCoverageTests:android.net.connectivity.android.net.ConnectivitySettingsManagerTest
Change-Id: I79469cfe865a585593219d226c8198206c06b589

Jimi Chen   commited 2025-06-10 12:18:35 +00:00
92e23acebb
Merge "Expose NetworkTemplate get/set transport type APIs" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-06-10 03:10:42 -07:00
5548278f28
Merge changes Ib28a762e,I35d2f50e,I881f14e9,I6382df96 into main
* changes:
  Make function void and remove outdated TODOs
  Remove mTetheringInterfaceHwAddr
  Log mPort when restarting IpClient
  s/getAllInterfaces/getAllEthernetPorts/g

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-10 01:22:58 -07:00
a4b1d41c35
Merge "Add getInterfaceMtu method in ProcfsParsingUtils" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-06-10 00:31:57 -07:00
b91b3afcd0
Merge "Replace String.split() with precompiled regex" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-09 21:15:55 -07:00
8f93c27ff9
Add getInterfaceMtu method in ProcfsParsingUtils
Flag: EXEMPT mainline
Bug: 406085682
Test: atest NetworkStackTests:com.android.networkstack.util.ProcfsParsingUtilsTest
Change-Id: I62e129c3903e0c432f4a4d84c7024cfb4e140dd5

Jimi Chen   commited 2025-06-10 03:07:10 +00:00
991a628dfe
Make function void and remove outdated TODOs
b/236892130 has long been addressed and there is an existing integration
test (EthernetManagerTest#testRemoveInterface_whileInServerMode).

The second TODO is just wrong. removeInterface() does nothing when the
interface is currently in tethering/server mode which is expected.
EthernetTracker#removeInterface() correctly deals with both client and
tethering/server mode interfaces, and multiple tests exist that validate
the callback behavior.

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

Patrick Rohr   commited 2025-06-09 19:43:36 -07:00
1a488e767d
Remove mTetheringInterfaceHwAddr
Since mTetheringInterface is now of type EthernetPort which contains the
MAC.

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

Patrick Rohr   commited 2025-06-09 19:43:36 -07:00
927c0f6668
Log mPort when restarting IpClient
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I881f14e9560b720fbcefdd3b599f0f14f029f49c

Patrick Rohr   commited 2025-06-09 19:43:36 -07:00
b3a78c0836
s/getAllInterfaces/getAllEthernetPorts/g
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I6382df9696c852fa51ee99b03d4475fa921c3ecd

Patrick Rohr   commited 2025-06-09 19:43:36 -07:00
14b9748fd0
Merge "bpf/progs/netd.c: increase per uid map sizes" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-09 17:10:00 -07:00
7366288354
bpf/progs/netd.c: increase per uid map sizes
Some devices are hitting limits, but these
maps are small.

Additionally one is indexed by app uid,
while the other by unix uid.

Where unix uid = nr Android users * nr app uids.

Give things a little bit more room for growth.

Also remove the useless constant from the .h,
most - if not all - of them should not be there.

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

Maciej Żenczykowski   commited 2025-06-09 15:17:01 -07:00
48879625cf
Add native call to retrieve driver name via ethtool API
This adds a JNI function to retrieve an interface's driver name via
ethtool API, which will be used to identify USB NCM interfaces.

Unfortunately, SIOCETHTOOL (ETHTOOL_GDRVINFO in particular) does not
allow passing in the interface index, meaning that this operation is
racy, i.e. the interface might have been replaced when
getDriverNameForInterface() is called.

SICOETHTOOL is slowly being replaced by a netlink alternative that
allows querying by interface index but, unfortunately, does not support
ETHTOOL_GDRVINFO yet.

Test: verified manually; automated test will be added shortly.
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I8bec47e36a607e7d8fe2fac2eebcd8dff0360a02

Patrick Rohr   commited 2025-06-09 14:54:38 -07:00
0eaec731ec
Merge "NetBpfLoad: add self-check for bpfGetNext{Prog,Map}Id()" into main
Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-06-09 10:29:00 -07:00
9e2cf07fbc
Merge "Fix netbpfload version info." into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-09 10:11:30 -07:00
3c89d0be7e
Fix netbpfload version info.
(This is viable now that tethering prebuilt is from M-2025-07)

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

Maciej Żenczykowski   commited 2025-06-09 08:23:06 -07:00
f51c1857c7
NetBpfLoad: add self-check for bpfGetNext{Prog,Map}Id()
This detects some kernel bugs, particularly on Xiaomi devices.

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

Maciej Żenczykowski   commited 2025-06-09 01:14:56 -07:00
18523cb5f3
Merge "Add NetworkTemplate get/set transport type methods" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-09 00:35:49 -07:00
206cf6b8a6
Expose NetworkTemplate get/set transport type APIs
This is needed for counter-part modules to query data usage
with specified transport type.

Flag: com.android.net.flags.netstats_transport_type
Test: atest ConnectivityCoverageTests --test-filter \
'NetworkTemplate*' --update-device
Bug: 419123367
Bug: 420531377

Change-Id: I7778de815bec947be3e6abbd6269e1727de5c550

Junyu Lai   commited 2025-06-08 23:14:07 -07:00
19ff6a1025
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 "Use multicast socket for group membership" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-06-08 20:53:07 -07:00
7353a461da
Replace String.split() with precompiled regex
String.split() will allocate and compile the given regex on every call.
The networkstack process spends 2.8% of cycles doing this.

https://pprof.corp.google.com/?id=%2Fcns%2Fpf-d%2Fhome%2Fandroid-telemetry-pitot-pprof-prod-data-owner%2Fstack_sampling_pprof%2F2025-06-07%2Fstack-sampling-pprof-6187fab4-56da-4842-b9c3-9d8db45801d1.pb.gz&metric=samples&filter=hide:%255Enterp_helper%2524,focus:regex%257Csplit&pivot=com.android.networkstack.com.android.net.module.util.ProcfsParsingUtils

I randomly noticed this while looking at CPU profiles.

Flag: EXEMPT refactor
Test: ApfFilterTest and any others that may be exercising the code
Change-Id: I811c0e8982a87d10fedcda93379b08e8ab38a11b

Shai Barack   commited 2025-06-07 19:46:06 -07:00
7c0faeeb68
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 updateInterfaceState
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: Id0c9cc4fd054f4e7096e0bf45ee3ffb5a9085698

Patrick Rohr   commited 2025-06-06 12:14:51 -07:00
ff317e73ef
Remove spurious VisibleForTesting and change visibility to public
The visibility modifiers in this file are all over the place. In
general, I would like to get to private / public where possible so the
code becomes more readable.

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

Patrick Rohr   commited 2025-06-06 12:14:51 -07:00
8191dd61c3
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
Pass EthernetPort to removeInterface
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: I4fd6658e95d65c65dad95b0a28f6878e4f5119fd

Patrick Rohr   commited 2025-06-06 12:14:51 -07:00
d5159a9c5f
Pass EthernetPort to stopTrackingInterface
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: Ia96d35041cbfedb3fd4f67d43bb7238bfdd86d40

Patrick Rohr   commited 2025-06-06 12:14:51 -07:00
88fdbf3093
Add getEthernetPorts and use it in getAllInterfaces
This CL adds getEthernetPorts() to EthernetNetworkFactory which returns
an unsorted list of EthernetPorts tracked by the factory (including
restricted interfaces).

This method is then used inside getAllInterfaces(), which in turn is
called by setIncludeTestInterfaces() and setEthernetEnabled().
setIncludeTestInterfaces() is not used in production code, so the
interface order should not matter. However, with this change
setEthernetEnabled() will update the administrative state of the network
interfaces in unspecified order. It is hard to conceive that this could
break anything, given that when tracking multiple interfaces, link state
changes (which trigger the same InterfaceStateCallback) can already
naturally occur in any order.

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

Patrick Rohr   commited 2025-06-06 12:14:18 -07:00
92077d1530
Rename getClientModeInterfaces to getClientModeInterfacesSorted
Test: TH
Flag: EXEMPT mainline
Bug: 1000001
Change-Id: Id33fb7200bc5927e05dfdd9926c392e973c1e58b

Patrick Rohr   commited 2025-06-06 11:29:38 -07:00
33782457b6
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 NetworkInterfaceState
mPort replaces name and mHwAddress.

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

Patrick Rohr   commited 2025-06-06 11:29:38 -07:00
d8f56bd600
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
Use multicast socket for group membership
Replace `ip addr` command with `multicastSocket` to join multicast groups.
This change improves robustness and directly leverages Java's networking capabilities for multicast management.

Flag: EXEMPT mainline
Bug: 419423721
Test: atest CtsConnectivityMultiDevicesTestCases:ApfV6Test
Change-Id: I2c941594985d98f86a4a91c9c9cd425eb75e8e97

Jimi Chen   commited 2025-06-06 13:48:18 +00:00
2474cc54e3
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 "DHCPv6 addr reg: parse IA Address option." into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-06-06 00:24:14 -07:00
1578e464f6
DHCPv6 addr reg: parse IA Address option.
Flag: EXEMPT guarded by an legacy experiment flag
Bug: 293393743
Test: TH
Change-Id: I29d201a69af220af00deb9e1b1d0c1253faa6200

Xiao Ma   commited 2025-06-06 14:37:50 +09:00
a129f4c5cd
Merge changes I9a57bb86,Ifbeb1187 into main
* changes:
  Pass EthernetPort to addInterface
  Change tethering interface to EthernetPort

Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-06-05 15:43:01 -07:00
594bd4bb56
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
Pass EthernetPort to addInterface
The netd dependency can be removed in a follow up change. Since the only
entrypoint to addInterface() is now EthernetNetlinkMonitor which calls
both addInterface() and updateInterfaceState(), the "IF_FLAG_RUNNING"
check inside addInterface() is no longer needed.

Also note that this change relies on the representation of
getMacAddress().toString() to match what netd returns. Configuration by
MacAddress is almost solely used by automotive devices which do not take
mainline, so making this change is relatively low-risk. In the unlikely
case automotive OEMs are broken by this, they have time to fix their
config overlays.

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

Patrick Rohr   commited 2025-06-05 11:40:58 -07:00
78956b3abb
Change tethering interface to EthernetPort
Note that the comparison is still solely based on interface name.

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

Patrick Rohr   commited 2025-06-05 11:40:58 -07:00
37edbb5105
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
Merge "DHCPv6 addr reg: add ADDR_REG_INFORM packet class." into main
Patrick Rohr   authored and   Android (Google) Code Review   commited 2025-06-04 19:56:10 -07:00
d5bb7759e4