Commit graph android_packages_modules_Co.../service/src/com/android/server/ConnectivityService.java
Message SHA1
Add a queue system server-side for NetworkAgent
The intent is to remove the queue on the NetworkAgent side.
This queue is triggered with the same conditions as the
existing one.

Test: ConnectivityCoverageTests, CtsNetTests
Change-Id: I4bc29b10e48e13cdf3c3a8a15a7c8d15954d2457

Chalard Jean   commited 2025-03-14 13:23:50 +09:00
34ccc71462
Unify registration and NM assignment in NAI
Registration is marked by the creation of the network monitor
for a given network agent. This patch makes this fact much
more ovbious.

Test: CtsNetTests ConnectivityCoverageTests
Change-Id: I94a56b2bce6f453322b1eb91d6a6f14b31e7a95f

Chalard Jean   commited 2025-03-14 13:23:50 +09:00
2e2f5faecd
Return the registry in registerNetworkAgent.
This is a resubmit of
I0fd90716b9f5501bdcdc7ee5165321737a0076ae
which did not account for testing of this private method
in Telephony tests.

Also make the network agent registry two way to eliminate
reordering possibilities.

Test: ConnectivityCoverageTest, CtsNetTests
Change-Id: I9ca025b1369dcb1202f906d5cff79e3d935b40da

Chalard Jean   commited 2025-03-14 13:23:50 +09:00
80d4326d76
Revert "Return the registry in registerNetworkAgent."
This reverts commit 70ede3260c.

Reason for revert: Likely culprit for b/402365566 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Change-Id: If72cc264c5e505348309c6c11dbbfd11adeaf31b

Chaitanya Cheemala (xWF)   authored and   Gerrit Code Review   commited 2025-03-11 06:05:49 -07:00
846fb39e8a
Return the registry in registerNetworkAgent.
Also make the network agent registry two way to eliminate
reordering possibilities.

Test: ConnectivityCoverageTest, CtsNetTests
Change-Id: I0fd90716b9f5501bdcdc7ee5165321737a0076ae

Chalard Jean   commited 2025-03-11 16:26:17 +09:00
70ede3260c
Merge "Enable early native network creation for local network" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-03-09 20:53:11 -07:00
daa1f52b02
Enable early native network creation for local network
This is needed by tethering local network feature, given that
the IpServer needs to setup forwarding after native network
creation and before signaling network availability.

Test: atest CtsNetTestCases:android.net.cts.NetworkAgentTest \
      ConnectivityCoverageTests:android.net.EthernetTetheringTest \
      ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest \
      --update-device
Bug: 349487600
Change-Id: I2bc2ec355e01be661b587406bd127dff11665047

Junyu Lai   commited 2025-03-10 10:31:11 +08:00
91ef9d38e3
Merge "Fix wrong condition for blocked status tracking wtf log" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2025-03-09 16:44:22 -07:00
f498a21182
Merge "Adding more test cases for stacked link properties for local network." into main
Sarup Dalwani   authored and   Gerrit Code Review   commited 2025-03-01 10:03:31 -08:00
9de6f57d2d
Merge "Fix : crash ConnectivityService when PendingIntent is canceled" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2025-02-26 22:17:11 -08:00
5c909394a6
Fix : crash ConnectivityService when PendingIntent is canceled
PendingIntent.send will throw CanceledException when the intent
can't be sent, because it was canceled or some other reason. In
some, but not all of these cases, it will still call onSendFinished
after the send is done. This means there is no way to be sure
to do something exactly once after the intent is sent.

Unfortunately, ConnectivityService must keep a wakelock until
sent is finished, and wakelocks must be released exactly once.
Too bad.

The simplest solution is to create a specialized listener object
that can manage the lifecycle of the wakelock. This allows
very localized code, easy review and checking, cheap thread
safety, and not creating multiple locks. It also avoids the
ConnectivityService class implementing OnFinished itself,
which is arguably not very readable considering how big
the class is.

Test: new test that crashes the system without the patch
Fixes: 390043283
Change-Id: Ice528eddaedb4d663098eb2bb0ae7183dafbc073

