Commit graph android_packages_modules_Co.../service/src/com/android/server/ConnectivityService.java
Message SHA1
Fix agents disconnecting in SUSPENDED state.
Network state is not changed to disconnected when a networkagent
is disconnected and network state is SUSPENDED.

So the function requiresClat return true. Clat is not stoped.

Bug: 277682237
Test: atest FrameworksNetTests

Change-Id: I5edfcf64aca5d2d34325d722dd29fab41bcf2600

wangshengrjxtjcb   authored and   Motomu Utsumi   commited 2023-05-16 16:35:03 +09:00
fd5d3d90e1
Merge changes from topic "firewall_socket_destroy"
* changes:
  Close sockets from ConnectivityService#setFirewallChainEnabled
  Add test to verify socket close when firewall is enabled

Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-05-12 09:18:40 +00:00
179d18b3ad
Merge "Immediately create native networks when NetworkAgents register."
Lorenzo Colitti   authored and   Gerrit Code Review   commited 2023-05-11 03:35:21 +00:00
18cdec34dd
Close sockets from ConnectivityService#setFirewallChainEnabled
And replace netd.socketDestroy by Java implementation

Bug: 270298713
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I0e200247ca010f9649254eeaac02740bd2bfdb21

Motomu Utsumi   commited 2023-05-11 12:22:09 +09:00
d44a33adb9
Optionally have ConnectivityService kill sockets for frozen apps
To do this we register a UidFrozenStateChangedCallback with
ActivityManager. The callback then queues up work on the Handler thread
to consume the original callback args and kill appropriate sockets.

Test: atest ConnectivityServiceTests
Bug: 277100090
Change-Id: I93f174811aef726145a18ea90443ddfc1456478e

Mark Fasheh   commited 2023-05-10 21:04:54 +00:00
7c999d8d4c
Immediately create native networks when NetworkAgents register.
Currently, native networks for non-VPN networks are created only
when the NetworkAgent goes into the CONNECTED state. This is not
ideal, because until the network is connected:

- Nothing routes to the network, so no IP packets can be sent on
  it (except via packet sockets).
- Many network configuration changes (e.g., routes and DNS
  servers) fail to apply because the network does not exist yet.
  These cause ENONET errors in the logs.

Fix this starting in U by creating the native network as soon as
the agent registers. This should not impact apps because
NetworkCallbacks are not sent until networks are connected.

Bug: 143158421
Test: new coverage in NetworkAgentTest
Change-Id: I26bfa8630c085422175558645c47a6c64be96ae6

Lorenzo Colitti   commited 2023-05-10 20:01:07 +09:00
4f87aa3f13
Fix isFeatureEnabled namespace and overload usage
From service-connectivity, NAMESPACE_TETHERING must be used, as
NAMESPACE_CONNECTIVITY is used for the NetworkStack module. Also the
isFeatureEnabled with module name must be used, otherwise the "android"
package version is queried instead of the tethering module version.

BpfNetMaps is using flag value 1 to workaround this issue.
flags in NsdService, AutomaticOnOffKeepaliveTracker, and ConnectivityFlags
were not pushed currently.
So, this change has no effect to devices.

Bug: 279108992
Test: TH
Change-Id: I2b4b6a13c048c20beef52b1f43b9e21aca0c637a

Motomu Utsumi   commited 2023-04-28 19:18:43 +09:00
278db58bf5
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

Remi NGUYEN VAN   authored and   Motomu Utsumi   commited 2023-04-28 19:18:39 +09:00
bee2ee14f3
Add some tests for packet wakeup logging changes
Cellular networks are now supported for marking wakeup packets. As a
result onWakeupEvent now also reports data relevant to the cell
transport.

These unit tests should add coverage for these new behaviors.

Test: atest FrameworksNetTests

Bug: 276498460
Change-Id: I0b8a03fff6255e067b736f3dbfb53de56420f90b

