Commit Graph

73838 Commits

Author SHA1 Message Date
Motomu Utsumi
00ccb51aa3 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
2023-06-09 17:28:47 +09:00
Motomu Utsumi
5dfaf4e176 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
2023-06-09 17:28:47 +09:00
Motomu Utsumi
2738f4fd4d Add test for default network activity APIs
Following CLs update LegacyNetworkActivityTracker to support multiple
network activities including non default network.
To avoid breaking default network activity APIs, this CL adds tests.
Following CL fix known issues of LegacyNetworkActivityTracker so this
CL also adds test for known issue behavior.

Bug: 279380356
Test: FrameworksNetTests
Change-Id: Ic180efe690807e940d0b412a38ebc5e6d22691c4
2023-06-09 17:28:44 +09:00
Chiachang Wang
e6f9de64af Merge "Correct the order of import and remove unused definition" 2023-06-07 09:18:10 +00:00
Lorenzo Colitti
c2851d45fd Merge "Remove spurious WTF on pre-U devices." 2023-06-07 09:00:13 +00:00
chiachangwang
8af048721a Correct the order of import and remove unused definition
Test: atest
Change-Id: I60c409db5436a5ba9fffdee9df24158f15751658
2023-06-07 06:46:29 +00:00
Junyu Lai
1edaaf291a Merge "Add more log when Range misconfigured" 2023-06-07 05:28:30 +00:00
Lorenzo Colitti
233f2d1d19 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
2023-06-07 11:42:20 +09:00
Junyu Lai
e4a6153d08 Add more log when Range misconfigured
Currently, when lower/upper bound of Range is incorrect,
there is no useful information for debugging.

Test: atest TrafficStatsTest
Bug: 285452306
Change-Id: I0e390692c20b37e14958ecc0fd45c93f73fe63e2
2023-06-07 10:41:08 +08:00
chiachangwang
c6a2f6faf5 Set DF flag on NAT-T keepalive packet
This commit
- Set the DF flag on the NAT-T keepalive packet
- Add comment for TTL value
- Do some cleanups

Bug: 196453719
Test: m
Change-Id: I401ae52d8f16e43120210cdea223fd251d53ea3b
2023-06-07 02:05:27 +00:00
chiachangwang
df347448a1 Make a v4 nattKeepalivePacket helper method
This is a preparation change for the subsequent changes to
separate the logic for constructing a v4 NAT-T keepalive
packets to a dedicated method.

Bug: 196453719
Test: atest FrameworksNetTests
Change-Id: If72b4875e65a547bbf90367eacce7b145358006a
2023-06-07 02:05:10 +00:00
Jean Chalard
f2b38772ac Merge "Fix a bug where the PAC proxy port is not set correctly." 2023-06-06 12:22:21 +00:00
Treehugger Robot
1667bfea04 Merge "Update record receipt time on records updated" 2023-06-06 08:34:39 +00:00
Remi NGUYEN VAN
5f921c4292 Merge "Take the multicast lock on mDNS usage" 2023-06-06 08:01:21 +00:00
Yuyang Huang
86f674187f Update record receipt time on records updated
The receipt time in the MdnsResponse need to be updated every time new
packet is received. And then the record refreshing logic could calculate
remaining TTL correctly.

Bug: 285260665
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Ib7a290ea0ea8e552c71c657696397e8114fcee52
2023-06-06 12:55:27 +09:00
Treehugger Robot
3e5aab1eda Merge "cronet tests: Do not run integration tests on R" 2023-06-06 03:03:12 +00:00
Remi NGUYEN VAN
a8efbe0e32 Take the multicast lock on mDNS usage
When an mDNS request (discovery, advertising, resolving...) is
registered and gets assigned a socket on a wifi network, take the
multicast lock to ensure that it can reliably receive mDNS responses.

This is limited to when the application has importance
FOREGROUND_SERVICE or higher.
NsdManager is not documented to require usage of the multicast lock,
which has caused various reports about its reliability. Taking the lock
while the app is in the foreground should address the large majority of
cases, while limiting battery impact.

