Commit graph android_packages_modules_Co.../tests/unit/java
Message SHA1
Exclude dns servers from LNP
Whenever ip interface is updated, we are updating local network
addresses. These may include dns servers that are needed to be excluded from
restrictions.

Bug : 393354879
Test: Manually and atest
ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSBpfNetMapsTest

Change-Id: Id4ebb33ab7de84ac1c81d485e599779c460bacdc

Neha Raj   commited 2025-02-18 03:28:42 +00:00
4792cc5d98
Populating local addresses to local_net_access_map
Whenever LinkProperties is added/modified/removes, we are updating local
network prefixes for the modified interface/addresses. These prefixes
are used by BPF egress and ingress cgroup hooks to disallow local
network packets if the calling application do not have required
permission.

Bug: 369815823
Test: Manually tested
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSLocalNetworkProtectionTest
Change-Id: Ie592ecb948ae05a0a73f47d0573560eb705f6bcf

Sarup Dalwani   commited 2025-02-17 20:34:41 +00:00
18b7262f60
Merge changes I963a1c84,I515d6b60,Iae99f0bc,I99d1240d,I49d078fb into main
* changes:
  Check whether a NetworkRequest is already tracked
  Check whether client NetworkRequest includes a valid specifier
  Add empty ClientOffer
  Delete L2capNetworkProviderTest
  Add support for an L2CAP server network

Patrick Rohr   authored and   Gerrit Code Review   commited 2025-02-14 15:10:29 -08:00
d74eb41b49
Merge "Fix test flake in MdnsDiscoveryManagerTests" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-02-14 00:46:57 -08:00
f89a40ae61
Exclude Google Cast app subtypes from mDNS offload
This commit excludes Google Cast app subtypes from mDNS offloading. The
large number of subtypes would consume excessive firmware resources if
offloaded.

Test: TH
Change-Id: I562a94187dc5c710ca37d4997e9ed6c1602918b6

Yuyang Huang   commited 2025-02-14 16:08:17 +09:00
9cb8a29436
Merge "Format MdnsAdvertiser with ktlint" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2025-02-13 22:56:33 -08:00
5c374ff035
Delete L2capNetworkProviderTest
These are later replaced by / moved to CSL2capProviderTest.kt

Test: TH
Change-Id: I99d1240dc941daa6c2bf57298d11dc668bcb6c3e

Patrick Rohr   commited 2025-02-13 15:53:02 -08:00
5fb5f07f65
Add support for an L2CAP server network
This change creates an AcceptThread inside ReservedServerOffer which
accepts all incoming L2CAP connections and creates an L2capNetwork for
each of them.

Note that these networks are indistinguishable, so CS will tear all but
the first one down. This is working as intended.

If the L2capNetwork or the AcceptThread encounter any error during
execution, the reserved offer is torn down and the reserving app will
receive an onUnavailable() callback (by virtue of reservation
semantics).

Test: atest NetworkReservationTest
Change-Id: I49d078fb32ff48c1201a8a4dc65cbe785dcc9179

Patrick Rohr   commited 2025-02-13 09:17:56 -08:00
f0abfb976b
Fix test flake in MdnsDiscoveryManagerTests
The MdnsDiscoveryManagerTests#testDiscoveryExecutor test is flaky
because the Future task sometimes fails to complete on the CF
target. This performance-dependent issue causes Future#isDone to
return a false value. Therefore, remove the isDone check, as
Future#get already performs the same check.

Bug: 392995312
Test: atest MdnsDiscoveryManagerTests#testDiscoveryExecutor \
      --iteration 100
Change-Id: I6a032e80da76eae5ec81bfe7900c0b0e3a3c6efa

