Commit graph android_packages_modules_Co.../tests/unit/java/com/android/server
Message SHA1
Destroy sockets of apps under background firewall chain restriction
Currently, CS destroys sockets of apps under firewall chain restriction
only when the firewall chains get enabled by setFirewallChainEnabled.

This CL updates CS to also destroy sockets of apps when the
setUidFirewallRule and replaceFirewallChain update uid rule and apps
lose network access due to FIREWALL_CHAIN_BACKGROUND.
This socket destruction is delayed until the cell modem is up in the
same way that CS destroys sockets of frozen apps.

Test: CSSocketDestroyTest
Bug: 300681644
Change-Id: I6a6fb5d6d7b71c0949a4195b84d30efef95bff37

Motomu Utsumi   commited 2024-05-24 13:47:21 +09:00
ff555a709c
Add blocked reason for internet permission
Currently, even if apps don't have INTERNET permission and can not use
network, network access is considered not blocked and
ConnectivityService send onBlockedStatusChanged callback with
blocked=false.
This CL introduced BLOCKED_REASON_NETWORK_RESTRICTED and consider
network access from apps targetting W+ on V+ releases is blocked if apps
don't have INTERNET permission.
Permission is set when the user is added or package is installed and
permission is removed when the user is removed or packages is
uninstalled.
So ConnectivityService does not need to monitor permission change to
send onBlockedStatusChanged callback by permission change.

Test: CSBlockedReasonsTest
Bug: 339559837

Change-Id: I58d2a4eddc714e205f5b96219f95b637f2826c58

Motomu Utsumi   commited 2024-05-24 13:45:51 +09:00
ee96ba0e60
Send onBlockedStatusChanged callback based on bpf map contents
Currently, CS receives the blocked status change from
NetworkPolicyCallback.
This CL update CS to generate blocked status based on bpf map contents
on V+.
When the data saver and firewal chain status is updated, CS generate new
blocked reasons based on bpf map contents.
U- keeps listening to NetworkPolicyCallback.

Bug: 328732146
Test: testNetworkCallbackMaximum, CSBlockedReasonsTest
Change-Id: I6fa3f1a44eadc67d9cff17133905ef69203c044a

Motomu Utsumi   commited 2024-05-24 13:45:41 +09:00
d20727f3cc
Move perUidCounter increment to outside NetworkRequestInfo constructor
This CL moves mPerUidCounter.incrementCountOrThrow from
NetworkRequestInfo constructor to the caller of NetworkRequestInfo
constructor and stop incrementing counter for internal NetworkRequestInfo
(e.g. per-app default requests).
Also, this CL update CS not to modify perUidCounter when CS updates
apps' track default network request when the per-app default request is
updated since this does not change the number of request for each uids.

Test: testNetworkCallbackMaximum
Bug: 339106399
Change-Id: I82dbeb82b1c762c2c277d5794d54997b57009b6a

Motomu Utsumi   commited 2024-05-24 13:27:27 +09:00
b16f75c3eb
Enable delay destroy socket as default
delay_destroy_frozen_sockets_version is rolled out to public 100%.
So this CL enables this flag as default with kill switch.
This flag is no-op if destroy_frozen_sockets_version is disabled, and
destroy_frozen_sockets_version is also rolled out to public 100%.
So this CL does not change any behabior on the production devices.

Upcoming CLs will update CS to destroy sockets of apps that are under
FIREWALL_CHAIN_BACKGROUND restriction as well.
So this CL renames flag name from delay_destroy_frozen_sockets_version
to delay_destroy_sockets which is not specific to frozen apps.

Bug: 300681644
Test: TH
Change-Id: Icb9edff4e517fca57408d7d690fe9e172754c35e

Motomu Utsumi   commited 2024-05-22 13:35:44 +09:00
390be06f64
Merge "Inform the DNS resolver of the interfaces in a network." into main
Lorenzo Colitti   authored and   Gerrit Code Review   commited 2024-05-21 06:45:37 +00:00
19fd149d8e
Add support to restore original values
In current design, this class is risky because developers might
assume that it's safe to set real device flags with it. This is
unsafe because the class does not restore the previous value.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Fix: 339154394
Change-Id: I2a12e7892eaf66e7572928de39e00de3faf5fa60