Going forward this should allow developers on U+ to not take the
lock themselves, allowing optimizations on devices supporting APF,
where instead of taking the lock APF would let through only select
mDNS packets.

Bug: 284389438
Test: atest
Change-Id: I1ce85220eac4a1529b6716d50727c1c462356846
2023-06-06 11:13:34 +09:00
Patrick Rohr
92c4636c5c cronet tests: Do not run integration tests on R
CtsNetHttpTestCases were missing a DevSdkIgnoreRule after updating the
min_sdk version to R+ (which made it installable on R where the cronet
classes are not in the bootclasspath.)

Test: atest CtsNetHttpTestCases
Bug: 259632936
Change-Id: I706ff92376227c1759fd6e542066fcff3a7cf052
2023-06-05 15:32:54 -07:00
Maciej Żenczykowski
9287d69620 Merge "Added additional logging to bpf handler" 2023-06-05 21:39:41 +00:00
Nick Wille
5076a021c8 Added additional logging to bpf handler
Bug: b/278923463
Test: Treehugger
Change-Id: I5b46b488723ebcde223b758c03c70fa8b1f14c25
2023-06-05 18:45:13 +00:00
Aaron Huang
9fe47bee09 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
2023-06-05 20:24:59 +09:00
Treehugger Robot
c133f6e29c Merge "On U+ require config_networkWakeupPacketMark/Mask to be 0x80000000" 2023-06-05 09:34:47 +00:00
Maciej Żenczykowski
cf41fc877a 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
2023-06-05 07:41:00 +00:00
Hansen Kurli
48e61a4520 Merge changes I8fcaa1f0,I8925fbe4,I78394645,Iadf9f060
* changes:
  FinalizePausedKeepalive in handleStopAllKeepalives.
  Add tests for pause, resume and stop keepalives.
  Ensure autoKi is not stored when keepalive stops or is not started.
  Add tests for NATT keepalives stopped internally in KeepaliveTracker.
2023-06-05 04:56:16 +00:00
Motomu Utsumi
d8b852fc06 Merge "Use netd socketDestroy for VPN in T-" 2023-06-05 03:04:19 +00:00
Xiao Ma
1eb19caf40 Merge "Add NetworkStackModuleTest annotation on the specific test case." 2023-06-05 01:45:01 +00:00
Motomu Utsumi
1d13726710 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
2023-06-04 23:12:58 +09:00
Paul Hu
83bd5a5927 Merge changes If830eb53,If03514f1
* changes:
  Update tethered/local only interfaces when no all networks request
  Use wifi p2p interfaces for mDNS
2023-06-02 13:10:51 +00:00
Paul Hu
bb69412f5b Update tethered/local only interfaces when no all networks request
If there is no request for all networks, the tethered/local only
interface changes will be ignored. However, these available
interfaces are not used for mDNS when a user requests a socket
with a null network because the interfaces are lost due to the
previous ignore. Therefore, the interface changes should be
retained and will be used for socket creations afterwards.

Bug: 284939720
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: If830eb53af26f21f497314477b131ce28468a971
2023-06-02 08:54:41 +00:00
Paul Hu
fbba5e8307 Use wifi p2p interfaces for mDNS
mDNS is used by wifi p2p in many places. However,
MdnsSocketProvider does not monitor changes to the wifi p2p
connection to get the names of the available wifi p2p interfaces.
This prevents mDNS from registering or discovering services on
the wifi p2p interfaces. Therefore, listen to the wifi p2p change
intent to know the available interfaces and status changes that
can be used by mDNS.

Bug: 284263838
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: If03514f1286c0507e5862372272234dd07eb084d
2023-06-02 08:54:41 +00:00
Yuyang Huang
c823dc2259 Merge changes from topic "refresh-record"
* changes:
  Renew the SRV/TXT records if half of TTL passed
  Turn on removeExpiredService feature