Paul Hu   commited 2025-02-12 06:28:24 +00:00
54a82760a2
Merge changes Icf49147d,I622c86fe,I3e789541 into main
* changes:
  Move reserved offer teardown into a function
  Store reserved offers in a Set instead
  Allocate a BluetoothServerSocket for the ReservedServerOffer

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-02-10 16:54:47 -08:00
37714f553c
Merge changes I7b966621,I082c7af8,I8cdc8004,Icfba2964 into main
* changes:
  Move L2capNetworkProvider#start() onto Handler thread
  Mark globals as private
  Move the common set of NetworkCapabilities to the provider class
  Add L2capNetwork class

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-02-10 14:44:22 -08:00
38f428c4a3
Merge "Add CTS test for ConnectivityManager#tether exception after V" into main
Quang Luong   authored and   Gerrit Code Review   commited 2025-02-09 22:04:43 -08:00
0e480b7857
Allocate a BluetoothServerSocket for the ReservedServerOffer
This change allocates a BluetoothServerSocket as a response to the
reservation. The resulting PSM is used to create the reserved
capabilities stored in ReservedServerOffer.

Test: TH
Change-Id: I3e789541474a492bb1c015d6316db12a3c995995

Patrick Rohr   commited 2025-02-07 14:27:00 -08:00
466bff2833
Merge "Add L2capPacketForwarder" into main
Patrick Rohr   authored and   Gerrit Code Review   commited 2025-02-07 12:58:48 -08:00
297793e2d2
Move L2capNetworkProvider#start() onto Handler thread
To prevent having to use locking or memory synchronization mechanisms
later on.

Test: TH
Change-Id: I7b966621012030ab78e7a7e21e49ddc5df37df75

Patrick Rohr   commited 2025-02-07 12:57:10 -08:00
195e65db5d
Mark globals as private
Otherwise, they may conflict with other definitions in the same package.

Test: TH
Change-Id: I082c7af8aa186b6101ec08714d1ace5d64c1c95e

Patrick Rohr   commited 2025-02-07 12:57:10 -08:00
735afa97d3
Adding access methods for local_net_access_map and
local_net_blocked_uid_map

Test: Manually tested this using dumpsys commands
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Bug: 392855578

Change-Id: I61522f3282aa502f20641d3c2692a66638edf706

Sarup Dalwani   authored and   Jacque Li   commited 2025-02-07 15:10:49 -05:00
448eb43f28
Listen to permission changes in permission monitor
Bug: 369646309
Test: atest
ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.PermissionMonitorTest

Change-Id: I23c524baaee6b9b06a855fb811906e5189ef03fd

Jacque Li   commited 2025-02-07 15:08:09 -05:00
2003e6ee49
Add L2capPacketForwarder
L2capPacketForwarder forwards packets between an L2CAP BluetoothSocket
and a tun fd.

It uses blocking i/o to do so, since the BluetoothSocket API does not
expose a file descriptor to poll() on.

It remains to be seen whether shutdown() on a tun interface fd is
actually implemented. Currently, the test uses a pair of SOCK_SEQPACKET
sockets which require to be shutdown to interrupt the blocking read.

Test: L2capPacketForwarderTest
Change-Id: I03d2a2dd76ec2b71fdb9e3ea7008daa6d1d124fe

Patrick Rohr   commited 2025-02-07 10:50:48 -08:00
65dc1295dc
Add CTS test for ConnectivityManager#tether exception after V
Current test was mistakenly added to the unit test version of
ConnectivityManagerTest instead of the CTS test. Move this to the CTS
test instead.

Bug: 392986269
Test: atest android.net.cts.ConnectivityManagerTest
Change-Id: Id64d21929fb6b6c42f46a821a3cd28bbcaf77cda

Quang Anh Luong   commited 2025-02-07 12:42:12 +09:00
6c478ee215
Format MdnsAdvertiser with ktlint
Test: TH
Change-Id: I6f41631329571dc3f9120ce968162e3314a956d3

Yuyang Huang   commited 2025-02-06 23:47:48 +09:00
ab9bb106c2
Stop tracking left-over test interfaces
When setIncludeTestInterfaces(false) is called, any RTM_DELLINK
callback for a testtap interface is ignored, since the interface is no
longer considered to be a valid ethernet interface.

