Commit Graph

647 Commits

Author SHA1 Message Date
Lorenzo Colitti
f255e047b7 Unit tests for new explicitlySelected behaviour.
ag/7905088 added the ability to pass in acceptUnvalidated without
passing in explicitlySelected. Add unit tests for that code.

While I'm at it, convert a couple of "== 1"s to toBool(), and
update the comments in NetworkAgent.

Bug: 130766237
Test: atest FrameworksNetTests
Change-Id: I6b550bd621e3596975f83464c7b4b8a14269120b
2019-06-28 23:57:22 +09:00
Chalard Jean
484c4219d9 Simplify Exception expressions in CSTest
Test: CSTest
Change-Id: Ie9b9fc334b85836bf156bda71e54e8d30885b82a
2019-06-28 14:22:30 +09:00
Lorenzo Colitti
c75633460e Remove all static members from NetworkStatsFactory.
NetworkStatsFactory is owned by NetworkStatsService, and any
accesses to NSF data should go through NSS.

Test: atest FrameworksNetTests
Change-Id: Idbd0dbbaeb11313f63474e7ec0e01f974349fc89
2019-06-27 17:39:05 +09:00
Chalard Jean
0fd0e96a40 Merge "Revert "Simplify Exception expressions in CSTest"" 2019-06-27 08:30:57 +00:00
Chalard Jean
de6bb3e852 Revert "Simplify Exception expressions in CSTest"
This reverts commit d209586554.

Reason for revert: Breaks the build because it removes an unused method that was used by a change intervening in the mean time

Bug: 136143444
Change-Id: Id3a17e0b16ec03276609ca96fb7b582188ed1077
2019-06-27 08:30:05 +00:00
Lorenzo Colitti
c657dd301f Merge "Transfer ownership of NetworkStatsFactory to NetworkStatsService." 2019-06-27 07:53:30 +00:00
Chalard Jean
afbf997ad5 Merge "Simplify Exception expressions in CSTest" 2019-06-27 07:09:36 +00:00
Chalard Jean
0272942bca Merge "Unify assertThrows" 2019-06-27 07:08:59 +00:00
Lorenzo Colitti
f5af7fcf16 Transfer ownership of NetworkStatsFactory to NetworkStatsService.
NetworkStatsService is the only consumer of the data coming from
NetworkStatsFactory, but the factory itself is instantiated and
owned by NetworkManagementService.

Move it into NetworkStatsService instead.

Test: atest FrameworksNetTests
Change-Id: I52df1e545c646927952579da22845a12d1d7563b
2019-06-26 19:29:51 +09:00
Remi NGUYEN VAN
5c28780629 Merge "Only show "Connected" note after opening portal" 2019-06-25 15:20:33 +00:00
Chalard Jean
d209586554 Simplify Exception expressions in CSTest
Test: CSTest
Change-Id: I2c7d9e3092497526ab7d87b40a508f2d4bc3d7a2
2019-06-25 20:40:41 +09:00
Chalard Jean
045d5fca24 Unify assertThrows
Test: atest FrameworksTestsNet NetworkStackTests
Change-Id: Ib6d5d2577a5b95f90857d8d146b00af516e9944d
2019-06-25 20:40:39 +09:00
Remi NGUYEN VAN
705b46b900 Only show "Connected" note after opening portal
The "Connected" notification would be shown every time a network
validates after being identified as a captive portal. This causes issues
on networks that have auto-login mechanisms, as a high priority
notification would be shown even though the user was not interacting
with the phone.

The "Connected" notification is intended to confirm to the user that
they successfuly logged in (manually), so only show it after the user
opens the portal on the network.

Bug: 134124044
Test: Flashed, connected to portal: notification shown
      Opened portal from command line + revalidate: no notification
      Tests passing with change, failing without

Change-Id: I89e7a7f49019bd7e4686712c56e00bd786eb3ef3
2019-06-25 19:18:16 +09:00
Hugo Benichi
5c8f9cf7ed NetworkStats: Fix race condition causing system server crashes
NetworkStatsService uses an internal boolean to know when it has
started for the purpose of preventing access to other internal
variables before they are initialized.