Junyu Lai   commited 2024-05-21 02:16:21 +00:00
a8ba04b132
Merge "Reorder clatStart() to setup 464xlat sockets before tun interface" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-05-19 13:38:40 +00:00
fe3dd9a23f
Update APIs that depends on isUidNetworkingBlocked to follow compat flag
NETWORKINFO_WITHOUT_INTERNET_BLOCKED compat flag only changed the
behavior of getActiveNetworkInfo that depends on
bpfNetMaps#isUidNetworkingBlocked.
But isUidNetworkingBlocked is used from other APIs(e.g. getActiveNetwork)
This CL update all APIs that depends on isUidNetworkingBlocked to follow
the compat flag to make behavior consistent between APIs.

aosp/3079290 will update onBlockedStatusChanged callback to follow this
compat flag.

Bug: 340773991
Bug: 339780435
Test: TH
Change-Id: If64ec800f21c2adc613884838202e2dece4a8d95

Motomu Utsumi   commited 2024-05-16 16:54:17 +09:00
b15be228d2
Reorder clatStart() to setup 464xlat sockets before tun interface
Modified the execution sequence within ClatCoordinator.clatStart() to
configure the local 464xlat read/write sockets before configuring and
bringing up the tun interface. This ensures that upon receiving an
RTM_NEWLINK message for the tun interface up event, the anycast address
is already configured on the physical interface.

Test: TH, manual test on physical device
Change-Id: I558cd370456091b8a61e1137a53305527fb651fd

Yuyang Huang   commited 2024-05-14 21:17:27 +09:00
584a5136a1
[mdns] Skip conflict check for incoming mDNS answer records which are
probed in the repository

There's a scenario where an undesired conflict happens:
1. Register a service and custom host with addresses and public key.
2. Register another service using the same hostname and public key.

While the second registartion is being probed, its KEY RR is considered
as conflicting with the address record of the first registraiton. This
shouldn't be a reasonable behavior because the address record itself is
from the repository itself.

Bug: 336936158
Bug: 336967571
Test: atest CtsNetTestCases:NsdManagerTest FrameworksNetTests:android.net.connectivity.com.android.server.connectivity.mdns.MdnsRecordRepositoryTest

Change-Id: Ibe6c8dd845540eba8f08152be6693be1dbc42ce9

Handa Wang   commited 2024-05-13 09:58:48 +00:00
034705d7a8
Add compat flag for ActiveNetworkInfo blocked state
Before aosp/3001087, getNetworkActiveInfo did not return network info
with blocked state for apps without PERMISSION_INTERNET even if the
network is actually blocked.
aosp/3001087 updated getNetworkActiveInfo to return correct blocked
state on V+.
However, this broke some apps that use getNetworkActiveInfo in wrong way
and depends on the previous behavior.
So this CL introduces the compat flag to keep previous behavior for apps
targeting U or older releases.

Test: TH
Bug: 333340911
Change-Id: I0e0950f2148de0ffdb45495903a5a87e0d4c1c0b

Motomu Utsumi   commited 2024-05-08 21:08:35 +09:00
0b4be79e52
Reapply "Use bpf map based isUidNetworkingBlocked on V+"
This reverts commit a658220234.

Change-Id: I53acd7ff4821a65583b2ad936e22efaa21965a14

Maciej Żenczykowski   authored and   Motomu Utsumi   commited 2024-05-08 14:50:38 +09:00
a08692f7c7
Use Bpf map based isUidRestrictedOnMeteredNetworks on V+
Bug: 328732146
Test: BpfNetMapsTest
Change-Id: I2d3820bf4dd82649941eef2995ad237276937ba9

Motomu Utsumi   commited 2024-05-07 18:36:39 +09:00
e55bcd578b
Add bpf map based getUidNetworkingBlockedReasons
Bug: 328732146
Test: NetworkStackBpfNetMapsTest BpfNetMapsTest
Change-Id: Ie802b3d18463e2b7e8a2b953088cbbcc117a841e

Motomu Utsumi   commited 2024-05-07 18:36:36 +09:00
eb92054f91
Merge "Fix DO check on headless devices" into main
Kholoud Mohamed   authored and   Gerrit Code Review   commited 2024-04-25 09:51:23 +00:00
45f71b0b3d
[mdns] service implementation for public key
Bug: 317946010
Bug: 333232582

Change-Id: Iab66bf0a1af14878c7b18a7a3015c2de7a6514c8

Handa Wang   commited 2024-04-24 07:17:00 +00:00
52497d66cc
Merge "Add firewall chains for HAPPY_BOX and user/admin PENALTY_BOX" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-04-24 03:51:09 +00:00
c04493234e
Merge "Use helper function getIndexForValue in MulticastRoutingCoordinator." into main
Yang Sun   authored and   Gerrit Code Review   commited 2024-04-23 12:58:39 +00:00
173ffb9278
Use helper function getIndexForValue in MulticastRoutingCoordinator.
The SparseArray.indexOfValue() uses == to compare values,
MulticastRoutingCoordinator uses SparseArray with String type values,
and the indexOfValue function would sometimes return -1 when looking for
a value in the SparseArray.