Change setIncludeTestInterfaces to go through all interfaces, and stop
tracking the ones which are no longer valid. Otherwise, they will
stick around forever (and break subsequent tests).

Bug: 390722214
Test: TH
Change-Id: Ied73e86c0452831f4d6b00f67908c51201af8bbd

Patrick Rohr   commited 2025-01-29 07:34:27 -08:00
d16138eeea
Merge "Add default capabilities for empty config" into main
Chris Desir   authored and   Gerrit Code Review   commited 2025-01-17 10:05:13 -08:00
bcbea35fb5
Add default capabilities for empty config
While doing some testing for another change (pa/2844131), I noticed that
an interface in config.xml with no network capabilities listed provided
no internet connection. parseEthernetConfig was updated to provide empty
 config capabilities with the default capabilities (which
 includes NET_CAPABILITY_INTERNET for non test ifaces).

Flag: BUG_FIX
Test: atest ConnectivityCoverageTests
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ethernet.EthernetTrackerTest

Bug: 352523028
Change-Id: I6f73b0554f95c20fd1912a3c8da2b3c64f2ac4c4

Chris Desir   commited 2025-01-16 14:47:34 -08:00
3133c0a52a
L2capNetworkProvider should use its own handler thread
Eventually, this will be started by CS, but it should not reuse the CS
handler thread.

Test: TH
Change-Id: I20dc252d91351cf92724d640e272f28ddc29dbf4

Patrick Rohr   commited 2025-01-16 09:52:35 -08:00
2e3904dc4e
Disallow legacy tether() API starting in B
As part of the major tethering refactor to associate every IpServer with
a TetheringRequest, tether()/untether() APIs should be completely
removed in B and all tethering should go through startTethering() (with
the exception of Wifi LOHS and Wifi P2P, which will move to
startTethering() in a future CL).

Bug: 216524590
Test: atest CtsTetheringTests TetheringTests

Change-Id: If7981f1ee7d80ff0a1cc0069ba7a4ebf79144160

Quang Anh Luong   commited 2025-01-15 08:59:42 +09:00
30d8a25db3
Register reserved offer
The reserved offer adapts the reservation requests capabilities, and
additionally populates its own capabilities (namely the PSM provided by
the BluetoothServerSocket).

Test: TH
Change-Id: Ida388b6f1e4552242726bd4d7eba6215bb0577a3

Patrick Rohr   commited 2025-01-13 13:57:20 -08:00
f1ae5ab86c
Add blanket offer to L2capNetworkProvider
Registers a blanket reservation offer which will receive reservation
requests filed using ConnectivityManager#reserveNetwork.

Test: TH
Change-Id: I2d37fe564a6c40f2c6dee1f6f7aa655c47628b85

Patrick Rohr   commited 2025-01-10 14:46:54 -08:00
77df9d3483
Add empty L2capNetworkProvider
The network provider is registered when BLE is supported.

Bug: 372936361
Test: L2capNetworkProviderTest
Change-Id: I8163339015f4a3bb0ff8911f6f52a38ec1730f39

Patrick Rohr   commited 2025-01-10 14:46:54 -08:00
47425dcb52
Merge "Add support for updating reserved offers" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-06 13:25:44 -08:00
f3f0da14a4
Add support for updating reserved offers
A NetworkOffer can be updated by registering a new set of capabilities
and score using an already registered NetworkOfferCallback object.

Since reserved offers are guaranteed to never send more than a single
onReserved() callback, they cannot support updating the capabilities
(not to mention that the reservationId is also part of the
capabilities).

This change changes NetworkOffer migration to only allow reserved offers
to update their NetworkScore. If a reserved offer tries to update its
capabilities, the existing offer is removed and the new offer is
silently rejected. This change does not affect regular offers (with
RES_ID_UNSET) nor blanket offers (with RES_ID_MATCH_ALL_RESERVATIONS).

Test: CSNetworkReservationTest
Change-Id: I872a1dbda209098f08391a7543b9446e1f50d4f0