However that boolean is set to true in systemReady() non-atomically
with respect to the initialization of the other variables it guards,
which can cause the system server to crash.

This patch fixes this concurrency bug by moving setting the internal
boolean flag and the variable it guards in one atomic synchronized
block.

This patch also removes code checking if bandwidth control is enabled,
because this is now always true.

Bug: 132767673
Test: Compiled.
Change-Id: Ia089b5767ce271d669879c975508654d4dd03429
2019-06-25 10:51:51 +09:00
Chalard Jean
af718367c2 Factorize custom asserts.
Also a few utilities that were in the way, and some opportunistic
cleanups.

Test: FrameworksNetTest NetworkStackTest
Change-Id: I385070e2044fd967cb18f1ffea9a86a4627b742e
2019-06-20 16:24:25 +09:00
Benedict Wong
fde4dfd156 Remove VPN info arrays from NetworkStats(Observer|Recorder)
This change removes the now-unused VPN arrays in the network stats
observer and recorder classes. These are always null values in every
call site.

Bug: 113122541
Bug: 120145746
Bug: 129264869
Bug: 134244752
Test: FrameworksNetTest passing
Test: Manual tests show data usage fixes maintained.
Change-Id: Ieb8645acc400fdaeb0df7092c5369b96f9f35af9
2019-06-14 11:41:31 -07:00
Benedict Wong
9308cd307a NetworkStatsFactory: Take VPNs into account for network/battery stats
This change fixes detailed UID stats to ensure network and battery stats
both take VPNs into account. NetworkStatsFactory is being made aware of
VPNs enabled, and the full set of underlying networks present.

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

This snapshot gets updated whenever NSF records a new snapshot
(based on various hooks such as VPN updating its underlying networks,
network getting lost, etc.), or NetworkStatsService's
getDetailedUidStats() method being called.

This change widens the scope of the existing mPersistentSnapshot lock,
renaming it to mPersistentDataLock, and ensures that TUN migrations are
not done in parallel. Additionally, mVpnInfos is updated via
pointer-swapping, to reduce the scope of the mPersistentDataLock.

The safety of this change is predicated on:
1. NetworkStatsFactory lock not held, so services cannot deadlock through
the cyclical lock.

2. The broadening of the scope of the lock in NetworkStatsFactory has no
threading implications, as it is always the last (leaf node) lock held,
and therefore is impossible to have lock inversion.

Additionally, to ensure VPNs work with 464xlat, the VPN info passed to
the NetworkStatsFactory includes all underlying interfaces, instead of
only passing the first one.

This (partially) re-applies changes from:
aosp/972848: Add one more test for VPN usage stats.
aosp/972847: Addressing comments for http://ag/7700679.
aosp/885338: NetworkStatsService: Fix getDetailedUidStats to take VPNs
             into account.
Co-developed with: Varun Anand <vaanand@google.com>

Bug: 113122541
Bug: 120145746
Bug: 129264869
Bug: 134244752
Test: FrameworksNetTest passing
Test: Manual tests show data usage fixes maintained.
Change-Id: I6466ec1411fc5ed6954125d27d353b6cd1be719e
2019-06-14 11:41:31 -07:00
Benedict Wong
6632202cb7 Remove duplicate line in clat_simple test file
This change removes a redundant line in the xt_qtaguid_with_clat test
file.

Bug: 134244752
Test: FrameworksNetTest passing
Change-Id: I87deb82ba960102b617ab27362e8c5899fa478f8
2019-06-14 11:16:03 -07:00
Benedict Wong
34857f82f5 Revert "Revert "Take all VPN underlying networks into account when migrating traffic for""
This reverts commit 048c1c6c32.

Reason for revert: Fix available for deadlocks.

Bug: 134244752
Change-Id: Ib65214598837289bd39dbf040b56ab7835f893ba
2019-06-13 15:36:27 -07:00
Varun Anand
048c1c6c32 Revert "Take all VPN underlying networks into account when migrating traffic for"
This reverts commit 612520f544.

Reason for revert: This change has been implicated in 4-way deadlocks as seen in b/134244752.

