Commit graph android_packages_modules_Co.../service/src/com/android/server/ConnectivityService.java
Message SHA1
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
Apply "most-recent" delivery policy to CONNECTIVITY_ACTION.
This allows us to skip any older CONNECTIVITY_ACTION broadcasts
waiting to be delivered when a new broadcast is dispatched.

Bug: 255545931
Test: TH
Change-Id: Iac5da2f727e295d1775bfe91358900f316258be4

Sudheer Shanka   commited 2023-01-09 03:21:44 +00:00
2453a3ada2
Merge changes from topics "ADD_JVMOVERLOADS", "VPN_NETWORK_PREFERENCE"
* changes:
  Add HostsideVpnTests for testing setVpnDefaultForUids()
  Add CTS for ConnectivityManager#setVpnDefaultForUids()
  Create a new API to make a set of UIDs use only VPN by default

Lucas Lin   authored and   Gerrit Code Review   commited 2022-12-21 01:13:47 +00:00
e0e9b0c701
Merge "Ensure MTU is set for new interfaces."
Maciej Å»enczykowski   authored and   Gerrit Code Review   commited 2022-12-20 14:51:33 +00:00
986fe9604b
Ensure MTU is set for new interfaces.
Setting the MTU for an interface should not be skipped when the
interface names are different. This occurs when a VPN network creates
a new interface with identical MTU.

Bug: 246398088
Test: atest ConnectivityServiceTest
Test: Manual test: Connect to VPN network and switch networks
Test: Confirm MTU of interface is set correctly with `adb shell ip addr`
Change-Id: I811a01feca2fb2130c57c6c924145314180434c5

Hansen Kurli   commited 2022-12-20 09:28:36 +00:00
0425203152
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

lucaslin   commited 2022-12-19 05:35:04 +00:00
3ba7cc25c0
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

Igor Chernyshev   commited 2022-12-16 17:55:53 +00:00
9dac660bf0
Make ProfileNetworkPreferenceList generic
This will be useful for VPN profile preferences.

Change-Id: Id3b7d57d29d32ff9e1fcd410f55148b3c85b1a7c
Test: FrameworksNetTests
      CtsNetTestCases
      FrameworksNetIntegrationTests
      NetworkStackTests
      NetworkStaticLibTests
      TetheringTests
      MtsTetheringTestLatestSdk
      TetheringIntegrationTests
Bug: 262482087

Chalard Jean   authored and   Jean Chalard   commited 2022-12-15 06:08:03 +00:00
0606fc83a6
Merge "Disconnect network when captive portal returns unwanted."
Hansen Kurli   authored and   Gerrit Code Review   commited 2022-12-12 06:43:01 +00:00
3597deb5e1
Merge "Ensure calling package and UID synchronized while calling dump()"
Chiachang Wang   authored and   Gerrit Code Review   commited 2022-12-05 00:48:25 +00:00
2217cd03f4
Revert consider TEMPORARILY_NOT_METERED as unmetered in data usage
Currently, NET_CAPABILITY_TEMPORARILY_NOT_METERED traffic is
counted as unmetered data usage, and "mobile data usage"
settings screen shows metered data usage which means it doesn't
include TEMPORARILY_NOT_METERED traffic. However, some carriers
show TEMPORARILY_NOT_METERED data usage in customer's bill which
would be confusing if the data usage in the device shows different
results. Thus, revert the change to avoid confusing.

Bug: 183776809
Test: FrameworksNetTests
Change-Id: I4ef25095462adf30b1ecf82134996739f167930d

Aaron Huang   commited 2022-12-02 16:04:55 +08:00
c5a05d1d8f
Ensure calling package and UID synchronized while calling dump()
This commit clear the calling identity before accessing the
DeviceConfig in ConnectivityService#dump().

The calling package of DeviceConfig.getProperties() comes from
ActivityThread.currentApplication(). In ConnectivityService#dump(),
the caller is ConnectivityService. It's OK to access DeviceConfig
from ConnectivityService. The same scenario applies to an app with
proper permission accessing DeviceConfig from its own context.

However, if cts would like to verify design by calling
ConnectivityService#dump(), the calling uid will comes from the
binder but package name will stay as ConnectivityService which
is 'android'. This will result in a SecurityException says that
the package does not match the uid and failed the test.

Bug: 255231779
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: I257e246b1cbf3b8a93bee2c326055ced9dfde588

chiachangwang   commited 2022-12-01 00:22:34 +00:00
18a6e8cf2f
Deal with permission update on handler thread
To ensure that permission cannot change while CS is doing works,
scoring networks, sending callbacks, etc. So making all
permission update are running on handler thread.

Bug: 232048835
Test: FrameworksNetTests CtsNetTestCases
Change-Id: I5380ec8ff1282a1056d9063848e0fff8b3a570ec

Paul Hu   commited 2022-11-22 07:18:36 +00:00
51f816be4a
Running PermissionMonitor#startMonitoring on handler thread
Most permission update functions are running on the handler
thread. So the startMonitoring() should be running on handler
thread as well to ensure the permission won't change while
processing CS's works.

