Commit Graph

649 Commits

Author SHA1 Message Date
Junyu Lai
fc938cf026 Merge "Limit data usage request per uid" 2022-05-13 09:06:41 +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
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
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
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
5ea6f517a6 Merge "Fallback should be evaluated for each preference" 2022-05-11 21:05:18 +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
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
Lorenzo Colitti
42791188b2 Merge "Do not remove profile network preference for different uids" 2022-05-09 09:40:52 +00:00
Sooraj Sasindran
a457b6fdf1 Merge "Add more tests for setProfileNetworkPreferences" 2022-05-09 09:12:48 +00:00
Junyu Lai
ef1fdc95dd Merge "Improve logging for NetworkStatsObservers" 2022-05-07 02:11:07 +00:00
Sewook Seo
baabe211be Merge "Support QosCallback with UDP socket. UnitTest" 2022-05-06 20:47:05 +00:00
Sooraj Sasindran
9cc129f37d 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
2022-05-06 00:58:33 -07:00
Sooraj Sasindran
95e02c5d5a 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
2022-05-06 00:58:28 -07:00
Hungming Chen
12c625bbf8 ClatCoordinator: replace BpfMap with IBpfMap
Test: atest ClatCoordinatorTest
Change-Id: I3d046d4f195be6bbedc15df08114fafb2b77c2d3
2022-05-05 23:48:37 +08:00
Hungming Chen
c03323c8ef Open and close clat bpf map while clat is starting and stoping
BpfMap class supports AutoCloseable interface which closes
file descriptor only in try-exit. BpfMap class doesn't close
fds while the object is released.

Change the timing of opening and closing bpf map file descriptors
to clat is starting and stoping.

Moreover, the reason that manual close BPF map file descriptors is
as follows. Just don't rely on that GC releasing to close the file
descriptors even if class BpfMap supports close file descriptor in
finalize(). If the interfaces are added and removed quickly, too
many unclosed file descriptors may cause unexpected problems.

Bug: 230880517
Test: manual test
Steps:
1. Connect to IPv6 only wifi (GoogleGuest) and mobile data
2. Check that map fds are appeared:
   /proc/$(system_server_pid)/fd/$(bpf_map_fd)

$ adb shell ps | grep system_server
system        1929   825 20311224 730060 do_epoll_wait      0 S system_server

$ adb shell ls -all proc/1929/fd | grep bpf-map
.. system system 64 2022-05-05 13:36:42 .. 331 -> anon_inode:bpf-map
.. system system 64 2022-05-05 13:36:42 .. 348 -> anon_inode:bpf-map

