Commit Graph

1493 Commits

Author SHA1 Message Date
Chiachang Wang
41c49d1a8e Merge "Enforce NETWORK_STACK permission for calling NSS#forceUpdateIfaces" 2019-04-10 02:27:30 +00:00
Benedict Wong
dcd06394d4 Merge "Fix remove-before-add for IpSecService RefcountedResource" 2019-04-09 17:22:56 +00:00
Chiachang Wang
f04137e99e Enforce NETWORK_STACK permission for calling NSS#forceUpdateIfaces
ConnectivityManager and its usages are removed from
NetworkStatsService. After that, forceUpdateIfaces requires
information that only ConnectivityService has, hence
restricting the calling permission to NETWORK_STACK or
MAINLINE_NETWORK_STACK permission. The required permission
will be changed from READ_NETWORK_USAGE_HISTORY to
NETWORK_STACK or MAINLINE_NETWORK_STACK. This change would make
it impossible to call outside the system.

Bug: 126830974
Test: atest FrameworksNetTests
Change-Id: I776484921b2dbb6735d7940c558fb5e4baed6d1e
2019-04-09 19:42:52 +08:00
Benedict Wong
04738f5b07 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
2019-04-08 18:51:50 -07:00
Treehugger Robot
c452cbf496 Merge "Move NetworkStatsFactory into service directory" 2019-04-05 19:27:22 +00:00
Lorenzo Colitti
066b321400 Merge "Fix flaky UdpEncapsulationSocket test" 2019-04-04 08:09:06 +00:00
Benedict Wong
29c3077ce0 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
2019-04-03 17:52:03 -07:00
Chenbo Feng
45fff45471 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
2019-04-03 11:33:40 -07:00
Varun Anand
ed2eb961e8 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.
2019-03-29 00:40:53 +00:00
Varun Anand
720133f79d 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
2019-03-28 10:31:51 -07:00
Varun Anand
c8dbdf35de 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
2019-03-28 10:31:49 -07:00
Andrei-Valentin Onea
60eacd60d1 Merge "Add @UnsupportedAppUsage annotations" 2019-03-22 13:12:41 +00:00
Andrei Onea
8841fd2f13 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
Merged-In: I9c2f8347952f3cc65759472b0e1a2717b285e44e
Change-Id: I14793863cf815fa3383fec6c6bf5a9365c2e17eb
2019-03-22 11:43:11 +00: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
Brett Chabot
97342bd4e5 Migrate frameworks/base/tests/testables and its users to androidx.test
See go/jetpack-test-android-migration

Test: atest TestablesTests NetworkStackTests FrameworksServicesTests SystemUITests FrameworksUiServicesTests ExtServicesUnitTests
Exempt-From-Owner-Approval: already reviewed
Change-Id: I083fcdaa71b503535aa2b3c257740f3ecf055373
Merged-In: Ib04d80954bd8536914d88c66b28e6632e60a6245
2019-03-01 17:23:42 +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
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
Xin Li
38b1a2d9df DO NOT MERGE - Merge pi-platform-release (PPRL.190205.001) into
stage-aosp-master

Bug: 124234733
Change-Id: Ic4f67fde0835da0b1c363906cccef0d244e38393
2019-02-14 09:48:06 -08:00
android-build-team Robot
4a44ee4a83 Snap for 5180536 from 1fc6d8adf1 to pi-platform-release
Change-Id: I7c5a9c9e96572c32eadd97448c4886f9c9150a19
2019-02-09 02:33:11 +00:00
Remi NGUYEN VAN
e4675dcaab Merge "Remove last NetworkStack usage of hidden APIs"
am: 16ec5d038c

Change-Id: I27c78d09938f672a4428a17436d5ed0541170d0d
2019-01-29 21:13:46 -08:00
Remi NGUYEN VAN
5db0919a0d Remove last NetworkStack usage of hidden APIs
Includes various small changes to stop using hidden APIs

Test: make NetworkStack
Test: flashed, booted, WiFi and tethering working
Bug: 112869080
Change-Id: Id2830795a444f484b377ed6437435a1cd833697a
2019-01-30 10:23:24 +09:00
Remi NGUYEN VAN
4d301b8d85 Merge "Add SocketUtils for NetworkStack"
am: d9cc11e8bd

Change-Id: I0db40afbf2de55d77d9d5493e556f499d2383f59
2019-01-28 21:19:36 -08:00
Nick Kralevich
7b51a98e96 Merge "jni: more O_CLOEXECs"
am: 0bd511611e

Change-Id: Id9eabfa92a488dbf7a27108aff8101d602e1adc9
2019-01-28 20:31:59 -08:00
Remi NGUYEN VAN
d9cc11e8bd Merge "Add SocketUtils for NetworkStack" 2019-01-28 23:14:08 +00:00
Nick Kralevich
cac3986f14 jni: more O_CLOEXECs
Prevent FDs from leaking across an execve() boundary.

Test: compiles and boots
Change-Id: I5f91046917b55b6abead0a5c6e939f82814e6f18
2019-01-28 10:39:10 -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
Chenbo Feng
03074c729f Merge "Use delta reads for per uid traffic stats"
am: 39de2905a5

Change-Id: I17faec2cc2a73e56d0f19abad32154b378857fc4
2019-01-24 10:55:09 -08:00
Chenbo Feng
39de2905a5 Merge "Use delta reads for per uid traffic stats" 2019-01-24 18:16:25 +00:00
Remi NGUYEN VAN
fef17fd05f Merge changes I1250730c,I7d00848c
am: e693d49c0a