Chalard Jean   commited 2025-02-27 11:46:06 +09:00
f34735ebdc
Enable NetworkCallback optimizations by default.
These optimizations are already launched to all public Pixel
devices and were in in 25Q2 beta releases as well. Enable them
by default on all supported releases. The appcompat risk is very
low (these changes are difficult even for an app to detect if
it's looking for them), the user benefits are substantial, and
there is a kill switch if any unforeseen issues do occur.

Bug: 327038794
Test: both codepaths are covered by existing tests
Change-Id: I42c7ceb71ef02d078bf4563744cb11afd412f267

Lorenzo Colitti   commited 2025-02-26 04:24:58 +09:00
2169522878
Adding more test cases for stacked link properties for local network.
Addressing feedback from previous change "Adding stacked link addresses
to local_net_access map" and adding more test cases for impact of
stacked link properties on local network prefixes.

Bug: 369815823
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSLocalNetworkProtectionTest
Change-Id: I4d32d86d3e083a1a14b845583fd80a7a4b18ae5f

Sarup Dalwani   commited 2025-02-20 05:46:02 +00:00
e53faa4e84
Check local network permissions when permission changes, or when user or
packages is added or removed

Bug: 388803658
Test: atest ConnectivityCoverageTests

Change-Id: I7d098c4d9a7614d0bd40ae23869a2010ee3f0779

Jacque Li   authored and   Neha Raj   commited 2025-02-20 04:59:45 +00:00
8d5c6eae80
Merge "Adding stacked link addresses to local_net_access map" into main
Sarup Dalwani   authored and   Gerrit Code Review   commited 2025-02-19 19:01:55 -08:00
c42f5fc47f
Start L2capNetworkProvider in CS
Starts L2capNetworkProvider in ConnectivityService. Alternatively, this
could be moved to ConnectivityServiceInitializer instead in a follow up.

When L2capNetworkProvider is created, it starts a handler thread, so
makeL2capNetworkProvider must return null in tests as otherwise the
thread leaks.

Test: atest NetworkReservationTest
Change-Id: I35c14815b1a71f0739c1bf63ad466763d611434c

Patrick Rohr   commited 2025-02-18 19:19:22 -08:00
611ce3f57c
Adding stacked link addresses to local_net_access map
Iterating over stacked link address to ensure correct mapping for
interface to local network ip prefixes.

Bug: 369815823
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSLocalNetworkProtectionTest
Change-Id: I3b2ed906caf43584ffb0e8041f9302c760099f7b

Sarup Dalwani   commited 2025-02-18 19:30:12 +00:00
7d0fcbb0d3
Exclude dns servers from LNP
Whenever ip interface is updated, we are updating local network
addresses. These may include dns servers that are needed to be excluded from
restrictions.

Bug : 393354879
Test: Manually and atest
ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSBpfNetMapsTest

Change-Id: Id4ebb33ab7de84ac1c81d485e599779c460bacdc

Neha Raj   commited 2025-02-18 03:28:42 +00:00
4792cc5d98
Populating local addresses to local_net_access_map
Whenever LinkProperties is added/modified/removes, we are updating local
network prefixes for the modified interface/addresses. These prefixes
are used by BPF egress and ingress cgroup hooks to disallow local
network packets if the calling application do not have required
permission.

Bug: 369815823
Test: Manually tested
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSLocalNetworkProtectionTest
Change-Id: Ie592ecb948ae05a0a73f47d0573560eb705f6bcf

Sarup Dalwani   commited 2025-02-17 20:34:41 +00:00
18b7262f60
Fix wrong condition for blocked status tracking wtf log
nri must be tracked for sending blocked status if
shouldTrackUidsForBlockedStatusCallbacks() && nri.mMessenger != null
is true. See trackUidAndMaybePostCurrentBlockedReason.
nri for pendingIntent which has null mMessenger and nonNull
mPendingIntent does not needed to be tracked since blocked status change
does not trigger anything.

Bug: 394732798
Test: testRegisterNetworkCallback_withPendingIntent
Change-Id: Ie97984c241e55cb1350438af4d5f1daf579e0830

Motomu Utsumi   commited 2025-02-05 23:37:51 -08:00
fa78c92bfa
Merge "Add missing permission check to offerNetwork" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-06 15:07:04 -08:00
1a76b01c08
Add missing permission check to offerNetwork
The missing permission check means that an unauthorized app could
have registered a network offer to intercept all NetworkRequests (by
trivially guessing an existing provider ID) which would have leaked
information about other apps on the system.

This adds a NETWORK_FACTORY or MAINLINE_NETWORK_STACK permission check
to offerNetwork per the API annotations in ConnectivityManager.
Test networks can be offered when holding the MANAGE_TEST_NETWORKS
permission which is consistent with similar APIs in this class.

There can be no legitimate use of this API a) offerNetwork is @hide
and only exposed via NetworkProvider, and b) it requires getting a
provider ID by calling registerNetworkProvider which correctly enforces
permissions.

