Commit Graph

838 Commits

Author SHA1 Message Date
Junyu Lai
2eefcdcf0c [MS82.1] Support network stats data migration process am: 27e0a9833e
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/18367994

Change-Id: I3e81555cd0871883571d925422b82d8fd7bdd10b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-19 14:55:21 +00:00
Lorenzo Colitti
e30044bb1f Add a PersistentInt class. am: 76c0f6f0e8
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/18437645

Change-Id: I9497d4812ab9cafb42e2b6a0653f6094cbc18cfa
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-19 14:55:19 +00:00
Treehugger Robot
e7f85a6d71 Merge "Changing automotive ethernet allowed UIDs check" am: 36cae536f0 am: fe4f42ff48
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2101472

Change-Id: I280093a80cdbc7add7bbeaf20bcb5adf09c90f9b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-19 14:17:46 +00:00
Treehugger Robot
36cae536f0 Merge "Changing automotive ethernet allowed UIDs check" 2022-05-19 13:29:16 +00:00
James Mattis
4eff0efb57 Changing automotive ethernet allowed UIDs check
Updating the automotive allowed UIDs check to only work if the
capabilities have a single transport equal to ethernet.

Bug: 229419469
Test: atest FrameworksNetTests
Change-Id: I91e987d6b943a3c5986ab88553a6eef0d479b079
2022-05-18 22:18:14 -07:00
Patrick Rohr
473b5411e2 Merge "Fix the ethernet setting API bug." am: 493ce14eaf am: 4fbfc8b270
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2099112

Change-Id: Ic998f930fcf57d04c04089ea5a7e919325b8acdf
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-18 21:30:57 +00:00
Junyu Lai
27e0a9833e [MS82.1] Support network stats data migration process
This includes:
1. Provide NetworkStatsRecorder#importCollectionLocked to
   allow caller to write a NetworkStatsCollection object to
   a standalone file.
2. Do not clear the collection in NetworkStatsRecorder#
   CombiningRewriter, this is safe since pending set will
   still be cleared during forcePersistLocked.
3. Implement the migration process, including recovery and
   safety measures.

Test: NetworkStatsServiceTest NetworkStatsCollectionTest
Test: manual test with
      adb shell device_config put tethering \
      netstats_store_files_in_apexdata true
      adb shell device_config put tethering \
      netstats_import_legacy_target_attempts 1
Ignore-AOSP-First: in a topic with internal-only changes
Bug: 230289468
Change-Id: Ic2002cbfd5a6b3c2226fa8dab22481f8ce656574
2022-05-18 23:34:30 +08:00
Lorenzo Colitti
76c0f6f0e8 Add a PersistentInt class.
This implements a simple integer written to disk backed by
AtomicFile.

Bug: 230289468
Test: new unit test
Ignore-AOSP-First: in a topic with internal-only changes
Change-Id: I1c73c8ac2429f92153cfba3b006b4374e75e65df
2022-05-18 20:54:50 +08:00
Xiao Ma
94a00dfc64 Fix the ethernet setting API bug.
After turning off the ethernet settings via api, the ethernet service
can still be started when plugging-in the cable. Improve the api by
ignoring the upcoming interface unsolicited event listener callbacks
and register new interface observer once the ethernet setting is enabled
again.

Bug: 231933028
Test: atest testListenEthernetStateChange_unsolicitedEventListener
Change-Id: I1b1cb7d157f023fca82d75592168bd360a6fa6e1
2022-05-18 17:23:32 +09:00
Treehugger Robot
caf8c958ed Merge changes I03e7cda7,I675c4ef5 am: af7101ff0f am: ec586c6cdb
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2072767

Change-Id: I7e55796d79e6a88ae2a43f7851ef8bccc6ccea04
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-18 04:07:26 +00:00
James Mattis
46491d7546 Allow ethernet on automotive to set allowed UIDs
Allow ethernet factories on automotive devices to set the allowed UIDs
on NetworkCapabilities.