Bug: 134244752
Change-Id: I2f1839d7776a613ca571af8a542755ddc5fc8760
Merged-In: Ibdaad3a4cbf0d8ef1ed53cfab1e454b9b878bae9
2019-06-10 16:00:48 -07:00
Varun Anand
fb0e689ea5 Revert "NetworkStatsService: Fix getDetailedUidStats to take VPNs into account."
This reverts commit 2af0b66aba.

Reason for revert: This change has been implicated in 4-way deadlocks as seen in b/134244752.

Bug: 134244752
Change-Id: I37f75c2b243ea548a88ef1dae88287405c6ef55f
Merged-In: I0c00e8f0e30cee987b71b561079a97bf09d4dae4
2019-06-10 16:00:38 -07:00
Varun Anand
5701cc30bb Revert "Addressing comments for http://ag/7700679."
This reverts commit 4d83f3e073.

Reason for revert: This change has been implicated in 4-way deadlocks as seen in b/134244752.

Bug: 134244752
Change-Id: I12ab724e2ef8a5c1b42078330ba74713ff86fdd1
Merged-In: I5fbb3443a39a21fc9d96442726cd10d20e8d61cd
2019-06-10 16:00:28 -07:00
Varun Anand
5cc78a32d6 Revert "Add one more test for VPN usage stats."
This reverts commit 635b441ff9.

Reason for revert: This change has been implicated in 4-way deadlocks as seen in b/134244752.

Bug: 134244752
Change-Id: I87ddc0af9ff6fbd9b7afd6d4d24985b9b7205416
Merged-In: I64b48d575f2e6ec4cb7d2d100a859a30af0501dc
2019-06-10 15:59:58 -07:00
Lorenzo Colitti
635b441ff9 Add one more test for VPN usage stats.
(cherry picked from commit 20204cdf6a)

Covers the case where the majority of traffic through the VPN is
caused by the VPN app itself, and ensures that that traffic is
correctly attributed to the VPN app as opposed to spread between
the other apps that use the VPN.

Bug: 120145746
Test: atest NetworkStatsServiceTest
Change-Id: Ibd7646dc088fa4180abd696e89c3148ff34ce190
Merged-In: Iffd3f95fc2e11d311691a797b010edb38d2ef3c6
2019-05-30 15:59:28 +00:00
Varun Anand
4d83f3e073 Addressing comments for http://ag/7700679.
(cherry picked from commit 78d5ac4f8f)

Note, that its in a separate CL so we could cherry-pick this CL to aosp.
http://ag/7700679 is already in aosp (http://aosp/865073).

Bug: 113122541
Bug: 120145746
Test: atest FrameworksNetTests

Change-Id: Ic1767bc8bf1460e4223f86465fc72344428e6055
Merged-In: I7cfda226b4ed11b67002b83b38fba0f5caf96718
2019-05-30 15:59:07 +00:00
Chalard Jean
8690e1f144 Merge "Always give VPN the INTERNET capability." 2019-05-30 08:36:19 +00:00
Chalard Jean
318feaf1ed Always give VPN the INTERNET capability.
Split-tunnel VPN (which are the only ones affected by this change)
always fall through to the default network for routes they don't
handle, and even if the underlying network(s) don't provide access
this may be a pinhole that can actually reach the broader network.

In practice this behaves like the original release of P and is the
safest thing to do for Q. In R we should evaluate giving the VPN
app the ability to simply tell the network stack whether it does
provide Internet access or not.

Bug: 119216095
Test: FrameworksNetTests NetworkStackTests
Change-Id: I262ca41fe0225660551c9a421562405366b6acac
2019-05-30 16:11:14 +09:00
Chen Xu
74f0698ce6 Merge "NetworkStatAccess Should checkCarrierPrivileges cross all subscriptions" 2019-05-29 17:15:41 +00:00
chen xu
d5e7114ee9 NetworkStatAccess Should checkCarrierPrivileges cross all subscriptions
Bug: 133236378
Test: Manual
Change-Id: I49fbde1fe73b33aadcf8fd23ad224f363b137bf3
2019-05-28 23:28:56 -07:00
Chalard Jean
e343bcc913 Add a common test library.
This is the most common test library for Connectivity tests. It is
meant to be usable in framework tests, network stack tests, CTS,
GTS. To achieve that, it can only depend on framework classes.

