Commit Graph

525 Commits

Author SHA1 Message Date
Benedict Wong
dedb6bb0e5 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.
Merged-In: I6466ec1411fc5ed6954125d27d353b6cd1be719e
Change-Id: Id45ae956ad7165be346ecc010e17d260563ac1c0
(cherry picked from commit 9fbbdebc61513982a6775460e1d400956f803bde)
2019-06-21 01:12:27 +00:00
Benedict Wong
2cca1ef390 Revert "Revert "Take all VPN underlying networks into account when migrating traffic for""
This reverts commit d8220c20507f0c346f517d715c7b9826b04d64e2.

Reason for revert: Fix available for deadlocks.

Bug: 113122541
Bug: 134244752
Merged-In: Ib65214598837289bd39dbf040b56ab7835f893ba
Change-Id: Ia90bf2c72ef686e80800d113d03548e0efcadb66
(cherry picked from commit a84d9fa57247cf78a9297b0c6dbd3d81b69e235f)
2019-06-21 01:09:49 +00:00
Benedict Wong
612ac19261 Revert "Take all VPN underlying networks into account when migrating traffic for"
This reverts commit 921b3f3e85.

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

Bug: 134244752
Change-Id: Ibdaad3a4cbf0d8ef1ed53cfab1e454b9b878bae9
2019-06-07 09:18:01 +00:00
Benedict Wong
75fc9e4e15 Revert "NetworkStatsService: Fix getDetailedUidStats to take VPNs into account."
This reverts commit 8481d9d55d.

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

Bug: 134244752
Change-Id: I0c00e8f0e30cee987b71b561079a97bf09d4dae4
2019-06-07 09:17:47 +00:00
Benedict Wong
bebb34732d Revert "Addressing comments for http://ag/7700679."
This reverts commit 81e79803de.

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

Bug: 134244752
Change-Id: I5fbb3443a39a21fc9d96442726cd10d20e8d61cd
2019-06-07 09:17:31 +00:00
Varun Anand
81e79803de Addressing comments for http://ag/7700679.
Note, that its in a separate CL so we could cherry-pick this CL to aosp.
http://ag/7700679 is already in aosp.

Bug: 113122541
Bug: 120145746
Test: atest FrameworksNetTests

Change-Id: I7cfda226b4ed11b67002b83b38fba0f5caf96718
2019-05-29 18:15:34 +09:00
Varun Anand
8481d9d55d NetworkStatsService: Fix getDetailedUidStats to take VPNs into account.
(cherry picked from commit 720133f79d)

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: I4b8d7c5b6905a4a12c1806dfd35c2c4c63610404
2019-05-29 18:15:24 +09:00
Varun Anand
921b3f3e85 Take all VPN underlying networks into account when migrating traffic for
VPN uid.

(cherry picked from commit c8dbdf35de)

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: I7f368c5970b2dcb969fe0daf5ef44edb1f51d09d
2019-05-29 18:15:17 +09:00
Lei Yu
3c6fb30f24 Use merged NetworkTemplate to query data usage
This CL uses merged NetworkTemplate so that it shows correct
data for carrier which is a virtual that has multiple
subscriberId under the hood.

By doing this, this CL also adds several hidden API so settings
can query by NetworkTemplate directly.

Fixes: 120566366
Test: RunSettingsLibRoboTests
Change-Id: I8b747697933c75b48b14387adafb5ac9ca165926
2019-05-13 11:42:23 -07:00
Lorenzo Colitti
22e0b2c514 Merge "Add IPsec checks for IPSEC_TUNNEL feature" into qt-dev 2019-05-09 03:25:35 +00:00
Benedict Wong
e9763752c7 Add IPsec checks for IPSEC_TUNNEL feature
This patch adds checks to ensure that the IPSEC_TUNNEL feature flag is
enabled.

Bug: 117183273
Test: Compiles & tests passing
Change-Id: I2699dda29e1eed139bc6fd1b70071e5ab33cad88
2019-05-08 00:11:28 +00:00
Benedict Wong
c45974b0d6 Add EPROTONOSUPPORT to IpSecManager SSE map
This change maps EPROTONOSUPPORT to the list of error codes that map to
UnsupportedOperationException in IpSecManager.

