Commit graph android_packages_modules_Co.../service/src/com/android/server/ConnectivityService.java
Message SHA1
ConnectivityService - do not dumpBpfProgramStatus before T
this is to fix some lint issues

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

Maciej Żenczykowski   commited 2024-06-16 05:22:58 -07:00
f0da1bee5e
Add a Log.wtf() on user builds to test Pitot reporting pipeline
Apparently, we have previously seen instances of the pipeline being
broken, so this is adding a Log.wtf() to test the pipeline.

It is only run on user builds to not randomly crash droidfood devices.

Test: cf boots
Change-Id: Ie4e6661adef6f1878529688561805f2485e58391

Patrick Rohr   commited 2024-06-15 14:11:55 -07:00
9161b153b4
Add a temporary hack to CS to report netbpfload result
Since BpfHandler::init() in the August module does not wait on
netbpfload (it only loads test.o), post on the ConnectivityService
handler and check that netbpfload ran to completion after 30s.

Log.wtf() on failure as these logs show up in Pitot even on release
builds.

Note that system server does not have access to any of the programs or
maps loaded from test.c, so all it can do is verify that mainline_done
exists.

Test: cuttlefish boots and does not crash
Change-Id: I6d2063f1d4f03207bbb6599b75954cfceb793af4

Patrick Rohr   authored and   Maciej Żenczykowski   commited 2024-06-15 03:58:43 -07:00
fe956d9189
Merge changes I62c990d0,I413bdb76,I020ba48e into main
* changes:
  Update NetworkRequestTest#testDefaultCapabilities
  Allow default messaging app to use constrained satellite network
  Introduce NET_CAPABILITY_NOT_BANDWIDTH_CONSTRAINED

Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-06-07 09:29:06 +00:00
3e07102814
Allow default messaging app to use constrained satellite network
On V+, there could be satellite network which is not restricted but
bandwidth constrained.
These satellite network has NET_CAPABILITY_NOT_RESTRICTED but does not
have NET_CAPABILITY_NOT_BANDWIDTH_CONSTRAINED.
Since NET_CAPABILITY_NOT_BANDWIDTH_CONSTRAINED is set by default, this
CL remove this capability from per-app default network request for the
default messaging app.

Test: CSSatelliteNetworkTest
Bug: 343823469
Change-Id: I413bdb764ead42d67ce1315c365500dbb8508eb3

Motomu Utsumi   commited 2024-06-07 09:26:19 +09:00
ab750abf29
Add config flag for useDeclaredMethodsForCallbacks
Add a DeviceConfig flag that will be used to control whether callbacks
should be sent selectively based on whether the receiving method has
been overridden (will be implemented in a future change).

This adds utilities to allow ConnectivityManager to check whether a
ConnectivityService flag is enabled, as that feature will work across
ConnectivityManager and ConnectivityService. ConnectivityManager runs in
app process and does not necessarily have permissions to use
DeviceConfig. Also if it checked DeviceConfig separately from
ConnectivityService, values may be out-of-sync.

Test: atest, and see change using this
Change-Id: I204fa719cc627e84edc5c1e043d947f5ef3f8dee

Remi NGUYEN VAN   commited 2024-06-05 15:54:49 +09:00
aa355ac875
Merge "Explicitly log portal detections" into main
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2024-05-31 11:27:11 +00:00
d1c52e3eb0
Merge "Clatd: add dump raw BPF map support" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2024-05-31 08:11:44 +00:00
3812c394ba
Clatd: add dump raw BPF map support
Add dump raw BPF map command to connectivity service. The result will
be encoded as base64 strings. This is a preparation for Clatd's tests.

Usage:
    dumpsys connectivity {clatEgress4RawBpfMap|clatIngress6RawBpfMap}

Bug: 285124667
Test: test with MtsEthernetTetheringTest#testTetherClatBpfOffloadUdp
      which will be uploaded in a separated CL
Change-Id: I02c8efadb1c4b861d9bf6168667816b13412dc75

KH Shi   commited 2024-05-31 06:34:41 +00:00
855712aa55
Merge "Revert^2 "Add blocked reason for internet permission"" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-05-28 00:00:07 +00:00
d86bd6faca
Revert^2 "Add blocked reason for internet permission"
This reverts commit cb74c08979.

Reason for revert: This change is not a cause of b/342557183

