Commit Graph

610 Commits

Author SHA1 Message Date
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
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
Patrick Rohr
da294fc886 Merge "Use completeExceptionally instead of second future" 2022-04-07 12:12:32 +00:00
Chiachang Wang
5850372963 Merge "Update test for new IkeTunnelConnectionParams field" 2022-04-07 10:24:03 +00:00
Paul Hu
09475308b7 Merge changes from topic "MDns_AIDL"
* changes:
  Use MDns aidl on NsdService
  Add MDnsManager
2022-04-07 02:06:35 +00:00
paulhu
2b9ed95ae5 Use MDns aidl on NsdService
- Use MDns aidl to communicate with mdns service and register
  event listener to receive callback.
- Remove all NDC relevant code on NsdService.
- Use MDns aidl on NsdServiceTest.

Bug: 209894875
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I65929dee3838fef753396e86c665abd66b6fec81
2022-04-04 15:18:27 +00:00
Patrick Rohr
fd87fb65fb Use completeExceptionally instead of second future
The onError callback can use the same future as the onResult callback by
calling completeExceptionally.
This change is also removing the test for a specific exception message.
Testing for a specific exception message would mean that tests break if we
ever were to update them. If we decide that there is value to
distinguish between different types of
EthernetNetworkManagementException we should probably subclass it
internally.

Test: atest EthernetNetworkFactoryTest
Change-Id: Ib6f8cf79fc26e0f856c880cbe505b101f12aa187
2022-04-04 14:59:42 +02:00
Remi NGUYEN VAN
40da62da48 Merge EthernetServiceTests into FrameworksNetTests
As per the TODO, merge EthernetServiceTests into the larger
FrameworksNetTests suite.

Similarly to NetworkStats, NSD or IpSec tests, the tests are also marked
as "non-connectivity-module-test", where "module" actually refers to
modules being built for release (from an S-based branch) today. This is
necessary as the tests and associated code cannot build without T APIs.

Also add FrameworksNetTests to presubmit as non-connectivity-module
tests are not run in presubmit without this.

Test: TH
Merged-In: Id533cdb4ac184b963f570af299dea04754ba88e9
Change-Id: I9950fcb49fdc2217134a59e993941cbe5da0b556
2022-04-01 15:12:18 +09:00
Hungming Chen
3dc0577ed3 ClatCoordinator: use Java class TcUtils to attach program
This a preparation to replace duplicated native functions with the
existing Java class.

Bug: 221213090
Test: atest FrameworksNetTests
Test: manual test
Steps:
1. Connect to IPv6-only wifi
2. Check tc filter on wlan0 and v4-wlan0

$ adb shell tc filter show dev wlan0 ingress
filter protocol ipv6 pref 4 bpf chain 0
filter protocol ipv6 pref 4 bpf chain 0 handle 0x1 prog_clatd_schedcls_ingress6_clat_ether:[*fsobj] direct-action not_in_hw id 23 tag 40918e0675598c8d

$ adb shell tc filter show dev v4-wlan0 egress
filter protocol ip pref 4 bpf chain 0
filter protocol ip pref 4 bpf chain 0 handle 0x1 prog_clatd_schedcls_egress4_clat_rawip:[*fsobj] direct-action not_in_hw id 26 tag 5d0057eab14480b7

$ adb shell tc filter show dev wlan0 egress
(empty)

$ adb shell tc filter show dev v4-wlan0 ingress
(empty)

Change-Id: Id4edbfd87de8f9c5d2fa483b2024718b484cb044
2022-03-31 16:04:42 +08:00
Hungming Chen
bd85f8903e ClatCoordinator: use Java class BpfMap to remove clat rule
This a preparation to replace duplicated native functions with the
existing Java class.

Bug: 221213090
Test: atest FrameworksNetTests
Test: manual check