Bug: 229419469
Test: atest FrameworksNetTests
Change-Id: I03e7cda75f1c530e0d0e4a756330bc9847a96668
2022-05-17 15:32:13 -07:00
Motomu Utsumi
1f96b8833d Merge changes If52ece61,Iedf344f6 am: f6131c483b am: 9d6decd77f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2095365

Change-Id: I6b73daf579d926f693ccb741615092b69200b82f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-17 02:45:29 +00:00
Motomu Utsumi
b08654ca04 Block incoming packets in VPN Lockdown mode.
Currently, even when VPN Lockdown mode is enabled, incoming packets are
not dropped if VPN is not connected.

This commit fixed this issue.
After this commit, If VPN Lockdown mode is enabled, incoming packets
are dropped regardless of the VPN connectivity.

Bug: 206482423
Test: atest TrafficControllerTest ConnectivityServiceTest PermissionMonitorTest
Change-Id: If52ece613c8aac1073355e43b6fb9cb3fcc87d1d
2022-05-16 10:40:59 +00:00
Junyu Lai
108d20f84a [MS81] Support remove history before cutoff timestamp
This is needed to ensure corrupted data can be clean up if
the data migration process dones't go well.

Test: NetworkStatsCollectionTest
Bug: 197717846
Change-Id: Ic76ad6f3e96f03791b48988fb2622c9c647ffc7c
(cherry picked from commit 306a00316c)
Merged-In: Ic76ad6f3e96f03791b48988fb2622c9c647ffc7c
2022-05-16 05:53:02 +00:00
Junyu Lai
165be7bf70 Merge "[MS81] Support remove history before cutoff timestamp" am: ac557274c1 am: 97dbe871a5
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2061368

Change-Id: I32f548eeb154ab3182b56d2c490325fa7c3f4648
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-14 00:01:24 +00:00
Junyu Lai
ac557274c1 Merge "[MS81] Support remove history before cutoff timestamp" 2022-05-13 22:40:32 +00:00
Junyu Lai
702e0f3deb Merge "Limit data usage request per uid" am: fc938cf026 am: 26acc088a5
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2085772

Change-Id: I8a9bee88f0f8ddec5f19b8bf5ce05d110d3f5aca
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-13 10:20:59 +00:00
Junyu Lai
fc938cf026 Merge "Limit data usage request per uid" 2022-05-13 09:06:41 +00:00
Chiachang
bc65e7e992 Address leftover comments
This is a follow-up commit from aosp/2076483. Mainly to update:
1. Update the hex string to human understandable code instead of
   byte code.
2. Use IgnoreUpTo() to do the SDK check
3. Avoid relying on the code being tested

Bug: 192078259
Test: atest FrameworksNetTests
Change-Id: I8973d248a1d30fdcb597677dbf051e146041f905
(cherry picked from commit a023f88193)
Merged-In: I8973d248a1d30fdcb597677dbf051e146041f905
2022-05-13 03:01:50 +00:00
chiachangwang
f2897b8a93 Test [set|get]AppExclusionList
Bug: 192078259
Test: atest FrameworksNetTests
Change-Id: Iee81d84b4127420121ce2d5a7defc3dbe34b6cde
(cherry picked from commit 218d5652de)
Merged-In: Iee81d84b4127420121ce2d5a7defc3dbe34b6cde
2022-05-13 02:47:56 +00:00
Hungming Chen
2a1430893e Revert "Open and close clat bpf map while clat is starting and stoping" am: b135921ed7 am: e5f50f95d3
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2092304

Change-Id: I0f95fbb9cddd7b63c2569c954ea2d35ee8614e48
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 14:28:40 +00:00
Hungming Chen
6f2fa97132 Revert "ClatCoordinator: replace BpfMap with IBpfMap" am: 9416307fa1 am: c88f684b8f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2092303

Change-Id: I55dfa80bc07273f797a506510ecf43b71788ec1b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 14:28:34 +00:00
Hungming Chen
e5f50f95d3 Revert "Open and close clat bpf map while clat is starting and stoping" am: b135921ed7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2092304

