Commit Graph

380 Commits

Author SHA1 Message Date
Jordan Silva
118c2646f3 Merge "Revert "[BR07.1] Expose setDataSaverEnabled from ConnectivityManager"" into main 2023-10-23 15:12:50 +00:00
Jordan Silva
457ae0f00f Revert "[BR07.1] Expose setDataSaverEnabled from ConnectivityManager"
Revert submission 2745215-npmsbpf

DroidMonitor: Potential culprit for Bug 307256512 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.


Reason for revert: 307256512

Reverted changes: /q/submissionid:2745215-npmsbpf

Change-Id: I27119a7484453d1369bbdf71ad2479edec7d664f
2023-10-23 13:23:01 +00:00
Junyu Lai
d88205a1ae Merge "[BR07.1] Expose setDataSaverEnabled from ConnectivityManager" into main 2023-10-23 11:21:53 +00:00
Junyu Lai
c279f1830e [BR07.1] Expose setDataSaverEnabled from ConnectivityManager
Currently, data saver switch is controlled in NPMS, which
calls into NetworkManagementService and netd when switching
status. In netd, BandwidthController manipulates the
bw_data_saver chain to control the overall behavior.

However, this code are all platform implementation, which
are not updatable. In order to migrate data saver switch
from iptables to bpf, this API is needed for Connectivity to
change the implementation to directly write bpf in later
patches.

Test: atest CtsHostsideNetworkTests:com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Test: atest FrameworksServicesTests:NetworkManagementServiceTest
Bug: 297836825
Change-Id: I71fa41ca739fef8e191fba91b02758ad5f732d5c
2023-10-19 17:43:44 +08:00
Chalard Jean
f9d0e3e94f Reapply "Add LocalNetworkConfig"
This reverts commit 6eea22b18c.

Change-Id: I0a2cef4ee992577674c92ecd384dc6f4361afa02
2023-10-18 15:50:02 +09:00
Anton Kulakov
6eea22b18c Revert "Add LocalNetworkConfig"
Revert submission 2777667

Reason for revert: DroidMonitor-triggered revert due to breakage, bug b/305187495

Reverted changes: /q/submissionid:2777667

Bug: 305187495

Change-Id: Iae4ef936a4c111ae5668e539ce4cdbbb14c811f4
2023-10-13 15:18:55 +00:00
Chalard Jean
fa21cafc1c Add LocalNetworkConfig
This doesn't do anything at this patchset, but the whole
pipe from the agent to ConnectivityService is built.

LocalNetworkInfo will be the name of the public information
sent in callbacks to clients.

Test: CSLocalAgentTests
Change-Id: I70e133031ef3b0aaf6c3e59ccc2ad895c66d339c
2023-10-13 14:40:45 +09:00
Remi NGUYEN VAN
bee2ee14f3 Move ConnectivityResources to service-connectivity
The ConnectivityResources class is only usable with QUERY_ALL_PACKAGES
permission, so it is not generally usable in framework-connectivity. It
is also backed by the ServiceConnectivityResources APK, which is
intended as resources for service-connectivity.

Move the class to service-connectivity and update callers. CTS needs a
way to determine the supported keepalive count as it used the
resources from KeepaliveUtils as @hide API, so provide a
ConnectivityManager @hide API for testing.

Bug: 279108992
Test: atest
Change-Id: I3c9a77c580b5ab87c922c32778bce15dc33b4d1d
2023-04-28 19:18:39 +09:00
Sherri Lin
9e8162c6e0 Merge "Update ConnectivityManager javadoc" 2023-03-07 16:50:15 +00:00
Motomu Utsumi
7f3dfbfacf Merge "Add getUidFirewallRule to ConnectivityManager" 2023-02-17 01:53:00 +00:00
Quang Luong
0f6a2e69cd Merge "Allow SUW to access registerSystemDefaultNetworkCallback" 2023-02-15 20:22:10 +00:00
Jean Chalard
17cbf06773 Correct a wrong doc tag
Change-Id: Icefc5599d0a500ccd9b5d2247ece75ac5cdc5c7e
Test: doc-only change
2023-02-13 05:08:11 +00:00
Quang Luong
98858d6b27 Allow SUW to access registerSystemDefaultNetworkCallback
registerSystemDefaultNetworkCallback is required by WifiTrackerLib to
detect the system default network for UI purposes. Currently this API is
allowed for holders of the NETWORK_SETTINGS permission, but not
NETWORK_SETUP_WIZARD. Since SUW also uses WifiTrackerLib, we should
allow this API for NETWORK_SETUP_WIZARD as well.