Change-Id: I2f19490a2340bdc2630162dfe9a277dffc5041fa
2019-01-23 08:26:33 -08:00
Remi NGUYEN VAN
63e61c427d Move IpClient to NetworkStack
Test: atest FrameworksNetTests NetworkStackTests
Bug: b/112869080
Change-Id: I7d00848c052382cd1b6ce458868bed6a1e9e8ec5
2019-01-23 16:44:21 +09: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
junyulai
19ec97e903 resolve merge conflicts of da290bec0c5418e758b92abad7be8e729cf37d68 to stage-aosp-master
Bug: None
Test: I solemnly swear I tested this conflict resolution.

Change-Id: I719965f13d1f726fdac5b475fd8733b07e28f5b6
Merged-In: I3d94acb71c142ec38b750e58822881ff383341cc
2019-01-21 12:22:13 +00:00
Mike SU
3657ce9690 fix getIfaceStats and getTotalStats bug
root cause: getIfaceStats and getTotalStats is directly reading
iface_stat_fmt or eBPF, not include tether stats.
solution: add tether stats to getIfaceStats and getTotalStats.

Bug: 120039819
Test case1:
1. tether offload is enabled on phone, enable MHS on phone.
2. Use test app to check getMobileRxBytes->getIfaceStats
3. Download 10M file on MHS client
4. Use test app to check getMobileRxBytes->getIfaceStats again
result: getMobileRxBytes increased around 10M

Test case2:
1. tether offload is disabled on phone, enable MHS on phone.
repeat above step 2~4
result: getMobileRxBytes increased around 10M

Following CTS cases passed
run cts -m CtsNetTestCases --test android.net.cts.TrafficStatsTest
run cts -m CtsUsageStatsTestCases --test android.app.usage.cts.NetworkUsageStatsTest

Change-Id: I3d94acb71c142ec38b750e58822881ff383341cc
2019-01-10 12:16:25 -06:00
Chenbo Feng
37cec67bdc Merge "Adjust map names due to new bpfloader"
am: 0317e9e374

Change-Id: If97a15a7f7b6a066bbf46db3497270a8c9a81026
2019-01-09 10:53:22 -08:00
Treehugger Robot
0317e9e374 Merge "Adjust map names due to new bpfloader" 2019-01-09 18:34:49 +00:00
junyulai
ac828b9ad4 [automerger skipped] Merge "DO NOT MERGE: Revert: use legacy way to get tcp packet count"
am: a1e93d0a66 -s ours
am skip reason: subject contains skip directive

Change-Id: I3b55e5cac6168719dc586013707c8d270b148206
2019-01-08 21:19:09 -08:00
Treehugger Robot
a1e93d0a66 Merge "DO NOT MERGE: Revert: use legacy way to get tcp packet count" 2019-01-09 05:10:05 +00:00
junyulai
579bf97659 DO NOT MERGE: Revert: use legacy way to get tcp packet count
In Q, legacy way to get tcp packet count is not planned to be
supported. Users who use this unsupported API e.g., data stall
detection are also planned to be removed.

Thus, this change reverts 0b4a66a1c2 which is the short term
solution in P.

Bug: 110443385
Test: atest FrameworksNetTests
Change-Id: Ia09f908edbf194b9aa873a3bdd5aee7b6fcb16bc
2019-01-09 10:38:32 +08: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
9c0075aad0 Merge "Ignore ipv6 tx traffic on clat uid."
am: 191f32fdc7

Change-Id: I181c3c812caa9bcd359fbddf74d14adeb7e83419
2019-01-04 08:13:29 -08:00
Junyu Lai
191f32fdc7 Merge "Ignore ipv6 tx traffic on clat uid." 2019-01-04 09:29:10 +00:00
Xin Li
c8c0caf117 [automerger skipped] Merge "DO NOT MERGE - Merge pie-platform-release (PPRL.181205.001) into master"
am: ab3b396c45  -s ours

Change-Id: I7710a0b1a5ba1bf7acd45d694818aec91853e546
2018-12-13 12:47:28 -08:00
Xin Li
964a5fb469 [automerger skipped] DO NOT MERGE - Merge pie-platform-release (PPRL.181205.001) into master
am: 6f9c73f8c9  -s ours

Change-Id: I60ae19c5ff7d5de669fac1ebd93d48283d9f27d8
2018-12-13 11:18:53 -08:00
Chenbo Feng
76b4d2fba2 Merge "Delete unused import"
am: e726c2654d

Change-Id: I8249bd4340b6e6e2e0a4fa687207198b534168b1
2018-12-12 22:18:40 -08: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
Chenbo Feng
f9eff38d9b Delete unused import
The hasBpfSupport() check from BpfUtils is not used by the native helper
in framework. Remove them.

Bug: 111441138
Test: Build without failure.
Change-Id: Icdd01bf1a03efd7883e4939d0d730303ec1004e7
2018-12-13 00:46:20 +00:00
Adrian Roos
ee2ba33204 Merge "API: Clean up redundant and ineffective usages of SystemApi and TestApi"
am: af0e1c2fa5

Change-Id: I016cacee1e1de6c7a8269fc3605ed25716598d9e
2018-12-12 08:33:17 -08: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