Steps:
1. Connect wlan and check map content {iface index, v4addr, v6addr, pfx96} manually
after clat started.
$ adb shell dumpsys netd
  ClatdController
    BPF ingress map: iif(iface) nat64Prefix v6Addr -> v4Addr oif(iface)
      47(wlan0) 64:ff9b::/96 2a00:79e1:abc:6f02:2479:2f51:25a9:28f1 -> 192.0.0.4 53(v4-wlan0)
    BPF egress map: iif(iface) v4Addr -> v6Addr nat64Prefix oif(iface)
      53(v4-wlan0) 192.0.0.4 -> 2a00:79e1:abc:6f02:2479:2f51:25a9:28f1 64:ff9b::/96 47(wlan0) ether

2. Disconnect wlan and check the bpf map is removed.
$ adb shell dumpsys netd
  ClatdController
    BPF ingress map: iif(iface) nat64Prefix v6Addr -> v4Addr oif(iface)
    BPF egress map: iif(iface) v4Addr -> v6Addr nat64Prefix oif(iface)

Change-Id: Ia0c90c7104c4a42d34a28a5ddf3cf13a289f8c76
2022-03-31 16:04:42 +08:00
Hungming Chen
cddd855f9e ClatCoordinator: use Java class TcUtils to detach program
This a preparation to replace duplicated native functions with the
existing Java class.

Bug: 221213090
Test: atest FrameworksNetTests
Test: manual test
Steps:
1. Connect to IPv6-only wifi

2. Check tc filter on wlan0 and v4-wlan0

$ adb shell tc filter show dev wlan0 ingress
filter protocol ipv6 pref 4 bpf chain 0
filter protocol ipv6 pref 4 bpf chain 0 handle 0x1 prog_clatd_schedcls_ingress6_clat_ether:[*fsobj] direct-action not_in_hw id 23 tag 40918e0675598c8d

$ adb shell tc filter show dev v4-wlan0 egress
filter protocol ip pref 4 bpf chain 0
filter protocol ip pref 4 bpf chain 0 handle 0x1 prog_clatd_schedcls_egress4_clat_rawip:[*fsobj] direct-action not_in_hw id 26 tag 5d0057eab14480b7

$ adb shell tc filter show dev wlan0 egress
(empty)

$ adb shell tc filter show dev v4-wlan0 ingress
(empty)

3. Disconnect from wifi

4. Check tc filter on wlan0 and v4-wlan0

$ adb shell tc filter show dev wlan0 ingress
(empty)

$ adb shell tc filter show dev v4-wlan0 egress
(empty)

$ adb shell tc filter show dev wlan0 egress
(empty)

$ adb shell tc filter show dev v4-wlan0 ingress
(empty)

Change-Id: Iaa67d5ae7c867d791d5f92a70a54bf549085053a
2022-03-31 16:04:42 +08:00
Hungming Chen
07fcf9ca49 ClatCoordinator: use Java class BpfMap to add clat rule
This a preparation to replace duplicated native functions with the
existing Java class.

Bug: 221213090
Test: atest FrameworksNetTests
Test: check map content {iface index, v4addr, v6addr, pfx96} manually.
The map fileds are the same as "ip addr" and clatd logging.

$ adb shell dumpsys netd
ClatdController
  BPF ingress map: iif(iface) nat64Prefix v6Addr -> v4Addr oif(iface)
    47(wlan0) 64:ff9b::/96 2a00:79e1:abc:6f02:f9e1:8c2d:604e:bc06 -> 192.0.0.4 53(v4-wlan0)
  BPF egress map: iif(iface) v4Addr -> v6Addr nat64Prefix oif(iface)
    53(v4-wlan0) 192.0.0.4 -> 2a00:79e1:abc:6f02:f9e1:8c2d:604e:bc06 64:ff9b::/96 47(wlan0) ether

$ adb shell ip addr
47: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ..
53: v4-wlan0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1472 ..

03-14 18:35:04.822 30852 30852 I clatd   : Starting clat version 1.5 on wlan0 plat=64:ff9b:: v4=192.0.0.4 v6=2a00:79e1:abc:6f02:f9e1:8c2d:604e:bc06

