Commit Graph

5630 Commits

Author SHA1 Message Date
Varun Anand
3a84b3cee7 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
2019-03-15 17:23:28 -07:00
Chalard Jean
dce527fbd6 Merge "[CS] Support "instant failure" from factories" 2019-03-12 12:04:46 +00:00
Lucas Lin
2d3cc4577a Merge "Check if network has partial connectivity" 2019-03-12 08:11:14 +00:00
lucaslin
2240ef679d Check if network has partial connectivity
In some networks, network validation may only get success
result for http probe but fail result for https probe.
For this kind of network, it may still work at some websites
or apps, but user didn't know about that. In order to fix this
issue, we will check if network has partial connectivity and
notify user to make a choice if they want to use this partial
connectivity or not.

Bug: 113450764
Test: 1. Build pass.
      2. Fake partial connectivity case for testing.
      3. atest FrameworksNetTests
      4. atest NetworkStackTests

Change-Id: I69ed00ac4850904ff708c9fef22e148879a10e92
2019-03-12 07:37:33 +00:00
Junyu Lai
a0b880c9e8 Merge "Improve keepalive offload documentation and error handling" 2019-03-12 05:11:50 +00:00
Etan Cohen
fbfdd84e7c [CS] Support "instant failure" from factories
Add a mechanism by which a factory can declare "instant failure" for
a request - which would result in it getting an OnUnavailable()
(even without a timeout).

Factories may only do this iff:
1. They know they are the only factory which may fulfill this
   request (common for transport-specific requests).
2. The know that the request can definitely not be
   fulfilled at any point in the future.