Bug: 80103456
Test: Compiles, CTS tests ran
Change-Id: Iec3d5fc4a9bcad7c104414afefae775232d46558
Merged-In: Iec3d5fc4a9bcad7c104414afefae775232d46558
(cherry picked from commit dcbc670688d815ce89954765fac46aa2ad6d8adb)
2019-05-07 14:32:17 -07:00
TreeHugger Robot
f3a812858c Merge "Restrict access to dangerous methods to <= P" into qt-dev 2019-04-22 07:14:10 +00:00
Chalard Jean
a69a73ece7 Restrict access to dangerous methods to <= P
Test: make
Fixes: 130143562
Change-Id: I1a6a472f83cf00a1ab174a9c5e67d3e9357a0c45
Merged-In: I95107f7b628eecb54e9f4411785186b668e9f3d8
Merged-In: I890030580fdad45c3f8589bf6adbe5798d578cfe
(cherry picked from commit 0bb53dbb64bbc937a23e1dc7641c8988a6d11d64)
2019-04-16 06:13:09 +00:00
Chalard Jean
65081e4cf6 Move TrafficStats tags for the network stack constants
As per API council feedback, these constants should live in
a place that is private to the network stack, only with a
range defined in system API.

Bug: 129433383
Test: m
Change-Id: I84a90f84a9af6fef4667ee4d512ebd0413222086
(cherry picked from commit 79a6330650ca04bd7a08afbd63f8016a3b30bc72)
2019-04-16 00:41:54 +09:00
Chenbo Feng
c1b3fc8712 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

Change-Id: Ifcfe4df81caf8ede2e4e66a76552cb3200378fa8
2019-04-03 14:28:41 -07:00
Andrei Onea
c5965f1f41 Add @UnsupportedAppUsage annotations
For packages:
  android.companion
  android.filterfw
  android.hardware.camera2.utils
  android.inputmethodservice
  android.net.nsd
  android.os
  android.preference
  android.security.keymaster
  android.service.dreams
  android.telecom
  android.telephony.ims.compat.feature
  android.telephony
  android.util
  android.view.accessibility
  android.media.effect

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
Change-Id: I9c2f8347952f3cc65759472b0e1a2717b285e44e
2019-03-21 14:04:57 +00:00
Varun Anand
1a96a9997c Merge "Add unit tests related to data accounting for VPNs with one underlying network." am: 289759e0d2 am: dd9d8de53b
am: cf038bfcd1

Change-Id: I80e3ebb556ac0b6bff5d232b881f7d869cb74f00
2019-03-19 09:47:04 -07:00
Varun Anand
d8fdea1c6e 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
Andrei-Valentin Onea
cdf8d71a9f Merge "Add @UnsupportedAppUsage annotations" 2019-03-06 17:18:05 +00:00
Jeff Sharkey
08a1c3662a All Parcelable CREATOR fields are @NonNull.
If they were null, then the Parcelable would fail to work.

Bug: 126726802
Test: manual
Change-Id: I7929ffa2f20e5de1c8e68e8263cca99496e9d014
Exempt-From-Owner-Approval: Trivial API annotations
2019-02-28 23:29:04 -07:00
Varun Anand
bc0dd9b3c7 Merge "Remove ConnectivityManager and its usages from NetworkStatsService." 2019-03-01 01:14:34 +00:00
Varun Anand
10fe088231 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
6cfd15e33e 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: I57e117bb4e9efe491b19d6b5a479f2d58d1c58e6
2019-02-28 13:43:02 -08:00
Andrei Onea
2a71a3d814 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
Andrei Onea
0fbf072ca6 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
Change-Id: I7489aad1dceeb18ed7ca48a1ed8829a668b3fa04
2019-02-27 13:31:33 +00:00
Remi NGUYEN VAN
83bde292f1 Merge "Add SocketUtils for NetworkStack" am: d9cc11e8bd am: 4d301b8d85
am: d3030bf5b4

Change-Id: I6d059f9cd1a694659bfd7ac09a32022d29c03f85
2019-01-28 23:47:36 -08:00
Remi NGUYEN VAN
894533059e Add SocketUtils for NetworkStack
These utilities can only be used for privileged apps. The underlying
implementation cannot be @SystemApi.

