Commit graph android_packages_modules_Co.../service/src/com/android/server/ConnectivityService.java
Message SHA1
Merge changes I30f8814c,Ifdf67318,If312b8f8 into main
* changes:
  Rename hasCarrierPrivilege... to isCarrierServiceUid...
  Detect discrepancies in subIds
  Allow carrier service UIDs to access their own WiFi networks.

Jean Chalard   authored and   Gerrit Code Review   commited 2023-11-20 06:55:04 +00:00
4a013c47c2
Stop CarrierPrivilegeAuthenticator thread in tests
Bug: 308519360
Test: CarrierPrivilegeAuthenticatorTest
Change-Id: I59164be00a9e1fcced8538537c1dcabd214f2170

Chalard Jean   commited 2023-11-20 14:31:32 +09:00
96ff954464
Rename hasCarrierPrivilege... to isCarrierServiceUid...
This method tests whether the UID is the carrier service
UID, not whether the UID has carrier privilege.

Note that in normal operation, the carrier service UID always
has carrier privilege.

Test: NetworkAgentTest
Change-Id: I30f8814cc0419a2d6bdbe75fdc82156516eba026

Chalard Jean   commited 2023-11-20 14:01:02 +09:00
8c63ed851f
Merge "Add more powerful CTS for allowedUids" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-11-20 04:44:22 +00:00
51c80a72d8
Add more powerful CTS for allowedUids
This tests that the network providers are subject to appropriate
limitations as to what they can set as allowedUids – both in the
positive (can do) case, and the negative (can't do) case.

Test: this
Change-Id: I115e2a4bc02ddcd03ecf2f35130fcb0378da22bd

Chalard Jean   commited 2023-11-20 12:16:39 +09:00
5301778ad8
Merge "Revert "Make PRIORITIZE_* networks non-default"" into main
Michał Brzeziński   authored and   Gerrit Code Review   commited 2023-11-17 12:21:56 +00:00
dec578072a
Revert "Make PRIORITIZE_* networks non-default"
This reverts commit 30fb9b1ca4.

Reason for revert: Potential culprit for CtsLibcoreTestCases test failures b/311612650

Change-Id: Ie7de97159f92a174476a8fa8ea83e3e01914aea1

Michał Brzeziński   authored and   Gerrit Code Review   commited 2023-11-17 11:18:56 +00:00
05cba24cd8
Merge "Make PRIORITIZE_* networks non-default" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-11-17 05:55:22 +00:00
9a5252ba50
Make PRIORITIZE_* networks non-default
As a specialized network, a network with PRIORITIZE_* is not
generally a good default network, and might cause unexpected
charges if allowed to become one.

Test: CSDefaultNetworkTests
Change-Id: I8f7184f80bb987da720bd067862bd7a546a38e26

Chalard Jean   commited 2023-11-16 18:45:10 +09:00
30fb9b1ca4
Apply forwarding rules before sending onAvailable
Ideally the rules should be set up before onAvailable is
sent, but onLocalNetworkChanged should be sent after.

The previous code had CSLocalAgentTests#testForwardingRules
flaky because it was waiting for onAvailable and immediately
checking that the routing rules have been set up.

There are other ways to fix this flake (e.g. wait for
onLocalNetworkChange in the test or add a timeout on
the verify(netd) call) but this patch probably implements
the best production code behavior.

Bug: 309688089
Test: CSLocalAgentTests#testForwardingRules 1'000 times
      Before this patch : flakes after 50~200 iterations
      After this patch : no flake in 1'000 iterations
Change-Id: I4dcccaa3607c1e28aa89f268f0c721d87b1e9466

Chalard Jean   commited 2023-11-16 17:04:15 +09:00
68eab721fc
Merge "Pass VPN uid range to AutomaticOnOffKeepaliveTracker" into main
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-11-16 01:30:48 +00:00
9481063d42
Merge changes from topic "multi_network_activity_tracking" into main
* changes:
  Make ConnectivityService update BatteryStats radio power state
  Track multiple network activities on V+
  Use netId as idleTimer label on V+

Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-11-15 13:58:37 +00:00
1cd89fca86
Pass VPN uid range to AutomaticOnOffKeepaliveTracker
This is a preliminary change for filtering sockets that is not
in the uid ranges for automatic on/off keepalives. This commit
itself is a no-op change to pass the uid information to
AutomaticOnOffKeepaliveTracker.

Bug: 311119352
Test: atest FrameworksNetTests
Change-Id: I7d96e7a0d3f3054d1409de350420a24378b28cdb

Chiachang Wang   commited 2023-11-15 08:50:27 +00:00
59bcabe3f4
Merge "Allow SysUi to see the connectivity diagnostic callbacks" into main
Quang Luong   authored and   Gerrit Code Review   commited 2023-11-15 05:51:28 +00:00
2cfffe7bfb
Allow SysUi to see the connectivity diagnostic callbacks
SysUi needs to see connectivity diagnostic callbacks to display
 "Checking for internet access..." -> "Connected" or "No internet access".

Bug: 307161342
Test: atest FrameworksNetTests, manually connect to a network without internet connectivity,
verify Internet Dialog doesn't get stuck showing
 "Checking for internet access..."

Change-Id: I86e2b852ff9e5dfbfc37ba711f477166b0ac6835

Quang Anh Luong   commited 2023-11-15 11:06:42 +09:00
28eefef05d
Make ConnectivityService update BatteryStats radio power state
Currently, BatteryStatsService register netd callback and track radio
power state only for the default network.
So, battery stats are not accurate if cellular and Wi-Fi networks are
active at the same time.

aosp/2561090 updates BatteryStatsService not to register netd callback
on V+ devices.
This CL updates LegacyNetworkActivityTracker to call BatteryStats API
and update radio power state for networks including non default networks
on V+ devices.

Bug: 267870186
Bug: 279380356
Test: atest FrameworksNetTests
Change-Id: I826b3b4046cc7b8aef46c13300854eaf14b1b777

Motomu Utsumi   commited 2023-11-14 15:50:42 +09:00
db537accdc
Track multiple network activities on V+
on V+ devices, NetworkActivityTracker adds idleTimer when the network is
first connected and removes idleTimer when the network is disconnected
so that activity tracker can receive netd
onInterfaceClassActivityChanged callback for multiple networks.

Bug: 267870186
Bug: 279380356
Test: atest FrameworksNetTests
Change-Id: I6f3a95c27e3e58f3f60c40065f562d00431a56b1

Motomu Utsumi   commited 2023-11-14 15:50:36 +09:00
1f5ffa4273
Use netId as idleTimer label on V+
Following CL adds idleTimer for multiple networks and track activities
including non default network on V+
Current LegacyNetworkActivityTracker uses transport type as an idleTimer
label but this makes it difficult to have multiple idleTimers.
So, this CL updates LegacyNetworkActivityTracker to support using netId
as an idleTimer label.

Bug: 267870186
Bug: 279380356
Test: atest FrameworksNetTests
Change-Id: I0039f5624ae1d142dbacba53aa90ca9bf6d43599

Motomu Utsumi   commited 2023-11-14 13:43:45 +09:00
5fce43e548
Merge "Add test to make sure that unwanted local nets disconnect correctly" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-11-09 02:08:36 +00:00
7cf6e5a3b0
New firewall chain for default background restrictions
A new firewall chain is needed to configure background network
restrictions for apps.
This change only adds the API stubs and traffic controller constants to
make the chain work. Policy changes using this chain will follow in
the framework code.

Test: atest CtsNetTestCases:ConnectivityManagerTest
Test: atest ConnectivityServiceTest

NO_IFTTT=The Lint rule along with the relevant code in Common.h is
being deleted in aosp/2819759

Bug: 304347838
Change-Id: I33e2db6671431f7c576fc931d9f96e684fc1e78a

Suprabh Shukla   commited 2023-11-08 10:17:30 +00:00
2d893b68a9
Add test to make sure that unwanted local nets disconnect correctly
Also add some toString() methods that were useful in debugging.

Test: new test in CSLocalAgentTests
Change-Id: Ife95815e39d92bbef84b1c5ea75a151882590d09

Chalard Jean   commited 2023-11-07 22:28:25 +09:00
4fe2339f2c
Add LocalNetworkInfo and send callbacks when it changes
Test: CSLocalAgentTest
Change-Id: I8caca97b891081f9212a01d428a34ed1a08d5126

Chalard Jean   commited 2023-11-07 17:29:38 +09:00
22350c93b4
Set up forwarding rules for local network agents
Test: CSLocalAgentTests, new tests for this
Change-Id: I8994af350a1799ab5f6ebb2872f2abfaf174bd61

Chalard Jean   commited 2023-11-06 20:18:50 +09:00
1e4c218c28
Enforce structural NetworkAgent constraints
Avoid network agents trying to do things that the stack
does not support.

Test: new test in this change
Change-Id: I3ffa1c3ddbb0b648b06862dc0a44f8525d358acc

Chalard Jean   commited 2023-11-02 23:25:11 +09:00
78c9a381c9
Merge "[BR02] Implement isUidNetworkingBlocked" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-11-01 03:40:05 +00:00
2c8e96d599
Merge "Destroyed networks can't hope to beat champions" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-31 10:01:09 +00:00
de33ada087
[BR02] Implement isUidNetworkingBlocked
This is needed for data stall detection mechanism in NetworkStack
to get the information about whether the network is blocked for
a given uid and conditions. Because the API will be called
frequently from NetworkStack to resolve all status for all uids
on the device, the API cannot call into the service which
creates IPC. Instead, the API need to directly access bpf maps
in the user process to retrieve the status. In this case the
user process is the network stack, the access control is provided
by linux file permission and selinux.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.ConnectivityManagerTest
NO_IFTTT=Refactor only change for firewall chains definitions
Bug: 297836825

Change-Id: Iaf983b71ec98cbfe5152dcfade8a3120f938f135

Junyu Lai   commited 2023-10-31 16:33:41 +08:00
e003152e2c
Pass metered information to DNS resolver
Dns Resolver needs to know whether a network is metered when checking if
DNS requests will be blocked by Data Saver.

Bug: 288340533
Test: atest FrameworksNetTests
Change-Id: Ia5822dc522c766c7815680003c7ba275d15ccaff

Ken Chen   commited 2023-10-31 07:38:40 +00:00
5a35cf9086
Write Data Saver setting to BPF map
The information is needed by modules who want to know whether a
specific UID is blocked by Data Saver feature.

1. Add a one-element map data_saver_enabled_map.
2. Update current data saver setting to the map.

Bug: 288340533
Test: atest FrameworksNetTests:android.net.connectivity.com.android.serv
er.BpfNetMapsTest
Test: atest bpf_existence_test

Change-Id: I981da4b569247c33cba2d365cb6f2691f673474e

Ken Chen   commited 2023-10-31 01:36:03 +00:00
243301748e
Destroyed networks can't hope to beat champions
In particular, this fixes a bug where a non-validated destroyed
network can't get disconnected after it's replaced by another
non-validated network because CS thinks it should keep it in
case it validates and beats the replacement network.

Test: new test for this : CSDestroyedNetworkTests
Change-Id: I5d7e413624d6fca28b06484e5369cd17e4a599a4

Chalard Jean   commited 2023-10-30 23:26:43 +09:00
80685f42c3
Pass NetworkCapabilities into DnsManager
1. At present, the transportTypes in NetworkCapabilities have been
passed into DnsManager::updateTransportsForNetwork() as a parameter. In
the following CL, we also need to pass the 'metered' (also in
NetworkCapabilities) as a parameter to the function. Instead of passing
the members of NetworkCapabilities one by one, it is better to pass the
entire NetworkCapabilities.

2. Rename updateTransportsForNetwork() to
updateCapabilitiesForNetwork().

Bug: 288340533
Test: presubmit
Change-Id: I0966124f87b12c1d5a2eaee681885c3d5c7f74dc

Ken Chen   commited 2023-10-30 08:29:58 +00:00
6b134f18f4
remove dead portions of BpfUtils.java
(mostly to improve code coverage)

We can always revert if it ever turns out this is useful,
but I'd prefer for cgroup attach to be a once-at-boot
thing and handled either from bpfloader or the netd updatable
which are both directly C++ code.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I79b5ca8a47388cb6b9189234942e74ab6056aab9

Maciej Żenczykowski   commited 2023-10-25 17:40:35 +00:00
de9d367ab2
Merge "Add a routing coordinator class" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-25 09:13:16 +00:00
4e47533688
Merge "Revert "Revert "[BR07.1] Expose setDataSaverEnabled from Connect..."" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-10-25 01:59:12 +00:00
0cfaea8d98
Add a routing coordinator class
Test: In followup changes : RoutingCoordinatorManagerTest
Change-Id: Ia6811d614e02123a072c7638291828745abae051

Chalard Jean   commited 2023-10-24 22:12:26 +09:00
2fb66f1b28
Revert "Revert "[BR07.1] Expose setDataSaverEnabled from Connect..."
Revert submission 2799494-revert-2745215-npmsbpf-OBOPDXREUI

Reason for revert: Need to 1. Merge API first. 2. Wait for prebuilt. 3. Merge the caller.

Reverted changes: /q/submissionid:2799494-revert-2745215-npmsbpf-OBOPDXREUI

Change-Id: Icd5f3d40595a0d2a221b016cec70568bf3597c16

Junyu Lai   commited 2023-10-24 07:30:23 +00:00
df210365fe
Merge "Revert "[BR07.1] Expose setDataSaverEnabled from ConnectivityManager"" into main
Jordan Silva   authored and   Gerrit Code Review   commited 2023-10-23 15:12:50 +00:00
118c2646f3
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

Jordan Silva   authored and   Gerrit Code Review   commited 2023-10-23 13:23:01 +00:00
457ae0f00f
Merge "[BR07.1] Expose setDataSaverEnabled from ConnectivityManager" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-10-23 11:21:53 +00:00
d88205a1ae
Merge "Reapply "Add LocalNetworkConfig"" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-20 06:25:14 +00:00
e32bf36be8
Merge "Support shell command to get bpf program id" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-10-19 22:35:04 +00:00
5c2b517d6a
[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

Junyu Lai   commited 2023-10-19 17:43:44 +08:00
c279f1830e
Merge "Dump bpf program status in dumpsys" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2023-10-19 09:33:27 +00:00
eb75416136
Support shell command to get bpf program id
Test: atest NetworkStatsIntegrationTest#testBpfProgramAttachStatus
Bug: 292156770

Change-Id: I815be0f3f3592442939872f98e3ad9d224a6aeb6

Junyu Lai   commited 2023-10-18 16:06:15 +08:00
452e464ee9
Dump bpf program status in dumpsys
Sample output:
Bpf Program Status:
  CGROUP_INET_INGRESS: 21
  CGROUP_INET_EGRESS: 22
  CGROUP_INET_SOCK_CREATE: 28
  CGROUP_INET4_BIND: 30
  CGROUP_INET6_BIND: 31

Test: adb shell dumpsys connectivity
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testDumpDoesNotCrash
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testDumpDoesNotCrash
Bug: 292156770
Change-Id: I312c90c524af12d093536156d6d5c6febd64305a

Junyu Lai   commited 2023-10-18 16:05:55 +08:00
155760b57b
Reapply "Add LocalNetworkConfig"
This reverts commit 6eea22b18c.

Change-Id: I0a2cef4ee992577674c92ecd384dc6f4361afa02

Chalard Jean   commited 2023-10-18 15:50:02 +09:00
f9d0e3e94f
Merge "Reapply "Tell netd about local networks"" into main
Jean Chalard   authored and   Gerrit Code Review   commited 2023-10-17 13:00:46 +00:00
de0f4e5b87
Move dumpsys to handler thread
I0afdda023208c3f8620cb5b89add66448af596d7 added some assertions
to ensure NetworkAgentInfo can only be accessed from the handler
thread. This is good to eliminate any potential concurrent
accessing problem. Howver, dumpsys runs on binder thread, this
change breaks dumpsys functionality.

Thus, this change:
  1. Copy Handler#runWithScissors() and related class
     locally since they are @hide methods.
  2. Run doDump on the handler thread and waits for return.

Test: adb shell dumpsys connectivity
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.HandlerUtilsTest
Fix: 303348620
Change-Id: Ic3a22f5d370bbf8c18b1972e86d695b6ad61bd0d

Junyu Lai   commited 2023-10-17 17:16:04 +08:00
f8dba342f1
Reapply "Tell netd about local networks"
This reverts commit cc409153b4.

Change-Id: Ied6bdb9b94e08e2bfe1092765d0f4591e603c3eb

Chalard Jean   commited 2023-10-17 17:39:23 +09:00
e0aaca5ac6
Revert "Tell netd about local networks"
Revert submission 2777667

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

Reverted changes: /q/submissionid:2777667

Bug: 305187495

Change-Id: Icb46558d17b56f9f6fd402f1489de9ed2b8f7644

Anton Kulakov   commited 2023-10-13 15:23:59 +00:00
cc409153b4