unofferNetwork does not currently require any permissions. Again, this
is consistent with the API annotations in ConnectivityManager.

Test: TH
Change-Id: If71ce012f927a34c647d36b5eaf3723de2c01879

Patrick Rohr   commited 2025-01-06 13:57:49 -08:00
ff65257bd0
Ensure multilayer requests cannot contain reservation
Resrvation requests are not currently supported in multilayer requests.
While they are not inherently incompatible, it is unclear how the two
concepts would / should interact, so this CL explicitly prohibits this
situation.

This is a follow up to a comment in aosp/3403183.

Test: TH
Change-Id: Ia5a2cc1780409e3f2d423f244be04fbedf6bbb63

Patrick Rohr   commited 2025-01-06 12:18:00 -08:00
8b42a11eda
Add support for updating reserved offers
A NetworkOffer can be updated by registering a new set of capabilities
and score using an already registered NetworkOfferCallback object.

Since reserved offers are guaranteed to never send more than a single
onReserved() callback, they cannot support updating the capabilities
(not to mention that the reservationId is also part of the
capabilities).

This change changes NetworkOffer migration to only allow reserved offers
to update their NetworkScore. If a reserved offer tries to update its
capabilities, the existing offer is removed and the new offer is
silently rejected. This change does not affect regular offers (with
RES_ID_UNSET) nor blanket offers (with RES_ID_MATCH_ALL_RESERVATIONS).

Test: CSNetworkReservationTest
Change-Id: I872a1dbda209098f08391a7543b9446e1f50d4f0

Patrick Rohr   commited 2025-01-06 12:03:45 -08:00
e7a4b081a4
Add reserveNetwork API
reserveNetwork allows a requestor to initiate the creation of a network
that requires the system to preallocate resources which can then be
advertised by the requestor on or off device in order to help create the
network.

For example, this API will be used to reserve a IP over L2cap server
network, which requires the system to first create a
BluetoothServerSocket and reserve a PSM (i.e. port). This information is
passed back to the requestor via onReserved() callback and subsequently
advertised via a BLE advertisement. The network is established as soon
as the client connects to the advertised PSM, which will trigger a call
to onAvailable(), just like a regular NetworkRequest.

onReserved() callbacks are exclusive to the reserveNetwork API and are
sent when an NetworkOffer is registered that matches the reservation ID
of an existing request. A reserved offer always follows the reservation
request as it is created in direct response. onReserved() can only be
called once. If for some reason the reservation gets cancelled by the
system (i.e. the NetworkOffer is retracted) or cannot be fulfilled,
onUnavailable() is called. It is up to the app to file a new
NetworkRequest when this happens.

An onReserved() callback is not queued, because
a) it cannot be called more than once for the same reservation,
b) it must always be the first callback, and
c) it only gets cancelled by onUnavailable().

This change does not handle NetworkOffer migrations, such as updating
the score, properly. This must be addressed before the feature can ship
as the yieldToBadWifi logic can update the score on all NetworkOffers.

API-Coverage-Bug: 372936361
Test: Very basic CSNetworkReservationTest; more to follow.
Change-Id: I9b349d469830bf28e006cf403c605574371db267

Patrick Rohr   commited 2024-12-22 22:01:22 -08:00
73eee542a1
Add NetworkCallback#onReserved
onReserved() is called in response to a successful Network reservation
with the NetworkCapabilities of the reserved network. onReserved is
called at most once. If the reservation is released, onUnavailable is
called.

Test: TH
API-Coverage-Bug: 372936361
Change-Id: Idcef572ab9d07981799efc349206aadb620e0e69

Patrick Rohr   commited 2024-12-20 15:15:28 -08:00
93136f13c6
Merge changes Id723dc9e,I3665d843 into main
* changes:
  Treat RESERVATION requests the same as REQUEST types
  Adds a new RESERVATION request type

Patrick Rohr   authored and   Gerrit Code Review   commited 2024-12-12 13:51:32 -08:00
b960664fa8
CaptivePortal: implement setDelegateUid API.
This API is designed to set the UID of the app that is allowed to
perform network traffic for captive protal login, communication will
bypass network access restrictions such as VPNs and private DNS settings
when a portal page is launched by Android Custom Tabs and bind the
upcoming traffic to that portal network.

Bug: 373773542
Test: atest ConnectivityCoverageTests
Change-Id: I9992671634b8e88f5a647455811a6157fb15a44b

Patrick Rohr   authored and   Xiao Ma   commited 2024-12-11 20:27:10 +09:00
7d6dfd52b2
Treat RESERVATION requests the same as REQUEST types
Test: CSNetworkReservationTest
Change-Id: Id723dc9edb67bf878fb5b2680327e7b598f6c64f