Bug: 230643853
Test: atest ConnectivityServiceTest
Change-Id: Ic01a186f91ed67b4603b6b8964921be7473a483a
2023-02-11 00:31:59 +00:00
Sherri Lin
443b7182a6 Update ConnectivityManager javadoc
Removed usages of throws with @link that generates bad HTML and added
@CallbackExecutor on executors.

Bug: 268170423
Test: atest ConnectivityServiceTest
Change-Id: I2e4264c201b1779b1636e3f1c581237490fd0930
2023-02-08 04:49:29 +01:00
chiachangwang
e0192a7433 [DK4-0]Add CM#setTestLowTcpPollingTimerForKeepalive for testing
The default TCP polling alarm timer is very large(2 mins).
It's expensive in the CTS to wait for a couple alarms.
The polling alarm should be deprecated soon and replace
with callback design, so add the hidden method for testing
purpose to support the short term usage until design is
replaced with callbacks.

With the hidden method, the alarm timer will decrease to
1 second for a specified time period. The TCP sockets status
could be verified every 1 second.

Bug: 259000745
Test: m ; atest HostsideVpnTests with the follow up test
Change-Id: I99d494d3b50b2fbee73b926e92e97b1e194d43d4
2023-02-06 13:25:01 +00:00
Chalard Jean
bdb8282604 [DK3] Send onPause/onResume keepalive callbacks
Test: CTS in the patch immediately on top of this, [DK4]
Change-Id: I208ceceb37c7977452479361f70f046fabafb37a
2023-02-06 13:23:13 +00:00
Chalard Jean
f0b261e7cc Use the binder to identify keepalive in IConnectivityManager
This is much simpler and less error-prone, as well as less
subject to race conditions.

It also allows for cleaning up some TODOs.

Test: FrameworksNetTests
      CtsNetTestCases
Bug: 267116236
Change-Id: I470c709446946ef35a0324427defe2f58b434339
2023-02-06 13:22:53 +00:00
Motomu Utsumi
900b806a3b Add getUidFirewallRule to ConnectivityManager
Upcoming CLs use this method to add chain status to failure log of
ConnectivityManagerTest#testFirewallBlocking which is a flaky test

Test: m
Bug: 262141231
Change-Id: Ieb6b4402a3435571decbd8a26fdf666b2db732fe
2023-02-01 17:05:39 +09:00
Chalard Jean
23f1bfd471 Always have an AutomaticOnOffKeepalive to manage a KI
Test: FrameworksNetTests 'CtsNetTestCases' CtsHostsideNetworkTests
Change-Id: Ic216b525d8297fce0f390daae327e667a14b7775
2023-01-31 02:34:44 +00:00
Junyu Lai
35665cc887 Enterprise slicing for profile blocking default
Test: atest ConnectivityServiceTest#testProfileNetworkPreferenceBlocking_networkChanges \
      ConnectivityServiceTest#testProfileNetworkPreferenceBlocking_changePreference \
      --rerun-until-failure 100
Bug: 263219497

Change-Id: Idbda582542bcabf0156e2bab9f8bea42fc908cae
2023-01-11 10:47:00 +08:00
lucaslin
3ba7cc25c0 Create a new API to make a set of UIDs use only VPN by default
Create a new API - setVpnNetworkPreference() for the caller to
set VPN as the preference network.

VPN will be disconnected when its underlying network is gone.
To prevent packets going through an underlying network when the
underlying network is back but VPN is not connected yet, set VPN
as the only preferred network for specific apps.