Suprabh Shukla   commited 2023-04-27 19:29:38 -07:00
53e1639b7d
Merge "Enable wakeup marking for Cellular transport"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-04-26 11:13:01 +00:00
d861f04a1b
Enable wakeup marking for Cellular transport
Starting with Android U, the config_networkWakeupPacketMark and
config_networkWakeupPacketMask values will be used to mark packets that
woke up the AP on the cellular transport also.

Test: Manual, by inspecting the output of `iptables -L -t -n -v mangle`

Bug: 276498460
Change-Id: I4c7d2801532604d436bfda96c4c52a791995a9ed

Suprabh Shukla   commited 2023-04-25 23:31:30 -07:00
7564228e3f
Use InetDiagMessage.destroyLiveTcpSocket instead of netd.socketDestroy
Netd is not updatable since it's not mainlined.
To make socket destroy code updatable, the code was re-implemented in
java and moved to Connectivity.

Bug: 270298713
Test: atest FrameworksNetTests
Change-Id: I5439c0c76c42a9f738a1b25a1f62e701755cbd05

Motomu Utsumi   commited 2023-04-19 11:59:18 +09:00
93a2218e41
Merge "Separate events usage for starting socket keepalives"
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-04-17 02:32:00 +00:00
2cf6b2c4fd
Separate events usage for starting socket keepalives
This is a clean up commit to correct the javadoc of
NetworkAgent.CMD_START_SOCKET_KEEPALIVE. This event was used
between ConnectivityService/NetworkAgent, and also
ConnectivityService/KeepaliveTracker with different semantics.
This may confuse the developers to update the doc incorrectly,
so also separate the usage to different events.

Also move the event definitions together so that a new event
definition will not mis-use the existing values.

Test: atest FrameworksNetTests
Change-Id: I73ebd8abcc610531da3057da2d643a41befb2099

chiachangwang   commited 2023-04-14 07:43:56 +00:00
f1b1fb4b7f
Move checkAnyPermissionOf to PermissionUtils
This is also needed in other classes in subsequent CLs, move to
a common place to prevent from code duplication.

Test: TH
Bug: 275532605
Change-Id: If7c757cecba8027b2f3b5209e6ea67733da50bf3

Junyu Lai   commited 2023-04-11 11:37:49 +08:00
4c6fe239fe
Merge "Restriction changes of #simulateDataStall"
Yan Yan   authored and   Gerrit Code Review   commited 2023-03-15 20:30:45 +00:00
0bb76546e6
Merge "Add comments to explain why mayCloseSockets is called twice."
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-03-13 09:52:13 +00:00
4028f90e82
Add comments to explain why mayCloseSockets is called twice.
Test: m
Change-Id: Ide8a5b649c7bda26c41e3d11a5071eb1af7ae0a2

Motomu Utsumi   commited 2023-03-13 13:24:50 +09:00
6345e4666a
Clear the CallingIdentity before in the context of property check
Using packageManager from ConnectivityService context to get the caller
application info in binder calls can cause the permission issue. Calling
the Binder.clearCallingIdentity() before interact with packageManager
can fix the permission issue.

Test: atest CtsHostsideNetworkTests
Bug: 272165411
Change-Id: I0a289afc6fb0e42a92aa3ffa0c77ed396c4485c3

Yuyang Huang   commited 2023-03-13 13:11:49 +09:00
2d13d437d0
Restriction changes of #simulateDataStall
This includes two restriction changes of simulateDataStall:
- Allow simulation on a network that has an underlying test
  network
- Allow simulation on networks created by the system server

This commit allows VCN and VPN to CTS test their abilities of
handling suspected data stall.

This commit is safe because #simulateDataStall is already protected
by two signature permissions MANAGE_TEST_NETWORKS and NETWORK_STACK,
and those permissions are granted to only preinstalled apps.

Bug: 263415068
Test: atest VcnManagerTest (new tests)
Change-Id: Ic0cdb66abb291fbf4a7545efe4114179e965d2b6