Patrick Rohr   commited 2024-12-10 13:28:08 -08:00
e4c602e9f5
Read idle timer configurations from the boot namespace
The values are only read during startup so moving these to a boot
namespace. This will ensure that the values are committed to logs only
after a boot.

The boot namespace is already provisioned, but going forward the
string constants for the namespace do not need to be defined in the
DeviceConfig module.

Test: atest ConnectivityCoverageTests:\
android.net.connectivity.com.android.server.CSNetworkActivityTest

Test: Manually using shell commands. E.g.:
adb shell device_config put tethering_boot \
cellular_data_inactivity_timeout 4

Bug: 377759682
Change-Id: Icd4bd3da288e5dfde620d779bd0708319da90be9

Suprabh Shukla   commited 2024-12-02 16:22:10 -08:00
392336b50d
Merge changes I2388220a,I5f282160 into main
* changes:
  Add a test for delayed teardown with unregisterAfterReplacement.
  Fix system crash when netd return error

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-11-12 18:47:07 +00:00
f45f40717b
Merge "Make the idle timer for network data tracking configurable" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-31 21:15:37 +00:00
cf3b26e3bf
Fix system crash when netd return error
API networkSetPermissionForNetwork return
ServiceSpecificException from netd is expected.
Don't crash system under this scenario.

Bug: 363854848
Test: TH
Change-Id: I5f2821603ff51104f38208775d7b3d60265aeeab

Xiaohui Niu   commited 2024-10-30 16:28:08 +08:00
339d6b20e7
Make the idle timer for network data tracking configurable
Networks can use widely varying timeouts for their connections. Because
cellular modems use a lot of power, having this configurable is more
useful for tuning this to an optimal value for power drain.

Adding a similar configurable value for WiFi for parity.

Test: atest ConnectivityCoverageTests:\
android.net.connectivity.com.android.server.CSNetworkActivityTest

Bug: 373733012
Change-Id: I2418f09233b2e3fa4e9cdd8fbb6149a35106b735

Suprabh Shukla   commited 2024-10-29 19:06:42 -07:00
c623c946f5
Merge changes I7184eaa0,I2c5951ab into main
* changes:
  Do not crash when adding UID ranges to a destroyed network.
  Test that UID ranges can incorrectly be added to a destroyed network.

Lorenzo Colitti   authored and   Gerrit Code Review   commited 2024-10-23 04:39:07 +00:00
6bf2ce44e4
Do not crash when adding UID ranges to a destroyed network.
aosp/3218864 fixed the crash when ranges are removed from a
destroyed network, but did not fix the case where the ranges are
added to a destroyed network.

This can happen if a multilayer request is filed when a network
has already been destroyed.

Fix: 368989698
Test: updated existing tests for this bug
Change-Id: I7184eaa01141f56b7ad774277c7dee03d5812298

Lorenzo Colitti   commited 2024-10-22 11:41:21 +00:00
dfe98fc5be
Standardize handler thread checks
Use HandlerUtils#ensureRunningOnHandlerThread to perform handler
thread checks instead of individual methods within the class.

Test: TH
Change-Id: I6d893dc9eedc588660797768a03e7ad7ab636479

Paul Hu   commited 2024-10-17 06:14:05 +00:00
c0e709700c
Introduce PrivateAddressCoordinator methods at RoutingCoordinatorManager
This CL exposes PrivateAddressCoordinator methods at
RoutingCoordinatorManager and implements the methods in
RoutingCoordinatorService.

The objective is to allow a system service like Thread to request an
IPv4 address allocation.

Bug: 350699020

Change-Id: I65dc309f0b503d544e0fddc1168131fa6174796c

Handa Wang   commited 2024-10-16 23:54:25 +00:00
e5e06f9f7c
Merge "Fix threading issue for mDefaultNetworkRequests" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-09-06 13:10:58 +00:00
a5a549bfd8
Fix threading issue for mDefaultNetworkRequests
Handler thread updates mDefaultNetworkRequests and Multiple threads
read/iterate mDefaultNetworkRequests without locking.
This caused NPE when there is concurrent updates and iterations.
This CL fixed this issue by using CopyOnWriteArraySet.
CopyOnWriteArraySet is suitable since number of default network request
is small (system default network request + per-app default network
requests) and updated infrequently but read frequently.

Bug: 293978451
Test: TH
Change-Id: Iaefe8e6e31c2b5257ebc51b4f848c3a7197781cb

