Commit graph android_packages_modules_Co.../tests/unit/java/com/android/server
Message SHA1
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
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
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
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
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
Treat RESERVATION requests the same as REQUEST types
Test: CSNetworkReservationTest
Change-Id: Id723dc9edb67bf878fb5b2680327e7b598f6c64f

Patrick Rohr   commited 2024-12-10 13:28:08 -08:00
e4c602e9f5
Merge changes I2388220a,I5f282160 into main
* changes:
  Add a test for delayed teardown with unregisterAfterReplacement.
  Fix system crash when netd return error

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-11-12 18:47:07 +00:00
f45f40717b
Add a test for delayed teardown with unregisterAfterReplacement.
Bug: 363854848
Test: test-only change
Change-Id: I2388220a97c50a8a39920c6354ec30c4936f045d

Lorenzo Colitti   commited 2024-11-12 15:34:00 +00:00
feeff37fca
Merge "Make the idle timer for network data tracking configurable" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-31 21:15:37 +00:00
cf3b26e3bf
Merge "Add config for client-side traffic stats rate-limit cache." into main
Junyu Lai   authored and   Gerrit Code Review   commited 2024-10-31 07:22:36 +00:00
30ff675df5
Merge changes Ia7ea051f,I38bdfe00 into main
* changes:
  Fix system caller cannot query stats for other uids
  Use device config to enable/disable the rate-limit cache feature

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-31 06:23:58 +00:00
05be25b8ba
Merge "Address review comments at aosp/3249945" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-10-31 06:23:56 +00:00
457b54a1ae
Add config for client-side traffic stats rate-limit cache.
This is a no-op change since the config is not used yet, and
the feature flag will be gradually rolled out instead of enabled
by default.
However, this change is necessary for follow-up changes to enable
toggling the feature and configuring its behavior through device
configuration flags.

This change includes:

 1. Disable the service-side cache flag if the client-side flag
    is enabled.
 2. Since the apps don't have enough permission to check the
    feature flag from DeviceConfig. Provides a binder interface
    for returning per-UID config,
    which only returns cache enabled if the SDK level is V+
    or the app's target SDK is V+.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.TrafficStatsTest \
      FrameworksNetTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest \
      CtsNetTestCases:android.net.cts.NetworkStatsBinderTest \
      FrameworksNetIntegrationTests:com.android.server.net.integrationtests.NetworkStatsIntegrationTest
Bug: 343260158
Change-Id: Id9761e4aea65fabe6466c875b787e178317a1da2

Junyu Lai   commited 2024-10-30 23:02:59 +08:00
b9071f8512
Make the idle timer for network data tracking configurable
Networks can use widely varying timeouts for their connections. Because
cellular modems use a lot of power, having this configurable is more
useful for tuning this to an optimal value for power drain.

Adding a similar configurable value for WiFi for parity.

Test: atest ConnectivityCoverageTests:\
android.net.connectivity.com.android.server.CSNetworkActivityTest

Bug: 373733012
Change-Id: I2418f09233b2e3fa4e9cdd8fbb6149a35106b735

Suprabh Shukla   commited 2024-10-29 19:06:42 -07:00
c623c946f5
Use device config to enable/disable the rate-limit cache feature
Currently, if the app's target SDK is V+, the rate-limit cache is
enabled regardless of whether the kill switch is enabled or not.
This creates problems if there is a need to disable the feature
entirely.

Thus, this change makes the kill switch override the target SDK
level. This is necessary for follow-up changes to enable
the client-side cache and disable the service-side cache
simultaneously.

This change also removes the need of initializing/clearing the
caches when the cache is entirely disabled.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.TrafficStatsTest \
      FrameworksNetTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest \
      CtsNetTestCases:android.net.cts.NetworkStatsBinderTest \
      FrameworksNetIntegrationTests:com.android.server.net.integrationtests.NetworkStatsIntegrationTest
Bug: 343260158
Change-Id: I38bdfe00220f59712ca4b095fe4e7a3731320708

Junyu Lai   commited 2024-10-28 14:43:15 +08:00
24fcc3668a
Address review comments at aosp/3249945
This change includes:
  1. Rename binder interfaces.
  2. Use a dedicated class to pass the result of
     get{Total|Iface|Uid}Stats, as it is 25% faster than passing
     a NetworkStats object through the binder interface.
  3. Remove the binder interface only used by the test.
  4. Remove NetworkStatsBinderTest on R and S, since the binder
     interface is removed, the mainlined service does not run on
     those versions and the chance of breaking these tests on
     R and S is low.
  5. Remove useless TODO comments.

Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest \
      CtsNetTestCases:android.net.cts.NetworkStatsBinderTest \
      FrameworksNetIntegrationTests:com.android.server.net.integrationtests.NetworkStatsIntegrationTest
