Commit graph android_packages_modules_Co.../tests/unit/java
Message SHA1
Use java BpfMap in BpfNetMaps#setChildChain
Bug: 217624062
Test: atest BpfNetMapsTest android.net.cts.ConnectivityManagerTest#testFirewallBlocking

Change-Id: I13e96911eccd7d1d0545a156ddc2859bcaac09eb

Motomu Utsumi   commited 2022-06-24 09:11:58 +00:00
18b287d285
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

Motomu Utsumi   commited 2022-06-24 09:11:53 +00:00
be3ff1e923
Merge "Add unit tests for IKEv2 VPN setup and MOBIKE"
Yan Yan   authored and   Gerrit Code Review   commited 2022-06-17 17:53:59 +00:00
554eb0699c
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

Yan Yan   commited 2022-06-17 00:14:32 +00:00
4b0e4b1f17
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

James Mattis   commited 2022-06-16 08:10:20 -07:00
265eba982d
Merge changes Ic6ff7a3d,Iff9b9792
* changes:
  Refactor code and improve tests for VPN filtering
  Remove LOCKDOWN from FirewallChain IntDef

Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-06-16 01:32:20 +00:00
5d787feef0
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

Yan Yan   commited 2022-06-13 19:51:52 +00:00
fcc7e905b2
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

Yan Yan   commited 2022-06-10 18:48:49 +00:00
cbd6205ae9
Refactor code and improve tests for VPN filtering
Bug: 206482423
Test: atest ConnectivityServiceTest PermissionMonitorTest

Change-Id: Ic6ff7a3d7695ad6ce96764a9bab2c0a641ba2ba6

Motomu Utsumi   commited 2022-06-10 03:18:32 +00:00
f8bd82cd67
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

Motomu Utsumi   commited 2022-06-10 02:49:25 +00:00
8b42e6d431
Merge "Test recoverable Ikev2 errors"
Lucas Lin   authored and   Gerrit Code Review   commited 2022-06-09 17:37:45 +00:00
281390e58c
Merge "Remove debug log from NetworkStatsService"
Aaron Huang   authored and   Gerrit Code Review   commited 2022-06-09 02:37:42 +00:00
bd96778236
Merge "ClatCoordinator: improve file descriptor clean up in error handling"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-06-08 07:19:31 +00:00
a58028e31a
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

Aaron Huang   commited 2022-06-08 12:20:55 +08:00
de99c7a9f4
Merge changes from topic "oom-fix"
* changes:
  Fix get summary does not include the latest bucket
  Add unit test for MultipathPolicyTracker

Junyu Lai   authored and   Gerrit Code Review   commited 2022-06-07 09:26:09 +00:00
093cd94972
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

lucaslin   commited 2022-06-07 16:28:47 +08:00
adb56e94a5
Merge "Hold wifi and mobile interfaces since boot in NetworkStatsService"
Aaron Huang   authored and   Gerrit Code Review   commited 2022-06-07 07:36:26 +00:00
5804b5c5df
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)

Junyu Lai   commited 2022-06-07 11:07:46 +08:00
04b2cb2f2d
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)

Junyu Lai   commited 2022-06-07 11:06:46 +08:00
207b125a20
Add 3rd deny firewall chain for OEM
Bug: 208371987
Test: atest
CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testFirewallBlocking
ConnectivityServiceTest

Change-Id: Ib521fa02f6a19270cb88a3d85321bda822516c78

Motomu Utsumi   commited 2022-06-06 07:47:35 +00:00
1d9054ba5f
Hold wifi and mobile interfaces since boot in NetworkStatsService
In current design, the interface will be removed from the list if
the network disconnected which will cause getUidStatsForTransport()
returns unexpected snapshot to caller since the list is empty.

This change also remove interface name from all entries before
the method returns the result.

Bug: 231514741
Test: FrameworksNetTests
      manual test
Change-Id: Ie60829a65d0d9b5b63ad353695a820c0586e3665
Merged-In: Ie60829a65d0d9b5b63ad353695a820c0586e3665