Change-Id: I91d0cb6e76c4ef7bacf91b996786308ff4918f35
2022-03-31 15:53:33 +08:00
Chiachang Wang
69aa988090 Update test for new IkeTunnelConnectionParams field
Bug: 184750836
Test: atest FrameworksNetTests
Change-Id: Iab55eba74b94f295a358c6e8474ebf9230c9b019
2022-03-31 14:45:59 +08:00
Michael Groover
3e712761a4 Merge "Revert "Use RECEIVER_NOT_EXPORTED in CarrierPrivilegeAuthenticator."" 2022-03-31 01:39:28 +00:00
Lorenzo Colitti
644fe232cd Merge "Don't throw in FullScore#policyNameOf." 2022-03-29 08:38:21 +00:00
Lorenzo Colitti
1727d9f1f2 Don't throw in FullScore#policyNameOf.
This code is correct on userdebug builds, but it is dangerous on
user builds because proguard might strip out the POLICY_*
constants and that would lead to crashes.

For now just log a wtf if an invalid policy name is found. A
better solution would be to make MessageUtils robust to this
problem, e.g., by having it store the SparseArray internally and
providing getters that do not throw, instead of the current
behaviour that returns the SparseArray. That is left to a future
CL.

Fix: 227161413
Test: atest FullScoreTest
Change-Id: I68b69ee9dd84773018e62c9a8f43e754ae04c486
2022-03-29 08:38:06 +00:00
Chiachang Wang
59e6e2b730 Merge "Add tests for VPN validation in NetworkMonitor" 2022-03-28 13:51:34 +00:00
Remi NGUYEN VAN
0395b70000 Use Sources.bp for building
Reference Sources.bp from Android.bp, so that they are used as build
files.

Sources.bp is separate from Android.bp as it was migrated from the
Android.bp files in the old code location. They can be merged into the
main Android.bp file (or removed by removing the filegroups) after the
migration is done.

Also remove references to the AIDL filegroups, as files are now merged
into the common framework/aidl-export directory which is used as include
directory for aidl source generation already, so they do not need to be
referenced separately. framework/aidl-export can contain AIDLs for S-
API classes that became updatable API in T (the contents of
framework-t), as they are the same as any other API class for the
purposes of AIDL code generation: it's OK for any S+ code to reference
S+ API classes.

Finally, fix reference to mByteStream in IpConfigStoreTest. It was
already wrong but did not break the build because the test was not being
built in the old location.

Bug: 222234190
Test: TH
Merged-In: I81893df9f327abb84f1561b2b33027a2d23a4d65
Merged-In: I67c703e3f7aa9d5787f032a79ed62e45412baf4f
Change-Id: I9093f9ae2f9d76e597f20de48680e459891755b4
2022-03-25 14:58:43 +00:00
Remi NGUYEN VAN
700ffc994f Merge history of ConnectivityT
Renamed files/directories:
ConnectivityT/service/Android.bp --> service-t/Sources.bp
ConnectivityT/framework-t/Android.bp --> framework-t/Sources.bp
ConnectivityT/framework-t/aidl-export --> framework/aidl-export
ConnectivityT/service --> service-t
ConnectivityT/framework-t --> framework-t
ConnectivityT/tests --> tests
ConnectivityT/OWNERS --> (removed)

BUG: 222234190
TEST: TH
Ignore-AOSP-First: Move with history done per-branch
Merged-In: I81893df9f327abb84f1561b2b33027a2d23a4d65
Merged-In: I67c703e3f7aa9d5787f032a79ed62e45412baf4f
Change-Id: I27a91f1a94f9d807f92762436f533c4b0d0114d5
2022-03-25 11:02:45 +00:00
Chalard Jean
2f23fa51d8 Add tests for VPN validation in NetworkMonitor
Test: New tests in this patch
      also FrameworksNetTests
Test: atest CtsNetTestCases CtsNetTestCasesLatestSdk
Change-Id: I68aa5201ad94531e5a40999816844faef5531525
2022-03-23 11:19:44 +00:00
Michael Groover
eef36c8917 Revert "Use RECEIVER_NOT_EXPORTED in CarrierPrivilegeAuthenticator."
This reverts commit 7569d51446.

