Commit graph android_packages_modules_Co.../service/src/com/android/server/ConnectivityService.java
Message SHA1
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
Pass bluetoothUseRandomAddress via RoutingCoordinator constructor
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

Motomu Utsumi   commited 2025-07-15 11:20:01 +09:00
323d22a497
Merge "ArrayMap for mIpToNetworksMap" into main
Sewook Seo   authored and   Android (Google) Code Review   commited 2025-07-07 04:49:48 -07:00
adfbfab056
Merge "[connectivity] refactor ensureSufficientPermissionsForRequest()" into main
Kangping Dong   authored and   Android (Google) Code Review   commited 2025-07-07 01:02:40 -07:00
ffe9cfb209
[connectivity] refactor ensureSufficientPermissionsForRequest()
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

Kangping Dong   commited 2025-07-07 14:31:45 +08:00
1bc657fa4b
ArrayMap for mIpToNetworksMap
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

Sewook Seo   commited 2025-07-06 17:13:45 +00:00
4a56e548dd
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
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
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
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
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
Compare InetAddress to update mIpNetworksMap
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

Sewook Seo   commited 2025-06-10 09:14:45 +00:00
af5eba5be2
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
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
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
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
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
Add atom definition for satellite access info
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

Junyu Lai   commited 2025-05-24 11:35:19 +08:00
0c5d445486
Update comments and local variables
PermissionMonitor#startMonitoring() was renamed to initialize().
Update comments and local variables accordingly.

Flag: EXEMPT refactor
Test: TH
Bug: 410731080
Change-Id: I840b5172e1ebc761cade0e6082fec0cab7fe9a3b

Junyu Lai   commited 2025-05-19 02:20:12 -07:00
871e7ea684
Enable REQUEST_RESTRICTED_WIFI and CARRIER_SERVICE_CHANGED_USE_CALLBACK by default with kill switch
Bug: 416044405

Test: atest ConnectivityManagerTest
      atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest
Change-Id: I1b67c00ce3d4054414ce9c538ec4d7b9a55b4302
Flag: com.android.net.flags.request_restricted_wifi

Ying Xu   commited 2025-05-14 10:56:45 -07:00
7e4e0952f8
Merge "Implement network avoid bad wifi from carrier config" into main
Jimi Chen   authored and   Android (Google) Code Review   commited 2025-05-08 17:46:53 -07:00
ae13aeb0fd
Add Kill Switch for PermissionMonitor Refactoring
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

Junyu Lai   commited 2025-05-08 19:01:25 +08:00
638c43f201
Implement network avoid bad wifi from carrier config
Flag: android.net.platform.flags.avoid_bad_wifi_from_carrier_config
Bug: 410976315
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.MultinetworkPolicyTrackerTest
Change-Id: I89c579a8d5c7299303278280c463aa4c7c5bea99

Jimi Chen   commited 2025-05-08 07:25:36 +00:00
0881fc0a7d
Merge "Update link properties early for VPN networks" into main
Paul Hu   authored and   Android (Google) Code Review   commited 2025-05-07 22:28:58 -07:00
c360088112
Merge "Listen to onExternalApplicationsAvailable in SatelliteAccessController" into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-04-28 06:37:49 -07:00
bc08a1ffcb
Listen to onExternalApplicationsAvailable in SatelliteAccessController
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

Junyu Lai   commited 2025-04-28 16:35:36 +08:00
63dbd3ec93
Update link properties early for VPN networks
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

Paul Hu   commited 2025-04-28 01:16:25 -07:00
515efcf47d
Merge changes I579b3cd9,Ib008e63c into main
* changes:
  Allow QuicConnectionCloser to close loopback QUIC connection
  Enable QUIC connection close by default in ConnectivityService

Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-04-27 22:20:38 -07:00
5ae058b9d4
Enable QUIC connection close by default in ConnectivityService
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

Motomu Utsumi   commited 2025-04-28 12:52:58 +09:00
2ea5939672
Support dumpsys for SatelliteAccessController
Sample output:
SatelliteAccessController:
  Sms-Role Apps: {0={10138}}
  Opt-In Uids: {10123}

Flag: EXEMPT flagged with a kill switch
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.SatelliteAccessControllerTest \
      --update-device
Bug: 410731080
Change-Id: Ib868d61b9b1c1b5d8adde4d78b6d005a57d5526d

Junyu Lai   commited 2025-04-28 10:21:57 +08:00
809869a8ee
File the per-app request for opted-in satellite-optimized apps
Test: ConnectivityCoverageTest
Bug: 410731080
Flag: EXEMPT controlled in counter-part change ag/33220291
Change-Id: I0307f697a441c2810cafd4643d381e66a0ac9243

Chalard Jean   commited 2025-04-27 02:12:44 +09:00
76a60c1654
Merge "Maintain a set self-certified apps in SatelliteAccessController" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-04-24 22:48:53 -07:00
2f92579f8a
Maintain a set self-certified apps in SatelliteAccessController
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

Junyu Lai   commited 2025-04-25 10:35:31 +08:00
fbe94c3b00
Merge "Move package enumeration out of PermissionMonitor" into main
Junyu Lai   authored and   Android (Google) Code Review   commited 2025-04-23 22:43:39 -07:00
4aa806dc20
Merge changes Id6191d5a,I9ace3ed0,Ic79afc18 into main
* 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 Chalard   authored and   Android (Google) Code Review   commited 2025-04-23 21:50:19 -07:00
0d578113f7
Move package enumeration out of PermissionMonitor
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

Junyu Lai   commited 2025-04-24 11:43:11 +08:00
830b579081
Move user intent reception out of SatelliteAccessController
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

Junyu Lai   commited 2025-04-24 10:50:44 +08:00
b14633ea2f
Move user/package intent reception out of PermissionMonitor
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

Junyu Lai   commited 2025-04-24 10:50:44 +08:00
8b1fe1976b
Improve the tests for the fallback network shell command.
- 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 Colitti   commited 2025-04-23 12:03:57 +09:00
c9baec4101
Add a shell command to set an app's fallback default network.
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 Colitti   commited 2025-04-22 22:46:34 +09:00
4a8e41d2ae
Simplify and correct isNetworkPotentialSatisfier.
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 Colitti   commited 2025-04-22 22:02:40 +09:00
dd577efdde
Simplify NetworkRequestInfo constructors.
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 Colitti   commited 2025-04-22 22:02:33 +09:00
f984b780ac
Merge "Style improvements to removeDefaultNetworkRequests." into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-04-21 00:19:58 -07:00
4f3632b57f
Merge "Minor refactoring of per-app fallback requests." into main
Treehugger Robot   authored and   Android (Google) Code Review   commited 2025-04-20 22:40:31 -07:00
9449d15813