Commit Graph

350 Commits

Author SHA1 Message Date
Chalard Jean
d94e48ff95 Add tests for getActiveNetwork.
Clean cherry-pick of ag/3918295
One-line adjustment for ag/3638326 which has not been put in AOSP.

Bug: 77737389
Test: runtest frameworks-net
Change-Id: I03ae2bbb08559f2cd44979e291c1f5d50eb215da
Merged-In: Iaa0285825735d3f16bba6e4946723a437fd9b0b9
Merged-In: Ia8f985b448251f911484e6bd63fa562bffc1b0e4
2018-06-06 08:24:12 +00:00
Remi NGUYEN VAN
bbfe4d043f Merge "Migrating remaining core networking tests to Junit4" 2018-05-25 03:27:39 +00:00
Remi NGUYEN VAN
3f6d2b08ad Merge changes I3b3bcbbd,I18b3f263,I3c416c1a
* changes:
  Use CaptivePortalProbeSpec method in portal app
  Add configurable captive portal probes
  Move CaptivePortalProbeResult to its own file
2018-05-24 07:53:00 +00:00
Hugo Benichi
e17657c0f1 Migrating remaining core networking tests to Junit4
Bug: 62918393
Test: runtest frameworks-net
Merged-In: I30f7eaa0307b8fad5a8de7a0da235a4f76c18677
(clean cherry-pick of I30f7eaa0307b8fad5a8de7a0da235a4f76c18677)

Change-Id: I272fea0bb4a9e7f6252bb3bd14a6b769a082039e
2018-05-24 16:24:47 +09:00
Remi NGUYEN VAN
f3eae13de9 Move CaptivePortalProbeResult to its own file
This is necessary to resolve visibility issues for the next change.

Bug: b/79499239
Test: runtest frameworks-net
Merged-In: Ia48b32307a51a66f2672d7112f71166dd6db41b1
Merged-In: I5df7ee9f16bc6be4f02353d40a843a383dd4cbd9
(Clean cherry-pick of pi-dev I50bc96afe6ae88c8f58a693f0a4e821f1f9b3299)

Change-Id: I3c416c1a91ebfdf914fd528ff8ab73e3eb490562
2018-05-24 12:04:27 +09:00
Remi NGUYEN VAN
899283d833 Merge "Fix testRegisterUsageCallback" 2018-05-08 07:55:42 +00:00
Remi NGUYEN VAN
b1ff5a381e Fix testRegisterUsageCallback
noteOp (introduced in go/ag/3897834) checks that the calling uid matches
the calling package, which is not correct when using a fake calling
package. Use the real package of the test so permissions are checked
properly.

The test currently only fails this way in pi-dev as noteOp is only used
in pi-dev.
Change-Id: I9ac3717af9335ba9efa0b8842a2df0d7b69ec9ab
Test: Fixed test now passes in pi-dev
Bug: b/78487385
2018-05-02 16:51:13 +09:00
Chenbo Feng
84c1437111 Remove the unused file parsing function
With the new xt_bpf support for iface stats. We no longer need to parse
the per interface stats from /proc/net/dev. And since the old xt_qtaguid
code path also not depend on it, we can completly remove that helper
function since no caller is depending on it now.

Bug: 72111305
Test: runtest frameworks-net -c com.android.internal.net.NetworkStatsFactoryTest
Change-Id: Icb7eaeef0eeb9fdffd32a90316c76ee05bafffbe
2018-05-01 14:13:55 -07:00
Chalard Jean
70be7a9dd0 Let DnsManager fill in LinkProperties for private DNSes
(clean cherry-pick from ag/3880157)

Test: new tests pass
Bug: 73641539
Change-Id: I971ef4d27b22a435d7459e1c4b31a8715ef6e610
Merged-In: I837df61e3c277ae08ebf4fdcd4c4e9ac8c550811
Merged-In: I72ecaa4f7d7320ffa2e0ba82fadafc947c8a6981
2018-04-27 13:32:10 +09:00
dalyk
1720e54568 Trigger NetworkCallback events when private DNS usage has changed.
Relies on events sent from netd in aosp/578162.

