Commit Graph

793 Commits

Author SHA1 Message Date
Motomu Utsumi
305975ffb0 Update error handling in BpfNetMaps
Address review comments from aosp/2117045
Throw AssertionError if bpf map init get error
Update tests to avoid getting AssertionError

Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: I2194b825aa73b88d5334077d17acb9abbd367c69
2022-07-11 03:13:04 +00:00
chiachangwang
826f0b01d2 Verify calling thread for intent receiver
Bug: 230548427
Test: atest VpnManagerServiceTest
Change-Id: Ibe5f7aba8e31dfecfb2eaac3fb109eb442879ede
2022-07-07 08:54:52 +00:00
chiachangwang
26de58ea79 Refactor to mock package add and remove event
Use mock intent receiver to handle intent related events instead
of exposing the private methods even for testing only.

The visibility for onPackageAdded, onPackageRemoved and
onUserStarted were exposed for testing only in former commit.
The test coverage for intent receiver part may be missed.
The other intent related methods will be verified in the
follow up commits. This refactor will also help to not to
expose further private methods.

Bug: 230548427
Test: atest VpnManagerServiceTest
Change-Id: If2aa88d8d5c1643e8bd4937673aa792186047fd8
2022-07-07 08:54:27 +00:00
chiachangwang
a412026c6b Test reconnect VpnManager VPN with always on enabled
Verify reconnect using startVpnProfile with the same package with
always-on package should work without exception.

Bug: 235322391
Test: atest FrameworksNetTests
Change-Id: I9a780d970208032e2468e9c5b3334373627c6a20
2022-07-07 06:46:15 +00:00
chiachangwang
9460f45c04 Update the prefix of VPN_APP_EXCLUDED in the test
Update the string according to the change in Vpn.java

Bug: 237345836
Test: atest FrameworksNetTests
Change-Id: I9bfe0a1fad29ba1435eeb8b8b2cffa9d385b1cb5
2022-07-07 06:46:08 +00:00
chiachangwang
72fe97ea1c Add tests to verify getProvisionedVpnProfileState
Add tests to verify that calling getProvisionedVpnProfileState works
normally from the same package but gets a security exception from a
differnet package.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I0132c42dce1b8269859fca8d0143304142162838
2022-07-07 06:45:55 +00:00
Treehugger Robot
78cf7c5e29 Merge "ClatCoordinator: Dump ClatdTracker information" 2022-07-05 15:01:11 +00:00
Hungming Chen
a760a10474 ClatCoordinator: Dump ClatdTracker information
Test: atest ClatCoordinatorTest
Change-Id: I6bb47c84321e1323496b728f2db939ee8d74504a
2022-07-05 15:30:50 +08:00
Motomu Utsumi
1f73fedfef Remove unnecessary null check
Address review comments from aosp/2131752 and aosp/2117045
sConfigurationMap must have a entry for UID_RULES_CONFIGURATION_KEY
because this bpf map is an array

Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: Ic52623e11c1f53e363416d57c0d8705d5510ef04
2022-07-04 09:20:23 +00:00
lucaslin
31dcf69b74 Test if VPN app can grant ACTIVATE_PLATFORM_VPN with CONTROL_VPN
Bug: 232051081
Test: atest FrameworksNetTests:VpnTest
Change-Id: I0580baca69df6a00d59f4a387ec9b357f6c988ab
2022-07-01 10:44:02 +08:00
Motomu Utsumi
51a03d629e Merge "Refactor BpfNetMaps and getChainEnabled" 2022-06-30 06:48:10 +00:00
Chiachang Wang
bb2e871cce Merge "Decouple security exception check test from ConnectivityServiceTest" 2022-06-30 01:36:46 +00:00
Chiachang Wang
5b4ad7c47a Merge changes from topic "appExclusionPackage"
* changes:
  Test VPN app exclusion
  Add VpnTestBase for VPN test common code
2022-06-30 01:34:54 +00:00
chiachangwang
1aef309197 Decouple security exception check test from ConnectivityServiceTest
Decouple security exception check test from ConnectivityServiceTest
to VpnManagerServiceTest.

These security exception tests landed in ConnectivityServiceTest
because of no VpnManagerServiceTest. Move the tests to the
VpnManagerServiceTest where is better place to put the VPN related
tests to reduce the size of ConnectivityServiceTest.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I94b691c4d1f63bd5226e3296e6d0160dcb03107c
2022-06-29 06:15:41 +00:00
chiachangwang
7f5d04962b Test VPN app exclusion
Initialize the VpnManagerServiceTest and verify app exclusion
design.

Bug: 231373589
Test: atest FrameworksNetTests
Change-Id: Icf3994a58de7b2fcc6fafe9712b5ac94e6c2c134
2022-06-29 06:15:41 +00:00
chiachangwang
9f672bdae6 Add VpnTestBase for VPN test common code
This is a no-op change to move some common codes that share
between different VPN unit tests to the new base class.
It's helpful to reduce the code duplication for the follow up
work to add the VpnManagerServiceTest and other test codes
refactor.