2023-06-02 08:10:52 +00:00
Yuyang Huang
f2cc01dc12 Renew the SRV/TXT records if half of TTL passed
As mentioned in RFC6762 7.1. The records only needed to be renewed if
at least half of the TTL passed. Usually A/AAAA records are included in
the response to the SRV record query, they are not refreshed individually.

Bug: 285261577
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Ifd7140de0d733191256184c5481412e1822d279b
2023-06-02 15:36:09 +09:00
Yuyang Huang
925a81b1dc Merge "Update the SDK version to 34 in ConnectivityTestsLatestSdkDefaults" 2023-06-02 06:22:18 +00:00
Maciej Żenczykowski
65075bb8f8 BpfHandler: abort on U+ if unexpected cgroup mount path
This is defined here:
http://cs/h/android/platform/superproject/+/master:system/core/libprocessgroup/profiles/cgroups.json?l=27
and has been a constant since
  https://android-review.googlesource.com/c/platform/system/core/+/1324649
was merged back on August 21, 2020 (ie. Android S)

But currently there's no easy way to get at this constant
from mainline code... which means it's very difficult
to do any bpf cgroup attach/detach from mainline.

btw. this appears to also be already hardcoded in:
http://cs/h/android/platform/superproject/+/master:packages/modules/Connectivity/service/src/com/android/server/connectivity/ConnectivityNativeService.java?l=48
as well

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I99f4a5a26dd10f6ea70bf73114af0d18098de630
2023-06-02 03:44:11 +00:00
Yuyang Huang
ff96322c4f Turn on removeExpiredService feature
Turn on removeExpiredService feature by: 1) Remove the unnecessary
allowSearchOptionsToRemoveExpiredService flag. 2) Turn on the
removeExpiredService flag in the MdnsSearchOptions.

Bug: 285260665
Test: atest CtsNetTest FrameworksNetTests
Change-Id: Ib115b40e70b0f81a7877deb73af7d61e2e0c385f
2023-06-02 12:33:55 +09:00
Xiao Ma
161b70c587 Add NetworkStackModuleTest annotation on the specific test case.
EthernetTetheringTest#testTetherZeroLengthDhcpPacket requires the latest
NetworkStack module, otherwise, the test will fail due to the loss of
the fix. Apply @NetworkStackModuleTest to exclude this testcase from
target test suite CtsTetheringTestLatestSdk.

Bug: 283200648
Test: atest CtsTetheringTestLatestSdk
Change-Id: Iebfb043e2b71427a6feaf90788fe79b6ab6b678d
2023-06-01 18:16:24 +09:00
Hansen Kurli
9656e23d91 FinalizePausedKeepalive in handleStopAllKeepalives.
In the case that a keepalive is paused and handleStopAllKeepalives is
called, there is no KeepaliveInfo for the paused keepalive and so no
onError callback will be called. The autoKi will also be cleaned up so
no callback will ever called that notifies the keepalive is stopped.

Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: I8fcaa1f07746235326c7ae05d97e20fd27927fea
2023-06-01 06:45:07 +00:00
Hansen Kurli
01d0ef1636 Add tests for pause, resume and stop keepalives.
The tests added verify the following:
1. Stopping the keepalive will cleanup the autoKi.
2. Pausing the keepalive does not cleanup the autoKi and stopping
   a paused keepalive will still call the onStopped callback.
3. A starting error by resuming the keepalive will cleanup the
   autoKi.
4. handleStopAllKeepalives also does the appropriate callback for paused
   keepalives.
5. Stopping a resumed keepalive stops the correct slot when a second
   keepalive is started while the first is paused.

Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: I8925fbe40323dc4584a111d0cf31de016525ef41
2023-06-01 06:44:52 +00:00
Hansen Kurli
0d179a3ff0 Ensure autoKi is not stored when keepalive stops or is not started.
In the cases below, the keepalive is already cleaned up internally in
KeepaliveTracker, but are not be cleaned up in
AutomaticOnOffKeepaliveTracker. This means the mAutomaticOnOffKeepalives
list is storing stopped keepalives and the metrics will still conisder
the keepalive as active.