Change-Id: Id5570149952ef685c37d63373d375839be8b7e52
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 14:07:30 +00:00
Hungming Chen
c88f684b8f Revert "ClatCoordinator: replace BpfMap with IBpfMap" am: 9416307fa1
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2092303

Change-Id: Ic3209c5995442ad1782df44ec30ece1d06218c37
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 14:07:25 +00:00
Nucca Chen
f889ed7a30 Merge changes from topic "wrap_fd_to_parcelfiledescriptor"
* changes:
  Catch new exceptions from BpfMap
  Revert "Open and close clat bpf map while clat is starting and stoping"
  Revert "ClatCoordinator: replace BpfMap with IBpfMap"
2022-05-12 13:42:23 +00:00
Martijn Coenen
27a3d32c5b Merge "Modify VPN unit tests to include SDK sandbox UIDs." am: fc43f671dc am: 4fb520fa44
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2073533

Change-Id: I1c154da26188e5c369dc37a0ecd65855ab842ec6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 12:43:13 +00:00
Martijn Coenen
c0cf5a9bac Modify VPN unit tests to include SDK sandbox UIDs.
VPN configurations in T should automatically include the corresponding
SDK sandbox UID of an application.

The existing tests used a UID range outside the regular application
range, which means the new sandbox UIDs wouldn't be tested. Modified the
UIDs to run in the regular UID range of [10000, 19999]. Changed the
tests to include the SDK sandbox UID where necessary.

Also, changed the entire class to only run on T+, since that is the only
place where the SDK sandbox UIDs will be added. Since VPN code is not
mainline updatable, having coverage on earlier releases doesn't really
help anyway.

Finally, fixed up testNetworkBlockedStatusAlwaysOnVpn() in
ConnectivityServiceTest, and only have that run on T+ for the same
reasons.

Bug: 225317905
Test: atest VpnTest
Test: atest ConnectivityServiceTest

Change-Id: I83009344c270e520ac8ad1558c067cf7e46b1d2e
Merged-In: I83009344c270e520ac8ad1558c067cf7e46b1d2e
2022-05-12 12:11:45 +00:00
Junyu Lai
306a00316c [MS81] Support remove history before cutoff timestamp
This is needed to ensure corrupted data can be clean up if
the data migration process dones't go well.

Test: NetworkStatsCollectionTest
Bug: 197717846
Change-Id: Ic76ad6f3e96f03791b48988fb2622c9c647ffc7c
2022-05-12 16:31:39 +08:00
Martijn Coenen
021d8b08c1 Modify VPN unit tests to include SDK sandbox UIDs.
VPN configurations in T should automatically include the corresponding
SDK sandbox UID of an application.

The existing tests used a UID range outside the regular application
range, which means the new sandbox UIDs wouldn't be tested. Modified the
UIDs to run in the regular UID range of [10000, 19999]. Changed the
tests to include the SDK sandbox UID where necessary.

Also, changed the entire class to only run on T+, since that is the only
place where the SDK sandbox UIDs will be added. Since VPN code is not
mainline updatable, having coverage on earlier releases doesn't really
help anyway.

Finally, fixed up testNetworkBlockedStatusAlwaysOnVpn() in
ConnectivityServiceTest to include the sandbox UIDs as well.

Bug: 225317905
Test: atest VpnTest
Test: atest ConnectivityServiceTest

Change-Id: I83009344c270e520ac8ad1558c067cf7e46b1d2e
2022-05-12 08:07:29 +00:00
Chiachang Wang
ce7f5db86b Merge "Address leftover comments" am: 68936325f0 am: 7478298be2
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2095368

Change-Id: I3f89b18d929a5c463826f767a0eb72983fd1ca4d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 07:04:53 +00:00
Chiachang Wang
68936325f0 Merge "Address leftover comments" 2022-05-12 06:06:40 +00:00
Chiachang
a023f88193 Address leftover comments
This is a follow-up commit from aosp/2076483. Mainly to update:
1. Update the hex string to human understandable code instead of
   byte code.