Aaron Huang   commited 2022-06-06 13:19:11 +08:00
f4f5de3993
Merge "ClatCoordinatorTest: add test for startClat error handling"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-06-03 15:17:10 +00:00
6d0b34ecb3
Merge "ClatCoordinatorTest: add testDump"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-06-03 15:17:06 +00:00
1076248194
Merge changes from topic "remove-ethernet-shims"
* changes:
  ethernet: add test for tethered interface callbacks
  ethernet: stop using EthernetManager shims
  ethernet: broadcast state change for server interfaces
  ethernet: increase timeout to deflake tests

Lorenzo Colitti   authored and   Gerrit Code Review   commited 2022-06-03 11:51:58 +00:00
337d512081
Merge "Add deny firewall chain for OEM"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-06-03 11:06:02 +00:00
181f7c85fc
Add deny firewall chain for OEM
Bug: 207773349
Bug: 208371987
Test: atest
CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testFirewallBlocking
--iterations 50 && atest ConnectivityServiceTest --iterations 10

Change-Id: I60d5540821abcced03356f366775f16ee369d7f9

Motomu Utsumi   commited 2022-06-03 09:10:57 +00:00
d980149817
ethernet: broadcast state change for server interfaces
Also update the test to ensure mFactory.hasInterface is mocked to match
mFactory.getInterfaceState: previously it would be called by the factory
in the mocked getInterfaceState, but the new code calls it directly.

Bug: 171872016
Test: atest EthernetManagerTest
Change-Id: I9ac959f181c88a7992991923b98a836f2833fa88

Patrick Rohr   authored and   Remi NGUYEN VAN   commited 2022-06-03 16:56:39 +09:00
f33f276b29
Verify if the VPN app has been added into power save whilte list
Bug: 234104087
Test: atest FrameworksNetTests:VpnTest
Change-Id: I2aa99b8ea8dbe668a45782f50a4a0ac82e72b7a2

lucaslin   authored and   Lucas Lin   commited 2022-06-02 20:19:09 +00:00
802fa5d0ec
ClatCoordinator: improve file descriptor clean up in error handling
- Make the file descriptor clean up better when an error happens.
- Remove unused TODO for iptables because it has been
  implemented by another approach. See b/218407445.

Test: atest com.android.server.connectivity.ClatCoordinatorTest
Change-Id: Ib8bfa8875ae774769ab7e416fa7e5fde140f58da

Hungming Chen   commited 2022-06-02 18:37:15 +08:00
b7bbdbebc6
ClatCoordinatorTest: add test for startClat error handling
Used to increase mainline test code coverage for startClat()
which has bunches of code for unwinding the native method failure.

For now, code coverage for startClat(): 51.89% (55/106 lines)

Test: atest com.android.server.connectivity.ClatCoordinatorTest
Change-Id: I398d5863359ff329b06966488053edd9006f17aa

Hungming Chen   commited 2022-06-02 15:20:14 +08:00
171377450f
ClatCoordinatorTest: add testDump
Used for verifying the dump content and increasing test coverage.

The test coverage for now:
dump:           0% (0/7 lines)
dumpBpfEgress:  0% (0/13 lines)
dumpBpfIngress: 0% (0/13 lines)

Test: atest com.android.server.connectivity.ClatCoordinatorTest
Change-Id: I5e444e95d50f7ca266555139b3639723773fd83d

Hungming Chen   commited 2022-06-02 15:20:09 +08:00
af5c235cfc
Merge "Add IpConfigStore testcase to improve the code coverage."
Xiao Ma   authored and   Gerrit Code Review   commited 2022-06-01 07:47:07 +00:00
c0e80ee9f9
Add IpConfigStore testcase to improve the code coverage.
Add new testcase in IpConfigStoreTest to cover the readIpConfiguration
usage, improve the code coverage for connectivity module.

To reduce the flakyness of test, this cl refactors DelayedDiskWriter
constructors by allowing to pass in a Dependencies instance, then
waitForIdle can be used to check if the delayed write operation
associated with the passed-in HandlerThread has completed in tests.