Test: Added tests to ConnectivityServiceTest. Added a new test
class DnsManagerTest. Built a simple app that appears to
receive onLinkProperties events correctly upon manual changes
to the private DNS settings on a Pixel.
Bug: 71828272
Change-Id: I68665aaf74b7d59182cc6f9586b80b55b0dfe427
2018-04-09 16:45:22 -04:00
Erik Kline
9a62f0108e Move the logic of (re)evaluation of Private DNS
Moves this out of ConnectivityService and into each NetworkMonitor
(where it's more self-contained).

Test: as follows
    - builds, flashes, boots
    - runtest frameworks-net passes
    - manual testing with working and non-working hostnames behaves
      somewhat (but not entirely) as expected, and not always quickly
Bug: 64133961
Bug: 72345192
Bug: 73872000
Bug: 77140445
Change-Id: Ic4322af3cb49149f2d975cb31f54b2ac7927f907
2018-04-05 15:17:38 -07:00
Chalard Jean
459c9109ca Limit the number of routes for performance
In evaluating whether "most" of the addressing space is
covered, the list of routes are obtained from a third-party
app, so it's possbile the system service stalls unless
some limit is enforced on how much work it has to do.
This change limits the number of routes to 400, as determined
by time measurement on various devices.

Bug: 74176086
Test: runtest framework-net
Change-Id: Ie4a96098bc044ade87b188839586f14dd101c100
2018-03-29 18:13:23 +09:00
Treehugger Robot
ce907ddfc4 Merge "Pass all relevant resolver info to netd" 2018-03-23 23:41:11 +00:00
Erik Kline
286974f384 Pass all relevant resolver info to netd
Test: runtest frameworks-net passes
Test: manual testing of opportunistic and strict mode works
Bug: 34953048
Bug: 64133961
Bug: 72345192
Change-Id: Ia4f1905e1fa60e7a468c2246fb809191d2ba796b
2018-03-22 23:50:13 -07:00
Chalard Jean
433c0e652f Merge "Have PermissionMonitor arbiter which app can access background networks" 2018-03-23 06:15:00 +00:00
Chalard Jean
e64b8d7bce Have PermissionMonitor arbiter which app can access background networks
This will let ConnectivityService send the right callbacks to the
relevant apps.

Test: manual with apps
      runtest frameworks-net
      cts
      new tests for this functionality
Bug: 67408339

Change-Id: I6f08efd9e73c7e191f833d7f307a3bf4c9e2f0b4
2018-03-22 19:03:59 +09:00
Remi NGUYEN VAN
1cb92c713f Add method to NetworkStatsService for UID stats.
Useful for clients such as BatteryStats which currently rely
on NetworkStatsFactory. Data at that stage is incomplete as
it does not account for tethering, VT data and corresponding
464xlat corrections.

Test: runtest frameworks-net, CTS tests pass.
Change-Id: I763b77f601c827fd2963204694fb5b45425cc791
2018-03-22 15:31:28 +09:00
Nathan Harold
bd12ffffc0 Check mOwnedByTransform to avoid DELSA on SPI
The owned by transform flag prevents the removal
of an SPI from accidentally deleting an associated
SA in the kernel. That flag wasn't actually being
checked, so deleting an SPI would result in the
transform being removed.

The existing code already guarantees that the SA is
deleted when the transform is deleted

Bug: 73258845
Test: runtest frameworks-net
Change-Id: I4c26aea7af817a5d9e54da5db1cdf4f943bcae06
2018-03-20 11:26:29 -07:00
Benedict Wong
3f3410ae6b Merge "Added implementation for VTI add/remove address" 2018-03-19 22:05:09 +00:00
Benedict Wong
0da1f39e22 Added implementation for VTI add/remove address
This change adds implementation details for add/remove addresses onto a
VTI.

Bug: 73675031
Test: New tests added, passing on Walleye
Change-Id: Idde9d943a5285d2c13c5c6b0f7b8a9faf718e6a5
2018-03-16 10:25:43 -07:00
Chalard Jean
faed85f2b0 Merge "Give apps with NETWORK_SETTINGS right to see any VPN." 2018-03-02 11:52:15 +00:00
Chalard Jean
9a396cc3c6 Give apps with NETWORK_SETTINGS right to see any VPN.
...not only the ones that apply to them.

Bug: 73217368
Test: runtest frameworks-net and CTS
Change-Id: I436972a3e51e98bdd815771b451bcedadf684763
2018-03-02 17:10:11 +09:00
Chalard Jean
9cbc882c08 Give VPNs the INTERNET capability when they route most of the IP space
Test: manual, plus wrote some new tests for this
Bug: 72765718
Change-Id: I9759da72b752fd8eeb1d0647db9ab341f04c0528
2018-03-02 16:20:22 +09:00
Andreas Gampe
94bb3f9b9e Frameworks: Annotate JUnit4 test with @Test
Mollify Errorprone.

Bug: 72076216
Test: m javac-check RUN_ERROR_PRONE=true
Test: atest IpSecServiceParameterizedTest
Change-Id: Ia3a253c4c5994937efc0f498ac047c5fb4eee3e9
2018-02-26 08:09:26 -08:00
nharold
cab3e6009c Merge "Fix ConnectivityServiceTest for NATT Keepalive" 2018-02-20 19:17:23 +00:00
Chalard Jean
9f48d166f6 [LT2] Fix release request while lingering.
Test: runtest framework-net
Change-Id: Ic28c5653d16351903b792e76ba8b199b7ed1f8d4
2018-02-19 11:00:58 +09:00
Nathan Harold
0990bc8b57 Fix ConnectivityServiceTest for NATT Keepalive
Fix test breakages I caused when adding cell
support for NATT keepalives.

-Make the minimum keepalive interval a constant in
 ConnectivityManager and use it in tests.
-Re-Disallow IPv6 Keepalives

Bug: 73327535
Test: 'runtest -x ConnectivityServiceTest' now passes
Change-Id: I5ec4367d250ee371014e65c897c3897a25a05e2d
2018-02-16 16:34:50 -08:00
Chalard Jean
a7c93b0b5b [LT1] Add a test for release request while lingering
Test: runtest framework-net
Change-Id: Ic635f97bf3dad8b695b3b8cc32c1a8b891166f9f
2018-02-16 18:09:42 +09:00
Chalard Jean
a23bc9e501 Publish FOREGROUND and add NOT_SUSPENDED capabilities.
NOT_SUSPENDED and FOREGROUND are capabilities that need to
be public so as to reach feature parity with what information
can be gotten through the use of CONNECTIVITY_ACTION and
synchronous calls to ConnectivityManager. This change makes
them public, and wires up the NOT_SUSPENDED capability.
This deprecates in effect the old onSuspended and onResumed
callbacks, but these have never been public.

This also converts the onAvailable path from a multiple
binder call design to a simpler, single binder call. This
is only for internal convenience

Test: runtest frameworks-net
Test: cts
Test: also manual testing
Change-Id: I6ea524bb361ecef0569ea2f9006c1e516378bc25
2018-02-14 15:14:41 +09:00
Chalard Jean
2550e069bc Send null UIDs to apps instead of single-uid lists.
Prior to this change ConnectivityManager used to patch in the UID
of the requesting app inside the NetworkCapabilities sent to it.
The rationale was that the app may not know what other apps may
use the network, so the view it should have of the network should
always say the network only applies to that app.

But this has an unfortunate side effect : apps can't match the
received network against a default NetworkCapabilities. Ostensibly
this only applies to the system because all involved calls are
@hide, but still : system code would get some NetworkCapabilities,
for example using networkCapabilitiesForType, and then try to
match the capabilities of an available network using
satisfiedByNetworkCapabilities. Because the passed network is
declared to only apply to one's own UID and the UIDs of the
NetworkCapabilities are set to null meaning "I need this network
to apply to all UIDs", the answer will be "false".

While this is WAI in a sense, it is very counter-intuitive that
code trying to match a network would be required to patch in its
own UIDs.
There are three ways of fixing this :
1. Require all apps to do the above. It's correct, but it's
   cumbersome and counterintuitive. Multiple places in existing
   code needs to be fixed, Tethering is an example.
2. Write the UIDs of the caller in any NetworkCapabilities object
   that is created. This is not very practical, because it imposes
   the converse requirement on all NetworkAgents, which would then
   have to clear the UIDs before they send the capabilities to
   ConnectivityService. All NetworkAgents need to be fixed.
3. Instead of sending an object with a list of one UID to apps,
   send a null list. The drawback is that the networks nominally
   look to apps like they apply to all apps. I argue this does
   not matter ; what matters is that the UID lists do not leak.
   Clients just see a null list of UIDs (and third party can't
   even access them without using reflection). No other changes
   are required besides this two-line patch.

This patch implements 3. I believe it is the saner approach, with
both the most intuitive behavior and the best backward compatibility
characteristics, as well as the easiest change.

This does not encroach on the future plans to make the actual
UID list available to apps with NETWORK_SETTINGS.

Test: runtest frameworks-net
Change-Id: I978d91197668119e051c24e1d04aafe1644a41cf
2018-02-14 12:47:15 +09:00
Treehugger Robot
997937820d Merge "Frameworks: Mark tests" 2018-02-06 06:03:09 +00:00
Andreas Gampe
3fa5c22fc8 Frameworks: Mark tests
Add @Ignore and @Test to make Errorprone happy.

Bug: 72076216
Test: m javac-check RUN_ERROR_PRONE=true
Test: atest ConnectivityServiceTest
Test: atest WifiManagerTest
Change-Id: Id2423c545eccaa768203faf86e14d0a558d927cd
2018-01-31 01:04:00 +00:00
Hugo Benichi
11f04e863e Fix default network validation overcounting
When switching from a validated default network to a new validated
default network (typically because of a better score),
DefaultNetworkMetrics would not reset the last validation timestamp.

This would cause the new default network to have a total recorded
validation time overcounted by the validation time of the previous
default network.

The following fix should be applied downstream for consumers of
previously recorded data:

  validation_time = min validation_time, duration_time);

