Commit graph android_packages_modules_Co.../service/src/com/android/server/ConnectivityService.java
Message SHA1
Merge "Use destroyLiveTcpSocketsByOwnerUids for frozen apps" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-08-09 05:17:14 +00:00
b7d3f3fd77
Revert isDefaultNetworkActive behavior when there is no default network
aosp/2605757 updated isDefaultNetworkActive returns false when there is
no default network.
But this change was not merged to U release branch and this change was
not well tested by dogfooding.
So this CL reverts the isDefaultNetworkActivity behavior change.

Bug: 279380356
Bug: 291870075
Test: atest FrameworksNetTests
Change-Id: Id88662faea9eeaba93d59ab2729f6204a3631ab1

Motomu Utsumi   commited 2023-08-01 12:50:00 +09:00
51e7a60359
Revert onNetworkActive callback behavior on U+
aosp/2605757 changed onNetworkActive callback behavior on U+ but this
change was not merged to U release branch.
This CL reverts the behavior change and keep the current behavior on U+.

Bug: 279380356
Bug: 291870075
Test: atest FrameworksNetTests
Change-Id: I91ccc7ee93f0827986401f316997b4a2df11318f

Motomu Utsumi   commited 2023-07-31 19:33:24 +09:00
1e51a64988
Use destroyLiveTcpSocketsByOwnerUids for frozen apps
Bug: 284900338
Test: FrameworksNetTests
Change-Id: Ia10f3c3b01c42d6ae5ba7b18786b66ca3209b108

Motomu Utsumi   commited 2023-06-29 11:41:06 +09:00
588a64587d
Never create native network immediately.
This patch flags off the functionality added by aosp/2162425
in the wake of b/286649301 where a race in ConnectivityService
breaks WiFi connectivity until reboot.

Bug: 286649301
Test: NetworkAgentTest
      ConnectivityServiceTest
Change-Id: I96d755445f6e1f88bb71a7d32742e87dae185250

Chalard Jean   commited 2023-06-27 20:05:20 +09:00
a16607f421
Revert "Always disconnect agents immediately."
This reverts commit 4bc9fa6b8c.

Reason for revert: b/288450518

Some iterations over mNetworkAgentInfos result in networks being
disconnected, which removes them from mNetworkAgentInfos during
iteration. This crashes with NPE or OOB exceptions.

Bug: 286649301
Bug: 288149251
Bug: 288450518
Change-Id: I6e0b5b614d9e88267db77cb807ae4bf09f88c0f6

Jean Chalard   authored and   Chalard Jean   commited 2023-06-27 19:19:11 +09:00
3160bc0825
Evaluation delay = 8 secs for explicitly selected networks
When a network was explicitly selected, the user just tapped it and
is likely waiting for it to connect. A shorter timeout is therefore
more appropriate for these.

Bug: 281970908
Test: New test in ConnectivityServiceTest
Change-Id: I99a263960cbc9292868fc4bb46a4f3b2f3c71541

Chalard Jean   commited 2023-06-20 18:48:39 +09:00
0f1413395d
Merge "Fixes isDefaultNetworkActive and onNetworkActive unreasonable behavior"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-20 01:00:24 +00:00
e0365d45ca
Fixes isDefaultNetworkActive and onNetworkActive unreasonable behavior
This CL changes the behavior as follows.

Before this CL, isDefaultNetworkActive returns true if there is no
default network.
After this CL, isDefaultNetworkActive returns false if there is no
default network on all releases.

Before this CL, LegacyNetworkActivityTracker does not call
onNetworkActive callback for networks that tracker does not add the idle
timer to (e.g.  ethernet, cell network configured with activity tracking
disabled).
After this CL,
On T-, onNetworkActive keeps the current behavior.
On U+, onNetworkActive is called regardless of the idle timer existence. This behavior is consistent with ConnectivityManager#isDefaultNetworkActive, which always returns true for a network that has no activity tracking.

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