Yan Yan   commited 2023-03-11 03:29:10 +00:00
fe96dde298
Update system APIs based on feedback.
API council has requested that the recently added BroadcastOptions
APIs be modified to better match API guidelines.

Bug: 267646347
Test: treehugger
Change-Id: Ia701ae31079476d0cc05079d62cd90ba81279cdd

Jeff Sharkey   commited 2023-03-06 14:10:34 -07:00
4ffd34cc42
Remove log spam of binderDied
When the network requester process has been killed, lots of
binderDied logs would be spewed out. These logs haven't been
useful for debugging but to be very spammy. Thus, remove this log
entirely.

Bug: 223128960
Test: Manual test
Change-Id: Ic3096bfee41167b1a54a9d04b474263d15217217

Paul Hu   commited 2023-03-03 11:49:24 +08:00
a3a80f7872
Merge "Remove debuggable restriction on testing purpose method"
Chiachang Wang   authored and   Gerrit Code Review   commited 2023-03-02 11:28:12 +00:00
492f7e3c1c
Remove debuggable restriction on testing purpose method
CM#setTestLowTcpPollingTimerForKeepalive() is hidden method for
CTS. The debuggable restriction will prevent it from running on
actual CTS. The method is protected by permission with parameter
range constraint. It should be enough for incorrect usage from
normal apps. Remove it to allow test case to run on actual CTS.

Bug: 259000745
Test: CTS is the follow up commit
Change-Id: I3d4627c75bae7411c6a72799643d3b29bbae4f2f

chiachangwang   authored and   Chiachang Wang   commited 2023-03-02 07:54:21 +00:00
61cb81aa32
Merge "Check network slicing declaration for network request"
Yuyang Huang   authored and   Gerrit Code Review   commited 2023-03-01 02:13:31 +00:00
a908d816de
Add network handle to the nflog prefix for wakeups
This is useful in the system server for better attribution of wakeup
events.
The logic for encoding the data in the prefix is still maintained ad-hoc
and should be standardized in the future.

Test: Builds, boots. Manually triggering a wifi wakeup doesn't result
in anything unexpected.
Test: atest FrameworksNetTests

Bug: 265742148
Change-Id: I7ef8a606459bb9f0630f629c01d3b34643ae5319

Suprabh Shukla   commited 2023-02-28 19:18:44 +00:00
1e31203fcc
Check network slicing declaration for network request
When the application wants to request network with
NET_CAPABILITY_PRIORITIZE_BANDWIDTH or
NET_CAPABILITY_PRIORITIZE_LATENCY, it has to declare
PackageManager.PROPERTY_NETWORK_SLICE_DECLARATIONS property and also
adds the declaration in a separate XML files. Otherwise, the request
will fail with a SecurityException being thrown.

Test: atest FrameworksNetTests CtsNetTestCases
Bug: 266524688
Change-Id: I6affc857b803211517368da288e1b2fdc06a955b

Yuyang Huang   commited 2023-02-28 17:38:30 +09:00
96e8bfee5f
Merge "Address comments at aosp/2361702"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-02-23 11:07:03 +00:00
ea5e220c90
Address comments at aosp/2361702
Test: 1. Patch local built module on T device
      2. atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest
Fix: 267968887
Change-Id: I86e5be9a0cee0621ff9ef0996d56a51fc5f408c2

Junyu Lai   commited 2023-02-23 15:21:29 +08:00
c53a169a90
Merge "Add getUidFirewallRule to ConnectivityManager"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-02-17 01:53:00 +00:00
7f3dfbfacf
Merge "Allow SUW to access registerSystemDefaultNetworkCallback"
Quang Luong   authored and   Gerrit Code Review   commited 2023-02-15 20:22:10 +00:00
0f6a2e69cd
Add underpinned Network parameter in SocketKeepalive.start()
Take a Network parameter to have an one-to-one mapping between
keepalive and its underpinned network on the automatic keepalive.