Bug: 231749077
Test: 1. atest FrameworksNetTests
      2. Create a test app to register default network and check if
         the VPN is the only default network for the test app.
Change-Id: Iabcd38e2fec2aefedbf78d20e338f222d83a9e7f
2022-12-19 05:35:04 +00:00
Igor Chernyshev
9dac660bf0 Add CDM dependency in Tethering
This change introduces a limited library for dependencies on
framework-connectivity from Tethering,
connectivity-internal-api-util, where all classes are annotated with
@RequiresApi(S) to ensure proper API checks are done before usage.

Bug: 245972418

Change-Id: I82bafd9063341adc71d07f0858e6d68283d081f0
2022-12-16 17:55:53 +00:00
Treehugger Robot
31ee1c1121 Merge "Allow USE_RESTRICTED_NETWORKS for registerSystemDefaultNetworkCallback" 2022-11-09 05:49:54 +00:00
Junyu Lai
aa4ad8c2d1 Allow USE_RESTRICTED_NETWORKS for registerSystemDefaultNetworkCallback
Some callers (e.g. iwlan) need to learn about system default
network but they cannot have NETWORK_SETTINGS permission.
To allow them to use this API but prevent from misuse by
unprivileged apps, enforce USE_RESTRICTED_NETWORKS for this API.

Test: atest com.android.server.ConnectivityServiceTest#testRegisterPrivilegedDefaultCallbacksRequireNetworkSettings android.net.cts.ConnectivityManagerTest#testRegisterNetworkCallback
Fix: 242456635
Change-Id: I80ab27445af874328c9c0f4814a8fbf035ae5df4
2022-11-02 14:16:36 +08:00
zhujiatai
79b0de9ef2 Fix memory leak of ConnectivityManager
The instance of ConnectivityManager is static, and so its inner class
should be static to avoid the memory leak. Otherwise, the inner class
will get the reference to the mContext.

Bug:248184860

Signed-off-by: zhujiatai <zhujiatai@xiaomi.com>
Change-Id: I2c755f04a689f3e9e5f829d9be48765816257366
2022-10-13 14:41:18 +08:00
Junyu Lai
c9f1ca62d9 [ST01] Attributes data usage of test network by specifier
Currently, data usage of all test networks are all attributed to
the same NetworkIdentity, which does not allow services to
distinguish upload & download traffic of different test networks.

Thus, this CL put specifier that comes along with
TestNetworkAgent into wifiNetworkKey field to build different
NetworkIdentity to attribute data usage to different for
individual networks. And allow querying test network usage with
wifiNetworkKeys.

Bug: 139774492
Test: atest FrameworksNetTests
      atest android.net.cts.ConnectivityManagerTest
Change-Id: I1bb38fd20781eaf3105735440a04b27bef36fcae
2022-08-29 13:55:08 +08:00
Treehugger Robot
bdedaacd88 Merge changes I036b7f23,I53c58e7b
* changes:
  Improve the JavaDoc for FIREWALL_CHAIN_OEM_DENY_x.
  Allow tests to set the NetworkAgent's callbacks when creating it.
2022-08-04 09:50:53 +00:00
Lorenzo Colitti
f683c40939 Improve the JavaDoc for FIREWALL_CHAIN_OEM_DENY_x.
State that the chains are equivalent and independent.

As requested by API council.

Fix: 235973271
Test: documentation-only change
Change-Id: I036b7f23a40d038920f308c81daf7532afbae242
2022-08-03 09:24:28 +00:00
Chalard Jean
0c7ebe9e44 Opportunistic comment fix
Test: comment only
Change-Id: Icdf8980ebb64e42afe9c7ebc86ea605f897e47ba
2022-08-03 14:46:09 +09:00
Motomu Utsumi
9be2ea0080 Use java BpfMap in BpfNetMaps#replaceUidChain
Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: Ib2a2c2646834110a3eeeb786a4ea7a3f85718be8
2022-07-27 06:01:47 +00:00
chiachangwang
9473c59980 Correct javadoc usage
"{@see" aren't rendered properly. Replace them with "See {@link"
or @see depending on the usage.