Change-Id: Iee8d9b05bbe130a46b627b12da525177b4ee89b2

Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-05-27 02:12:43 +00:00
cfd5a517da
Merge "Revert "Add blocked reason for internet permission"" into main
Priyanka Advani   authored and   Gerrit Code Review   commited 2024-05-24 18:56:26 +00:00
fb1b1b3773
Revert "Add blocked reason for internet permission"
This reverts commit ee96ba0e60.

Reason for revert: Droidmonitor triggered revert due to b/342557183. Will be verifying through ABTD before submission.

Change-Id: I7e185c3ac11da27c7bb9d95e4221f7dfc22cf48c

Priyanka Advani   authored and   Gerrit Code Review   commited 2024-05-24 18:11:45 +00:00
cb74c08979
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
Support multiple reasons for socket destroy
This CL is a no-op and does not change any behavior.
Upcoming CL updates CS to destroy socket of background apps.
As a preparation, this CL updates socket destroy code non specific to
frozen apps.

Bug: 300681644
Test: ConnectivityServiceTest
Change-Id: I027766db342bf9a05d4532ecf9a60e6854e9456d

Motomu Utsumi   commited 2024-05-22 13:36:01 +09:00
8fad95cd61
Move mPendingFrozenUids empty check to destroyPendingSockets
Test: ConnectivityServiceTest
Bug: 300681644
Change-Id: Ic31f6b1ccea8bab8cce948736b74cf3e8e7fb2ba

Motomu Utsumi   commited 2024-05-22 13:35:56 +09:00
333f01d303
Rename closePendingFrozenSockets to destroyPendingSockets
As a preparation to update CS to destroy sockets for background apps,
renamed socket destroy methods to non specific to frozen apps

Bug: 300681644
Test: TH
Change-Id: I64c108aee1ee0d60df30ef055c8c9df8c6562d0f

Motomu Utsumi   commited 2024-05-22 13:35:50 +09:00
dff5df5b65
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 "Add comment for per-app preference priority" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2024-05-21 09:48:06 +00:00
1243420eb1
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
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 comment for per-app preference priority
Clarify that only the highest priority preference is applied if the uid
is target of multiple preferences.

Test: TH
Change-Id: I55b6a37995bcfe876ed609cf653077df2b5e7615

Motomu Utsumi   commited 2024-04-26 18:33:16 +09:00
300a83cc15
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
Add @RequiresApi(TIRAMISU) to BpfNetMapsUtils
With this annotation, errorprone build will fail if callers don't check
sdk version before calling any methods in BpfNetMapsUtils.

Bug: 328732146
Test: TH
Change-Id: Ifa52dc1d2766f8d46dfdc4f6ca9dbb963406c084

Motomu Utsumi   commited 2024-04-24 13:16:42 +09:00
2c248d2108
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
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
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 "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
Use bpf map based isUidNetworkingBlocked on V+
NetworkPolicyManager#isUidNetworkingBlocked does not know about some
firewall chains status(e.g. FIREWALL_CHAIN_OEM_DENY_1)
So BpfNetMaps#isUidNetworkingBlocked is more correct but there could be
some behavior difference.
To avoid breaking devices and have longer verification time, this CL
updates to use BpfNetMaps#isUidNetworkingBlocked only on V+ devices.

Bug: 328732146
Test: TH
Change-Id: I60f84a5fff90386103692841dead465652249446

Motomu Utsumi   commited 2024-03-26 19:16:57 +09:00
9b272fa53a
Merge "Use connectivityHandler in CarrierPrivilegeAuthenticator" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-03-21 07:22:41 +00:00
98eb360c0d
Use connectivityHandler in CarrierPrivilegeAuthenticator
When request_restricted_wifi is enabled CarrierPrivilegeAuthenticator
calls CarrierPrivilegesLost callback passed from ConnectivityService.
But CarrierPrivilegeAuthenticator was using its own handler thread to
receive broadcast and callbacks so CarrierPrivilegesLost callback needed
to post a message to the CS handler.
This CL updates CarrierPrivilegeAuthenticator to use CS handler if
request_restricted_wifi is enabled, and remove the message post in
ConnectivityService.

Test: TH
Change-Id: Ib41304a30e3dd366b0f6f1d7df81145f0e05ece1