Existing design could not really tell which network should the
automatic keepalive check for the TCP socket status if there are
multiple automatic keepalives enabled, e.g. Bothe IWLAN and VPN
on WiFi enable the automatic keepalive. The keepalive for IWLAN
should check if there are any TCP sockets on the IWLAN network
instead of VPN network.

Bug: 259000745
Test: atest FrameworksNetTests
Test: Cts in the follow up commit
Change-Id: I7353f4ef43e8fdad02c4d4a0bb5f6efa7d94c1b4

chiachangwang   commited 2023-02-14 10:29:19 +00:00
676c84ef98
[DK5]Add debugging information for automaticOnOff keepalive
Print state and keepalive information in the dump.

Also update ConnectivityService and the corresponding test to
create AutomaticOnOffKeepaliveTracker from a Dependencies class.
ConnectivityService#dump() will require READ_DEVICE_CONFIG
permission because of the new dump() in AutomaticOnOffKeepaliveTreacker.
ConnectivityServiceTest should focus on verifying design in
ConnectivityService, so skipping the DeviceConfig check via a fake
Dependencies class in the unit test.

Sample dump:

AutomaticOnOff enabled: true
  AutomaticOnOffKeepalive [KeepaliveInfo [ type=1 network=100 startedS ... ], state=STATE_ENABLED ]

Bug: 259000745
Test: m ; atest FrameworksNetTests CtsNetTestCases
Change-Id: I9ac725bcef7daec1d1a12bad592b7fa6856a1707

chiachangwang   commited 2023-02-13 09:54:36 +00:00
7c17c283ea
Merge changes I99d494d3,I208ceceb
* changes:
  [DK4-0]Add CM#setTestLowTcpPollingTimerForKeepalive for testing
  [DK3] Send onPause/onResume keepalive callbacks

Jean Chalard   authored and   Gerrit Code Review   commited 2023-02-13 05:06:20 +00:00
b5ebe944b5
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

Quang Luong   commited 2023-02-11 00:31:59 +00:00
98858d6b27
Merge "Use the binder to identify keepalive in IConnectivityManager"
Jean Chalard   authored and   Gerrit Code Review   commited 2023-02-07 08:17:26 +00:00
b5a87674f0
Suppress lint for methods using APIs promoted from system to public
Bug: 259743961
Test: errorprone build
Change-Id: Ia47cc8e765cb2007da5aeca9a609ad7db688e17c
Merged-In: Ia47cc8e765cb2007da5aeca9a609ad7db688e17c