Test: runtest -x frameworks/base/tests/net/../IpConnectivityMetricsTest
Change-Id: I303d11023527c19435f5f5e796a0295ae3f76d9f
2018-01-29 16:07:33 +09:00
Hugo Benichi
f78548d222 Prevent crash in NetworkManagementServiceTest#shutdown()
The shutdown method in NetworkManagementServiceTest was trying to close
the local socket on the test side, causing the NativeDaemonConnector
internal to NetworkManagementService to sometime crash due to the
output stream on NetworkManagementService side to throw on pending
reads.

The correct fix would be to shutdown the NativeDaemonConnector
inside NetworkManagementService and implement NetworkManagementService's
shutdown method, however there is no way to cleanly close a
NativeDaemonConnector.

Instead, this patch doesn't do any cleanup of the listening socket, the
test local socket, and its output stream. These objects' resources get
eventually collected by the system when the test process exits.

Test: runtest frameworks-net
Change-Id: I72c9aa43403754b55e9d23bf4f3ba8b7b4a3e10a
2018-01-29 16:01:56 +09:00
Benedict Wong
859629fa0b Add tunnel-mode calls to netd in IpSecService
Adds calls to relevant netd methods in IpSecService, enabling Tunnel
mode functionality.

Bug: 63588681
Test: Compiles, passing CTS + unit tests
Change-Id: I6deb68584cddb03f21bd76370d4ef69cadc1bf16
2018-01-24 08:19:55 +00:00
Benedict Wong
145b425fac Add TunnelInterface API and KernelResourceRecords
This change adds one KernelResourceRecord type (TunnelInterfaceRecord),
and adds methods for the creation of TunnelInterfaces, as well as the
application of Transforms to the given TunnelInterfaces