Bug: 231373589
Test: atest FrameworksNetTests
Change-Id: Id5111e7ca33ea8f9eb4bcc6c13d0e681f0664d24
2022-06-29 03:06:09 +00:00
chiachangwang
337726529b Use import for testAndCleanup
Follow up work to remove the TODO since it's available in all
branches.

Test: ates VpnTest
Change-Id: I0830148e8577f98616f24d9ee4224496f51bd692
2022-06-28 10:57:25 +00:00
Paul Hu
57852487b8 Merge "Add mdns files and unit tests" 2022-06-28 05:43:58 +00:00
Paul Hu
3e1f4489bf Add mdns files and unit tests
- Put mdns code to service/mdns because we don't want to impact
  coverage for code that's not yet in use.
- Also fix some lint errors
  - Common typo errors
  - Lines longer than 100 characters
- Update IgnoreUpTo from S to SC_V2 because the tests should be
  ignored until T.

Bug: 232766079
Test: atest FrameworksNetTests
Change-Id: I19af3bf7ae004bd37960f2ad9014cf0c6a804c8d
2022-06-28 09:54:39 +08:00
Motomu Utsumi
25cf86fc95 Refactor BpfNetMaps and getChainEnabled
Address comments from aosp/2117045 and aosp/2131752
Rename USE_NETD to PRE_T
Rename getChainEnabled to isChainEnabled
Remove unnecessary parentheses
Fix comment

Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: Iaff8c9fc5f74de3fe41a7fb010355b1742fbce90
2022-06-27 14:33:28 +00:00
Motomu Utsumi
bccf9df50e Merge "Use java BpfMap in BpfNetMaps#setChildChain" 2022-06-27 05:44:38 +00:00
Motomu Utsumi
6421d8456c Merge "Add API to get current firewall chain status" 2022-06-27 05:43:46 +00:00
Motomu Utsumi
18b287d285 Use java BpfMap in BpfNetMaps#setChildChain
Bug: 217624062
Test: atest BpfNetMapsTest android.net.cts.ConnectivityManagerTest#testFirewallBlocking

Change-Id: I13e96911eccd7d1d0545a156ddc2859bcaac09eb
2022-06-24 09:11:58 +00:00
Motomu Utsumi
be3ff1e923 Add API to get current firewall chain status
This commit adds ConnectivityManager#getFirewallChainEnabled to read the
current firewall chain status

Bug: 208371987
Test: m
Change-Id: I1eadb69f953af5d031cd8dabde3e1f098cf0f4df
2022-06-24 09:11:53 +00:00
Remi NGUYEN VAN
522cea7d4e Add test for startPptp
The test verifies arguments used to start the daemon

Bug: 201660636
Test: atest VpnTest
Change-Id: I0854fbeaf1a3e3554c157fde227a7bfa187b1013
Merged-In: I0854fbeaf1a3e3554c157fde227a7bfa187b1013
2022-06-24 03:33:30 +00:00
Treehugger Robot
85694dc277 Merge "Validate or set the eth specifier on update Iface" 2022-06-23 16:16:05 +00:00
James Mattis
59d98c07a7 Validate or set the eth specifier on update Iface
When a calling the updateInterface API, if no eth specifier was set it
would be removed not allowing follow-up network requests to request by
ethernet specifier.

This CL makes sure that the eth specifier is always set as expected when
updateInterface is called by either validating the input or setting the
specifier if the passed one is null.

Bug: 236294399
Bug: 229207021
Test: atest FrameworksNetTests
:com.android.server.ethernet.EthernetNetworkFactoryTest

Change-Id: Ic05ca7fe4adaa94f79e59758569f7595ab4c4f54
2022-06-23 07:51:20 -07:00
Aaron Huang
80767e64ef Add wipeOnError flag to NetworkStatsRecorder
If reading data happens exception while doing data migration,
the file will be deleted by legacy recorders. This would cause
legacy persistent data being lost and cannot be retrieved by
any method. To avoid the files being deleted, add a wipeOnError
flag to recorder which indicates this recorder will wipe on
error or not . If the flag is set to true then deletes all files
when it throws, otherwise keeps all files.

(cherry-picked from ag/18910973)
Bug: 233828210
Test: FrameworksNetTests:NetworkStatsRecorderTest

Change-Id: Id7a3d8bebf8a00d814f9e84bf4c10d927e6ff749
Merged-In: Id7a3d8bebf8a00d814f9e84bf4c10d927e6ff749
2022-06-22 17:37:51 +08:00
Junyu Lai
11e9887fa8 Disable comparison in user release builds
This CL disable the comparison mechanism introduced
in previous beta releases to stop receiving log.wtf signals
from beta users.