Motomu Utsumi   commited 2023-06-20 00:59:46 +00:00
6225d57b18
Merge "Remove locks from LegacyNetworkActivityTracker"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-20 00:58:14 +00:00
d66e846764
Merge "Add executing thread check in LegacyNetworkActivityTracker"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-20 00:57:45 +00:00
48d4e66542
Merge "Add idleTimer existence check before removing idleTimer"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-20 00:45:03 +00:00
40177cf4cb
Merge "Move network activity change processing to handler thread"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-20 00:44:47 +00:00
df9a2d7e20
Remove locks from LegacyNetworkActivityTracker
Following CLs update LegacyNetworkActivityTracker to support multiple
network activity tracking on U+ devices.
This CL is a preparation for them.

Reasons for having locks in LegacyNetworkActivityTracker were 1)
mNetworkActive can be updated from non handler thread 2)
isDefaultNetworkActive can be called from non handler thread and this
return boolean based on mNetworkActive and mActiveIdleTimers.

aosp/2606673 moves the activity change processing to handler thread
and resolved the first reason.
This CL updates isDefaultNetworkActive to just return
mNetworkActive and resolved the second reason.

So, now LegacyNetworkActivityTracker doesn't need locks and this CL
removed the locks.

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

Motomu Utsumi   commited 2023-06-19 16:03:29 +09:00
c298cf0c2d
Always disconnect agents immediately.
Currently, various codepaths in ConnectivityService disconnect
networks using NetworkAgentInfo#disconnect. This posts a message
to the NetworkAgent to disconnect and also posts a message to
ConnectivityService to call disconnectAndDestroyNetwork, which
performs all cleanup in ConnectivityService. These two messages
race and the order is non-deterministic.

Instead, always disconnect using disconnectAndDestroyNetwork,
and have disconnectAndDestroyNetwork post the message to the
agent to disconnect.

This fixes a bug where if wifi uses unregisterAfterReplacement
twice in quick succession, when the third agent connects it
doesn't work because the interface is still being used by the
second network.

Also remove the import of IllegalArgumentException to keep the
linter happy (java.lang.* never needs to be imported).

Bug: 286649301
Test: covered by existing tests
Change-Id: Ie01f5589d6839ac6db25f0ba98fc929fbb5b0a96

Lorenzo Colitti   commited 2023-06-14 18:03:02 +09:00
4bc9fa6b8c
Merge changes I4994dd8d,I98c1aab4
* changes:
  Annotate ClatCoordinator with RequiresApi(T), part 2
  Annotate ClatCoordinator with RequiresApi(T)

Maciej Å»enczykowski   authored and   Gerrit Code Review   commited 2023-06-09 09:06:25 +00:00
472d51344c
Annotate ClatCoordinator with RequiresApi(T), part 2
Test: TreeHugger
Bug: 284253984
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4994dd8d4e5e303bca6c33928d359064632b3c4d

Maciej Å»enczykowski   commited 2023-06-09 09:06:19 +00:00
7b05987701
Add executing thread check in LegacyNetworkActivityTracker
One of the reasons for having locks in LegacyNetworkActivityTracker is
mNetworkActive is updated from non handler thread.
aosp/2606673 moves network activity change processing to handler thread.
All the methods that update mNetworkActive and mActiveIdleTimers should
be called from handler thread now.

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

Motomu Utsumi   commited 2023-06-09 17:41:01 +09:00
e0ecaea594
Add idleTimer existence check before removing idleTimer
IdleTimer tracking can be disabled if configured timeout is 0 or
negative value.
In this case, setupDataActivityTracking does not add idleTimer and
removeDataActivityTracking causes NPE.
This did not cause crash since the code to cause NPE is wrapped by try
catch.
This CL adds check to avoid causing NPE.

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

Motomu Utsumi   commited 2023-06-09 17:28:47 +09:00
00ccb51aa3
Move network activity change processing to handler thread
Following CLs update LegacyNetworkActivityTracker to support multiple
network activity tracking on U+ devices.
This CL is a preparation for them.

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

Motomu Utsumi   commited 2023-06-09 17:28:47 +09:00
5dfaf4e176
Merge "Remove spurious WTF on pre-U devices."
Lorenzo Colitti   authored and   Gerrit Code Review   commited 2023-06-07 09:00:13 +00:00
c2851d45fd
Remove spurious WTF on pre-U devices.
aosp/2162425 added a WTF if a NetworkAgent changed state before
its native network has been created. This was intended to apply
only to the new U+ codepath, where networks are always created
immediately as soon as their agents register them. But the WTF is
logged on pre-U devices as well.

