Commit graph android_packages_modules_Co.../tests/net/java/com/android
Message SHA1
Merge changes Id598ae1d,I475bd011
* changes:
  Fix a possible crash when the listener is null
  Straighten AIDL interface for the memory store

Chalard Jean   authored and   Gerrit Code Review   commited 2019-04-22 02:15:04 +00:00
8fe63a3498
Straighten AIDL interface for the memory store
Some names were still wrong somehow, and the wrappers were
missing.

Test: NetworkStack & FrameworkNetTests
Change-Id: I475bd011ad9bc714a07021a9dfd85c4876f8e9ad
Merged-In: I475bd011ad9bc714a07021a9dfd85c4876f8e9ad

Chalard Jean   commited 2019-04-22 00:40:28 +00:00
08c2d9e81f
Make LegacyTypeTracker testable
...and add basic trivial tests for it.

Test: this, and ConnectivityServiceTest
Bug: 62650382
Change-Id: Ie7ca938e6f66f1b15feb6ed93afa0aebb20884ae

Chalard Jean   commited 2019-04-19 15:33:44 +09:00
3a3f5f2a08
Merge "Backwards-incompatible resolv module API change for making setResolverConfiguration take a parcelable."
Wayne Ma   authored and   Gerrit Code Review   commited 2019-04-17 13:58:11 +00:00
c9308bb32d
Backwards-incompatible resolv module API change for making setResolverConfiguration take a parcelable.
Test: built, flashed, booted
      atest FrameworksNetTests

Change-Id: I3b4e8672f5273c3baa9378025bfaef2e6514df64

waynema   authored and   Wayne Ma   commited 2019-04-17 13:55:53 +00:00
7b76545b94
Merge "Release keepalive slot after stopped"
Junyu Lai   authored and   Gerrit Code Review   commited 2019-04-16 04:46:18 +00:00
79c7b5a300
Release keepalive slot after stopped
Currntly, keepalive slot is released when stop() is called. Next
starting keepalive can use the same slot number while previous
keepalive is still stopping. When the previous keepalive is
stopped, the incoming as will be processed by the new keepalive.

This change release keepalive slot after the result of stopping
has returned. Thus, newly created keepalive cannot allocate the
same slot number while lower layer is still processing stop event.

This change also disable flaky assertions that are caused by
test port has been occupied by other process.

Bug: 129512753
Test: 1. atest com.android.server.ConnectivityServiceTest \
         #testNattSocketKeepalives --generate-new-metrics 100
      2. atest FrameworksNetTests --generate-new-metrics 10
      3. simulate the fail case manually.

Change-Id: I1991627545519ee5cb408a3df3a006f710f4af7b

junyulai   commited 2019-04-15 17:44:48 +08:00
e1bed4ddfa
Revert new tests and PackageManager mock
A mocked PackageManager caused test failures in existing tests.
Revert that for now to make tests pass again.

Bug: 114231106
Bug: 130397860
Test: atest FrameworksNetTests
Change-Id: I4f181789152438f18e6cd2d235d76fabe3872ea3

Lorenzo Colitti   commited 2019-04-12 19:52:45 +09:00
44c6efb9c1
Revert "Revert "Block incoming non-VPN packets to apps under fully-routed VPN""
This reverts commit bc571c7cc8.

Reason for revert: Rolling forward, will fix tests in same CL stack.

Bug: 114231106
Bug: 130397860
Test: FrameworksNetTests
Change-Id: Ia8a0c99b4e1fd5dff26c881715cd876618ca4321

Lorenzo Colitti   commited 2019-04-12 19:52:32 +09:00
bad9d911b8
Revert "Block incoming non-VPN packets to apps under fully-routed VPN"
This reverts commit 4773027064.
This change does not have any topic: not reverting the other 2 commits in the original topic.

Reason for revert: broke FrameworksNetTests presubmit: b/130397860

Change-Id: Iff41d9fe97fafea44680c8d67d1ce19277548cc0

Remi NGUYEN VAN   commited 2019-04-12 09:05:40 +00:00
bc571c7cc8
Block incoming non-VPN packets to apps under fully-routed VPN
When a fully-routed VPN is running, we want to prevent normal apps
under the VPN from receiving packets originating from any local non-VPN
interfaces. This is achieved by using eBPF to create a per-UID input
interface whitelist and populate the whitelist such that all
non-bypassable apps under a VPN can only receive packets from the VPN's
TUN interface (and loopback implicitly)