Patrick Rohr   commited 2025-01-06 12:03:45 -08:00
e7a4b081a4
Merge "Remove the transactionId field" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-12-24 21:22:07 -08:00
8231494aaa
Merge "Revert "Use timerfd to improve the accuracy of query timing"" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-12-24 05:15:27 -08:00
58e8845eb4
Revert "Use timerfd to improve the accuracy of query timing"
This reverts commit 3d51a99dc8.

Reason for revert: Does not close the timerfd object properly, which may cause a memory leak.

Change-Id: I25d7da13591696c9dfda60ee0fdd2574dbcdf337

Paul Hu   commited 2024-12-24 09:18:06 +00:00
a481dc184f
Merge "Add API for FLAG_SKIP_PROBING" into main
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2024-12-23 23:03:44 -08:00
1272722cc0
Add API for FLAG_SKIP_PROBING
The flag, used in the newly exposed AdvertisingRequest, allows
skipping the probing step when the service name is known to be unique
already.

This allows implementing RFC 6762 section 8.1 that specifies probing
SHOULD be skipped if it is known via other means that the record set
is unique.

Bug: 384841047
Test: atest CtsNetTestCases:NsdManagerTest
Change-Id: I19d67ff2863af631bd9c2f518b004f1688ac5f87

Remi NGUYEN VAN   commited 2024-12-24 16:00:53 +09:00
7a3423b65b
Add a test to ensure reservation requests do not match regular offers
Test: TH
Change-Id: I5c5c4ec3a3a31c916e2e4d22c0035ff59f2766e8

Patrick Rohr   commited 2024-12-22 22:01:22 -08:00
f734831221
Add reserveNetwork API
reserveNetwork allows a requestor to initiate the creation of a network
that requires the system to preallocate resources which can then be
advertised by the requestor on or off device in order to help create the
network.

For example, this API will be used to reserve a IP over L2cap server
network, which requires the system to first create a
BluetoothServerSocket and reserve a PSM (i.e. port). This information is
passed back to the requestor via onReserved() callback and subsequently
advertised via a BLE advertisement. The network is established as soon
as the client connects to the advertised PSM, which will trigger a call
to onAvailable(), just like a regular NetworkRequest.

onReserved() callbacks are exclusive to the reserveNetwork API and are
sent when an NetworkOffer is registered that matches the reservation ID
of an existing request. A reserved offer always follows the reservation
request as it is created in direct response. onReserved() can only be
called once. If for some reason the reservation gets cancelled by the
system (i.e. the NetworkOffer is retracted) or cannot be fulfilled,
onUnavailable() is called. It is up to the app to file a new
NetworkRequest when this happens.

An onReserved() callback is not queued, because
a) it cannot be called more than once for the same reservation,
b) it must always be the first callback, and
c) it only gets cancelled by onUnavailable().

This change does not handle NetworkOffer migrations, such as updating
the score, properly. This must be addressed before the feature can ship
as the yieldToBadWifi logic can update the score on all NetworkOffers.

API-Coverage-Bug: 372936361
Test: Very basic CSNetworkReservationTest; more to follow.
Change-Id: I9b349d469830bf28e006cf403c605574371db267

Patrick Rohr   commited 2024-12-22 22:01:22 -08:00
73eee542a1
Add NetworkCallback#onReserved
onReserved() is called in response to a successful Network reservation
with the NetworkCapabilities of the reserved network. onReserved is
called at most once. If the reservation is released, onUnavailable is
called.

Test: TH
API-Coverage-Bug: 372936361
Change-Id: Idcef572ab9d07981799efc349206aadb620e0e69

Patrick Rohr   commited 2024-12-20 15:15:28 -08:00
93136f13c6
Merge "Advertise with short hostnames" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-12-19 01:04:01 -08:00
f6ddd7f759
Advertise with short hostnames
Advertise with a shorter hostname by default (can be disabled via a
chicken bit), instead of "Android_[32 characters]" as the hostname.