Motomu Utsumi   commited 2024-09-06 11:04:00 +09:00
7b906dea29
Skip TestDropPacketToVpnAddress if the feature is disabled
INGRESS_TO_VPN_ADDRESS_FILTERING is disabled due to b/352424251 and
testDropPacketToVpnAddress fails if the feature is disabled.
So skip testDropPacketToVpnAddress if the feature is disabled.

Bug: 362434644
Test: adb shell device_config put tethering
      ingress_to_vpn_address_filtering -1
Test: atest CtsHostsideNetworkTests

Change-Id: Ib16a7550dcf93dd9ecf29047b1c4f101ff6d610d

Motomu Utsumi   commited 2024-09-02 15:21:30 +09:00
9d5d7d0779
Add mIngressToVpnAddressFiltering to dump
Example output:

Multicast routing supported: true
Background firewall chain enabled: true
IngressToVpnAddressFiltering: false

Bug: 362434644
Test: adb shell dumpsys connectivity
Change-Id: I36e0726d7b7ffe873ed6498a45f57c459cc884cc

Motomu Utsumi   commited 2024-08-29 19:24:47 +09:00
727dd5dea4
Check network destroy status before networkRemoveUidRangesParcel
networkRemoveUidRangesParcel throws ServiceSpecificException if the
native network is already destroyed.
This can happen when
1) per-app default network request is satisfied by network1
2) unregisterAfterReplacement is called to the network1. This calls
   netd.networkDestroy and network is removed from netd.
3) per-app default network request is removed. This calls
   netd.networkRemoveUidRangesParcel but netd does not know about this
   netid anymore.

This CL fixes this issue by skip calling networkRemoveUidRangesParcel if
the request satisfier is already destroyed.

Bug: 336961452
Bug: 357974842
Test: CSSatelliteNetworkTest
Change-Id: Id775cca6fffd03545f1c4bc5016d0de4813f17df

Motomu Utsumi   commited 2024-08-19 16:25:39 +09:00
471f20142f
Skip adding ingress discard rule to OEM VPN
OEM VPNs might need to receive packets to VPN address via
non-VPN interface.

Bug: 352424251
Test: CsIngressDiscardRuleTest
Change-Id: Ia9000bcbb5b3b9e1e0d396ba78946be36e2fc5ba

Motomu Utsumi   commited 2024-08-06 19:02:33 +09:00
c14288f7c7
Merge changes If787d3f3,I6de357ac into main
* changes:
  Rename getShrinkedBackingArray to getMinimized*
  Suspend callbacks for frozen apps

Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2024-08-05 00:15:39 +00:00
057369c840
Rename getShrinkedBackingArray to getMinimized*
"Shrinked" should actually be "shrunk" or "shrunken"; in any case
"minimized" is simpler and possibly more accurate (it's the minimum size
required to hold the values).

Test: atest
Change-Id: If787d3f3d6e1046338d4e89ed924bce183e74bd6

Remi NGUYEN VAN   commited 2024-08-02 19:27:41 +09:00
dfb159289b
Suspend callbacks for frozen apps
To avoid filling the binder buffers, and sending unnecessary callbacks
when apps are unfrozen (for example successive LinkProperties changes or
onAvailable+onLost are not useful), queue and aggregate callbacks for
apps that are suspended.

Test: atest
Bug: 327038794
Bug: 279392981
Change-Id: I6de357ac2834f1f7e960dfbaa63adfc3825f2a82

Remi NGUYEN VAN   commited 2024-08-02 19:24:17 +09:00
2d78124348
Skip adding ingress discard rule to legacy VPN
Some legacy VPNs need to receive packets to VPN address via
non-VPN interface.

Bug: 352424251
Test: CsIngressDiscardRuleTest
Change-Id: Iad06dc69c5bf5ccda476e89ed9b0fc1bc63d2ebe

Motomu Utsumi   commited 2024-08-02 19:15:59 +09:00
1b376f0fc4
Fix import order
Reorganize imports to make linter happy.

Test: m
Change-Id: If0e290cf9f2d12d8479848b6a74690412b673439

Remi NGUYEN VAN   commited 2024-07-19 11:59:40 +09:00
42dc6e49e0
No-op refactoring for suspending callbacks
No-op refactoring of ConnectivityService, in preparation for a change to
suspend callbacks for frozen apps.

Test: atest
Bug: 327038794
Bug: 279392981
Change-Id: I55bdd6c1244d6829d40223883ca148ce9ac5dca8

Remi NGUYEN VAN   commited 2024-07-16 15:53:09 +09:00
a65af5f8e1