Bug: none
Test: NetworkMonitorTest
Test: NsdManagerTest
Test: ConnectivityServiceTest
Test: OffloadControllerTest
Test: NetworkStatsObserversTest
Test: NetworkStatsServiceTest
(all the touched classes)

Change-Id: Ic47cbe7ba0e407145fa6bc49bb2adb3c5937dbc4
2019-05-28 22:20:51 +09:00
Chalard Jean
ce2f2fe2e8 Merge "Let the system server have CONNECTIVITY_USE_RESTRICTED_NETWORKS." 2019-05-28 12:26:10 +00:00
Chalard Jean
b807dd8884 Let the system server have CONNECTIVITY_USE_RESTRICTED_NETWORKS.
Also :
- Fix testUidFilteringDuringVpnConnectDisconnectAndUidUpdates that
  was failing on devices with a first released SDK >= Q
- Add a test actually tests that the system has the permission, as
  the test was only testing what's in the mock

Bug: 119770201
Test: New test making sure this stays true
Change-Id: I74cf5f0fa17fcf818f1fed78c7e3e4375c20152e
2019-05-27 16:35:22 +09:00
Chiachang Wang
b8d3727aa1 Clean up for multiple validation result update
This is a follow-up commit for aosp/955431 to update commets
and minor updates in unit test.

Test: atest com.android.server.ConnectivityServiceTest#testCaptivePortalOnPartialConnectivity
Bug: 130683832
Change-Id: I581eae8daeddd2c4c186e7b40e27fef2aaa7ab43
2019-05-24 03:29:56 +00:00
Chiachang Wang
5af07137d7 Merge "Update multiple validation result to ConnectivityService" 2019-05-24 02:50:54 +00:00
Etan Cohen
1f1bcb0b68 [CM] Fix NPE due to unvalidated callback value
Fix flaky test resulting from the above fix.

Bug: 132950880
Test: atest ConnectivityServiceTest
Change-Id: I1ddf3bb016239bf88cdd8843a71dcb5e582e83ac
2019-05-23 08:16:20 -07:00
Chiachang Wang
eff1897661 Update multiple validation result to ConnectivityService
Once a network is determined to have partial connectivity, it
cannot go back to full connectivity without a disconnect. This
is because NetworkMonitor can only communicate either
PARTIAL_CONNECTIVITY or VALID, but not both. Thus, multiple
validation results allow ConnectivityService to know the real
network status.

Bug: 129662877
Bug: 130683832
Test: atest FrameworksNetTests
Test: atest NetworkStackTests
Test: atest --generate-new-metrics 50
NetworkStackTests:com.android.server.connectivity.NetworkMonitorTest
Test: Simulate partial connectvitiy
Change-Id: I406c9368617c03a2dd3ab15fb1f6dbf539d7c714
2019-05-23 16:29:30 +08:00
Etan Cohen
b58e366f2d [CM] Fix NPE due to unvalidated callback value
When unregistering callback due to ON_UNAVAILABLE did not check for
a non-null callback.

Bug: 132950880
Test: atest ConnectivityServiceTest
Change-Id: I8f3322963f322e6690f1403681bf66e8b38b35f8
2019-05-22 04:56:09 +00:00
Treehugger Robot
0e6d2b5f4f Merge "Clean up the permission control code in framework" 2019-05-13 18:04:50 +00:00
Chalard Jean
9db77747a6 Merge "Support strict mode private DNS on VPNs that provide Internet." 2019-05-10 09:39:17 +00:00
Lorenzo Colitti
2fca7e3cb3 Support strict mode private DNS on VPNs that provide Internet.
Currently, strict mode private DNS does not work on VPNs because
NetworkMonitor does not validate VPNs. When a VPN connects, it
immediately transitions to ValidatedState, skipping private DNS
hostname resolution.

This change makes NetworkMonitor perform private DNS hostname
resolution and evaluation even on VPNs.

In order to ensure that the system always immediately switches to
the VPN as soon as it connects, remove the unvalidated penalty
for VPN networks. This ensures that the VPN score is always 101
and the VPN always outscores other networks as soon as it
connects. Previously, it would only outscore other networks
when no-op validation completed.