This CL only affects logging on user release builds.

Test: 1. NetworkStatsServiceTest
      2. manual test with script
Bug: 233752318
Change-Id: I7047106b1019c29460d6633b148f501ffa62f139
Merged-In: I7047106b1019c29460d6633b148f501ffa62f139
  (cherry-picked from ag/18869740)
2022-06-22 11:00:17 +08:00
Junyu Lai
e72c849a61 Disable fallback when comparison result is different
Follow-up from ag/18452103, where we add fallback code that runs
with the importer to make sure they are identical.
When the result is different, we'll take the result from fallback
code to minimize the rollout risk. However, since the OEMs might
change the importer implementation. The fallback code would no
longer valid and that makes OEM modified code not working. Hence
the fallback code must be disabled before release.

This change keeps comparison enabled for all cases to keep getting
signals from beta users. And will switch it to read overlay value
for OEM to debug their solution.

Test: 1. NetworkStatsServiceTest
      2. Test all datasets with script
Bug: 233752318
Change-Id: I869ff05297149bde6e13a204bd8c5a4fece75de0
Merged-In: I869ff05297149bde6e13a204bd8c5a4fece75de0
  (cherry-picked from ag/18849946)
2022-06-22 10:59:10 +08:00
Junyu Lai
dbe8ddca71 Address comment at ag/18491259 and ag/18486388
Test: TH
Bug: 230289468
Change-Id: Id91fabb47b542d8526d6aa787b5947238c3934fb
Merged-In: Id91fabb47b542d8526d6aa787b5947238c3934fb
  (cherry-picked from ag/18579048)
2022-06-22 10:57:38 +08:00
Junyu Lai
079717052c Persisting status int on the device if fallback happened
This CL also stop from incresing "successes" counter if the
importer finishes with fallback.

Test: manual
Bug: 230289468
Change-Id: I88fce1b2d0dea3772a8b31df8f8fa93bf13bffad
Merged-In: I88fce1b2d0dea3772a8b31df8f8fa93bf13bffad
  (cherry-picked from ag/18486388)
2022-06-22 10:35:25 +08:00
Yan Yan
37a1ba2202 Verify VPN can handle network loss
This commit also
- verifies that during network switch with MOBIKE
  enabled, the cleanup task is scheduled upon network loss and
  cancelled when new network is available.
- improves the retry tests to avoid waiting for actual timeout

Bug: 192077544
Test: atest VpnTest (new tests)
Change-Id: I5b47ba98116ac4523a36bc495e8788f29a9ecf20
2022-06-17 21:27:03 +00:00
Yan Yan
554eb0699c Merge "Add unit tests for IKEv2 VPN setup and MOBIKE" 2022-06-17 17:53:59 +00:00
Yan Yan
4b0e4b1f17 Add unit tests for IKEv2 VPN setup and MOBIKE
Add unit tests for IKEv2 VPN setup and handling network change.

Bug: 192077544
Test: atest VpnTest (new tests)
Change-Id: Idd13a3ae57a521901c576bdd33ca0170e94be048
2022-06-17 00:14:32 +00:00
James Mattis
265eba982d Send callback if ip provisioning is interrupted
A callback is expected to be sent on either success or failure when the
EthernetManager#updateConfiguration API is called.

Currently, if this API is called for an active interface and marked
restricted, after the IP provisioning process is started in
EthernetNetworkFactory, the interface will then processe all the
onNetworkUneeded requests for the newly restricted network. Assuming no
apps have requests for this particular network or restricted networks,
the network will be stopped once the outstanding network request count
reaches zero.

If provisioning hasn't completed yet for the original
updateConfiguration call, the original callback will be cleared out on
stop and will never notify the original caller of
EthernetManager#updateConfiguration whose call was aborted.

Bug: 235907515
Test: eth unit and cts tests
Change-Id: I91359272c07e090039049370ba9f438546fce3ad
2022-06-16 08:10:20 -07:00
Motomu Utsumi
5d787feef0 Merge changes Ic6ff7a3d,Iff9b9792
* changes:
  Refactor code and improve tests for VPN filtering
  Remove LOCKDOWN from FirewallChain IntDef
2022-06-16 01:32:20 +00:00
Yan Yan
fcc7e905b2 Revert "Add unit tests for IKEv2 VPN setup and MOBIKE"
Revert "Make VPN more testable and update NC during network change"

Revert submission 2113906-mobike-ut

Reason for revert: b/235853154 Test files build failed on tm-mainline-prod
Reverted Changes:
I739016db1:Add unit tests for IKEv2 VPN setup and MOBIKE
Ic0f0c5496:Make VPN more testable and update NC during networ...