Motomu Utsumi   commited 2024-03-18 22:16:53 +09:00
4fcaa4e803
Drop packets to VPN address ingressing via non-VPN interface
When there are addresses that are used by a single VPN interface,
ConnectivityService sets ingress discard rules to drop packets to this
address from the non-Vpn interfaces

Test: FrameworksNetTests
Bug: 295800201
Change-Id: I089d01a38eff3f37a851627fa9e4acefb8d9ad5e

Motomu Utsumi   commited 2024-03-15 15:23:50 +09:00
b4772b1e5d
Merge "Make the subscriptionIds and allowedUids public" into main
Ying Xu   authored and   Gerrit Code Review   commited 2024-03-14 14:33:38 +00:00
a37386a6b6
Merge "Ignore no permission calls for CaptivePortal.appRequest" into main
Chiachang Wang   authored and   Gerrit Code Review   commited 2024-03-14 06:48:06 +00:00
4cd5b9e2d2
Ignore no permission calls for CaptivePortal.appRequest
This enforceNetworkStackPermission() should be adopted to check
the required permission but this may be break OEM captive portal
apps. Simply ignore the request if the caller does not have
permission.

This commit also fixes the format issues that is auto-fixed by
ktlint.

Fix: 329385091
Test: ates FrameworksNetTests
Change-Id: Ia973a1078eda3134fc8ff261d3954cd050767880

Chiachang Wang   commited 2024-03-14 04:32:11 +00:00
73be9a0933
Merge "Add CompatChange for local network matching" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-03-13 02:34:57 +00:00
d2c103ea14
Fix wrong request_count in connectivityStateSample and add tests
This CL updates CSTest to use mocked appOpsManager to bypass
checkPackage enforcement so that test can file network request as
SYSTEM_UID

Bug: 314627716
Test: atest ConnectivitySampleMetricsTest
Change-Id: I0a5f3b1bf2c343644e6f5e2a4ec1b0460e2645c4

Motomu Utsumi   commited 2024-03-12 19:07:08 +09:00
e08de4d322
Revert "Log bpf rc file if it differs from the template files."
This reverts commit 41557553f6.

(this is no longer needed, as it rolled out with January module,
while the May module this is targetting already includes an rc,
thus eliminating the need for this warning)

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

Maciej Żenczykowski   commited 2024-03-05 19:49:20 -08:00
cf3d20011c
Make the subscriptionIds and allowedUids public
This CL allows everyone to see the subscriptionIds and the network owner
to see the allowedUids from the NetworkCapabilities.

Bug: 324357121
Test: atest ConnectivityManagerTest
      atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest
Change-Id: I91e360827d2a9a64625f1d6ae0f808aa327c7d22

Ying Xu   commited 2024-03-04 14:51:20 -08:00
611b80456a
Add CompatChange for local network matching
Apps that target an SDK before V will not see networks with
NET_CAPABILITY_LOCAL_NETWORK unless they explicitly set this capability
in their network requests.

Bug: 319212206
Test: CSLocalAgentTests
Change-Id: I414b03dfea9a8aac83304c6be501f03d637739b4

Motomu Utsumi   commited 2024-03-04 17:50:27 +09:00
ad480e0c58
Correct the method used for permission check
The hasNetworkStackPermission() method does not enfore the
permission check. It should be replaced with
enforceNetworkStackPermission().

Bug: 325984919
Test: atest FrameworksNetTests
Change-Id: I9ad0b47190dbc9afd2ee6f5dfc21a4935036733a

Chiachang Wang   commited 2024-02-26 03:08:22 +00:00
ac162f2272
Store the SubscriptionId together with the Carrier UID
Always store the corresponding SubscriptionId together with the Carrier
uid so that when the carrier loses the Privilege, both the uid and
SubscriptionID will be used in the onCarrierPrivilegesLost callback

Bug: 324357121
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.connectivity.CarrierPrivilegeAuthenticatorTest
      atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest
Change-Id: I28e51c583261a67d4441c6f825ade6781b862ee4

Ying Xu   commited 2024-02-20 08:58:31 -08:00
0d06b9460a
Merge "Enable CloseFrozenAppSockets feature on V+" into main
Motomu Utsumi   authored and   Gerrit Code Review   commited 2024-02-13 07:37:10 +00:00
8960842e6a