This is the framework part of the change that build the whitelist.
The whitelist needs to be updated in the following cases:
* When a VPN is connected and disconnected
    This will cover the change to allowBypass bit, since that can't be
    changed without reconnecting.
* When a VPN's NetworkCapabilites is changed (whitelist/blacklist app changes)
* When a new app is installed
* When an existing app is removed
* When a VPN becomes fully-routed or is no longer fully-routed

New user/profile creation will automatically result in a whitelist app change
transition so it doesn't need to be handled specially here.

Due to the limitation of the kernel IPSec interacting with eBPF (sk_buf->ifindex
does not point to the virtual tunnel interface for kernel IPSec), the whitelist
will only apply to app VPNs but not legacy VPN connections, to prevent breaking
connectivity with kernel IPSec entirely.

Test: atest PermissionMonitorTest
Test: atest android.net.RouteInfoTest
Test: atest com.android.server.ConnectivityServiceTest
Test: atest HostsideVpnTests
Bug: 114231106
Change-Id: I143b03d60e46cb1b04732b4a4034f5847b4d1b1a

Rubin Xu   commited 2019-04-10 17:05:54 +01:00
4773027064
Merge "Fix remove-before-add for IpSecService RefcountedResource"
Benedict Wong   authored and   Gerrit Code Review   commited 2019-04-09 17:22:56 +00:00
342d6de289
Fix remove-before-add for IpSecService RefcountedResource
This patch fixes a bug where if a binder dies before the linkToDeath
call, the cleanup will be performed before the entry is added to the
array. While it is safe in that quotas and tracking performs as per
normal, the RefcountedRecord may not be cleaned up.

Rethrowing this exception is safe, since the only paths that would hit
this are all on binder threads coming from applications. Further, it
seems there is only one real way of this getting hit - if the app that
called the creation died during the binder call.

Bug: 126802451
Test: Compiled, CTS tests passing
Change-Id: I6db75853da9f29e1573512e26351623f22770c5d

Benedict Wong   commited 2019-04-08 18:51:50 -07:00
2d9864ab3c
Merge "Move NetworkStatsFactory into service directory"
Treehugger Robot   authored and   Gerrit Code Review   commited 2019-04-05 19:27:22 +00:00
c832132056
Merge "Fix flaky UdpEncapsulationSocket test"
Lorenzo Colitti   authored and   Gerrit Code Review   commited 2019-04-04 08:09:06 +00:00
95e8a2b5c3
Fix flaky UdpEncapsulationSocket test
This commit reduces the flakiness of the
testOpenAndCloseUdpEncapsulationSocket by retrying up to three times.
Unfortunately, testing port-selected socket creation is racy against
other applications. This helps to handle the same race condition as done
in IpSecService#bindToRandomPort

Bug: 128024100
Test: 200x runs of testOpenAndCloseUdpEncapsulationSocket
Change-Id: I7e036ce821019dbac6c50899bd0894e89d2fe82a

Benedict Wong   commited 2019-04-03 17:52:03 -07:00
b5bc70dc6a
Move NetworkStatsFactory into service directory
In order to notify netd to swap eBPF maps before pulling the
networkStats from eBPF maps, NetworkStatsFactory need to use the
NetdServices to issue binder calls. So it need to be moved from
framework/base/core to framework/base/service since object in
framework/base/core cannot get any system services. This change is also
necessary for setting up a lock inside NetworkStatsFactory to prevent
racing between two netstats caller since the lock need to be hold before
netd trigger the map swap.

Also fix the compile problem caused by moving the NetworkStatsFactory
and the related tests. Rename the packages and the jni functions to a
more proper name.

Bug: 124764595
Bug: 128900919
Test: NetworkStatsFactoryTest
      android.app.usage.cts.NetworkUsageStatsTest
      android.net.cts.TrafficStatsTest

Merged-In: Ifcfe4df81caf8ede2e4e66a76552cb3200378fa8
Change-Id: Ifcfe4df81caf8ede2e4e66a76552cb3200378fa8

Chenbo Feng   commited 2019-04-03 11:33:40 -07:00
550ed56426
Merge "Clean up permissions when uids are no longer used"
Treehugger Robot   authored and   Gerrit Code Review   commited 2019-04-03 17:15:48 +00:00
9235821478
Merge "Add tests for PermissionMonitor"
Treehugger Robot   authored and   Gerrit Code Review   commited 2019-04-03 06:12:12 +00:00
4e39721f18
Clean up permissions when uids are no longer used
The kernel eBPF maps have a blacklist to store all the uids that doesn't
have internet permission. When an app is unintalled from the device and
it is the last package on device that uses that uid, make sure we
cleaned the uid from the map and do not add no longer used uids into the
eBPF map. This action helps reduce the number of entries stored in the
map and reduce the chance of overflow the eBPF map.