Fix this so that the WTF is only logged when the new codepath is
running.

Fix: 285999421
Test: TH
Change-Id: I28bda08a006978ab760fe8891bf5cf15b536201a

Lorenzo Colitti   commited 2023-06-07 11:42:20 +09:00
233f2d1d19
Merge "Fix a bug where the PAC proxy port is not set correctly."
Jean Chalard   authored and   Gerrit Code Review   commited 2023-06-06 12:22:21 +00:00
f2b38772ac
Fix a bug where the PAC proxy port is not set correctly.
Test: new test for this behavior in the preliminary change
Test: FrameworksNetTests NetworkStackTests
Fixes: 138810051
Fixes: 140610528
Change-Id: I95a979d232fb60ece2e33e972bf5d66d20357a1f

Aaron Huang   authored and   Chalard Jean   commited 2023-06-05 20:24:59 +09:00
9fe47bee09
Merge "On U+ require config_networkWakeupPacketMark/Mask to be 0x80000000"
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-06-05 09:34:47 +00:00
c133f6e29c
On U+ require config_networkWakeupPacketMark/Mask to be 0x80000000
See system/netd/include/Fwmark.h which reserves the bottom 21 bits
of skb->mark for netid, etc... so out of necessity these have to be
in the top 11 bits.

In practice the only values that really make sense are either:
  mark == mask == 0 (disabled)
or (mark == mask) being one of the top 11 available bits, for example:
  mark == mask == 0x80000000 (enabled, using top-most bit)
(only a single bit makes sense, as this is really just a boolean signal,
 and only the topmost is known to be used on any real devices)

Let's just force the use of 0x80000000 for ecosystem consistency.

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

Maciej Å»enczykowski   commited 2023-06-05 07:41:00 +00:00
cf41fc877a
Merge "Use netd socketDestroy for VPN in T-"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2023-06-05 03:04:19 +00:00
d8b852fc06
Use netd socketDestroy for VPN in T-
aosp/2490881 updated to use InetDiagMessage.destroyLiveTcpSocket for all
devices.
But it is possible that netd socketDestory is modified in T- devices.
So this CL revert changes to keep using netd socketDestroy in T-
devices.

Test: atest FrameworksNetTests
Bug: 284253763
Change-Id: I9b61f10e975d2e38e9829a8c01d3af706e2518ef

Motomu Utsumi   commited 2023-06-04 23:12:58 +09:00
1d13726710
Merge "Add tests for PAC proxies."
Jean Chalard   authored and   Gerrit Code Review   commited 2023-06-01 05:20:37 +00:00
5e76b40973
Add tests for PAC proxies.
Test: this is a change that adds a test
Bug: 138810051
Bug: 140610528
Change-Id: I6e7b77320f6baf32ac2f98634fa2e3231d1bf12f

Aaron Huang   authored and   Chalard Jean   commited 2023-05-30 15:53:11 +09:00
40b524448c
Instrument SDK level and change IDs to help testing
This patch mocks the SDK level and/or change IDs to help
developing functionality that depends on these without
having to flash a new device every time.

Test: TH
Change-Id: I1011193c99e123a0e5501ed313c9cecbceebdae6

Chalard Jean   commited 2023-05-29 18:42:31 +09:00
df29a85ee7
Merge "Revert "Suppress lint for methods using APIs promoted from system to public""
Treehugger Robot   authored and   Gerrit Code Review   commited 2023-05-25 08:21:39 +00:00
22df1c47ec
Revert "Suppress lint for methods using APIs promoted from system to public"
This reverts commit 73f6948915.

Reason for revert: The bug that necessitated this workaround has been addressed.

Change-Id: Idac3903df029e841bde6c57c9d453b56760d2553
Test: TH

Jean Chalard   commited 2023-05-23 07:47:35 +00:00
cf83d376bc
Use "don't actively prefer" timeout when avoiding bad wifi
Test: ConnectivityServiceTest
Change-Id: I6e99aff77c55805630d878e472f466bd31bba360

Chalard Jean   commited 2023-05-23 13:47:15 +09:00
6f6c353baf
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