Bug: 31382922
Test: atest ConnectivityServiceTest
Merged-In: I9bce0f4d85fa8cad7f8a9998819f945b778c5ac5
Change-Id: I9bce0f4d85fa8cad7f8a9998819f945b778c5ac5
2019-03-11 16:15:43 -07:00
Chalard Jean
80c8a33c95 Merge "Add tethering event callback API" 2019-03-11 17:04:57 +00:00
Treehugger Robot
4e9a6e4c53 Merge "[PT17.5] Revert to booleans for send/not send broadcast constants." 2019-03-11 11:07:21 +00:00
Chalard Jean
2a67906ec5 [PT17.5] Revert to booleans for send/not send broadcast constants.
In PT17, for security of the patch these two constants have been
switched from boolean to enum values. While this is nice for making
sure a patch is correct, it's also pretty wasteful. Now that it's
certain that the values of these fields don't matter, they can be
set to logical values (as opposed to reversed as it was the case
before PT17.

Test: runtest
Change-Id: I93a0780e23c2f658687be066dc16f27529baaa86
2019-03-11 15:58:31 +09:00
Treehugger Robot
ef59cd5d8b Merge "Convert tests/**/Android.mk files to Android.bp" 2019-03-08 22:54:11 +00:00
markchien
4ef53e8819 Add tethering event callback API
Provide OnTetheringEventCallback for system app to know
tethering's upstream.

Bug: 125583822
Test: -build, flash, boot
      -atest FrameworksNetTests

Change-Id: I7ca81b27c9b805cc01884509f5b20d9d0a24cd36
Merged-in: I7ca81b27c9b805cc01884509f5b20d9d0a24cd36
2019-03-09 00:35:55 +08:00
Luke Huang
06ef4a5bc4 Merge "Minor changes to the async DNS query JAVA API" 2019-03-08 03:19:55 +00:00
Sasha Smundak
2e39455210 Convert tests/**/Android.mk files to Android.bp
See build/soong/README.md for more information.

Note: tests/ImfTest/Android.mk causes conflict as it hasn't been yet
ported to internal master. Do it later.
Note: the conversion in the following directories has to be done in the
internal master first because of the conflicts:
* tests/ActivityManagerPerfTests
* tests/AppLaunch
* tests/AppLaunchWear
* tests/BackgroundDexOptServiceIntegrationTests
* tests/Camera2Tests/CameraToo
* tests/Camera2Tests/SmartCamera/SimpleCamera
* tests/Compatibility
* tests/Internal
* tests/RcsTests
* tests/ServiceCrashTest
* tests/UsbTests

Bug: 122332340
Test: treehugger
Change-Id: Ie17590c6a96aee5caa80d38092a3de5c1b6efe8d
2019-03-07 16:14:00 -08:00
Benedict Wong
6525e97ea5 Merge changes Ie66ba631,Ic42c09a3
* changes:
  Implement TestNetworkService
  Add shell TestNetworkManager and Service
2019-03-07 23:32:55 +00:00
Mark Chien
cdfb2b941d Merge "Fix TetheringEntitlementValueListener related API" 2019-03-07 13:21:53 +00:00
Luke Huang
1244835690 Minor changes to the async DNS query JAVA API
1. refine the naming in DnsPacket and add more comment
2. add comment in DnsResolver

Test: built, flashed, booted
      atest DnsResolverTest DnsPacketTest

Change-Id: Ib482d079d6823fd1d9bff163427b7aad38374199
2019-03-07 16:40:49 +08:00
junyulai
97767bf71c Improve keepalive offload documentation and error handling
Bug: 123987401
Test: atest FrameworksNetTests
Change-Id: Id651cfb743f02b05ca3845af3c393eaf5762bb20
2019-03-07 16:01:30 +08:00
Treehugger Robot
e69a7a1554 Merge "Migrate frameworks/base/tests/net/ to androidx.test" 2019-03-07 05:42:07 +00:00
markchien
bf5ab01869 Fix TetheringEntitlementValueListener related API
Test: -build, flash, boot
      -atest FrameworksNetTests
bug: 126701557
bug: 126392011

Change-Id: I6dda10fbfe8ffaef71269617750a22563396f5ea
2019-03-07 13:33:21 +08:00
Benedict Wong
2ffe4b8998 Implement TestNetworkService
This change adds the relevant JNI implementations, as well as the
implementations and NetworkAgent tracking code in the TestNetworkService.

TestNetworkService (And Manager) is designed for use exclusively in
testing code, allowing for the creation of TUN and IPsec backed networks
in test code. Specifically, this allows for testing of components such
as IP, DHCP, or DNS clients, as well as kernel features such as IPsec.

Access to the TestNetworkService will be conditioned upon the
MANAGE_TEST_NETWORKS permission that will be granted only to the Shell.
CTS will use UiAutomation.adoptShellPermissionIdentity() to gain the
ability to use this service.

Bug: 72950854
Test: CTS tests passing
Change-Id: Ie66ba631a548b5f9c6b5ed0797582f86688debe5
2019-03-06 15:37:52 -08:00
Andrei-Valentin Onea
7e3ccaa77a Merge "Add @UnsupportedAppUsage annotations" 2019-03-06 17:18:05 +00:00
Brett Chabot
147f6cf341 Migrate frameworks/base/tests/net/ to androidx.test
Test: atest FrameworksNetTests
Change-Id: Iaa59d606f5e1678cc5aaca9ed37e184fad894e5d
2019-03-05 09:05:47 -08:00
Varun Anand
8cf699851a Merge "Fix isActiveNetworkMetered for VPNs." 2019-03-05 01:37:30 +00:00
Amit Mahajan
a32315e69a Merge "Adding new APN type for Mission Critical Services." 2019-03-04 18:23:30 +00:00
Mark Chien
acb289f34e Merge "Return not supported if no necessary socket option" 2019-03-04 09:16:07 +00:00
Treehugger Robot
37cde6b81d Merge "Fixed all APIs not meeting API review requirement" 2019-03-03 04:27:32 +00:00
Treehugger Robot
57ca4b2743 Merge "Ensure handleUpdateLinkProperties runs on the CS handler thread." 2019-03-02 05:38:21 +00:00
Treehugger Robot
72a6706e8b Merge "getConnectionOwnerUid: Clarify documentation" 2019-03-02 03:42:22 +00:00
Amit Mahajan
b7aafd26aa Adding new APN type for Mission Critical Services.
Test: build
Bug: 124447962
Change-Id: I9f608badd363703394432640dc892a4465660b6d
2019-03-01 16:52:17 -08:00
Jack Yu
9fc82e3a86 Fixed all APIs not meeting API review requirement
To address the API review feedback provided by
the API council.

Bug: 126702995
Bug: 126701710
Bug: 126702357
Bug: 126701113
Bug: 126701239
Bug: 126700713
Bug: 126700064
Test: Manual
Change-Id: I4b902c1fc2c09133022b05dacdda8964436205d2
2019-03-01 14:37:47 -08:00
Paul Duffin
e59e8c6255 Fix Automated API Review: InetAddresses
Add @NonNull annotations as required by the automated review.

Bug: 126702338
Test: make checkbuild
Change-Id: I9057f06de8d7ea846af00d5cefa744d4206b4b63
2019-03-01 14:06:18 +00:00
Benedict Wong
a4ca3c6312 Add shell TestNetworkManager and Service
This adds the scaffolding for TestNetworkManager and TestNetworkService.
These are separate from the ConnectivityManager/ConnectivityService in
order to prevent polluting the API space, and making them harder to
maintain.

Bug: 72950854
Test: Compiles, CTS tests relying on this pass
Change-Id: Ic42c09a33d962471e2587ec27f3fab2d72bbcd42
2019-02-28 21:46:58 -08:00
Varun Anand
f3fd8dd454 Remove ConnectivityManager and its usages from NetworkStatsService.
NSS needed it for getting VpnInfo[], NetworkState[] and
activeLinkProperties which it used to query via ConnectivityManager.

For VpnInfo[], this was racy as NSS may ignore intermediate changes to a
VPN's underlying networks. See http://b/123961098 for more context.

It may also lead to deadlocks b/w ConnectivityService and
NetworkStatsService. See http://b/126245192 for more info.

This change will ensure that NSS is never contending on any of
ConnectivityService locks.

Bug: 123961098
Bug: 126245192
Bug: 120145746
Test: atest FrameworksNetTests
Change-Id: Id1da446b54d95ee68ed14079107b1a10318bcf8b
Merged-In: I57e117bb4e9efe491b19d6b5a479f2d58d1c58e6
2019-03-01 00:10:52 +00:00
Varun Anand
83b6d76c93 Fix isActiveNetworkMetered for VPNs.
This change is basically a revert of http://ag/3580901.
It was made because previously VPN capabilities did not use to update
based on its underlying networks. That is no longer the case anymore.

This was previously returning meteredness on the basis of VPN's first
underlying network which is incorrect in cases such as VPN using
multiple underlying networks, or VPN that has explicitly marked itself
as metered via VpnService.Builder#setMetered API.

Bug: 123936838
Test: atest FrameworksNetTests
Change-Id: Ia54b8570fbad4a638a6d43a95e0271c6baf66685
2019-02-28 13:18:11 -08:00
Andrei Onea
23393e21ec Add @UnsupportedAppUsage annotations
For packages:
  android.net
  android.net.wifi
  android.nfc

This is an automatically generated CL. See go/UnsupportedAppUsage
for more details.

Exempted-From-Owner-Approval: Mechanical changes to the codebase
which have been approved by Android API council and announced on
android-eng@

Bug: 110868826
Test: m
Merged-In: I7489aad1dceeb18ed7ca48a1ed8829a668b3fa04
Change-Id: I16570aef456b45a5543bf889dddc7a0d25441928
2019-02-28 14:39:20 +00:00
Treehugger Robot
1dd83b17a9 Merge "Fix broken javadoc links" 2019-02-28 13:34:52 +00:00
Lorenzo Colitti
868f0589c8 Merge changes from topic "nat64"
* changes:
  Catch ServiceSpecificException instead of IllegalStateException.
  Manage NAT64 prefix discovery lifecycle in the framework.
  Track NAT64 in the framework and start clatd iff NAT64 detected
  Change Nat464Xlat lifecycle.
  Minor improvements to verifyTcpBufferSizeChange.
2019-02-27 23:37:42 +00:00
Jeff Vander Stoep
440df92ff3 getConnectionOwnerUid: Clarify documentation
Test: build
Bug: 117573763
Change-Id: Ia899a541987b9c72a83287ed69fc47ab4d38f680
2019-02-27 13:37:37 -08:00
Lorenzo Colitti
bb6bacc130 Ensure handleUpdateLinkProperties runs on the CS handler thread.
In its own change for ease of rollbacks due to the risk of
possibly crashing existing codepaths.

Bug: 65674744
Test: atest FrameworksNetTests
Test: builds, boots. Wifi, cell data, private DNS work
Change-Id: I2c0acc1c7b8367803f17b4a12c1df0fdfbc29691
2019-02-27 18:21:22 +09:00
Lorenzo Colitti
cdd4722829 Catch ServiceSpecificException instead of IllegalStateException.
The old NetworkManagementService methods to start clatd threw
IllegalStateException, but the new netd methods throw
ServiceSpecificException. Update the catch clauses so that if
starting clatd fails, the system doesn't crash.

Also stop logging stack traces but only include the exception
message itself.

Bug: 65674744
Test: atest FrameworksNetTests
Test: connecting/disconnecting to v6-only wifi in a loop does not crash
Change-Id: I4a9ec7f104712fbbe08f4f67e3288df03e8ed873
2019-02-27 18:21:22 +09:00
Chiachang Wang
3b723c2ee8 Fix broken javadoc links
Bug: 123683994
Test: Verify with javadoc
Change-Id: I4b1b936e3cf86104ace5fcb6829778710801f2d5
2019-02-27 17:18:40 +08:00
Lorenzo Colitti
84298d8e5e Manage NAT64 prefix discovery lifecycle in the framework.
Currently NAT64 prefix discovery, which runs in netd, is started
by netd itself when a network is programmed with all-IPv6 DNS
servers. Unfortunately this is not correct because in many cases
we program DNS servers before the network is connected and it's
actually possible to send packets to them.

In general netd does not have enough visibility into network
lifecycle management to decide when to start and stop prefix
discovery. So move it into the framework with the rest of the
464xlat control plane.

Bug: 65674744
Test: atest FrameworksNetTests
Change-Id: I8fa051a9c216d9c05082bf7d0bbb0cbd56000162
2019-02-27 00:18:13 +09:00
Lorenzo Colitti
f7e1739d9b Track NAT64 in the framework and start clatd iff NAT64 detected
Currently, both netd and clatd do NAT64 prefix detection, and we
start clatd on all IPv6-only networks regardless of whether netd
has detected a NAT64 prefix or not.

Instead, track the NAT64 prefix in the framework, and only start
clatd if the prefix is detected. This will allow us to remove
DNS64 detection in clatd, and pass the NAT64 prefix and the IPv6
address to clatd on the command line instead of clatd finding it
itself. That way, netd and the framework will always know how
464xlat is configured, and we'll be able to use that information
in netd.

Test: builds, boots
Test: atest FrameworksNetTests
Change-Id: Ida32d5760c5aecf7aeebef08fdb596291b2ce14a
2019-02-25 11:42:00 +09:00
Lorenzo Colitti
7b0732fff7 Change Nat464Xlat lifecycle.
Currently, NetworkAgentInfo keeps a Nat464Xlat object only on
networks where we're starting clatd (i.e., IPv6-only networks).
Simplify this code by making the Nat464Xlat object final and
always non-null. This allows us to use Nat464Xlat to store
information, such as the NAT64 prefix, even if the clat daemon
has not been started yet.

Also, remove the STOPPING state which waits for the interface to
be removed. Instead, when stop() is called, immediately enter the
IDLE state.
- This is necessary in order to be able to call start() again
  before the interface removal notification has arrived.
- It's also arguably more correct than the current code,
  because when stop() returns clatd has already terminated
  (ClatdController::stopClatd calls waitpid), and thus the tun
  fd is already closed and the tun interface is gone.

Also, now that Nat464Xlat objects are reused after stop(), add
test coverage for calling start() after stop, in both cases:
- The notification that the previous interface was removed
  arrives before the second start().
- The notification that the previous interface was removed
  arrives after the second start() but before the notification
  that the second interface was added.

Also fix a couple of lint warnings.

Test: builds, boots
Test: atest FrameworksNetTests
Test: clatd stops when IPv4 address added
Test: clatd restarts after "adb shell killall clatd"
Change-Id: I3dc66d155aa27606681f3473daf2170434d8c6d0
2019-02-25 11:42:00 +09:00
Lorenzo Colitti
c11592ce7c Minor improvements to verifyTcpBufferSizeChange.
1. Remove "throws Exception" from the signature so it can be used
   in tests that do not already throw Exception.
2. Update comment to reflect the fact that TCP buffer sizes are
   set on default network switch, not on connect.
3. Move into the method a class-level static constant that is
   only used in that method.

Test: atest ConnectivityServiceTest
Change-Id: Ic2e4fbedc23065efc20e45ea84996b577a8e94b6
2019-02-25 11:41:50 +09:00
markchien
822935397c Return not supported if no necessary socket option
In order to support tcp keepalive offload, some socket
options are necessary. If one of them isn't supported in
kernel, just return ERROR_HARDWARE_UNSUPPORTED to the
caller.
e.g.
TCP_REPAIR starts from kernel 3.5
TCP_REPAIR_QUEUE starts from kernel 3.5
TCP_QUEUE_SEQ starts from kernel 3.5
TCP_REPAIR_WINDOW starts from kernel version 4.8

Bug: 124453402
Test: -boot, flash, atest FrameworksNetTests
      -start tcp keepalive offload in kernel 4.4 and 4.9 device.

Change-Id: I6f87e5be2f2ca7aae1293820c164d0bc7b664eb6
2019-02-22 06:12:14 +00:00
Remi NGUYEN VAN
edb26a53d3 Merge "Add logging to NetworkStackClient" 2019-02-21 22:13:31 +00:00
Treehugger Robot
c60e99de22 Merge "Send special permission information to netd" 2019-02-21 20:27:58 +00:00
Remi NGUYEN VAN
31c44d7bc4 Add logging to NetworkStackClient
The current logging relies on the system log that may rotate. This is a
problem to investigate bugs where the network stack service is not
started. Add a SharedLog to NetworkStackClient and dump it in
ConnectivityService (for lack of a better place to dump it).

Bug: 124307802
Test: Booted, dumpsys connectivity shows the log
Change-Id: If596451d0613645f68a8a32acb032eea76ea506c
2019-02-21 17:09:12 +09:00
Chenbo Feng
92c4d5e649 Send special permission information to netd
Netd need the list of apps that have permission INTERNET or permission
UPDATE_DEVICE_STATS at run time to make decisions about application
request. To avoid protential deadlock and reduce the traffic between
netd and system server, Use packageManagerServcie to send the list of
apps that have those permissions to netd when device boot and when new
apps get installed.

Bug: 111560570
Bug: 111560739
Test: install and uninstall packages and dumpsys netd trafficcontroller
Change-Id: Idb9905f424557a5c59e35d41f5eafe345aca87e0
2019-02-20 14:07:18 -08:00