Change-Id: I9e8695078633822d3051aed27dcd617e0b8da6e5
2022-06-13 19:51:52 +00:00
Yan Yan
cbd6205ae9 Add unit tests for IKEv2 VPN setup and MOBIKE
Add unit tests for IKEv2 VPN setup and handling network change.

Bug: 192077544
Test: atest VpnTest (new tests)
Change-Id: I739016db1b139b722b54c828fcc3babc5b1f14c4
2022-06-10 18:48:49 +00:00
Motomu Utsumi
f8bd82cd67 Refactor code and improve tests for VPN filtering
Bug: 206482423
Test: atest ConnectivityServiceTest PermissionMonitorTest

Change-Id: Ic6ff7a3d7695ad6ce96764a9bab2c0a641ba2ba6
2022-06-10 03:18:32 +00:00
Motomu Utsumi
8b42e6d431 Remove LOCKDOWN from FirewallChain IntDef
LOCKDOWN_VPN was in the FirewallChain IntDef but this was not a right
place because LOCKDOWN_VPN was not a valid value for Connectivity APIs
that take an argument annotated with @FirewallChain(setUidFirewallRule,
setFirewallChainEnabled, replaceFirewallChain).

LOCKDOWN_VPN was in the FirewallChain IntDef because
BpfNetMaps#setUidRule was used to add/remove LOCKDOWN_VPN entries.
This commit adds BpfNetMaps#updateUidLockdownRule and uses this to
add/remove LOCKDOWN_VPN entries instead of BpfNetMaps#setUidRule and
removes LOCKDOWN from FirewallChain.

Bug: 206482423
Test: atest TrafficControllerTest ConnectivityServiceTest
PermissionMonitorTest HostsideVpnTests#testBlockIncomingPacket

Change-Id: Iff9b9792fc0f208f153e10e396c6d5034b412d7c
2022-06-10 02:49:25 +00:00
Lucas Lin
281390e58c Merge "Test recoverable Ikev2 errors" 2022-06-09 17:37:45 +00:00
Aaron Huang
bd96778236 Merge "Remove debug log from NetworkStatsService" 2022-06-09 02:37:42 +00:00
Treehugger Robot
a58028e31a Merge "ClatCoordinator: improve file descriptor clean up in error handling" 2022-06-08 07:19:31 +00:00
Aaron Huang
de99c7a9f4 Remove debug log from NetworkStatsService
This change reverts aosp/1777887. The exception was used to get
the stack while the mMobileIfaces contains null interface, and
currently mMobileIfaces is protected by making it volatile so
it is fine to be removed.

Also, fix style error in NetworkStatsServiceTest

Test: build, FrameworksNetTests
Change-Id: I8435354f8cfd05589c0231f3bb8cbaa66c0525cf
2022-06-08 12:20:55 +08:00
Junyu Lai
093cd94972 Merge changes from topic "oom-fix"
* changes:
  Fix get summary does not include the latest bucket
  Add unit test for MultipathPolicyTracker
2022-06-07 09:26:09 +00:00
lucaslin
adb56e94a5 Test recoverable Ikev2 errors
Test if retry mechanism is working or not when there is a
recoverable Ikev2 error.

Bug: 229350078
Test: atest FrameworksNetTests:VpnTest
Change-Id: I5e881c6b42aeb98adce598587e2a7e49be7d9643
2022-06-07 16:28:47 +08:00
Aaron Huang
5804b5c5df Merge "Hold wifi and mobile interfaces since boot in NetworkStatsService" 2022-06-07 07:36:26 +00:00
Junyu Lai
04b2cb2f2d Fix get summary does not include the latest bucket
In internalGetSummaryForNetwork, the history object will not
include the latest bucket because of the logic in
NetworkStatsHistory#recordHistory would only include buckets
that atomically occur in the inclusive time range.

This makes querySummaryForDevice callers who are also sensitive
to the latest bucket fails.

This CL revert the behavior back to S, in T this is temporarily
changed after aosp/1937268.

Also, for test purpose, this CL change System.currentTimeMillis to
use mClock when querying.

Test: NetworkStatsServiceTest#testGetLatestSummary
Bug: 233733267
Change-Id: I55e2a5d953622b68da36a9b8d3e57c88d57543b0
Merged-In: I55e2a5d953622b68da36a9b8d3e57c88d57543b0
  (pure cherry-picked from ag/18670248)
2022-06-07 11:07:46 +08:00
Junyu Lai
207b125a20 Add unit test for MultipathPolicyTracker
This CL adds unit test to test onThresholdReached event
would unregister and re-register usage callback.

Test: MultipathPolicyTrackerTest#testOnThresholdReached
Bug: 233733267
Change-Id: I6e43ae93055009d91b0795a4466f2c02f4403c0a
Merged-In: I6e43ae93055009d91b0795a4466f2c02f4403c0a
  (pure cherry-picked from ag/18579049)
2022-06-07 11:06:46 +08:00