Test: m
Bug: 112869080
Change-Id: Idfa90561102e5b03ab2b79486d3ad46457128bf8
2019-01-28 20:11:27 +09:00
junyulai
1677ea7de5 Hide Keepalive offload API in IpSec
Since the new keepalive API is exported in ConnectivityManager,
hide Keepalive API in IpSec, also make system-current.txt sync
for this part.

Bug: 114151147
Test: m -j
Change-Id: I076030bdbab1cd7d69f6a034577d529970b050dc
2019-01-25 14:41:19 +08:00
Chenbo Feng
ac4d7d1258 Merge "Use delta reads for per uid traffic stats" am: 39de2905a5 am: 03074c729f
am: cf8d605cfb

Change-Id: Ia2d3aad715dc1a2ff65ea9ec1a5badeda47c47a6
2019-01-24 11:57:26 -08:00
Chenbo Feng
a9382c9793 Use delta reads for per uid traffic stats
For the detailed network stats of each uid and tag, the native
implementation provides delta read instead of consistent stats
data since boot. Every time the readNetworkStatsDetail function gets
called, the data pulled will be cleared. We will keep a persistent data
since boot in NetworkStatsService instead.

Fixed some checkstyle complains in related files as well.

Bug: 79171384
Test: android.app.usage.cts.NetworkUsageStatsTest
      NetworkStatsServiceTest
Change-Id: I50bcf278739135081d522e50b0e88d76fd9ab131
2019-01-22 13:50:35 -08:00
Chenbo Feng
14c16b87a9 Merge "Adjust map names due to new bpfloader" am: 0317e9e374 am: 37cec67bdc
am: 50252f86f3

Change-Id: Iedbb541ba2fa5916048e3f40d5cc128a83d0dc6b
2019-01-09 11:34:54 -08:00
Treehugger Robot
0317e9e374 Merge "Adjust map names due to new bpfloader" 2019-01-09 18:34:49 +00:00
Chenbo Feng
150dc6f187 Adjust map names due to new bpfloader
With the new loader support added. The bpf map format is defined by bpf
kernel program as well. Change the netd bpf program to the new format.

Test: CtsUsageStatsTestCases
Bug: 112334572
Change-Id: I34e38e0a8cf0cca54dc52ec897771452f9d90525
2019-01-04 12:06:35 -08:00
Junyu Lai
92c56063be Merge "Ignore ipv6 tx traffic on clat uid." am: 191f32fdc7 am: 9c0075aad0
am: 59c7f1a494

Change-Id: I1ac85ac863026ea99117c5b0115bcc0c9144fb7b
2019-01-04 08:47:41 -08:00
Junyu Lai
191f32fdc7 Merge "Ignore ipv6 tx traffic on clat uid." 2019-01-04 09:29:10 +00:00
Treehugger Robot
ab3b396c45 Merge "DO NOT MERGE - Merge pie-platform-release (PPRL.181205.001) into master" 2018-12-13 05:45:20 +00:00
Adrian Roos
be53fbb8d5 API: Clean up redundant and ineffective usages of SystemApi and TestApi
Everything that is marked SystemApi or TestApi, but not @hide is still
part of the public SDK, it is therefore not sound to have that combination.

In the future, specifing such a combination will be considered an error
to prevent inadvertently exposing SystemApi and TestApi as public API.

Bug: 115333477
Change-Id: Ibd5d6a22862fdbc1e20a1cb3925280f5a682edea
Merged-In: Ibd5d6a22862fdbc1e20a1cb3925280f5a682edea
Test: METALAVA_PREPEND_ARGS="--error UnhiddenSystemApi" m checkapi
Exempt-From-Owner-Approval: API cleanup
2018-12-12 15:02:26 +01:00
Xin Li
6f9c73f8c9 DO NOT MERGE - Merge pie-platform-release (PPRL.181205.001) into master
Bug: 120502534
Change-Id: Idc8bfb6d97a869b76cfb87ca1a494201baf9e8bd
2018-12-11 14:13:44 -08:00
Adrian Roos
ef420e9754 API: Clean up redundant and ineffective usages of SystemApi and TestApi
Everything that is marked SystemApi or TestApi, but not @hide is still
part of the public SDK, it is therefore not sound to have that combination.

In the future, specifing such a combination will be considered an error
to prevent inadvertently exposing SystemApi and TestApi as public API.