Added a helper function getIndexForValue in CollectionUtils to get index
by comparing values with equals, and used this function in MulticastRoutingCoordinator.

Updated
MulticastRoutingCoordinatorServiceTest#testMulticastRouting_applyConfigNone_removesMfc
test case to use copies of interface names when updating the multicast
configs, so the test would fail without this fix.

Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.CollectionUtilsTest#testGetIndexForValue
atest android.net.connectivity.com.android.server.connectivity.MulticastRoutingCoordinatorServiceTest#testMulticastRouting_applyConfigNone_removesMfc

Change-Id: I862242d6be01b8552cdd6af6c9691948a9f0bfe0

Yang Sun   commited 2024-04-23 17:22:15 +08:00
4e7baadc71
Add firewall chains for HAPPY_BOX and user/admin PENALTY_BOX
Follow up CLs will update CS to generate blocked reason from bpf map
instead of asking NPMS.

However, one issue is NPMS set PENALTY_BOX for
BLOCKED_METERED_REASON_USER_RESTRICTED and
BLOCKED_METERED_REASON_ADMIN_DISABLED without telling the reason.
So, CS can not know the reason of PENALTY_BOX.

This CL add new firewall chain and match to distinguish reasons.
NPMS must call setUidFirewallRule with
FIREWALL_CHAIN_METERED_DENY_USER or FIREWALL_CHAIN_METERED_DENY_ADMIN
based on the reason so that CS can know the reason of restriction.

Bug: 332628891
Test: atest com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Change-Id: Ia4ad4bdb345abc22c782630e828edfad2452db36

Motomu Utsumi   commited 2024-04-23 15:04:28 +09:00
11d3345daa
Merge "Assert fixed test method count in ConnectivityServiceTest" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-23 03:38:41 +00:00
0168ae22f6
[mdns] add elapsedRealTime() to Dependencies for MdnsRecordRepository
This CL adds elapsedRealTime() to Dependencies so that in the unit test
we can simulate the elapse of time.

Bug: 336268432
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.connectivity.mdns.MdnsRecordRepositoryTest
Change-Id: I64cf0ac1772f54edf187cf9ca6351a75b81fd859

Handa Wang   commited 2024-04-22 16:06:38 +00:00
a1a80ad9c3
Assert fixed test method count in ConnectivityServiceTest
ConnectivityServiceTest is deprecated but people sometimes still
add new test methods to it, and getting review feedback to rewrite
tests in CSTest. This wastes resources.
Thus, assert fixed test method count to make it fails locally for
people to aware of it.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testTestMethodCount
Bug: N/A
Change-Id: I0a98a0e3fcd97484f372737e7c6fe24743c21834

Junyu Lai   commited 2024-04-22 17:11:50 +08:00
08f5b59482
[mdns] separate the multicast reply quota for IPv4 and IPv6
This CL separates the multicast reply quota for IPv4 and IPv6. Before
this change, when an IPv4 mDNS query and an IPv6 mdns query arrives at
the same time for the same record (which is a common behavior for DNS-SD
resolvers), MdnsRecordRepository will only respond to one of them. The
other response will be throttled silently.

It's especially problematic when the IPv4 query and IPv6 query are sent
by different hosts. One of the hosts will get no reply.

Bug: 335096961
Test: Unit test and verified on a local device.

Change-Id: I0d7a9fad2b43bbfb8b042828295cdf08bf4ae5c8

Handa Wang   commited 2024-04-22 07:37:22 +00:00
c8de4cb79f
Fix DO check on headless devices
Bug: 289515470
Test: btest a.d.c.PreferentialNetworkServiceTest
Merged-In: Id93322caca55e122339701e4c69b4ded57b8f6cc
Change-Id: Id93322caca55e122339701e4c69b4ded57b8f6cc

Kholoud Mohamed   authored and   Android Build Cherrypicker Worker   commited 2024-04-19 09:35:36 +00:00
7a7d1ac87d
Inform the DNS resolver of the interfaces in a network.
Also simplify DnsManagerTest by using the autogenerated equals()
method in ResolverParamsParcel instead of a hand-rolled
comparison method.

Test: covered by existing tests
Change-Id: Ie1b1bd011a440be0175420f903f39a4153d2245e