Bug: 372851500
Bug: 343260158

Change-Id: Ibd79a17218f54f0117d8ef5d7b9ec6073356f923

Junyu Lai   commited 2024-10-28 10:59:35 +08:00
9fb574d0c3
Merge changes I7184eaa0,I2c5951ab into main
* changes:
  Do not crash when adding UID ranges to a destroyed network.
  Test that UID ranges can incorrectly be added to a destroyed network.

Lorenzo Colitti   authored and   Gerrit Code Review   commited 2024-10-23 04:39:07 +00:00
6bf2ce44e4
Do not crash when adding UID ranges to a destroyed network.
aosp/3218864 fixed the crash when ranges are removed from a
destroyed network, but did not fix the case where the ranges are
added to a destroyed network.

This can happen if a multilayer request is filed when a network
has already been destroyed.

Fix: 368989698
Test: updated existing tests for this bug
Change-Id: I7184eaa01141f56b7ad774277c7dee03d5812298

Lorenzo Colitti   commited 2024-10-22 11:41:21 +00:00
dfe98fc5be
Test that UID ranges can incorrectly be added to a destroyed network.
This will likely crash the system.

Bug: 368989698
Test: test-only change
Change-Id: I2c5951ab4ccb2c17c4e87912053130377b9941ba

Lorenzo Colitti   commited 2024-10-22 11:40:09 +00:00
a81bfafda5
Move buildMdnsServiceInfoFromResponse to MdnsUtils.
Move this utility method buildMdnsServiceInfoFromResponse from
MdnsServiceTypeClient to MdnsUtils so it can be used by other
classes.

Bug: 355421878
Test: atest FrameworksNetTests NsdManagerTest
Change-Id: I8ce1028de325da46f112a5ec58516453727151fe

Paul Hu   commited 2024-10-15 03:00:58 +00:00
f311b43bef
Fix the test flake in testRemoveServicesAfterSocketDestroyed
The removeServices() is running on a different handler, which
might take some time to complete. Therefore, the verification
should include a timeout to wait longer and prevent test flake.

Bug: 367429622
Test: atest MdnsDiscoveryManagerTests#testRemoveServicesAfter\
      SocketDestroyed --iteration
Change-Id: I79626bad680a62993c3e7d6b356acc10755257e3

Paul Hu   commited 2024-09-26 05:56:28 +00:00
78bd66003a
Merge "Remove cached services when the network is disconnected or unrequested" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-09-13 11:40:45 +00:00
6a7e703f17
Remove cached services when the network is disconnected or unrequested
The services in the cache are no longer useful after the network
is disconnected. Because either the Network object or the
interface index will change after the network is reconnected,
these cached services won't be used for any discovery/resolution/
service info callback requests. Therefore, these cached services
should be removed after the network is disconnected. Otherwise,
these useless cached services will occupy memory until the device
is rebooted.

In addition, the cached service may not be reliable after the
last listener is unregistered. Because the socket is
disconnected, the service type client won't receive any updates
for the services. Therefore, remove these cached services after
exceeding the keeping time.

Bug: 355421878
Test: atest FrameworksNetTests NsdManagerTest
Change-Id: I06ff320fec84f71dc2ed742c50fa46f25c284170

Paul Hu   commited 2024-09-13 06:13:37 +00:00
079c77c296
Rename Service Side TrafficStats Cache
Rename TrafficStatsRateLimitCache related
variables to TrafficStatsServiceRateLimitCache.
This is needed since client side cache
would be added.

Test: TH
Bug: 343260158
Change-Id: I12ae977ce33cfb5815aa908d719543d5c8e46f11

Yun-Chen Cheng   commited 2024-09-12 07:06:32 +00:00
a8746d5a92
Merge "No-op refactoring for TrafficStats APIs" into main
Yun-Chen Cheng   authored and   Gerrit Code Review   commited 2024-09-11 01:56:42 +00:00
05fb57ea97
No-op refactoring for TrafficStats APIs
Prepare for implementation of client side
TrafficStats rate limit cache.