Bug: 238753273
Test: make doc-comment-check-docs ; Check the doc result
Change-Id: I70cb2f36e7c5fa8102b5949054df5184d755202c
2022-07-15 03:44:46 +00:00
chiachangwang
e9c44ce718 Correct javadoc for ConnectivityManager#requestNetwork
Fix: 238753273
Test: make doc-comment-check-docs ; Check the doc result
Change-Id: I41c35b9cb31dcf3a372a61ad84f19295b0bc0ceb
2022-07-14 02:43:03 +00:00
Motomu Utsumi
25cf86fc95 Refactor BpfNetMaps and getChainEnabled
Address comments from aosp/2117045 and aosp/2131752
Rename USE_NETD to PRE_T
Rename getChainEnabled to isChainEnabled
Remove unnecessary parentheses
Fix comment

Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: Iaff8c9fc5f74de3fe41a7fb010355b1742fbce90
2022-06-27 14:33:28 +00:00
Motomu Utsumi
18b287d285 Use java BpfMap in BpfNetMaps#setChildChain
Bug: 217624062
Test: atest BpfNetMapsTest android.net.cts.ConnectivityManagerTest#testFirewallBlocking

Change-Id: I13e96911eccd7d1d0545a156ddc2859bcaac09eb
2022-06-24 09:11:58 +00:00
Motomu Utsumi
be3ff1e923 Add API to get current firewall chain status
This commit adds ConnectivityManager#getFirewallChainEnabled to read the
current firewall chain status

Bug: 208371987
Test: m
Change-Id: I1eadb69f953af5d031cd8dabde3e1f098cf0f4df
2022-06-24 09:11:53 +00:00
Motomu Utsumi
5d787feef0 Merge changes Ic6ff7a3d,Iff9b9792
* changes:
  Refactor code and improve tests for VPN filtering
  Remove LOCKDOWN from FirewallChain IntDef
2022-06-16 01:32:20 +00:00
Motomu Utsumi
62385c884f Make FIREWALL_CHAIN_OEM_DENY API
Bug: 208371987
Test: m
Change-Id: Ie0c2ad862c02f9fd4561869cf5a1adc44f1be11b
2022-06-12 11:37:19 +00:00
Motomu Utsumi
8b42e6d431 Remove LOCKDOWN from FirewallChain IntDef
LOCKDOWN_VPN was in the FirewallChain IntDef but this was not a right
place because LOCKDOWN_VPN was not a valid value for Connectivity APIs
that take an argument annotated with @FirewallChain(setUidFirewallRule,
setFirewallChainEnabled, replaceFirewallChain).

LOCKDOWN_VPN was in the FirewallChain IntDef because
BpfNetMaps#setUidRule was used to add/remove LOCKDOWN_VPN entries.
This commit adds BpfNetMaps#updateUidLockdownRule and uses this to
add/remove LOCKDOWN_VPN entries instead of BpfNetMaps#setUidRule and
removes LOCKDOWN from FirewallChain.

Bug: 206482423
Test: atest TrafficControllerTest ConnectivityServiceTest
PermissionMonitorTest HostsideVpnTests#testBlockIncomingPacket

Change-Id: Iff9b9792fc0f208f153e10e396c6d5034b412d7c
2022-06-10 02:49:25 +00:00
Motomu Utsumi
1d9054ba5f Add 3rd deny firewall chain for OEM
Bug: 208371987
Test: atest
CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testFirewallBlocking
ConnectivityServiceTest

Change-Id: Ib521fa02f6a19270cb88a3d85321bda822516c78
2022-06-06 07:47:35 +00:00
Motomu Utsumi
d980149817 Add deny firewall chain for OEM
Bug: 207773349
Bug: 208371987
Test: atest
CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testFirewallBlocking
--iterations 50 && atest ConnectivityServiceTest --iterations 10

Change-Id: I60d5540821abcced03356f366775f16ee369d7f9
2022-06-03 09:10:57 +00:00
Motomu Utsumi
b08654ca04 Block incoming packets in VPN Lockdown mode.
Currently, even when VPN Lockdown mode is enabled, incoming packets are
not dropped if VPN is not connected.