2. Use IgnoreUpTo() to do the SDK check
3. Avoid relying on the code being tested

Bug: 192078259
Test: atest FrameworksNetTests
Change-Id: I8973d248a1d30fdcb597677dbf051e146041f905
2022-05-12 02:50:22 +00:00
Paul Hu
2edf88960a Merge changes from topic "cherrypicker-L53700000954454916:N44100001263878999" into tm-dev
* changes:
  Check carrier privilege for CBS network requests synchronously
  Allow 3p apps to request restricted networks
2022-05-12 02:48:34 +00:00
Sooraj Sasindran
95aa795f56 Merge "Fallback should be evaluated for each preference" am: 5ea6f517a6 am: 8522fc4532
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2092882

Change-Id: I232ff4d279e7e2d26654637247967055f2e666e4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 00:56:06 +00:00
Paul Hu
0554b3e11b Merge changes I5eaeb415,I236f1550 am: 7d180e679a am: af3dffefd7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2015175

Change-Id: Ib20e505f1a6776a49e0c7bfc31a709328e77edf5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 00:55:45 +00:00
Junyu Lai
f3c946278c Limit data usage request per uid
Currently, there is no limtation for an app to request
data usage callback, which is dangerous if the app fire
hundreds of thousands requests and potientially this might
cause OOM if the apps don't free them.

Test: atest NetworkStatsObserversTest#testRegister_limit
Bug: 229103088
Change-Id: I8299f46fd47a82ec9b25ba2e0d3c95db5512c331
2022-05-12 08:53:21 +08:00
Sooraj Sasindran
d359d19813 Fallback should be evaluated for each preference
1) alowFallback flag was incorrectly not reset while setting profile
   preference. Corrected it.

2) Threw exception if default preference and enterprise preference are
set together

3) renamed clearUser to withoutUser

Bug: 231670730
Test: ConnectivityServiceTest

Change-Id: If92ebe0cc23f18c8808893926d5e1d12ff2e3650
Merged-In: Iaf49237bdc791c7e1dd884d069eff64e74757477
2022-05-11 23:56:48 +00:00
Sooraj Sasindran
5ea6f517a6 Merge "Fallback should be evaluated for each preference" 2022-05-11 21:05:18 +00:00
junyulai
f9fc36ea3a Check carrier privilege for CBS network requests synchronously
Normally if an app calls requestNetwork with capabilities that it
does not have permission to request, it gets a SecurityException,
except if it requests NET_CAPABILITY_CBS, in which case the request
will not throw but the app will get an onUnavailable callback.

Make this codepath throw as well. This simplifies the code and makes
the app-visible behaviour more consistent (and consistent with what
happens in S and below). The reason the code was written this way is because the carrier privilege app should receive a callback if it
loses permission. But onUnavailable is also not the best callback to
send, since it is used very rarely and also releases the app's
request. It seems better to leave the request registered and send
onLost.

Test: atest FrameworksNetTests
Bug: 194332512
Change-Id: I5eaeb415a6654851246e38599a996fbd9366fde0
(cherry picked from commit 96bd9fe4de)
Merged-In: I5eaeb415a6654851246e38599a996fbd9366fde0
2022-05-11 13:50:06 +00:00
Sooraj Sasindran
b0e283c900 Fallback should be evaluated for each preference
1) alowFallback flag was incorrectly not reset while setting profile
   preference. Corrected it.

2) Threw exception if default preference and enterprise preference are
set together

3) renamed clearUser to withoutUser

Bug: 231670730
Test: ConnectivityServiceTest

Change-Id: Iaf49237bdc791c7e1dd884d069eff64e74757477
2022-05-10 22:11:55 -07:00
Paul Hu
7d180e679a Merge changes I5eaeb415,I236f1550
* changes:
  Check carrier privilege for CBS network requests synchronously
  Allow 3p apps to request restricted networks