1. Write Typeless versions of getIfaceStats,
getUidStats, getTotalStats in INetworkStatsService.aidl
that returns NetworkStats instead of Long.
This is needed because in follow-up changes,
the NetworkStats instead of indiviual numbers will
be stored as a cache entry

2. Move some utils from NetworkStatsService
to TrafficStats. This is needed because in the follow-up
changes, these utils would be both accessed by TrafficStats
and NetworkStatsService.

Test: CtsNetTestCases:android.net.cts.TrafficStatsTest
Test: CtsNetTestCases:android.net.cts.NetworkStatsBinderTest
Test: FrameworksNetIntegrationTests:com.android.server.net.\
		integrationtests.NetworkStatsIntegrationTest
Test: FrameworksNetTests:android.net.connectivity.com.android.\
		server.net.NetworkStatsServiceTest
Test: FrameworksNetTests:android.net.connectivity.\
		android.net.TrafficStatsTest
Test: ConnectivityCoverageTests:android.net.connectivity.\
	android.net.TrafficStatsTest
Bug: 343260158
Change-Id: Iace251e1495fd3b81e072526e92ca97cbc7246eb

Yun-Chen Cheng   commited 2024-09-10 14:36:25 +00:00
69b83606ca
Merge changes Id9799762,I9d749393 into main
* changes:
  Introduce FlagOverrideProvider#getIntValueForTest
  Add DiscoveryExecutor#executeDelayed

Paul Hu   authored and   Gerrit Code Review   commited 2024-09-06 05:59:02 +00:00
70896174e2
Add DiscoveryExecutor#executeDelayed
This method can execute the task after the specified amount of
time elapses.

Bug: 355421878
Test: atest FrameworksNetTests NsdManagerTest
Change-Id: I9d749393bd5435cdba5072d48242cd0d17332b67

Paul Hu   commited 2024-09-05 15:33:58 +00:00
61a220eaf8
Merge "Inform DNS resolver whether DDR is enabled." into main
Lorenzo Colitti   authored and   Gerrit Code Review   commited 2024-08-26 06:43:19 +00:00
ea68942848
Inform DNS resolver whether DDR is enabled.
This is needed to cleanly flag on/off DDR and to ensure that
when it is flagged on, DnsResolver ignores the hardcoded list of
DoH providers and only uses DDR.

Bug: 240259333
Test: updated existing tests
Change-Id: I84c103a5a4d18294b6a4cc3301d0037d1a6673a4

Lorenzo Colitti   commited 2024-08-23 18:23:42 +09:00
7cde306fa3
Merge "Check network destroy status before networkRemoveUidRangesParcel" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-08-20 07:02:34 +00:00
5dcee89808
Check network destroy status before networkRemoveUidRangesParcel
networkRemoveUidRangesParcel throws ServiceSpecificException if the
native network is already destroyed.
This can happen when
1) per-app default network request is satisfied by network1
2) unregisterAfterReplacement is called to the network1. This calls
   netd.networkDestroy and network is removed from netd.
3) per-app default network request is removed. This calls
   netd.networkRemoveUidRangesParcel but netd does not know about this
   netid anymore.

This CL fixes this issue by skip calling networkRemoveUidRangesParcel if
the request satisfier is already destroyed.

Bug: 336961452
Bug: 357974842
Test: CSSatelliteNetworkTest
Change-Id: Id775cca6fffd03545f1c4bc5016d0de4813f17df

Motomu Utsumi   commited 2024-08-19 16:25:39 +09:00
471f20142f
Merge "Shedule task with current run if there is a service in the cache" into main
Paul Hu   authored and   Gerrit Code Review   commited 2024-08-16 06:59:24 +00:00
435ca438bb
Shedule task with current run if there is a service in the cache
A service record exists in the cache, and a query transmission
with a long duration has been scheduled because the service
information was recently updated. However, the query will be sent
immediately if a new discovery/resolution/service info callback
listener is registered. Therefore, to reduce unnecessary queries
in aggressive query mode, if a service exists in the cache, the
query timing should either reuse the scheduled run or use a
backoff time if there is no scheduled run.

Fix: 345146854
Test: atest FrameworksNetTests NsdManagerTest
Change-Id: I3335a0f6e0018526a8677dfbfbf053dd0dc906e5

Paul Hu   commited 2024-08-15 09:37:36 +00:00
89abf5331c