1. In KeepaliveInfo.start, return whether the keepalive is successfully
   starting(i.e. mStartedState == STARTING). Check for this in
   handleStartKeepalive and return early on failure, without storing the
   autoKi. Also check in handleResumeKeepalive.
2. In handleEventSocketKeepalive, return whether the handleStopKeepalive
   is called, indicating the keepalive is forced to stop and was not
   already STOPPING. This should happen when the state is STARTING but
   the network agent returned an unsuccessful event.
3. In handleCheckKeepalivesStillValid, move the checking logic to
   AutomaticOnOffKeepaliveTracker so the handleStopKeepalive is called.

Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: I7839464534baed43abbd40b321287132da25b978
2023-06-01 06:02:16 +00:00
Jean Chalard
5e76b40973 Merge "Add tests for PAC proxies." 2023-06-01 05:20:37 +00:00
Sudheer Shanka
bdd3ca1ac6 Merge "Avoid hardcoding BATTERY_PLUGGED_ANY constant." 2023-05-31 19:19:11 +00:00
Yuyang Huang
c2baf9403a Merge "Matches all MdnsServiceTypeClient if using MdnsSocketClient" 2023-05-31 10:14:32 +00:00
Yuyang Huang
d72daab448 Matches all MdnsServiceTypeClient if using MdnsSocketClient
MdnsSocketClient doesn't support requesting specific network. As a
result, when processing the response, all the MdnsServiceTypeClient
should be called.

Bug: 285064577
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: Id95f1e78d60063ccee7f5855a21fa6b5a48fbd3e
2023-05-31 15:39:08 +09:00
Mark Chien
72fe588d45 Merge "Add CtsTetheringTestLatestSdk into mainline-presubmit" 2023-05-31 06:13:31 +00:00
Treehugger Robot
f9f9784d4c Merge "Only allow libconnectivity_native usage on U+" 2023-05-31 05:35:20 +00:00
Mark Chien
f8870fa7af Add CtsTetheringTestLatestSdk into mainline-presubmit
Also test CtsTetheringTestLatestSdk on physical devices
physical SIM in mainline-post

Test: TH

Change-Id: Ia9806c46fbe49282017011ea6ca414e2c58fe00b
2023-05-31 03:50:26 +00:00
Sudheer Shanka
234c2895e8 Avoid hardcoding BATTERY_PLUGGED_ANY constant.
Bug: 284904539
Test: TH
Change-Id: I8685f8008fd4a431136ef2900b45509f2ef7cc0b
2023-05-30 21:51:29 +00:00
Hansen Kurli
76adfacd84 Add tests for NATT keepalives stopped internally in KeepaliveTracker.
Add tests where NATT keepalives are stopped and cleaned up within
KeepaliveTracker in these scenarios:
1. startNattKeepalive is called with an invalid interval.
2. The state is STARTING and the network agent returns an error event.
3. The keepalive started successfully but becomes invalid and
   handleCheckKeepalivesStillValid is called on the network.

Bug: 281646074
Test: atest FrameworksNetTests
Change-Id: Iadf9f06030cae20f36d950f520c8dcc4181924ad
2023-05-30 11:27:11 +00:00
Treehugger Robot
ae9b229b7e Merge "Add MdnsDiscoveryManager constructor without looper" 2023-05-30 10:24:27 +00:00
Yuyang Huang
243d1a5de4 Add MdnsDiscoveryManager constructor without looper
In some use cases for the MdnsDiscoveryManager, providing looper as an
argument to the MdnsDiscoveryManager constructor is not feasible. Adding
a constructor without looper can help to match those use cases. If
constructor without looper is used. The shutDown() must be called as a
part of cleanup process.

Bug: 283914408
Test: atest FrameworksNetTests
Change-Id: I0ab04d67bae127628c6d67c4b8c109201612a54b
2023-05-30 17:14:54 +09:00