Bug: 234315786
Test: atest com.android.server.net.IpConfigStoreTest
Change-Id: I57c8bd02a771f1cca815252ba502cda0210d1385

Xiao Ma   commited 2022-06-01 14:47:47 +09:00
b4a8fd534a
Merge "Add test coverage for ConnectivityService.dump with arguments"
Chiachang Wang   authored and   Gerrit Code Review   commited 2022-06-01 05:41:50 +00:00
c0b2b37faa
Merge "Fix service resolve on tethering downstreams"
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2022-06-01 05:31:14 +00:00
5eaefa21bf
Add test coverage for ConnectivityService.dump with arguments
Test: atest FrameworksNetTests
Change-Id: I389ef6e89a7570cb3e7f8cedab48517c25c4c0b0

chiachangwang   commited 2022-06-01 03:58:25 +00:00
9673c4ddad
Merge changes from topic "stats-migration"
* changes:
  Skip PersistentIntTest on S- device
  Don't clobber existing history entries.
  Ensure NetworkStats migrated snapshot is identical
  [MS82.1] Support network stats data migration process
  Add a PersistentInt class.

Natasha Lee   authored and   Gerrit Code Review   commited 2022-06-01 03:03:02 +00:00
bcdb3c12ee
Fix service resolve on tethering downstreams
Tethering downstreams do not have NetworkAgents, and although they have
a netid of 99, Networks with netId 99 are not usable by apps for most
connectivity APIs.

Recent refactoring in NsdService adds the Network of a found service
into its NsdServiceInfo, and uses that network to resolve the service.
In that case the Network has netId 99 and resolving the service fails.

Avoid that problem by:
 - Keeping the Network field null when a service is found on a tethering
   downstream; this avoids giving apps a confusing and unusable Network
   with netId 99
 - Using the interface index found during discovery to resolve the
   service, if the app uses the NsdServiceInfo that was obtained from
   discovery to resolve. If not, all interfaces will be used to resolve,
   as per legacy APIs.

Bug: 233979892
Test: atest NsdServiceTest
      Also manual test with 2 devices connected via hotspot
Change-Id: Idd176153b67ccbd1d4f1b1fd66dafaa2f3a9e27a

Remi NGUYEN VAN   commited 2022-05-31 13:06:22 +09:00
1a8ee102d3
Merge "Fix crash when decrementing data usage request"
Treehugger Robot   authored and   Gerrit Code Review   commited 2022-05-27 10:02:33 +00:00
019e6eb2d7
Fix crash when decrementing data usage request
When unregistering, if the caller process is dead. The system
can unregsiter for the caller. But the request decrement should
be counted onto the caller uid instead of system uid.

Test: NetworkStatsObserversTest#testUnregister_knownRequest_invalidUid_doesNotUnregister
Bug: 233580307
Change-Id: I85aee8f395739929bc7086883ace81ac1ecd0730
Merged-In: I85aee8f395739929bc7086883ace81ac1ecd0730
  (pure cherry-picked from ag/18579047)

Junyu Lai   commited 2022-05-27 09:50:52 +00:00
a1970dafa1
Add some non-connectivity-module-test back to ConnectivityCoverageTests
In S, the tests are listed in the non-connectivity-module-test
where their testing files are not in the connectivity module.
But some files move into the connectivity module in T. So some
tests can be removed from non-connectivity-module-test and will
be running on ConnectivityCoverageTests to count their code
coverage.

Also update some tests to make them compatible with
mockito-extended and ignore some tests which need to test with
T apis.

Bug: 234000451
Test: atest FrameworksNetTests ConnectivityCoverageTests
Change-Id: I47fb59334d00ae7fee91c5694548b3cf89b09b2d