Bug: 128944261
Test: PermissionMonitorTest
Change-Id: I10dd0113d00d6cf9ca39902d9721f2591d387d4a

Chenbo Feng   commited 2019-04-02 20:31:57 -07:00
fe00494c97
Add tests for PermissionMonitor
Add more tests to PermissionMonitor to verify the functionality related
to INTERNET permission and UPDATE_DEVIE_STATS permission. Modified some
of the class design of PermissionMonitor so that it is easier to test
the new functionalities.

Bug: 111560570
Test: PermissionMonitorTest

Change-Id: Ic5585f337db5de48e2f87bf4f01ed7d85c349827

Chenbo Feng   commited 2019-04-02 20:31:49 -07:00
1401715e6f
Merge "Address leftover comments on 923337 and 930217."
Paul Hu   authored and   Gerrit Code Review   commited 2019-04-02 07:39:04 +00:00
a9b8e31cf8
Merge "Add DHCP address lease expiry in IpMemoryStore."
Xiao Ma   authored and   Gerrit Code Review   commited 2019-04-01 12:59:20 +00:00
98aa76e2e8
Address leftover comments on 923337 and 930217.
- Restrict unprivileged apps to use
  NetworkRequest.Builder#setSignalStrength.

- Remove the "throws NullPointerException" in
  CaptivePortalProbeSpec constructor.

- Remove the null check in LinkProperties.

- Add annotataion into all ConnectivityManager.NetworkCallback
  methods.

Change-Id: Id275cac1d6a30d7515cd7b113394f5e8a0179314
Fix: 129097486
Test: atest FrameworksNetTests

paulhu   commited 2019-04-01 16:24:10 +08:00
1a40765101
Merge "Fix race when starting NetworkMonitor"
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2019-04-01 03:54:03 +00:00
ef8485cc65
Fix race when starting NetworkMonitor
NetworkMonitor obtained LinkProperties and NetworkCapabilities via
synchronous calls to ConnectivityManager after receiving an asynchronous
notification, which is prone to races: the network could be gone before
the LinkProperties/NetworkCapabilities can be fetched.

Fix the race by passing LinkProperties/NetworkCapabilities directly to
NetworkMonitor in the asynchronous notifications.

Test: atest FrameworksNetTests NetworkStackTests
Test: booted, WiFi works
Bug: 129375892
Change-Id: I200ac7ca6ff79590b11c9be705f650c92fd3cb63

Remi NGUYEN VAN   commited 2019-04-01 11:33:10 +09:00
ca33d197d9
Merge "Use IDnsResolver instead of INetd for resolver related binder commands"
Luke Huang   authored and   Gerrit Code Review   commited 2019-03-29 08:45:19 +00:00
efa4301a7f
Add DHCP address lease expiry in IpMemoryStore.
Bug:122710829
Test: atest FrameworksNetTests
Change-Id: I643fe1231edcd18923514ab66c64a6cf83e69443

Xiao Ma   commited 2019-03-29 16:51:47 +09:00
3c33ee5d81
Merge changes from topic "vpn_data_accounting"
* changes:
  Move BatteryStats and StatsCompanionService to use NetworkStatsService.
  NetworkStatsService: Fix getDetailedUidStats to take VPNs into account.
  Take all VPN underlying networks into account when migrating traffic for VPN uid.

Varun Anand   authored and   Gerrit Code Review   commited 2019-03-29 00:40:53 +00:00
06b4b6f92e
NetworkStatsService: Fix getDetailedUidStats to take VPNs into account.
This API is similar to one provided by NetworkStatsFactory with the
difference that NSS also migrates traffic from VPN UID to other apps.

Since traffic can only be migrated over NetworkStats delta, NSS
therefore maintains NetworkStats snapshot across all UIDs/ifaces/tags.

This snapshot gets updated whenever NSS records a new snapshot
(based on various hooks such as VPN updating its underlying networks,
network getting lost, etc.), or getDetailedUidStats API is invoked by
one of its callers.