Michael Groover   commited 2023-02-06 15:12:18 -06:00
73f6948915
[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

chiachangwang   commited 2023-02-06 13:25:01 +00:00
e0192a7433
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

Chalard Jean   authored and   chiachangwang   commited 2023-02-06 13:22:53 +00:00
f0b261e7cc
Use the binder token to reference AutoKI in alarm
This patch uses the binder token represented by the callback
to communicate the identity of the AutoOnOffKeepalive through
the alarm mechanism. This is a lot more robust and easy to
understand.

Addressing this, on top of the robustness and readability
advantages, corrects three bugs.

• The |obj| in the message to CMD_MONITOR_AUTOMATIC_KEEPALIVE
  is now the binder token both on the sender side and the
  receiver side, while the previous code had a Network in the
  sender while the receiver expected AutoOnOffKeepalive,
  crashing the system server with a wrong cast.
• The intent sent in the alarm would have a yet-uninitialized
  value for the slot, so it would not be possible to find the
  auto keepalive when the alarm fires.
• When the slot is reassigned, the alarm continued to fire
  with the same slot value, so the auto keepalive would no
  longer be found after a pause/resume cycle that would
  change the slot.

Test: FrameworksNetTests
Change-Id: Ibdbfcd884e0d3559206cbaae7b6b7a524972c3ca

Chalard Jean   authored and   chiachangwang   commited 2023-02-04 08:05:00 +00:00
98732dbd6d
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

Motomu Utsumi   commited 2023-02-01 17:05:39 +09:00
900b806a3b
[DK2-3]Do not attemp to stop keepalive on nonexistent network
Bug: 266771129
Test: atest FrameworksNetTests
Change-Id: I42cfe0720eddac70d76abbb340ea427f2d714c3a

chiachangwang   commited 2023-01-31 07:53:11 +00:00
d50f951340
Always have an AutomaticOnOffKeepalive to manage a KI
Test: FrameworksNetTests 'CtsNetTestCases' CtsHostsideNetworkTests
Change-Id: Ic216b525d8297fce0f390daae327e667a14b7775

Chalard Jean   authored and   chiachangwang   commited 2023-01-31 02:34:44 +00:00
23f1bfd471
Make mPermissionMonitor in ConnectivityService private
Since mPermissionMonitor is not used from test now.

Test: m
Change-Id: I049274023d60c8a04fccae9b6cf5cac03dd4878e

Motomu Utsumi   commited 2023-01-30 17:54:30 +09:00
f360aa6058
Add defer-until-active policy to CONNECTIVITY_ACTION.
This allows deferring the broadcast delivery to apps in
the Cached state.

Bug: 255545931
Test: TH
Change-Id: Idd94ad5f9dbabf88f6070108bdfc8e60f34304a6

Sudheer Shanka   commited 2023-01-24 19:33:06 +00:00
74fe7178af
Fix a bug where adding a user doesn't update network allow lists
Even if there are no preferences, the allow list needs
to be updated upon adding a new user, because it's set
unconditionally when the network connects.

Adding all existing UIDs would address this issue too
and we probably want to do it, but immediately this
seems simpler.

Bug: 266136779
Test: new test for this
Change-Id: I77091a6c3d3ccf2b80ab0aaa01d09ef0df922501

Chalard Jean   commited 2023-01-23 17:40:01 +09:00
e0abd52557
[DK2]Add new SocketKeepalive.start to dynamically control keepalive
Add SocketKeepalive.start with parameter to enable dynamic
keepalive mode based on the existence of TCP connections.

This supports IPSec mode to notify KeepaliveTracker to disable
keepalive when keepalive is unnecessary to improve battery life.

Keepalive is controlled by periodically TCP socket status check
for both enable and disable. This is a transition commit and
is expected to be updated based on the socket creation or
destroy.

Bug: 259000745
Test: m ; atest FrameworksNetTests
Change-Id: Ie4d598d69a73c4931c7d0b6dfde0e459e5dca6b4

chiachangwang   authored and   Chalard Jean   commited 2023-01-20 13:51:20 +09:00
9ef4ffe8d4
[DK2-0]Create AutomaticOnOffKeepaliveTracker
Add a new AutomaticOnOffKeepaliveTracker class between
ConnectivityService and KeepaliveTracker to handle the automatic
on/off keepalive. This commit only creates this new class and
move the TCP polling code to the new class as a preparation for
the following commit.

The original test file was created for testing the TCP polling
mechanism, so rename it to match the new class.

Bug: 259000745
Test: m ; atest FrameworksNetTests
Change-Id: I1b229f906283c0f5ef7a3efdb0572fcbfc5df72b

chiachangwang   authored and   Chalard Jean   commited 2023-01-19 13:17:54 +09:00
3d60bacfa0
Merge "Apply "most-recent" delivery policy to CONNECTIVITY_ACTION."
Jean Chalard   authored and   Gerrit Code Review   commited 2023-01-12 06:37:26 +00:00
526df99b53
Enterprise slicing for profile blocking default
Test: atest ConnectivityServiceTest#testProfileNetworkPreferenceBlocking_networkChanges \
      ConnectivityServiceTest#testProfileNetworkPreferenceBlocking_changePreference \
      --rerun-until-failure 100
Bug: 263219497

Change-Id: Idbda582542bcabf0156e2bab9f8bea42fc908cae

Junyu Lai   commited 2023-01-11 10:47:00 +08:00
35665cc887