This should allow decreasing the size of APF programs necessary for
advertising offload, and make the advertiser compatible with Matter
use-cases. Some Matter implementations (notably CHIP) interpreted
the example in "4.3.1.1. Host Name Construction" of the spec as
if only 16 character hostnames needed to be supported, despite not
following the rule to construct the hostname based on link-layer
addresses.

The hostname changed once in T when migrating from mdnsresponder to the
current advertiser implementation, so changing the format again is
unlikely to create problems, especially since this keeps the "Android_"
prefix.

Bug: 341141476
Test: atest
Change-Id: Ic8311f41a1a943ec8230203fcd74eda7a26a691c

Remi NGUYEN VAN   commited 2024-12-19 15:06:07 +09:00
5e99d1fea1
Remove the transactionId field
The transactionId is just a query counter similar to queryIndex, except
that it wraps at UNSIGNED_SHORT_MAX_VALUE.

Calculate it based on queryIndex instead.

Test: atest
Change-Id: I3d18f398f3ca3aac363daacbc2840349baba9125

Remi NGUYEN VAN   commited 2024-12-19 14:46:06 +09:00
e3af4d493b
Move query scheduling time to MdnsQueryScheduler
Instead of having query scheduling time split between MdnsQueryScheduler
and QueryTaskConfig, where QueryTaskConfig has the base run time and
MdnsQueryScheduler does backoff, consolidate it all in
MdnsQueryScheduler.

This allows QueryTaskConfig to only contain parameters used when the
task runs, and not scheduling info.

Test: atest
Change-Id: Ie060802ff2d13c1cea339955d8b609ba95f762f2

Remi NGUYEN VAN   commited 2024-12-18 17:51:30 +09:00
a6e9c66eea
Merge "Use timerfd to improve the accuracy of query timing" into main
Paul Hu   authored and   Gerrit Code Review   commited 2024-12-13 00:16:21 -08:00
69ce1b9f15
Merge "Support optional parameters for CSLocalAgentCreationTests" into main
Junyu Lai   authored and   Gerrit Code Review   commited 2024-12-13 00:15:07 -08:00
a5bd71c4fe
Merge changes Icecb889a,Id06116ad into main
* changes:
  Set the reservationId when a new NetworkRequest is created
  Add reservationId to NetworkCapabilities

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-12-12 16:08:35 -08:00
3a5b37a87c
Set the reservationId when a new NetworkRequest is created
This populates the reservationId with the value of the requestId when a
new NetworkRequest is created. Conceptually, the reservationId is not
related to the requestId; however, the requestId fulfills the same
uniqueness requirements that are needed for the reservationId, so it can
just be reused for this purpose.

Test: atest NetworkRequestTest
Change-Id: Icecb889a5269554add5791587f1ce7319271fd9e

Patrick Rohr   commited 2024-12-12 14:23:47 -08:00
06fa57b206
Merge changes Id723dc9e,I3665d843 into main
* changes:
  Treat RESERVATION requests the same as REQUEST types
  Adds a new RESERVATION request type

Patrick Rohr   authored and   Gerrit Code Review   commited 2024-12-12 13:51:32 -08:00
b960664fa8
Use timerfd to improve the accuracy of query timing
Timerfd can provide more accurate delayed callbacks than
Handler#postDelayed because it accounts for the time the device
spends in deep sleep. Using timerfd allows for more precise query
timing, which reduces the possibility of TTL expiration caused
by inaccurate delayed callbacks.

Bug: 366373064
Test: atest FrameworksNetTests NsdManagerTest
Change-Id: I980ec8fd43f63976ef5387bb57c7ed70a1b68d82

Paul Hu   commited 2024-12-12 02:57:00 +00:00
3d51a99dc8
Support optional parameters for CSLocalAgentCreationTests
This is a test-only no-op refactor which only enables the
ability for follow-up changes to add more parameters without
exponentially increasing the number of parameter combinations.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSLocalAgentCreationTests
Bug: 349487600
Change-Id: I61bcabf7c93dab43984da0ade3e61a7117fe040a

Junyu Lai   commited 2024-12-11 15:23:02 +08:00
a950b32db5