Bug: 113122541
Bug: 120145746
Test: atest FrameworksNetTests
Test: manually verified that battery stats are migrating traffic off of
TUN (after patching above CL where we point BatteryStats to use this
API).
Change-Id: Ib0f0c2d4d41ee1d7a027ea9da457baaf198d649e

Varun Anand   commited 2019-03-28 10:31:51 -07:00
2af0b66aba
Take all VPN underlying networks into account when migrating traffic for
VPN uid.

Bug: 113122541
Bug: 120145746
Test: atest FrameworksNetTests
Test: Manually verified on device that stats from VPN UID are moved
      appropriately based on its declared underlying network set.
Test: vogar --mode app_process --benchmark NetworkStatsBenchmark.java

Change-Id: I9d8d0cc58d18002c1c96f8ddff780ef8dc452d21

Varun Anand   commited 2019-03-28 10:31:49 -07:00
612520f544
Merge changes I0baf582f,I4bba01ba
* changes:
  Block unpriviledged apps which create keepalives with null fd
  Fix keepalive don't get removed when lower layer error

Junyu Lai   authored and   Gerrit Code Review   commited 2019-03-28 00:53:20 +00:00
6d7c97dc5c
Block unpriviledged apps which create keepalives with null fd
Currently, socketKeepalive implementation is accepting null fd
due to backward compatibility with legacy packet keepalive API.
However, due to lack of the fd, the service cannot guarantee the
port is not reused by another app if the caller release the port
for any reason.

Thus, grant the null fd access only for priviledged apps.

This commit also address some comments from aosp/918533.

Bug: 126699232
Test: atest FrameworksNetTests
Change-Id: I0baf582ff4ca8af6082c3754e8dfbcd867f39792

junyulai   commited 2019-03-27 19:51:08 +08:00
828dad188c
Use IDnsResolver instead of INetd for resolver related binder commands
migrate resolver related commands from INetd to IDnsResolver

Bug: 126141549
Test: atest FrameworksNetTests ConnectivityServiceTest Nat464XlatTest
      atest DnsManagerTest
Change-Id: I559c0c1304d53dde408c062e1a52e742595e7cbe

Luke Huang   commited 2019-03-27 17:39:07 +08:00
8141319b4d
Merge "Fix flaky test for ConnectivityServiceTest#testPartialConnectivity"
Lucas Lin   authored and   Gerrit Code Review   commited 2019-03-27 01:29:51 +00:00
52feef4450
Fix flaky test for ConnectivityServiceTest#testPartialConnectivity
There are 2 problems will make testPartialConnectivity flaky:
1. If we call setNetworkValid() before expectCapabilitiesWith(),
there may be a timing issue that network will become VALID before
NetworkMonitor send PARTIAL_CONNECTIVITY to ConnectivityService.
Solution:
We should set network to valid after ConnectivityService received
NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY to ensure NetworkMonitor
will send PARTIAL_CONNECTIVITY to ConnectivityService first then
send VALID.

2. When test case call explicitlySelected(true) first then call
connect(true), NetworkMonitor will report the network validation
test result twice because ConnectivityServiceTest() will trigger
notifyNetworkTested() when setAcceptPartialConnectivity() is
called, it may cause a timing that before the second test result
send to ConnectivityService, connect() already called
setNetworkInvalid. So, NET_CAPABILITY_VALIDATED will be removed
and ConnectivityService will trigger onCapabilitiesChanged()
unexpectedly.
Solution:
Don't trigger notifyNetworkTested() when
setAcceptPartialConnectivity() is called. If there is needed,
use mCm.reportNetworkConnectivity() to report the test result
instead.

Bug: 128426024
Test: 1. atest FrameworksNetTests: \
      ConnectivityServiceTest#testPartialConnectivity \
      --generate-new-metrics 1000

Change-Id: I7200528378201a3c7c09a78ff827b41f2741dfa1

lucaslin   commited 2019-03-26 17:49:49 +08:00
9df5336349
Reveal the call trace of failed test cases which run in executors
Currently, the fails in testTcpSocketKeepalives are triggered by
fail() inside the executor, which is hiding the actual call trace
but only message remains. And it made the fail case hard to
debug.

So this commit is to bubble up the Exception by using a custom
functional interface.

Bug: 123987272
Test: 1. atest FrameworksNetTests
      2. manually fail the test case and see the call trace

Change-Id: I125e673938a5e9d1de86f83c1a732227a4bd3207