As part of the generation of ikeys/okeys, a ReserveKeyTracker manages a
java bitset to avoid collisions and reserve/release keys.

Bug: 63588681
Test: Compiles, CTS, unit tests all pass on AOSP_marlin
Change-Id: I9e9b6455e27073acd4491eae666aa966b3b10e0f
2018-01-24 07:24:27 +00:00
Benedict Wong
da7f993d34 Merge "Add xfrm mark in IpSecConfig" 2018-01-24 05:53:29 +00:00
Chalard Jean
515b2e9434 Merge changes I3b16caad,Iaf5ea7ab,I09a94042,I69a39039,I35300309, ...
* changes:
  Let network requests see VPNs.
  Move constants into a new file.
  Make sure listen requests from VPN apps see their own networks
  Add a test for new UID checking code.
  Remove UID_RANGES_ADDED and REMOVED.
  Move VPN allowed UIDs into NetworkCapabilities.
  Pre-import to remove a conflict.
2018-01-24 04:09:44 +00:00
Treehugger Robot
e339107631 Merge changes from topic "bpfStats"
* changes:
  Use /proc/net/dev to get stats summary
  Add bpf support for NetworkStatsFactory
  Add BPF support for NetworkStatsService
2018-01-24 04:08:29 +00:00
Benedict Wong
e9f609ee76 Merge "Add checks to ensure SPIs are not reused" 2018-01-23 18:00:06 +00:00
Chalard Jean
fd3a4ae0fe Let network requests see VPNs.
Test: runtest frameworks-net
Test: also tested with VPN app
Test: also cts passing
Change-Id: I3b16caad7787c3c1f2921ca1583815c89efbadc5
2018-01-23 21:38:00 +09:00
Chalard Jean
92a116d264 Add a test for new UID checking code.
Test: manual, this is a new test and it passes
Change-Id: I69a39039647ec05f970700e36c5f1e1e6e110f4a
2018-01-23 21:38:00 +09:00
Lorenzo Colitti
c4ba57cadd Disable IpConnectivityMetricsTest.
This test has been failing for a while, and we are do not have
bandwidth to fix it during the next week.