Paul Hu   commited 2022-05-27 07:16:46 +00:00
516d5dc0ea
Merge "Remove automotive restriction from enable/disableInterface"
Patrick Rohr   authored and   Gerrit Code Review   commited 2022-05-25 02:00:51 +00:00
345655f7bc
Merge "Skip VPN filtering tests on unsupported versions"
Motomu Utsumi   authored and   Gerrit Code Review   commited 2022-05-25 01:22:16 +00:00
badf2ebed7
Skip VPN filtering tests on unsupported versions
Lockdown filtering rule and interface filtering rule with null interface
were introduced to T+ devices.
So, skip related tests in pre-T devices.

Bug: 232902954
Test: atest ConnectivityServiceTest
Change-Id: I9ee76096c1bd04c9333bc561ffc8064a14780ce5

Motomu Utsumi   commited 2022-05-24 13:41:36 +00:00
ca314e7f77
Remove automotive restriction from enable/disableInterface
Allow calling enable/disableInterface on non-automotive devices. Also,
fixing the naming of these functions to be consistent with the API.

Test: atest EthernetManagerTest
Bug: 171872016
Bug: 225317990
Change-Id: Ic20185a855d0e639582132bf1103e0183f6f78c3

Patrick Rohr   commited 2022-05-24 03:54:38 +00:00
fd829a5cb2
Skip PersistentIntTest on S- device
This class is only used in the service runs on T+ devices.
Thus run this test on S- device does not make senses.

Bug: 230289468
Test: atest ConnectivityCoverageTests:PersistentIntTest
      on S device
Change-Id: I97a29df17ef9ee9ab373655f045cdb5c820e06ef
Merged-In: I97a29df17ef9ee9ab373655f045cdb5c820e06ef
  (pure cherry-picked from ag/18486287)

Junyu Lai   commited 2022-05-24 11:38:20 +08:00
1190ea3eb7
Don't clobber existing history entries.
Currently, adding a history to a NetworkStatsCollection.Builder
will overwrite any history that was previously passed in with the
same key. This breaks the importer (which is the primary/only
caller of this code), because the importer re-uses the same
NetworkStatsCollection object to import multiple files.

Instead, simply add any passed-in entries after the ones that
were already there. Require the caller to pass in entries in
order, because NetworkStatsHistory internally assumes that
entris are always sorted.

Bug: 230289468
Test: manually verified this unbreaks the importer
Change-Id: Ic8647ff28fca78d579d5f759f96a864877f8158b
Merged-In: Ic8647ff28fca78d579d5f759f96a864877f8158b
  (pure cherry-picked from ag/18453213)

Lorenzo Colitti   authored and   Junyu Lai   commited 2022-05-24 11:37:42 +08:00
ec2fbb7159
Ensure NetworkStats migrated snapshot is identical
Read migration snapshot both from the platform API and the legacy
method, and Log.wtf if they are different. Use the legacy method data if
they are.

This ensures that using the migration API is a no-op, and that errors
are reported (through Log.wtf) if it would not have been if used as-is.

Test: NetworkStatsServiceTest
Bug: 230289468
Change-Id: I857ad18183d63d1aa16e89f89eb24009648720a2
Merged-In: I857ad18183d63d1aa16e89f89eb24009648720a2
  (pure cherry-picked from ag/18452103)

Remi NGUYEN VAN   authored and   Junyu Lai   commited 2022-05-24 11:37:12 +08:00
c62261f140
[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
Bug: 230289468
Change-Id: Ic2002cbfd5a6b3c2226fa8dab22481f8ce656574
Merged-In: Ic2002cbfd5a6b3c2226fa8dab22481f8ce656574
  (pure cherry-picked from ag/18367994)

Junyu Lai   commited 2022-05-24 11:36:36 +08:00
a388d4bf06
Add a PersistentInt class.
This implements a simple integer written to disk backed by
AtomicFile.

Bug: 230289468
Test: new unit test
Change-Id: I1c73c8ac2429f92153cfba3b006b4374e75e65df
Merged-In: I1c73c8ac2429f92153cfba3b006b4374e75e65df
  (pure cherry-picked from ag/18437645)

Lorenzo Colitti   authored and   Junyu Lai   commited 2022-05-24 11:35:58 +08:00
2ce66fc8e6