junyulai   authored and   Junyu Lai   commited 2019-03-25 12:56:47 +00:00
c3106feee7
Fix SocketKeepalive APIs which do not meet API review requirement
Per API review, change the use of FileDescriptor to
ParcelFileDescriptor.
This change also fix nullability according to API review
feedbacks.

Fix: 126698610
Fix: 126699425
Fix: 126699232
Fix: 126700278

Test: 1. m -j
      2. atest FrameworksNetTests --generate-new-metrics 50
      3. m -j doc-comment-check-docs
Change-Id: I19476c50dd1ca290bf3f41973829da2bd229796a

junyulai   commited 2019-03-25 15:56:35 +08:00
7e06ad4ce9
Merge "Temporarily disable flaky test."
Treehugger Robot   authored and   Gerrit Code Review   commited 2019-03-21 15:04:15 +00:00
a7f5cf3adb
Temporarily disable flaky test.
Test: None
Bug: 128426024
Change-Id: I6fa12e50decbafe9d934030865c5a8f20d42b86f

lucaslin   commited 2019-03-21 19:14:32 +08:00
3bc80ae915
Merge "Cleanup NetworkManagementService for Netd commnads binder migrartion"
Luke Huang   authored and   Gerrit Code Review   commited 2019-03-21 06:01:25 +00:00
df7d47d182
Merge "Improve partial connectivity"
Lucas Lin   authored and   Gerrit Code Review   commited 2019-03-21 03:34:30 +00:00
8d77a4b813
Cleanup NetworkManagementService for Netd commnads binder migrartion
remove dead code used for netd UNIX sokcet

Bug: 65862741
Test: atest NetworkManagementServiceTest FrameworksNetTests
Change-Id: I5db61cb86325b71ac8a8fce7b15dbf569abc5935

Luke Huang   commited 2019-03-20 20:02:24 +08:00
ca5270422a
Improve partial connectivity
Improve the design and fix some nits.

Bug: 113450764
Test: 1. Build pass
      2. atest FrameworksNetTests
      3. atest NetworkStackTests
      4. Change captive_portal_https_url to https://invalid.com
      to simulate partial connectivity.
Change-Id: Ia56645841d00d2ed8406cfeacb86a4a27fd58650

lucaslin   commited 2019-03-20 18:21:59 +08:00
f9bff5b0dc
Merge "Add unit tests related to data accounting for VPNs with one underlying network."
Treehugger Robot   authored and   Gerrit Code Review   commited 2019-03-19 16:18:28 +00:00
43c87768e0
Merge "Remove NetworkParcelable"
Remi NGUYEN VAN   authored and   Gerrit Code Review   commited 2019-03-18 01:30:25 +00:00
7b9d4803b6
Add unit tests related to data accounting for VPNs with one underlying
network.

This is to establish a baseline for the existing behavior, and to ensure
that following changes are not causing a regression in existing
behavior.

This CL is also adding missing cleanup for NetworkStatsCollectionTest
which was forcing all network types in NetworkTemplate that was causing
NetworkStatsService related tests to fail.

Bug: 113122541
Bug: 120145746
Test: atest FrameworksNetTests
Change-Id: I285f186cfb16bc9fa704c797996b1e4f8a73dee4

Varun Anand   commited 2019-03-15 17:23:28 -07:00
3a84b3cee7
Remove NetworkParcelable
With the @JavaOnlyStableParcelable annotation, Network can now be used
as-is as a framework parcelable.

Test: atest FrameworksNetTests NetworkStackTests
Bug: 126477266
Change-Id: I5d9695a31b3ac48d10edcf08ccd0c34375353b79

Remi NGUYEN VAN   commited 2019-03-16 03:51:09 +09:00
eb42f2f9e7
[KA02.5] Use binder thread and executor to invoke callback
Currently, client side of keepalive event handling rely on a
newly created thread, looper, messenger and handler per object.

However, by creating oneway AIDL interface with the executor,
the callbacks can be invoked on the binder thread with user
specified context, which not only greatly simplify the design
but also reduce the cost of current thread modeling.

Bug: 114151147
Bug: 123969871
Test: 1. atest FrameworksNetTests --generate-new-metric 10
      2. atest-deflake.sh

Change-Id: I27504074cd28d5b5eb94a7ec0e97ebaaaaa1ae3d

junyulai   commited 2019-03-14 19:24:12 +08:00
070f9ff460
Merge "Tell the factory it is already serving a request."
Chalard Jean   authored and   Gerrit Code Review   commited 2019-03-13 02:07:29 +00:00
11230da789