Bug: 122652057
Test: atest FrameworksNetTests NetworkStackTests
Test: manually ran a VPN with private DNS in strict mode
atest android.net.cts.ConnectivityManagerTest com.android.cts.net.HostsideVpnTests
Change-Id: Iaa78a7edcf23755c89d7b354edbc28d37d74d891
2019-05-10 14:30:54 +09:00
Treehugger Robot
5cb924da73 Merge changes Ibff278a6,If6d537a3
* changes:
  Revert "Add NATT keepalive resources and methods into IpSecService"
  Revert "[KA11] Verify fd ownership and allocate resource for NattKeepalive"
2019-05-10 01:42:26 +00:00
Junyu Lai
b4864e6c40 Revert "Add NATT keepalive resources and methods into IpSecService"
This reverts commit bdf7048571.

Reason for revert: Adds dependency between IpSecService and
                   ConnectivityService may lead to future deadlock
		   problems. Uses a simpler approach instead,
		   hence the solution is not needed.
		   See aosp/954040.

Change-Id: Ibff278a6eee666cd85dba81c2bed94d568679b02
2019-05-10 00:58:18 +08:00
Xiao Ma
14b9e8b6d8 Merge "adopt non-blocking method to obtain the IpMemoryStore service." 2019-05-09 11:30:56 +00:00
Etan Cohen
6cb6599ddd [CS] Unregister callback as part of onUnavailable dispatch
The onUnavailable semantics promise that it is equivalent to calling
the unregister callback method. But - it doesn't unregister the callback
allowing it to be reused. Fixed.

Additionally, modified the unregisterNetworkCallback method to not fail
on duplicate unregistration (since a callback could now self
unregister). Instead simply print a log.

Bug: 130651445
Test: atest ConnectivityServiceTest
Change-Id: I4c54b003a733eb0b1e4fd8674ed13081b1bef8e3
2019-05-09 02:41:40 +00:00
Xiao Ma
afc8845452 adopt non-blocking method to obtain the IpMemoryStore service.
Test: atest FrameworksNetTests
Change-Id: I7de4f23370bdf9c9df5e74ed074c794080d93d95
2019-05-09 10:39:50 +09:00
Junyu Lai
d09adf6456 Revert "[KA11] Verify fd ownership and allocate resource for NattKeepalive"
This reverts commit 2bb85a0bc0.

Reason for revert: Adds dependency between IpSecService and
                   ConnectivityService may lead to future deadlock
                   problems. Uses a simpler approach instead,
                   hence the solution is not needed.
                   See aosp/954040.

Change-Id: If6d537a39595cf132d3ed81d4eaac6700f5f0ab3
2019-05-08 11:44:20 +08:00
Chenbo Feng
4737299d94 Clean up the permission control code in framework
Delete the unused NetworkManagementService API for set/remove
permissions. Use PERMISSION_NONE to replace NO_PERMISSIONS so the
framework now use the same set of permission constant when communicate
with netd.

Bug: 128944261
Test: PermissionMonitorTest.java

Change-Id: I25224c9576f52d2a0a0bd2182325c7aac7b28eb5
2019-05-07 13:50:25 -07:00
Paul Hu
ebf3945e1a Merge "Add CTS API coverage for APIs which are used by NetworkStack" 2019-05-02 01:37:26 +00:00
paulhu
e878a6c64f Add CTS API coverage for APIs which are used by NetworkStack
Change-Id: I4f6c34f3bcfa65e60cf73fc1b7cab2d83c32836a
Bug: 129200003
Bug: 129200292
Bug: 129199996
Bug: 129200261
Bug: 129200513
Bug: 129200316
Bug: 129200589
Bug: 129200181
Bug: 129200669
Bug: 129200504
Bug: 129200478
Test: atest FrameworksNetTests
Test: atest CtsNetTestCases: added tests pass
2019-04-30 17:26:24 +08:00
Aaron Huang
df1edb385c Support adding NATT keepalive packet filter
Support adding NATT keepalive packet filter to APF
filter.
Generating APF program will be addressed in another CL.

Bug: 33530442
Test: - atest NetworkStackTests
      - atest FrameworksNetTests

Change-Id: I4961d5da343d8700600269632787c28112f0f9f1
2019-04-29 19:33:45 +08:00