This commit fixed this issue.
After this commit, If VPN Lockdown mode is enabled, incoming packets
are dropped regardless of the VPN connectivity.

Bug: 206482423
Test: atest TrafficControllerTest ConnectivityServiceTest PermissionMonitorTest
Change-Id: If52ece613c8aac1073355e43b6fb9cb3fcc87d1d
2022-05-16 10:40:59 +00:00
markchien
d201566169 Fix ConnectivityManager memory leak
ConnectivityManager have a self reference static instance. This
causes a leak if context is refernce from a static variable. Using
the applicationContext, which will never be freed for the life of the
application, for the sInstance static instance.

Bug: 202978965
Test: atest ConnectivityManagerTest
Change-Id: I87206e1bfbb1f877b5a10f5fdbc25e2f9f11bef4
2022-04-29 08:01:23 +00:00
markchien
011a7f51c1 Improve JavaDoc for FirewallRule constants
Bug: 226946569
Test: TH
Change-Id: I8366bd58194e24da7ea74bf398aae196482d0151
2022-03-29 12:28:25 +08:00
markchien
3c04e66da0 Api review: change updateFirewallRule to setUidFirewallRule
Bug: 218494748
Test: TH

Change-Id: I52a02ebe109b687359f579c16fded4af3c9cd242
Merged-In: I52a02ebe109b687359f579c16fded4af3c9cd242
2022-03-25 18:49:08 +08:00
Lucas Lin
ba61dca57c Merge "Rename redactNetworkCapabilitiesForPackage and update its javadoc" 2022-03-14 08:05:08 +00:00
Mark Chien
cc29690fc1 Merge "Split updateMeteredNetwork{Allow, Deny}List into add and remove" 2022-03-09 05:00:58 +00:00
markchien
e46042b833 Split updateMeteredNetwork{Allow, Deny}List into add and remove
Split the updateXXX methods into an addXXX and removeXXX instead of using
a boolean parameter to indicate whether the uid should be added or removed

Bug: 218494748
Test: atest FrameworksNetTests
Change-Id: I868cf35c8f51b25d8719e618c6c48a5cd642da7f
2022-03-09 11:17:27 +08:00
markchien
49e944cc1c Remove ConnectivityManager swapActiveStatsMap API
swapActiveStatsMap is temporary added for the NetworkStatsFactory to
call BpfNetMaps#swapActiveStatsMap in tethering mainline module. Now
NetworkStatsFactory already be mainlined, calling BpfNetMaps#swapActiveStatsMap
directly.

Bug: 218494448
Test: atest ConnectivityCoverageTests
      atest FrameworksNetTests
Change-Id: I3358e4ac5fb7ed0964273afdbccd1b4128ca7645
2022-03-07 12:25:47 +08:00
lucaslin
d2b0613814 Rename redactNetworkCapabilitiesForPackage and update its javadoc
The API won't modify the passed NetworkCapabilities and
LinkProperties, but redactNetworkCapabilitiesForPackage and
redactLinkPropertiesForPackage sound like they will. To reduce
the confusion, rename the API with prefix "getRedacted".
Also modify the javadoc to describe more about what the API will
do if the given UID doesn't have location permission.

Bug: 220367512
Test: atest CtsNetTestCases
Change-Id: I964f1062da1ae96df9b369b911486da1379b8a19
2022-03-02 10:56:57 +08:00
lucaslin
c582d50b8e Add new methods to redact NetworkCapabilities & LinkProperties
Some system components like VPN need to know how to redact
NetworkCapabilities & LinkProperties that they received from
the system but need to send to third-party applications with
less privilege than themselves. To make sure the redaction is
consistent, expose system API methods to do it that are wired
to the same redaction code used by ConnectivityService.

Bug: 191413541
Test: atest CtsNetTestCases, which includes new CTS for these
Change-Id: Ia3ae4755b5192884c147d6828f96cedac000a25b
2022-02-12 15:21:13 +09:00