Reason for revert: ag/17318348 moved the declaration of the protected-broadcasts from the telephony package to the platform's manifest, so a flag is no longer required when registering for these. In addition, ag/17307852 is syncing the behavior of unexported runtime receivers with that of manifest receivers by limiting the UIDs that can broadcast to these receivers to the root and system UIDs; with the RECEIVER_NOT_EXPORTED flag from this commit, these receivers would no longer be able to receive these broadcasts when sent from the telephony UID.

Bug: 225999840
Change-Id: Ifb15506434edabdfacf84c302881d0cf97d3add8
2022-03-23 02:04:57 +00:00
Nucca Chen
a59eec920c Merge "ClatCoordinator: wrap clatd information" 2022-03-22 08:40:15 +00:00
Hungming Chen
328d15271b ClatCoordinator: wrap clatd information
This is a preparation for accessing BPF program and map from existing
Java class. The new class ClatdTracker stores the clatd information
for forking clatd, accessing BPF maps and attaching BPF programs.
Using an object is easier to pass all required parameters and reuse
known resource.

Also refactor existing function and rename existing variables for this
commit.

Bug: 221213090
Test: atest FrameworksNetTests
Change-Id: I02ea889de89329c52710726fbcf1d2eac61707d7
2022-03-22 15:20:17 +08:00
Benedict Wong
a5604ea50f Allow sending of Administrator UIDs for *NETWORK_STACK
This change allows callers with the NETWORK_STACK or
PERMISSION_NETWORK_STACK to receive administrator UIDs. This will be
used by the VCN to ensure that administrator UIDs are accurately
populated, ensuring that the ConnectivityDiagnostics are triggered for
the VCN.

Bug: 193204385
Test: atest ConnectivityServiceTest
Change-Id: I3ecfbef6847dcc78adac05d0229719c97e3a220c
2022-03-18 21:52:57 +00:00
Martijn Coenen
b643f2a356 Merge "Setup permissions for SDK sandbox UIDs." 2022-03-18 13:35:51 +00:00
Lorenzo Colitti
004cbbcdad Merge "Support ignoring validation failures after roam." 2022-03-18 03:15:49 +00:00
he_won.hwang
881307a834 Support ignoring validation failures after roam.
In some scenarios, Wi-Fi connectivity is disrupted after roam. If an application reacts to network errors by calling reportNetworkConnectivity(false), validation will immediately fail and the device will switch to cell data.

Add a way to ignore these validation failures for up to 10 seconds after Wi-Fi roams.

Bug: 216567577
Test: new unit tests

Change-Id: I58de486533bcc7c6e32b23536ae15bccb779e394
2022-03-18 10:30:28 +09:00
Patrick Rohr
1b13af010a Merge changes from topic "nullable-ipconfig"
* changes:
  Add test for nullable IpConfiguration
  Add Nullable IpConfiguration to ethernet update request
  Replace assertParcelSane with assertParcelingIsLossless
2022-03-17 06:17:02 +00:00
Patrick Rohr
fb82c3f702 Add test for nullable IpConfiguration
Test: atest EthernetNetworkUpdateRequestTest
Change-Id: Ibf565d46cfac0d44976ee6187db7234bb082da41
2022-03-16 20:29:10 +01:00
Chalard Jean
de665266cd Rename setAccessUids to setAllowedUids
Bug: 217725769
Test: ConnectivityServiceTest CtsNetTestCases
Change-Id: Ic8a3f91553d1462b7f54259c467fb90a950bdd59
Merged-In: I8860fbb353eedf5d01e9dc248e4d765046bd562c
2022-03-16 17:58:20 +00:00
Sooraj Sasindran
2ccbfe9d8f Merge "Use int array for included and excluded uids" 2022-03-16 17:56:08 +00:00
Patrick Rohr
ceae88da2d Replace assertParcelSane with assertParcelingIsLossless
Per review comment on aosp/2012897.