2022-05-10 14:38:30 +00:00
junyulai
96bd9fe4de Check carrier privilege for CBS network requests synchronously
Normally if an app calls requestNetwork with capabilities that it
does not have permission to request, it gets a SecurityException,
except if it requests NET_CAPABILITY_CBS, in which case the request
will not throw but the app will get an onUnavailable callback.

Make this codepath throw as well. This simplifies the code and makes
the app-visible behaviour more consistent (and consistent with what
happens in S and below). The reason the code was written this way is because the carrier privilege app should receive a callback if it
loses permission. But onUnavailable is also not the best callback to
send, since it is used very rarely and also releases the app's
request. It seems better to leave the request registered and send
onLost.

Test: atest FrameworksNetTests
Bug: 194332512
Change-Id: I5eaeb415a6654851246e38599a996fbd9366fde0
2022-05-10 10:26:54 +00:00
Junyu Lai
4c14d7a94d Improve logging for NetworkStatsObservers
In order to have better logging to gather information
about the callers. This change includes:
 1. Add pid and package name into RequestInfo for better logging.
 2. Print current observers in dumpsys section.
 3. Enable register/unregister usage request logging by default.

The log added in the dumpsys section looks like:
Stats Observers:
  RequestInfo from pid/uid:2001/1000(android) for DataUsageRequest [...] accessLevel:3
  ...

Test: NetworkStatsObserversTest
Bug: 229103088
Change-Id: Ide68776dc279610e8dee0efd924b59a1fac2b7b6
(cherry picked from commit c259e615e6)
Merged-In: Ide68776dc279610e8dee0efd924b59a1fac2b7b6
2022-05-10 10:56:44 +08:00
Lorenzo Colitti
784d9b492c Merge "Do not remove profile network preference for different uids" am: 42791188b2 am: e625192614
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2076720

Change-Id: I6cbdc8dedb869a45190482e8c5f71d8278f5ba59
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-09 14:26:47 +00:00
Sooraj Sasindran
235dfbd6a8 Merge "Add more tests for setProfileNetworkPreferences" am: a457b6fdf1 am: d248be0c71
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2083223

Change-Id: Ia92b4bc8b691163ae15ba36c98bd136ec7106a3d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-09 14:26:37 +00:00
Hungming Chen
b135921ed7 Revert "Open and close clat bpf map while clat is starting and stoping"
Test: build
This reverts commit c03323c8ef.

Change-Id: I0cd8b2b409bb4df248d9b9d49a3392a1fe7ecafe
2022-05-09 19:37:19 +08:00
Hungming Chen
9416307fa1 Revert "ClatCoordinator: replace BpfMap with IBpfMap"
Test: build
This reverts commit 12c625bbf8.

Change-Id: I100dc77a8e29ac21ca649d6487563021e8cf0f80
2022-05-09 19:37:08 +08:00
Sooraj Sasindran
ca9e8fe1c9 Do not remove profile network preference for different uids
Multiple enterprise slice can be setup within single user profile based
on different uids. So do not remove profile network preference with same
user profile but with different uids

Bug: 229644102
Test: manual system test and ConnectivityServciceTest
Change-Id: I897b643e01240958fff575de9e15182069efc698
(cherry picked from commit 9cc129f37d)
Merged-In: I897b643e01240958fff575de9e15182069efc698
2022-05-09 09:44:35 +00:00
Sooraj Sasindran
38b5ce570c Add more tests for setProfileNetworkPreferences
1. Test that adding a new preference replaces the existing preference.
2. Test that if we pass in two simultaneous preferences for the same user.
   (e.g., two different groups of apps), the second overrides the first.

Bug: 229644102
Test: ConnectivityServciceTest
Change-Id: I819247711f8457b12792585216ff47be31457ae8
(cherry picked from commit 95e02c5d5a)
Merged-In: I819247711f8457b12792585216ff47be31457ae8
2022-05-09 09:44:33 +00:00
Lorenzo Colitti
42791188b2 Merge "Do not remove profile network preference for different uids" 2022-05-09 09:40:52 +00:00