Lorenzo Colitti   commited 2024-04-17 23:05:14 +09:00
191f1b2c8c
Merge "[mdns] allow hostnames beginning with a digit" into main
Handa Wang   authored and   Gerrit Code Review   commited 2024-04-16 08:25:38 +00:00
f41e6019dd
[mdns] allow hostnames beginning with a digit
A Matter device uses a hex as the hostname so it may begin with a digit
which wasn't allowed in NsdService. This CL looses this check to allow
Matter devices to register their services at Android Thread Border
Router.

Bug: 334828525
Test: CI
Change-Id: Ia779791e214158a08c2ec06adf8d5630ec8ea616

Handa Wang   commited 2024-04-16 05:52:01 +00:00
8310a5e2d4
Merge "Revert "Use bpf map based isUidNetworkingBlocked on V+"" into main
Patrick Rohr   authored and   Gerrit Code Review   commited 2024-04-11 19:37:46 +00:00
c6678bbd71
Revert "Use bpf map based isUidNetworkingBlocked on V+"
This reverts commit 9b272fa53a.

Reason for revert: possible root cause of b/333340911.

Change-Id: Ic4923fd19db7e4704a3ef02d79644b47c271e18e

Patrick Rohr   authored and   Gerrit Code Review   commited 2024-04-11 16:54:04 +00:00
a658220234
Merge "Report sent query count in resolution stop metrics" into main
Paul Hu   authored and   Gerrit Code Review   commited 2024-04-11 08:42:54 +00:00
cede6542da
Merge changes from topic "rate-limit-trafficstats" into main
* changes:
  Make cache duration and max entries configurable
  Create TestRule: SetFeatureFlagsRule
  Rate-limit on TrafficStats#get*[Bytes|Packets] API calls
  Clear TrafficStats cache before getting readings from TrafficStats

Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-11 07:26:14 +00:00
47c819640d
Report sent query count in resolution stop metrics
In the reportServiceResolutionStop function, the sent query count
is not set. This means it's impossible to track how many queries
are sent when a service is not resolved successfully. To track
this information, add the sent query count to
reportServiceResolutionStop.

Fix: 333302084
Test: atest FrameworksNetTets NsdManagerTest
Change-Id: Ida2a33ea35e9bb7393fe860245eb5ad8578d5ff6

Paul Hu   commited 2024-04-10 09:21:29 +00:00
edaeecda7b
Make cache duration and max entries configurable
Field trials could be used to find ideal values.

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Bug: N/A
Change-Id: Ia1304d041a19a81f54b7fdfbbbf1871c7c58a57f

Junyu Lai   commited 2024-04-08 10:43:48 +08:00
233362bf28
Create TestRule: SetFeatureFlagsRule
This rule works by reading the annotation and dynamically
invoking a user-specified method before evaluation to handle the feature flag configuration.

Usage:
class MyTestClass {
  @get:Rule
  val setFeatureFlagsRule = SetFeatureFlagsRule(setFlagsMethod = (name, enabled) -> {
    // Custom handling code.
  })

  // ... test methods with @FeatureFlag annotations
  @FeatureFlag("FooBar1", true)
  @FeatureFlag("FooBar2", false)
  @Test
  fun testFooBar() {}
}

Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Bug: N/A
Change-Id: I439e8ee40b8e81b6eb3857925912a3b843e8dfa1

Junyu Lai   commited 2024-04-08 10:43:42 +08:00
5ed8003915
Use NsdServiceInfo ifIndex in MdnsDiscoveryManager
NsdServiceInfo may contain an interface index if it was obtained from a
previous discovery callback which found a service on an interface that
does not belong to any Network.

In that case, subsequent resolve or registerServiceInfoCallback queries
using that NsdServiceInfo should only be done on the matching interface.
Apps may otherwise receive replies from other networks, with different
interface addresses.

As a simple fix, still request sockets from all interfaces in that case,
but only create the MdnsServiceTypeClients on matching sockets.

The sockets are created / cleaned up based on the lifecycle of the
requests, which does not change.

Fixes: 332262554
Test: atest
Change-Id: I2bbb498d4a0d37725f019a4cf5e367fef76fa0e8

Remi NGUYEN VAN   commited 2024-04-03 12:58:51 +09:00
894f181c89
Merge "Allow HW address retrieval from EthernetNetworkFactory" into main
Chris Desir   authored and   Gerrit Code Review   commited 2024-04-02 16:27:09 +00:00
36061871d7
Rate-limit on TrafficStats#get*[Bytes|Packets] API calls
This change put a rate-limit on TrafficStats getter APIs to
reduce the need of accessing bpf map. For any caller who calls
this method within 1 second, a stale result will be returned.