Test: make -j64 FrameworksNetTests RUN_ERROR_PRONE=true
Test: atest FrameworksNetTests:IpConnectivityMetricsTest
Test: runtest -x frameworks/base/tests/net/java/com/android/server/connectivity/IpConnectivityMetricsTest.java
Change-Id: I59d73c1773e160a726996f3ab4ad20312decc127
Merged-In: I59d73c1773e160a726996f3ab4ad20312decc127
2018-01-23 18:38:48 +09:00
Chenbo Feng
b25ada3657 Use /proc/net/dev to get stats summary
If the qtaguid proc file is no longer exist, the device is running new
eBPF module to do traffic accounting. So the NetworkStatsFactory need to
use the proc/net/dev interface to get the per interface traffic stats
summary. Also, adding a test to verify the helper function work properly

Bug: 30950746
Test: run NetworkStatsFactoryTest
Change-Id: Ia36808bf02f1637dd41a3e7c50917b91b1a77524
2018-01-23 00:35:02 -08:00
Chenbo Feng
7224ab835a Add bpf support for NetworkStatsFactory
Add the native method used to read the detail information of network
stats from bpf maps. The native method of NetworkStatsFactory should
choose the correct implementation to get the stats detail depending on
the kernel version. Currently the bpf result is printed as a reference
and the actual behavior of NetworkStatsFactory should not change.

Test: NetworkStatsFactory related cts test should not fail.
Bug: 30950746
Change-Id: I4715a23559b5b2306bd556cea0431f0ed172a993
2018-01-23 00:34:53 -08:00
Benedict Wong
bb31e20bcd Add checks to ensure SPIs are not reused
This change adds an additional check in CheckIpsecConfig to prevent
users from using the same SPI twice. This allows for a more granular
error message.

Bug: 70642141
Test: Tests added in IpSecServiceParameterizedTest
Change-Id: I9621fb05c6b162bd8ae8db4ac1e64feaa9d0ac73
2018-01-22 21:09:47 -08:00
Benedict Wong
3dcee3120b Merge "Address comments and final cleanup from refcounting integration" 2018-01-22 20:32:18 +00:00
Benedict Wong
77883ceedc Merge "Rename create/delete transform methods" 2018-01-22 17:57:15 +00:00
Benedict Wong
01e9f19d7b Rename create/delete transform methods
CreateTransportModeTransform and DeleteTransportModeTransform are both
agnostic as far as which mode of transform it creates/deletes. As such,
to facilitate the implementation of tunnel mode, this patch renames them
to CreateTransform and DeleteTransform, along with all test names.

Bug: 63588681
Test: frameworks/base unit tests and CTS tests run, passed
Change-Id: I1f015eb7ad0e85fca966658a9402485ca2b44091
2018-01-19 10:43:01 -08:00
Treehugger Robot
5087f93c36 Merge changes Id8776d14,Ifa291c62,I5ea9d200
* changes:
  Track and persist in stats whether traffic is on the default network.
  Add the default network to NetworkStats and NetworkStatsCollection.
  Pass all default networks to NetworkStatsService
2018-01-19 14:48:52 +00:00