Bug: 115333477
Change-Id: Ibd5d6a22862fdbc1e20a1cb3925280f5a682edea
Test: METALAVA_PREPEND_ARGS="--error UnhiddenSystemApi" m checkapi
Exempt-From-Owner-Approval: API cleanup
2018-12-11 20:38:02 +01:00
Junyu Lai
83a52f5fb2 Merge "Refactoring of deleting stats in NetworkStats based on uids." am: c8dcfb8b4b am: 2d00948a0c
am: 2d79ef94f8

Change-Id: I29c57276424464afd54e184c369d30a5e9707f14
2018-12-10 03:10:15 -08:00
junyulai
6fe079615b Ignore ipv6 tx traffic on clat uid.
Currently, 464xlat counts its ipv6 tx traffic into root uid.
When user is making ipv4 upload over ipv6-only network, ipv4
tx traffic may sometimes be counted faster then ipv6 tx
traffic.

Thus, NetworkStatsService may detect non-monotonic values due
to 464xlat adjustment.

So the solution is that: for clatd, make ipv6 tx traffic counts
into clat uid, and then ignore it in the framework side.

Bug: 118602783
Test: 1. manually verify clatd traffic on clat uid.
      2. runtest frameworks-net

Change-Id: Ifb478b79e3e281918c70e16d1f90682c78f33db1
2018-12-10 15:19:03 +08:00
Junyu Lai
2d79ef94f8 Merge "Refactoring of deleting stats in NetworkStats based on uids." am: c8dcfb8b4b
am: 2d00948a0c

Change-Id: Icfe86f71f9416dcd5fcc9aafd8c346197cde7cff
2018-12-09 21:46:07 -08:00
junyulai
bbaddec5d7 Refactoring of deleting stats in NetworkStats based on uids.
In follow-up commits, current API would create new NetworkStats
every time when 464xlatAdjustment wants to filtered out some
uids.

This commit refactors it to delete stats in-place to get better
performance.

Bug: 118602783
Test: atest FrameworksNetTests
Change-Id: I858f95d1fa7733111786243b4e261ce8a70a068d
2018-12-06 19:01:17 +09:00
Benedict Wong
a041d6fb80 Merge changes from topic "xfrmi-support" am: f928c1e4b9 am: 719761f60c
am: 0cfc49485c

Change-Id: I9c543d38c88181b12cdbc7bdb93d7e38f1dfd425
2018-11-25 19:38:35 -08:00
Benedict Wong
0cfc49485c Merge changes from topic "xfrmi-support" am: f928c1e4b9
am: 719761f60c

Change-Id: I13a826f5ae3c4cb700be789b369848685da1bc41
2018-11-25 19:26:26 -08:00
Benedict Wong
5d74984c24 Add XFRM-I support to IpSecService
This change adds support for XFRM-I to all IpSecService netd calls.
Fallback logic is in netd, and thus both VTI and XFRM-I parameters are
always passed down to IpSecService.

Bug: 78589502
Test: All java, CTS tests passing
Change-Id: Ie4186f0ad7e50763b21831f6fa411b5ee436de78
2018-11-21 08:34:54 -08:00
Benedict Wong
683441d87a Disable attempted updating of SA marks
SA marks are never updated during the UPDSA call. This change disables
the attempts to update the specified SAs, ensuring that the config
stored in IpSecService matches that of the allocated kernel resources.

Bug: 111854872
Test: Unit, CTS tests passing
Change-Id: Ic1fb862c8021ffa260c3e262ec698d8af0a826d9
2018-11-21 08:34:54 -08:00
Junyu Lai
0ab82da19f Merge "Fix negative uid stats caused by 464xlat adjust when eBPF is on." am: 0d63da86e2 am: a38302f84f
am: fcb523e095

Change-Id: I9d0d8b67ed0159ba2a71059620ebe5698eb79ccb
2018-10-30 19:56:01 -07:00
Junyu Lai
fcb523e095 Merge "Fix negative uid stats caused by 464xlat adjust when eBPF is on." am: 0d63da86e2
am: a38302f84f

Change-Id: I3ee791e4b6fdd9d508807810183dc02c69bd2c0b
2018-10-30 19:46:18 -07:00