One expected outcome is this change would break any test which
relies on immediate change of the result of TrafficStats after
making network traffic. Thus, related tests are fixed in the
counter part CL accordingly.

Test: atest CtsNetTestCases:android.net.cts.TrafficStatsTest --rerun-until-failure 100
Test: atest CtsNetTestCases:android.net.cts.NetworkStatsManagerTest
Test: atest NetworkStackIntegrationTests:android.net.NetworkStatsIntegrationTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Bug: N/A

Change-Id: Ibd6ae92d7c806481bb8a5124dd231f8f5aa206f2

Junyu Lai   commited 2024-04-02 15:25:10 +08:00
3c9089c1d1
Merge "Add a flag to disable the background firewall chain" into main
Suprabh Shukla   authored and   Gerrit Code Review   commited 2024-04-02 05:47:56 +00:00
aeacff5033
Add a flag to disable the background firewall chain
The BACKGROUND firewall chain has been recently added. We want to
be able to turn it off in case of contingencies with a device-config
flag flip.

The flag is assumed to be boot-stable and its value is read at boot.
When the flag is off, we ignore any operation on this firewall chain.

Additionally, this chain is always considered disabled on versions
upto UPSIDE_DOWN_CAKE.

Note: All firewall chains are in disabled state at boot by default.

Test: atest FrameworksNetTests
Test: Manually, using adb shell device_config commands.

Bug: 331484830
Change-Id: I9ccc483e02e27a584da6714931466a9f2ec95ca9

Suprabh Shukla   commited 2024-04-01 16:37:32 -07:00
724d8972e4
Allow HW address retrieval from EthernetNetworkFactory
Test: atest EthernetNetworkFactoryTest
Bug: 142259350
Change-Id: I160d8ffd02a1a520d245fbf2b41832d9b3951a89

Chris Desir   commited 2024-04-01 13:45:19 -07:00
e50dd30fc8
Merge "Changes to support satellite stats appear as TYPE_MOBILE" into main
Nagendra Prasad Nagarle Basavaraju   authored and   Gerrit Code Review   commited 2024-04-01 14:33:37 +00:00
ad48c49ee0
Changes to support satellite stats appear as TYPE_MOBILE
With satellite transport supported at device and satellite
network to appear under type mobile, considers cellular or
satellite, or combination of both interfaces under mobile interfaces.

Note: getUidStatsForTransport(TRANSPORT_SATELLITE) is not supported,
considering the same interface name could be used by cellular as well,
supporting this might lead to double counting problem.

Bug: 329003473
Test: atest FrameworksNetTests
Change-Id: I85465cedcc5550fa0555dc36b3be364ac90aade1

Nagendra Prasad Nagarle Basavaraju   commited 2024-04-01 10:53:02 +00:00
756ca07f80
Merge "Revert "Use Service handler thread for NetworkStatsObservers"" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-04-01 10:20:27 +00:00
93c6bf6f84
Revert "Use Service handler thread for NetworkStatsObservers"
This reverts commit 8b1d824ad2.

Reason for revert: b/332214348


Fix: 332214348
Change-Id: Iac8b9a11fb5b1c2e704eada62869c8c8552b3804

Junyu Lai   commited 2024-04-01 09:06:55 +00:00
86edb59bd4
Merge "SatelliteAccessController enhancements to handle delete user scenario" into main
Nagendra Prasad Nagarle Basavaraju   authored and   Gerrit Code Review   commited 2024-04-01 06:19:52 +00:00
6cbb7cf3d5
SatelliteAccessController enhancements to handle delete user scenario
- Handle onRoleHoldersChanged is not triggered even if the user has a
  default app setup and gets deleted scenario.

- Adding ACTION_USER_REMOVED intent filter, to monitor for User
  removal. This to used to update satellite fallback uid list
  and to keep allowed uid range updated at multi layer request
  of track default and satellite transport with Internet
  restricted capability

Bug: 326373613
Test: atest FrameworksNetTests
Change-Id: I1f30cd129309486bccbc61802ed600c142077411

Nagendra Prasad Nagarle Basavaraju   commited 2024-04-01 04:19:12 +00:00
0668238d50
Address kotlin coding style erros
Test: m
Change-Id: Id2109a57d062df9629b6a41bc33d3a2f2662b2cd

Paul Hu   commited 2024-03-29 07:08:32 +00:00
48321f8d4a
Merge "Support multiple query packets" into main
Paul Hu   authored and   Gerrit Code Review   commited 2024-03-29 01:12:31 +00:00
e805c9a9ce