However, startMonitoring() has a dependency with
MultipathPolicyTracker. It needs to call and complete the
permission update before calling MultipathPolicyTracker#start.
Thus, we need to check the startMonitoring done in the end of
systemReadyInternal because we are processing it on the handler
thread.

Bug: 232048835
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I41fef14d6c163eb5676eab3ccd43416ea1fe1414

Paul Hu   commited 2022-11-22 07:08:05 +00:00
3c8c810110
Disconnect network when captive portal returns unwanted.
When the user selects "Do not use this network" in the captive portal
app, it indicates that the user does not want to log in and does not
want to use the network. Thus, the network should be disconnected.

Internally handle the network disconnect in ConnectivityService upon
receiving a captive portal app response of APP_RETURN_UNWANTED.

Test: atest ConnectivityServiceTest
Change-Id: I789ddb663b533a71a77ed435fa91b0c20d3bbfd4

Hansen Kurli   commited 2022-11-14 03:42:32 +00:00
553969769d
Merge "Revert "Partially enforce permission when calling getNetworkInfoForUid""
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-11-10 12:13:56 +00:00
016269fbb8
Revert "Partially enforce permission when calling getNetworkInfoForUid"
This reverts commit 163cb98751.

Reason for revert: b/257407201

Change-Id: I412140117d25f4a4b439fff5aaa50785f33b0689

Junyu Lai   authored and   Gerrit Code Review   commited 2022-11-10 03:19:06 +00:00
d0cf7784dc
Merge "Allow USE_RESTRICTED_NETWORKS for registerSystemDefaultNetworkCallback"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-11-09 05:49:54 +00:00
31ee1c1121
Merge "Notify NetworkStatsService if TEMPORARILY_NOT_METERED changed"
Aaron Huang   authored and   Gerrit Code Review   commited 2022-11-08 11:55:53 +00:00
4bf6a92a0a
Notify NetworkStatsService if TEMPORARILY_NOT_METERED changed
Currently 5G usage includes both metered and unmetered usage.
To support 5G unmetered usage metrics, unmetered usage should
be separated from the 5G usage. Thus, ConnectivityService needs
to inform NetworkStatsService if TEMPORARILY_NOT_METERED has
changed. Then NSS will count temporarily not metered usage as
unmetered.

Bug: 222339311
Bug: 183776809
Test: FrameworksNetTests:ConnectivityServiceTest
Change-Id: I0c7e1eb98925184f36e322e09b4d3d8c6f056fa6

Aaron Huang   commited 2022-11-08 16:01:54 +08:00
c067c87672
Merge "Receive user added/removed intents from PermissionMonitor"
Paul Hu   authored and   Gerrit Code Review   commited 2022-11-07 04:58:44 +00:00
38f2832f8a
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

Junyu Lai   commited 2022-11-02 14:16:36 +08:00
aa4ad8c2d1
Merge "Add nullability annotations for functions called by updateLinkProperties"
Junyu Lai   authored and   Gerrit Code Review   commited 2022-10-31 05:43:07 +00:00
20a347f825
Add nullability annotations for functions called by updateLinkProperties
This address left over comment at aosp/2243498

Test: TH
Change-Id: Ie381e51f204dd73bbe4dd4bba299dee9984e512a

Junyu Lai   commited 2022-10-27 15:39:58 +08:00
970963ed9c
Merge "Notify NetworkStats only when interfaces changed in updateLinkProperties"
Junyu Lai   authored and   Gerrit Code Review   commited 2022-10-27 06:49:33 +00:00
0f4cb380f0
Notify NetworkStats only when interfaces changed in updateLinkProperties
In ConnectivityService, updateLinkProperties calls NetworkStats
even though the ip address or interface name has not changed and
only the tcp buffer size has changed. This is noisy and could
be problematic when RAT change occurs frequently, since when
RAT changes tcp buffer size configuration also changes.

This CL also fixes a wrong nullability annotation where the oldLp
of updateLinkProperties could be null when updateNetworkInfo
is called.

Test: atest ConnectivityServiceTest#testStatsIfacesChanged
Fix: 232048480
Change-Id: Ic226eb4a8aa1f38cba293510813f1cb55f0ea658

Junyu Lai   commited 2022-10-25 15:27:53 +08:00
2ed7d4182a
Merge changes I0789d9bd,Idf4cf74a
* changes:
  Disable ignoring validation on roam just after boot.
  Minor cleanups for ignore validation failures after roam tests.

Treehugger Robot   authored and   Gerrit Code Review   commited 2022-10-25 02:15:29 +00:00
a40faea28d
Disable ignoring validation on roam just after boot.
shouldIgnoreValidationFailureAfterRoam will incorrectly return
true in the first few seconds after boot even if the network
never roamed. This is extremely unlikely to happen, but add a
check for that just in case.

Fix: 230450214
Test: new unit test
Change-Id: I0789d9bdaa0bd9e78673e8f4248a2ca610052f1e

Lorenzo Colitti   commited 2022-10-24 23:28:56 +09:00
580d0d53be