Test: atest EthernetNetworkUpdateRequestTest
Change-Id: Ie2f21d821709cc82af9294d70826f153506fda4f
2022-03-16 17:20:36 +01:00
Patrick Rohr
6dde8ac532 Merge changes from topic "ethernet_mainline"
* changes:
  Fix the NPE thrown when starting Ethernet service in OS lower than T.
  Remove the stub ethernet service from Connectivity module.
  Update hidden API files for EthernetManager API move.
  Provide a stub ethernet service to build in sc-mainline-prod.
  Build ethernet framework source into framework-connectivity-tiramisu
2022-03-16 16:03:30 +00:00
Sooraj Sasindran
4904176454 Use int array for included and excluded uids
Use int array for included and excluded uids so that uses
same data type as in PreferentialNetworkServiceConfig

Bug: 217365439
Test: ran connectivity service unit tests
Change-Id: I9ac7e6498df2fd20b8397b2c110296e019c7389e
2022-03-16 07:19:11 +00:00
Lorenzo Colitti
8b7896b51a Merge "Rename setUidForeground to noteUidForeground" 2022-03-15 23:33:26 +00:00
Martijn Coenen
3f01be0407 Setup permissions for SDK sandbox UIDs.
Applications may have an additional SDK sandbox process that should run
with the same network policy as the app itself. There is a 1:1 mapping
between appId and the SDK sandbox process that belongs to it; use that
mapping to set the same policy for SDK sandbox processes as for the app
that they belong to.

Bug: 215012578
Test: atest com.android.server.PermissionMonitorTest
Change-Id: Ibd2ada09c94d46e048f5731b90a721d8e85d3289
2022-03-15 10:06:39 +01:00
Xiao Ma
0a171c006c Build ethernet framework source into framework-connectivity-tiramisu
- move ethernet APIs, build it into framework-connectivity-tiramisu
- start ethernet service from ConnectivityServiceInitializer
- fix EthernetManager dependnecy in Tethering module
- fix EthernetNetworkSpecifier dependency in framework-connectivity
- fix the ethernet related config resource

Bug: 210586283
Test: m
Test: atest FrameworksNetTests EthernetServiceTests
Change-Id: I54857b8517649048a343c72797668394d5225766
Merged-In: I54857b8517649048a343c72797668394d5225766
2022-03-14 14:06:35 +00:00
Xiao Ma
dbc8e0fb2b Split out the ethernet API surface and use framework-connectivity-t
Ethernet framework and service source code is going to be moved to
Connectivity mainline module, this CL contains below corresponding
changes to adapt the migration in f/b side:

1. Split out ethernet module-lib APIs to Connectivity module.
   Add the ethernet resource filegroup to tiramisu-updatable-sources
   filegroup as well, build them together. Also update the module-lib
   and system api txt to reflect the APIs change. Remove the hidden
   APIs which are moved to Connectivity module. This removal fixes the
   api inconsistent issue with Tethering/apex/hidden/.

2. Remove EthernetService from SystemServer which will be registered
   from ConnectivityServiceInitializer.

3. Replace the BackgroundThread class(imported from f/b/core/java)
   with the one in the modules-utils-backgroundthread lib, which is
   visible to Connectivity module.

Bug: 210586283
Test: m
Test: atest FrameworksNetTests EthernetServiceTests
Change-Id: I3e13cb9c0e348333af295c2537d459aa6700ff17
Merged-In: I1956848d3248cc56e9841d221e5e4c160bed65a4
2022-03-14 13:47:01 +00:00
Aaron Huang
5417280f17 Rename setUidForeground to noteUidForeground
Addresses API review feedback. Both setUidForeground in
NetworkStatsManager and NetworkStatsService are renamed to
noteUidForeground. Thus, the caller in test should be also
modified.

Bug: 222291301
Test: atest FrameworksNetTests
Change-Id: Ifa1e1af3d9fd8b1dc75a8f37947a5958f60ed415
2022-03-10 18:33:50 +08:00