3. Check the clat maps are added.
$ adb shell dumpsys connectivity
NetworkAgentInfo{network{105}  handle{454377263117}  ni{WIFI ..
Nat464Xlat:
..
  Forwarding rules:
    BPF ingress map: iif nat64Prefix v6Addr -> v4Addr oif
      47 /64:ff9b::/96 /2a00:79e1:abc:6f02:f182:6c29:ab56:9961 -> /192.0.0.4 62
    BPF egress map: iif v4Addr -> v6Addr nat64Prefix oif
      62 /192.0.0.4 -> /2a00:79e1:abc:6f02:f182:6c29:ab56:9961 /64:ff9b::/96 47 ether
NetworkAgentInfo{network{106}  handle{458672230413}  ni{MOBILE[LTE] ..
    Nat464Xlat:
      <not start>

4. Disconnect from wifi

5. Check that map fds are disappeared:
   /proc/$(system_server_pid)/fd/$(bpf_map_fd)

$ adb shell ls -all proc/1929/fd | grep bpf-map
(fd 331 and 348 were not found)

Change-Id: I60c0301bf00beae5cf5ab3535c6a3da68a2a4a9b
2022-05-05 18:53:37 +08:00
sewookseo
04ced836b8 Support QosCallback with UDP socket. UnitTest
Adding unit tests to QosSocketFilterTest

Bug: 203146631
Test: atest & verified on LTE test equipment
Change-Id: I0cd82dde0067d754dfab01ed0406370d7debb937
2022-05-05 08:45:00 +00:00
Junyu Lai
c259e615e6 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
2022-05-05 16:30:50 +08:00
chiachangwang
218d5652de Test [set|get]AppExclusionList
Bug: 192078259
Test: atest FrameworksNetTests
Change-Id: Iee81d84b4127420121ce2d5a7defc3dbe34b6cde
2022-05-04 10:13:46 +00:00
Aaron Huang
132df4ed06 Merge "Add NetworkTemplateTest to common test for cts coverage" 2022-05-03 07:01:55 +00:00
Mark Chien
8e3b96b61f Merge "Fix ConnectivityManager memory leak" 2022-05-03 02:46:05 +00:00
Mark Chien
15b83ab323 Merge "Add a test to identify memory leak in ConnectivityManager" 2022-05-03 02:43:24 +00:00
Treehugger Robot
a14bd2a032 Merge "Follow-up 2076940: Allow device owner to configure profile network preference " 2022-05-02 15:00:55 +00:00
Vadim Caen
baade1ca1e Follow-up 2076940: Allow device owner to configure profile network preference
https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2076940

Fixes build failure


Bug: 231104107
Test: tests/unit/java/com/android/server/ConnectivityServiceTest.java
Change-Id: I7b6a3880ce0b0b9ad6fc6aa7a5fd4e249bb1606d
2022-05-02 09:22:32 +00:00
Sooraj Sasindran
07a20408db Merge "Allow device owner to configure profile network preference" 2022-05-02 07:13:21 +00:00
Sooraj Sasindran
bb65aa8fc2 Allow device owner to configure profile network preference
isMangedProfile returns true for managed profiles.
But enterprise device can be fully managed like device owner.
Hence check specifically if request is coming on fully managed
device.

Bug: 226966328
Bug: 231071836

Test: ran DevicePolicyManager CTS and ConnectivityServiceTest
Change-Id: I7827466bd61e24ba9c36c3a2e25043257e2ed602
2022-05-01 21:20:36 -07:00
Treehugger Robot
6a957c70c0 Merge "[MS83] Add Cts for NetworkStatsCollection/History builders" 2022-05-02 02:26:55 +00:00
Lucas Lin
025a3c993a Merge changes from topics "CATEGORY_ERROR_IKE", "CATEGORY_ERROR_NETWORK", "CATEGORY_ERROR_USER_DEACTIVATED", "CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED"
* changes:
  Test VpnManager event for CATEGORY_EVENT_NETWORK_ERROR
  Test VpnManager event for CATEGORY_EVENT_IKE_ERROR
  Test VpnManager event for CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED
  Test VpnManager event for CATEGORY_EVENT_DEACTIVATED_BY_USER
2022-04-29 08:13:51 +00:00
markchien
d201566169 Fix ConnectivityManager memory leak
ConnectivityManager have a self reference static instance. This
causes a leak if context is refernce from a static variable. Using
the applicationContext, which will never be freed for the life of the
application, for the sInstance static instance.

Bug: 202978965
Test: atest ConnectivityManagerTest
Change-Id: I87206e1bfbb1f877b5a10f5fdbc25e2f9f11bef4
2022-04-29 08:01:23 +00:00
markchien
ed0fab0356 Add a test to identify memory leak in ConnectivityManager
The sInstance static instance which self reference to
ConnectivityManager which holds a reference to a ConnectivityManager
instance causes the Context referenced by that instance to never be
GCed.

Bug: 202978965
Test: atest ConnectivityManagerTest
Change-Id: I0227f63dbc27688ea5f4ef9275fd0f9c247ad14c
2022-04-29 16:00:50 +08:00
lucaslin
cfec723ef9 Test VpnManager event for CATEGORY_EVENT_NETWORK_ERROR
Bug: 191413541
Test: atest FrameworksNetTests:VpnTest
Change-Id: Idffd5f5f8fc6614281f3fb0884228a797d783fe3
2022-04-26 01:10:10 +00:00
lucaslin
827b44daea Test VpnManager event for CATEGORY_EVENT_IKE_ERROR
Bug: 191413541
Test: atest FrameworksNetTests:VpnTest
Change-Id: Iebc0ac281eb03fac9626c64e44cdd14be1462d89
2022-04-26 01:10:03 +00:00
lucaslin
0772c169b5 Test VpnManager event for CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED
Bug: 225010642
Test: atest FrameworksNetTests:VpnTest
Change-Id: I078be4e00470efd9d7a2a87b40919116b99c83b8
2022-04-26 09:09:03 +08:00
lucaslin
c5bf088ced Test VpnManager event for CATEGORY_EVENT_DEACTIVATED_BY_USER
Bug: 191413541
Test: atest FrameworksNetTests:VpnTest
Change-Id: Idc876275b88c2f4ddeb85c43d37d5f657b0f307b
2022-04-25 23:12:26 +08:00
Chiachang Wang
2e670756ac Merge "Test Ikev2VpnProfile provisioned with IkeTunnelConnectionParams" 2022-04-25 08:44:45 +00:00
Maciej Żenczykowski
0736d7bd91 adjust for new T bpfloader net_shared location
(this is safe because on pre-T none of these maps and programs are mainlined
 and thus safe to access from mainline code anyway)

Test: TreeHugger, manual
Bug: 218408035
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I23e565d665247f33e084978890a1ee8ffe0fe568
2022-04-23 09:03:06 +00:00
chiachangwang
476e2a08bf Test Ikev2VpnProfile provisioned with IkeTunnelConnectionParams
Bug: 223841137
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: I683f6242e4ed4a469893e3a17fe7b479a7a768e5
2022-04-21 14:49:41 +08:00
Hungming Chen
eb15a2d816 [CLATJ#27] Use ClatdCoordinator since T+ devices
- For clatd start and stop, use ClatdCoordinator on T+ and Netd on S-
- Fix the unit test for T+ and S- devices
  Note that mokito.verify(.., times(1)) is replaced by verify(..)
  because times(1) is the default and can be omitted.
  See verify in mockito/src/main/java/org/mockito/Mockito.java

Note that this commit needs to be merged with aosp/1956072.

Bug: 212345928
Test: atest FrameworksNetTests
      manual test
      1. Connect to ipv6-only wifi.
      2. Try IPv4 traffic.
         $ ping 8.8.8.8
      3. Check bpf entries are added
      4. Disconnect from ipv6-only wifi.
      5. Check bpf entries are removed
      6. testipv4.com shows 10/10

Change-Id: I7dfda6eec19de94e4258971effcd8a1210542473
2022-04-21 13:24:36 +08:00
Aaron Huang
c3a43b4063 Fix NullPointerException happens in dumpCheckin
Currently dumpCheckin passes a null object to create
the contructor of NetworkStatsCollection.Key but the
constructor requires non-null object. Thus, it caused
the NPE in dumpCheckin. To fix this exception, create
an NetworkIdentitySet() object instead of using an
null object.

Bug: 225131008
Bug: 226539404
Test: dumpsys netstats --checkin is fine
      FrameworksNetTests
Change-Id: I7f2dadf0647b3f42e0f667d96291d2ae37e23faf
2022-04-19 17:49:30 +08:00
Natasha Lee
7f85379b07 Merge "Save appIds permissions for each user" 2022-04-12 23:55:06 +00:00
paulhu
a501e47e19 Save appIds permissions for each user
PermissionMonitor does not store any information regarding
traffic permission. It just checks permission from each package
and sends the result to netd. In addition, bpf can store traffic
permissions for appIds only because of memory limitations.

However, there is a mistaken permission overwriting when
different packages are installed on multi-user. Because
PermissionMonitor updates appIds traffic permissions to netd
from each user, so the permission result will depend on the
latest user state.

To fix the problem, save the traffic permissions by each user and
appId on PermissionMonitor. An appId has a permission if and
only if at least one uid in that appId has that permission.

bug: 224775316
Test: atest FrameworksNetTests CtsNetTestCases \
      CtsNetTestCasesUpdateStatsPermission \
      CtsNetTestCasesInternetPermission
Change-Id: Ieb01fb21f6201a58723eb7e6446b127627be2c0e
2022-04-12 11:06:46 +00:00
Paul Hu
631c2387a6 Merge "Remove NativeDaemonConnector relevant files" 2022-04-12 07:37:16 +00:00
paulhu
cee953bd09 Remove NativeDaemonConnector relevant files
NsdService is using binder call to communicate with
mdnsresponder, so there is no one to use NativeDaemonConnector
now. Thus, remove NativeDaemonConnector relevant files.

Bug: 209894875
Test: atest FrameworksNetTests
Change-Id: Ic70d9417dc85c04c537e09d8f8586a762ac9a97b
2022-04-12 07:35:31 +00:00
Maciej Żenczykowski
b3bf5fedab Merge changes I2c3242f8,Iaa67d5ae
* changes:
  Remove unused TcUtils{, Test}, bpfhelper from libclat
  ClatCoordinator: use Java class TcUtils to detach program
2022-04-11 20:47:50 +00:00
Maciej Żenczykowski
932459748a Merge "ClatCoordinator: use Java class TcUtils to attach program" 2022-04-11 20:47:26 +00:00
Maciej Żenczykowski
7b75c07cda Merge changes from topic "access_clat_bpf_map_from_clatcoordinator"
* changes:
  ClatCoordinator: use Java class BpfMap to remove clat rule
  ClatCoordinator: use Java class BpfMap to add clat rule
2022-04-11 20:46:59 +00:00