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
This refactoring changes how the bluetoothUseRandomAddress flag is
accessed.
PrivateAddressCoordinator is in a library used by multiple mainline
modules(Tethering, NetworkStack, CaptivePortal, WiFi) and cannot
directly read a Tethering mainline beta flag.
To fix this, the flag's value is now passed down through constructors.
An alternative solution would be to split the Java library for each module,
but with this solution, a single utility class cannot be shared.
This commit is a no-op as the passed value is hardcoded to false.
Test: TH
Flag: EXEMPT refactor
Bug: 287177081
Change-Id: I5f2174ee94b55e7a7298b9742221d6e6c3c5cac5
This a pure refactor commit that it adds two more parameters to the
existing ensureSufficientPermissionsForRequest() method to prepare it
for permission checking on NetworkSpecifiers.
The new parameters are not used in this CL and there are behavior
changes.
Bug: 374037595
Flag: EXEMPT pure refactor, no behavior changes
Change-Id: Ieb747794e250df9454b21f7c5a68fff590b70338
Use ArrayMap for mIpToNetworksMap instead of HashMap
for better memory efficiency and performance.
Bug: 429496715
Flag: EXEMPT trivial chage
Test: atest ConnectivityCoverageTests
Change-Id: I7a988ce16ef5d6c8fbd6b88ea0a2e932de07ad98
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
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
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
Since we update network lists mapped to InetAddress(mIpNetworksMap) for
socket destruction, compareAllAddresses should compare InetAddress list
instead of LinkAddress one.
Bug: 373280981
Flag: android.net.platform.flags.connectivity_service_destroy_socket
Test: atest ThreadNetworkIntegrationTests
Change-Id: I2ea0cce3cc2be648b142e3e9b17e9260f0d4ef96
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
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
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
* 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 Seoauthored and Android (Google) Code Reviewcommited 2025-05-30 16:00:11 -07:00
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
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
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
These fields are needed to answer:
1. Opt-in uid count in the device
2. How often do apps get on the satellite network
Test: TH
Flag: EXEMPT atom definition only change
Bug: 419123367
Change-Id: Iefebaa0d54b4b616e1b2a64a3357a0102ef61c1d
PermissionMonitor#startMonitoring() was renamed to initialize().
Update comments and local variables accordingly.
Flag: EXEMPT refactor
Test: TH
Bug: 410731080
Change-Id: I840b5172e1ebc761cade0e6082fec0cab7fe9a3b
As a follow-up to ag/33089478 and ag/33101784, the intent
receiving and dispatching logic was refactored and centralized
within the newly introduced BroadcastReceiveHelper.
However, due to the potential risks associated with this
refactoring, a kill switch is being added specifically for the
PermissionMonitor refactoring. This will allow for reverting
to the previous implementation (potentially involving code
duplication) to mitigate risks if issues arise.
Flag: EXEMPT flagged with a kill switch
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.PermissionMonitorTest \
ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest \
--update-device
Bug: 410731080
Change-Id: I7889ef457d841c750da60a80e50ed6208c45448f
For maintaining constrained data satellite opt-in apps, this is
needed for tracking apps installed on the storage.
Flag: EXEMPT flagged with a kill switch
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest \
--update-device
Bug: 410731080
Change-Id: I2a686a5a37747de97dcee6b78f66965cb4fd9942
When LinkProperties are updated after a private DNS configuration
is set in updateNetworkInfo(), particularly when private DNS mode
is set to opportunistic and the VPN server uses its own DNS
servers, this can cause the private DNS to use the underlying
network for TLS handshaking, potentially leading to a leak.
To fix this, adjusting the order of operations—setting the private
DNS configuration before updating LinkProperties should resolve
the issue. This ensures that private DNS validation occurs after
the VPN's network configuration is fully applied.
Bug: 274867806
Test: atest ConnectivityCoverageTests
Flag: EXEMPT legacy flag early_link_properties_update_for_vpn
Change-Id: If684b51e6522a8284d5baee8db0d2f767405d359
This feature will be controlled by the caller.
Cronet calls the register/unregisterQuicConnectionClosePayload APIs only
when the Chromium experiment flag is enabled
(http://crrev.com/c/6421621/).
This CL also updates testRegisterQuicConnectionClosePayload
to be skipped on U or older releases since FIREWALL_CHAIN_BACKGROUND is
supported on V or higher releases.
Flag: EXEMPT guarded by chromium flag
Bug: 311792075
Test: TH
Change-Id: Ib008e63c585cfe8775b25783cd55b0873bb5e2f0
This is needed for tracking the applications which opted-in to
use the constrained data satellite network as its default by
adding the following property to the <application> tag of its
manifest:
<property
android:name="android.telephony.PROPERTY_SATELLITE_DATA_OPTIMIZED"
android:value="<package name>" />
Flag: EXEMPT flagged with a kill switch
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest \
--update-device
Bug: 410731080
Change-Id: I00c0ce5e0d7aac1192272e79a19fbab4e3a5e6f1
* changes:
Add light-weight DefferedBroadcastReceiver for handling broadcast events
Move user intent reception out of SatelliteAccessController
Move user/package intent reception out of PermissionMonitor
Jean Chalardauthored and Android (Google) Code Reviewcommited 2025-04-23 21:50:19 -07:00
The PackageManager#getInstallPackagesAsUser method is time
consuming (30~200ms) and blocks boot time while it executes.
This change moves the getInstallPackagesAsUser
method from PermissionMonitor. This is a performance-focused
refactoring to allow for efficient sharing of package enumeration
results in subsequent changes, avoiding redundant time-consuming
operations.
Flag: EXEMPT refactor
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest \
ConnectivityCoverageTests: android.net.connectivity.com.android.server.ConnectivityServiceTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.PermissionMonitorTest \
ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.BroadcastReceiveHelperTest \
--update-device
Bug: 410731080
Change-Id: I3929fa28ff9419329622f3abdf10336289730607
This is a no-op refactoring that moves the reception of
user-related intents in SatelliteAccessController to
ConnectivityService.
It then dispatches these events to the SatelliteAccessController.
Flag: EXEMPT refactor
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest \
ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest
Bug: 410731080
Change-Id: I9ace3ed09a161446dc92d40bc0d400e32051de32
This is a no-op refactoring that moves the reception of
package and user-related intents in PermissionMonitor to
BroadcastReceiveHelper.
It then dispatches these events to the PermissionMonitor.
This change is necessary to centralize intent receivers
from other subclasses to ConnectivityService in
subsequent modifications.
This reverts the design change introduced in aosp/2183343, which
had PermissionMonitor listening to user change events instead
of ConnectivityService.
Flag: EXEMPT refactor
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.PermissionMonitorTest \
ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest \
ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.BroadcastReceiveHelperTest \
--update-device
Bug: 410731080
Change-Id: Ic79afc18a6e8603ddf8d48a1f78cf8d98f2447ae
- Also verify the netd operations that add and remove UID ranges.
- Don't set the network to keep connected, since that is not
representative of what happens on a real device.
Test: test-only change
Bug: 410731080
Flag: TEST_ONLY
Change-Id: Ib4305748b5f1627546b7a63fb9596308b14155e0
Lorenzo Colitticommited 2025-04-23 12:03:57 +09:00
This adds two new shell commands to ConnectivityService that sets
a given UID to fall back to a given transport type if there is no
system default network. The syntax is:
cmd connectivity set-debug-fallback-network-for-uid <uid> <transport>
cmd connectivity clear-debug-fallback-network-for-uid <uid>
This works only on debug builds and should be used only for
manual testing.
Test: none yet
Bug: 410731080
Flag: TEST_ONLY
Change-Id: I9e0ac0713dbb95e59b22faa7cd45bdc8c1070f08
Lorenzo Colitticommited 2025-04-22 22:46:34 +09:00
This makes the code clearer, and also fixes a bug: currently, a
TRACK_DEFAULT request in a multilayer request can cause a network
to remain needed. This is incorrect: only requests should be able
to keep a network up.
This prevents satellite networking from disconnecting when the
default network reappears (see changes in unit test).
This CL removes the code before the loop that special-cases
non-multilayer listens because it is not very useful. Any
non-multilayer listen will either:
- Immediately return false, if it's the active request, or:
- Cause the code to continue (because it's not the active
request), and because mRequests only has one element, will
hit the "return false" statement after the loop.
Flag: EXEMPT bug fix
Test: covered by existing tests
Change-Id: I7295ce469335af924aa20b7976cc4a9136ef5d61
Lorenzo Colitticommited 2025-04-22 22:02:40 +09:00
There are currently 6 or 7 contructors, and some code duplication.
Reduce this to one constructor per use case (callback-based;
PendingIntent based; internal), and use a private constructor to
reduce code duplication.
Bug: 410731080
Flag: EXEMPT refactor
Test: refactor covered by existing tests
Change-Id: I49337374990d646bf5526354cceeea83f3b9c980
Lorenzo Colitticommited 2025-04-22 22:02:33 +09:00