Commit Graph

2161 Commits

Author SHA1 Message Date
android-build-team Robot
83ab94e48d Snap for 6690197 from 3affbe4d9f964d5ac060e265f331cafe2a4798a9 to rvc-release
Change-Id: Iff50afbc6d986908a3a16c7c79d1c8aa9a7af3ce
2020-07-18 01:02:10 +00:00
junyulai
fba76f64a6 Attribute data usage to virtual RAT type for 5G non-standalone mode
Test: atest NetworkStatsSubscriptionsMonitorTest#test5g
Bug: 160727498
Change-Id: I8753e68140c0993773017c9a49bd8a666a364071
Merged-In: I8753e68140c0993773017c9a49bd8a666a364071
(cherry-picked from ag/12167624)
2020-07-16 15:33:35 +08:00
android-build-team Robot
30eac99496 Snap for 6617762 from 7bf84ecb6a5ae5833891a6b90a221ed99294e6bb to rvc-release
Change-Id: I2601dfb3a00cd1fe368ae543efec586de69fba64
2020-06-23 01:07:43 +00:00
Michael Groover
3e045d41e1 Merge "Update docs for methods that require subscriberId" into rvc-dev 2020-06-22 19:30:10 +00:00
Michael Groover
3dae8b1b41 Update docs for methods that require subscriberId
In Android 10 additional restrictions were required to access the
subscriberId. The NetworkStatsManager has several methods that accept
a subscriberId of the mobile network for which usage should be queried.
This commit updates the docs for these methods to reference the new
access restrictions and offer null as an option to obtain the usage
for all mobile networks.

Fixes: 157871064
Test: m docs
Change-Id: I95c730c9418fced6312eb3ba4e0d69e6299f3ded
2020-06-19 19:48:07 -07:00
android-build-team Robot
da8a65a11b Snap for 6586393 from a840c1f3ea1e9c3cde2ee985212f80864ff1e8d7 to rvc-release
Change-Id: I2ee507de15484671c09c996a38d5a0a47564658e
2020-06-13 01:09:12 +00:00
Aaron Huang
da12e7f732 Add unit test for NetworkStatsSubscriptionsMonitor
Bug: 154080205
Test: atest FrameworksNetTests:com.android.server.net.NetworkStatsSubscriptionsMonitorTest
Change-Id: I4ef3f1ab2e5ea1322133edd80db3ccd0022e9c91
2020-06-09 00:40:36 +08:00
android-build-team Robot
f8e63dc156 Snap for 6538416 from 4911db037b82a92a30c0bed2ce01b7516c4f414a to rvc-release
Change-Id: I4f4c4465f8c042839083209d51b523e41d30f896
2020-05-29 01:02:11 +00:00
Maciej Żenczykowski
9d862381bb NetworkStats: apply464xlatAdjustments - don't remove CLAT_UID
This should no longer be needed after all the cleanups.

Test: atest NetworkStatsTest NetworkStatsFactoryTest
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I289d935f84b616ed857ef4c5a7427d57c282d00c
Merged-In: I289d935f84b616ed857ef4c5a7427d57c282d00c
2020-05-28 02:44:20 -07:00
Maciej Żenczykowski
c7d0224c75 NetworkStats: apply464xlatAdjustments - remove useBpfStats parameter.
Test: atest NetworkStatsTest NetworkStatsFactoryTest
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0121a4ac7ee824adc5930bab786d550b2f00b05b
Merged-In: I0121a4ac7ee824adc5930bab786d550b2f00b05b
2020-05-28 02:44:10 -07:00
Maciej Żenczykowski
5c9097c9e0 NetworkStats - no need for xt_qtaguid clat bw fixups
This is due to the previous addition of the ip6tables raw PREROUTING
drop rules for incoming ipv6 clat traffic pre-translation to ipv4.

Since we no longer double account, we no longer need these fixups.

Test: atest bpf_module_test clatd_test libbpf_android_test libnetdbpf_test
  netd_integration_test netd_unit_test netdutils_test
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia171b7797cdc99367064d0649bf1293c71579941
Merged-In: Ia171b7797cdc99367064d0649bf1293c71579941
2020-05-28 02:43:22 -07:00
Maciej Żenczykowski
d4ce044ad1 NetworkStatsService - xt_qtaguid non-ebpf - account stacked interface stats
Test: atest bpf_module_test clatd_test libbpf_android_test libnetdbpf_test
  netd_integration_test netd_unit_test netdutils_test
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I297fcad0a83bd8c32c0fa6c6a77d83b42cd8c428
Merged-In: I297fcad0a83bd8c32c0fa6c6a77d83b42cd8c428
2020-05-28 01:57:37 +00:00
android-build-team Robot
7c415dd66c Snap for 6492800 from 6688c811a265ea3266644833db6298a5cdb799ee to rvc-release
Change-Id: Ic6ac3408ca5355a7009e665dad35e2073651c391
2020-05-14 01:03:05 +00:00
android-build-team Robot
df3731afd3 Snap for 6488384 from 7cf3ea0f2bc94301bfd0871dc574a3dd64b3a086 to rvc-release
Change-Id: Iadc36ba1ffaa6e9b6ce1d266b3af59a48eb2b9fc
2020-05-13 01:13:36 +00:00
Junyu Lai
358fe14bce Merge "Use CopyOnWriteArrayList to store list of NetworkStatsProviderCb" into rvc-dev 2020-05-13 00:42:42 +00:00
TreeHugger Robot
d7aa055b61 Merge changes I37dd459d,I1959f308 into rvc-dev
* changes:
  Add tests for Tunnel, Transport mode application with released SPIs
  Use TransformRecord to get SPI instead of SpiRecord
2020-05-12 20:30:03 +00:00
Treehugger Robot
1d4d01a8a8 Use CopyOnWriteArrayList to store list of NetworkStatsProviderCb
In NetworkStatsService, mStatsLock will be held when
iterating through the provider list. This is to protect the list
from concurrent broadcast that triggered by
NetworkPolicyManagerService. This is not good since the binder
call is oneway, it does not make sense to block every
access to the providers.

This change also remove unuse variable and reduce verbose log.

Test: atest FrameworksNetTests TetheringTests
Bug: 150418178
Change-Id: If74e9f2ea597a0d5ae4668c3358bc687f342bbb5
Merged-In: If74e9f2ea597a0d5ae4668c3358bc687f342bbb5
(cherry picked from commit 5d8f96c6967d5b1a42ba374521078e75a9e6f187)
2020-05-12 11:36:03 +00:00
android-build-team Robot
6c5ee93463 Snap for 6477313 from 00f681a5827512248c79180a5fdb364f6140a660 to rvc-release
Change-Id: Ib9ad0f2e587d8fc6f5203b1c589ac135d1489a58
2020-05-09 01:14:12 +00:00
Benedict Wong
003c5c9807 Use TransformRecord to get SPI instead of SpiRecord
IpSecService.applyTunnelModeTransform() currently does not take an
SpiRecord instance, yet implicitly requires that the SpiRecord instance
is still alive based on the stored SpiRecord resourceId in
the TransformRecord's IpSecConfig.

This check is unnecessary, as the SpiRecord has been subsumed into the
TransformRecord, and the kernel resources are kept alive whether or
not the SpiRecord is still held by the user.

This allows users of the IpSecManager API to allocate short-lived SPIs
during the creation of an IpSecTransform, without having to keep track
of both of them (even though the SPI is no longer usable).

The TransformRecord.getSpiRecord() call is already used in
multiple other places in the same method.

Bug: 142072071
Test: New tests added, passing.
Change-Id: I1959f3080946267243564459ff4207647922566e
Merged-In: I1959f3080946267243564459ff4207647922566e
(cherry picked from commit 5258b1b82f39bf17e0751bcb94479464250aaec5)
2020-05-08 00:01:45 -07:00
Lucas Lin
55119e823e Broadcast ACTION_NETWORK_STATS_UPDATED in NetworkStatsHandler
There is a corner case which may cause the deadlock:
When NetworkStatsService tried to broadcast the intent,
NetworkStatsService was waiting for a lock which was hold by
ActivityManagerService. In the same time, ActivityManagerService
was waiting for ActiveService#startServiceInnerLocked() to get a
lock which was hold by ConnectivityService. ConnectivityService
was waiting for a lock which was hold by BatteryStatsImpl.
BatteryStatsImpl was waiting for a lock which was hold by
NetworkStatsService, and the lock was locked by
NetworkStatsService when NetworkStatsService tried to broadcast
the intent.

To prevent deadlock when broadcasting the intent in
performPollLocked(), move the intent broadcasting from
performPollLocked() to NetworkStatsHandler.

Bug: 150418178
Bug: 155155473
Test: 1. Create the second user and see if the device will
         do factory reset or not.
      2. Factory reset manually and see if there is a deadlock.

Change-Id: I80569cb4388beb3fd6cbf64a7885bccee8b1c53c
Merged-In: Icf88d3e7a38562ab15187f6c71bc8fb0486d37c0
(cherry picked from commit 3f8ab0350450202910ea702799570c538e96d5cd)
2020-05-08 02:59:28 +00:00
android-build-team Robot
6161ae6324 Snap for 6449986 from 4b42462c25f53a0b2738d4266d704b42d1f211a1 to rvc-release
Change-Id: Iab2ba4cf22c235596383b7cf8b505af0104603ec
2020-05-01 01:13:46 +00:00
Chiachang Wang
abfadbefef Filter debug entries for each vpn
NetworkStats calculation needs to filter out debug entries to
prevent over counting. While NetworkStatsFactory migrates data
usage over a VPN to the TUN network, NetworkStatsFactory does
not filter out debug entries per vpn which will cause debug
entries left and cause exception.

Bug: 152678151
Test: atest com.android.server.net.NetworkStatsFactoryTest
      and verify no exception
Change-Id: I3525edc385b07858b48c7add2d331c4b5a2e84ad
Merged-In: I3525edc385b07858b48c7add2d331c4b5a2e84ad
2020-04-30 02:39:15 +00:00
android-build-team Robot
2e3e72d638 Snap for 6440900 from 144788b5bb46b8ef52e9cd53b4d50e558e3d52e7 to rvc-release
Change-Id: I70cfc31e85c8497a91825a099852573d42aff086
2020-04-29 01:14:26 +00:00
TreeHugger Robot
0f3164c79d Merge "Enforce permission check in getUidStats function" into rvc-dev 2020-04-28 09:13:32 +00:00
Chenbo Feng
d80a6ed9e2 Enforce permission check in getUidStats function
The NetworkStatsService.getUidStats() currently doesn't have any
permission check to make sure unpriviledged apps cannot read the stats
of a different uid. It will protentially have security problem since
apps with ACCESS_NETWORK_STATS permission can directly calling into
NetworkStatsService and bypass the check in TrafficStats. Move the uid
check from TrafficStats to NetworkStatsService to fix the problem.

Bug: 129151407
Test: atest AppSecurityTests#testAppFailAccessPrivateData_full
Test: atest AppSecurityTests#testAppFailAccessPrivateData_instant
Test: atest android.app.usage.cts.NetworkUsageStatsTest
Test: atest NetworkStatsBinderTest

Change-Id: Iae85676cfe5f114da69ec278afc2c904bc907234
2020-04-27 18:38:56 +08:00
android-build-team Robot
704eca30df Snap for 6408188 from ff9701f94856b114a1e74e3bb6591c1e18413763 to rvc-release
Change-Id: I0eb357db7408b3e7596c74efa9d4bd4d3b09486c
2020-04-18 23:15:12 +00:00
TreeHugger Robot
fdbc50b386 Merge "Narrow access to getDataLayerSnapshotForUid()." into rvc-dev 2020-04-18 00:42:17 +00:00
android-build-team Robot
1be2fb4bdc Snap for 6398428 from bcb2d73e48ca3d4b1c14b85b055ba20103211896 to rvc-release
Change-Id: I0b5a894f5adc4f7fa731ce128432391d01cbe556
2020-04-16 01:02:25 +00:00
junyulai
f0fcc339c3 [SM10] Adopt helper class to monitor RAT type change per sub
Test: atest NetworkStatsServiceTest
Bug: 146415925
Change-Id: I45c3aa9046b316c8cd0943543d620a22e4afefd1
Merged-In: I45c3aa9046b316c8cd0943543d620a22e4afefd1
(cherry picked from commit 219faff07bdc58c14fe58fc525e86383db1f8167)
2020-04-15 10:30:49 +00:00
Jeff Sharkey
7bab8e86df Narrow access to getDataLayerSnapshotForUid().
This method is used in TrafficStats to obtain the snapshot for the
calling UID, so narrow it to only return data for that specific case.

We might be tempted to throw an exception or adjust the method
signature, but apps are using the raw AIDL in the greylist, so we
return them an empty NetworkStats if they ask about other UIDs.

Bug: 119672472
Test: manual
Change-Id: I3064630039f1d8473d6425dd663f17813a4ae3a1
2020-04-10 13:54:45 -06:00
android-build-team Robot
4caf0b45ef Snap for 6378851 from a23f461e1b75c50692c41e5eb4cb41e1922c9608 to rvc-release
Change-Id: I95095b7a4b626e3119f61e68a3e9de5355b740a3
2020-04-09 02:11:07 +00:00
junyulai
5d0d638f54 [SM09] Add helper class to monitor RAT type change per sub
In current design, Rat type change in NSS is only for default
subscription. This is only correct for single sim project.
However, it does not correct for multi-sim scenarios such as
CBRS or DSDS, given that all data usage will be attributed
to the Rat type of default sub.

Thus, add a helper class to monitor subscription change event,
and register/unregister dynamically for Rat type change for
every subscription.

Note that unit test of the helper class will be addressed
in follow-up patch.

Test: m -j
Bug: 146415925
Change-Id: I0055f6b55c209a073ce997fc7a144477f9db7069
Merged-In: I0055f6b55c209a073ce997fc7a144477f9db7069
(cherry picked from commit 306de26c138ec135846f2a74a952464cf00dce54)
2020-04-08 08:50:22 +00:00
android-build-team Robot
de7df19396 Snap for 6370344 from d5729ebc66f333af206c96e81f9e1c18129d7f83 to rvc-release
Change-Id: Ia051ce889de0ccce3eb4d428daee4e33d7f23046
2020-04-07 02:05:37 +00:00
junyulai
d81034383d [SP26.2] add a method in NetworkStats that removes empty entries
In current design, entries with zeros are preserved after
addition/subtraction. These entries are not very useful
and lead to difficulty of verifying the result of
addition/subtraction.

However, change the behavior in the original NetworkStats
is considered risky in current stage.

Thus, this change provide a function that could remove these
empty entries in tests.

Test: atest FrameworksNetTests
Bug: 152827872
Bug: 150644692

Change-Id: I40a76935d55712b8083ee1e17e137a8a4ef5e029
Merged-In: I40a76935d55712b8083ee1e17e137a8a4ef5e029
(cherry picked from commit 6c7bef3064dbe949b7b213036b8e70c125ddd343)
2020-04-06 02:18:50 +00:00
android-build-team Robot
4128dfbb7a Snap for 6357023 from a957475923108063af3ec244042df20b74cbb4f3 to rvc-release
Change-Id: Id122ed286906bb61dbb2310805eccca8a6122c73
2020-04-02 02:04:43 +00:00
android-build-team Robot
dd7d4c668f Snap for 6353066 from d9f9a8d70f9af4769cbdaab366285408dcf89e0e to rvc-release
Change-Id: Ia9e4d7125d6cbdb552b59ee81e27873c094550d5
2020-04-01 02:04:53 +00:00
TreeHugger Robot
8444a9440f Merge "[SM06] Collect mobile NetworkStats metrics by collapsed rat type" into rvc-dev 2020-04-01 01:12:41 +00:00
junyulai
eba72cd4ef [SM06] Collect mobile NetworkStats metrics by collapsed rat type
Test: adb shell cmd stats pull-source 10000~10003
      adb shell dumpsys netstats --uid
Bug: 129082217

Change-Id: I726e74f5c63a6ed456cb13ea259b58c7a33bec76
Merged-In: I726e74f5c63a6ed456cb13ea259b58c7a33bec76
(cherry picked from commit c82dfeb4225e1a8a17eedc969a90f921e0bf845c)
2020-03-31 09:25:27 +00:00
android-build-team Robot
756c7d52e4 Snap for 6348860 from 28fa2620497efc7b590d6e8eec5d3a11afaea48e to rvc-release
Change-Id: I1734224041e259bce83b032d83750cc1536d4ddb
2020-03-31 02:14:16 +00:00
Benedict Wong
3fafd684c5 Automatically set IPsec tunnel interface as up
This change makes IPsec tunnel interfaces automatically get brought up
once they are created. Originally this was considered to be an
additional safety check, as they would not be start routing traffic
until explicitly brought up. However, in the intervening time, the
NetworkManagementController now requires the NETWORK_STACK permission to
set an interface as up. Additionally, that call is a hidden API, and
thus not usable for use cases such as IWLAN.

Bug: 149348618
Test: FrameworksNetTests, CtsNetTestCases passing.
Change-Id: I55b63a748463a388e1e2991d2d5d6b3023545e60
Merged-In: I55b63a748463a388e1e2991d2d5d6b3023545e60
(cherry picked from commit 7c5704d177a903034ae1b6ae4800cc3b8457977a)
2020-03-25 06:14:13 +00:00
Automerger Merge Worker
fd266f85b6 Relax IPsec resource count restrictions.
IPsec resource counts were selected to be conservative, due to unknowns
about device capabilities. Since then, it appears that we no longer need
such stringent quotas, and this can be relaxed.

Bug: 152368091
Test: FrameworksNetTest passing
Change-Id: Id53d14e5698e5fcc410868424176b00350c7ae79
Merged-In: Id53d14e5698e5fcc410868424176b00350c7ae79
(cherry picked from commit 224699fc0b485dd75e6157a88f66a53d64e5a6fd)
2020-03-25 06:07:24 +00:00
android-build-team Robot
3b3529b5f4 Snap for 6314400 from 975130e08acdfb708338c99f92e45dd52b793afb to rvc-release
Change-Id: I9395826c82efad441bd953a3c757b4c9f0da081b
2020-03-20 02:08:32 +00:00
Lorenzo Colitti
8723291cee Make Ethernet interfaces more testable.
This CL adds a setIncludeTestInterfaces method to EthernetManager
that, when called, causes the Ethernet service to recognize and
manage test interfaces created by TestNetworkManager.

Bug: 150644681
Test: Tested by EthernetTetheringTest in same topic
Change-Id: I86eef7a93267f800dbfc8eafd307effa76a344ca
Merged-In: I86eef7a93267f800dbfc8eafd307effa76a344ca
(cherry picked from commit 3410fb0aa92bbd4f9d7dc031e89f6f528ff34245)
2020-03-19 12:30:39 +00:00
junyulai
1e30781571 [SM07] Make combine subtype configurable from Settings
Note that enabling/disabling would not take effect until device
reboot. This will be addressed in follow-up patch.

Test: 1. atest NetworkStatsServieTest SettingsBackupTest
      2. adb shell settings put global netstats_combine_subtype_enabled 1|0
Bug: 146415925

Change-Id: Ic94da540afa479ed18f1b6fbda4ae3216c37476b
Merged-In: Ic94da540afa479ed18f1b6fbda4ae3216c37476b
(cherry picked from commit c4f77ac90bf2e48a655ad19b162fe74a23bf3fb0)
2020-03-19 01:40:55 +00:00
junyulai
dddf7d0a9a [SM05] Enable record mobile network stats by collapsed rat type
Switch on the recording in device side. Metrics will be
collected in follow-up patches which can be independently
enabled/disabled.

This change also fix the fail in NetworkStatsCollectionTest
which caused by enabling this feature, where the rounding
problem happened when records are distributed into smaller
buckets and categorized into more NetworkIdentity.

Test: atest FrameworksNetTests
Bug: 129082217
Change-Id: If330e85330a4ff713dd420c98d42fa741eabd90a
Merged-In: If330e85330a4ff713dd420c98d42fa741eabd90a
(cherry picked from commit 2d4fa2c0fae8c2d79a25093d9f732a33c2f91dd4)
2020-03-18 08:08:01 +00:00
junyulai
00d94e3335 [SM04] Support fetching data with NetworkTemplate with subType
Add a NetworkTemplate build function that allows user to specify
subType. NetworkStats corresponding to the same group would
be retrieved.

Test: atest FrameworksNetTests
Bug: 129082217

Change-Id: Ie2d229be0b6bd239f799989c070475c73a096d71
Merged-In: Ie2d229be0b6bd239f799989c070475c73a096d71
(cherry picked from commit e19045cc4ab1f2cd133ce5dc0c3a38e3275417ad)
2020-03-18 08:07:12 +00:00
junyulai
825f0828ac [SM02] Support record mobile network stats by collapsed rat type
Previously network stats could be recorded by different rat type.
However, the feature was disabled by ag/173504 since rat type
frequently flapping between HSPA+ and UMTS.

Given that this feature might be useful for collecting metrics,
re-implement it based on current architecture and reduce the
overhead introduced by frequently flapping by:
  1. only react when rat type changes between 2G/3G/4G/5G.
  2. reduce the number of records by only recording a subset
     of rat type that represented for a given network class.
  3. enforce 1 second rate limit if flapping too much.

Note that the feature is still disabled but will be enabled
in follow-up patches.

Test: manual test
Bug: 129082217
Change-Id: Ic6b2f10f2c8b082820e0662eb9cee70d70d28cd6
Merged-In: Ic6b2f10f2c8b082820e0662eb9cee70d70d28cd6
(cherry picked from commit 15ab452e7e3f00289fbedbdb86c512ad560dda7e)
2020-03-18 07:59:44 +00:00
android-build-team Robot
b506297680 Snap for 6305839 from 099628bfe626a770516a319d6e056065ee89dac8 to rvc-release
Change-Id: I47ab1b00b2d3da5651e9387b761b2a406675594a
2020-03-18 02:01:54 +00:00
junyulai
544bc807a4 [SP25] Rename functions that add Entry conditionally
Currently, in NetworkStats, there are many methods to manipulate
the records. However, some methods are similar and ambiguous,
such as addEntry, addValues, setValues, addIfaceValues,
combineValues and combineAllValues.

Thus, properly grouping and renaming methods are necessary.
In this change, for methods that add one record conditionally,
name them addEntry.
  addValues -> addEntry

Test: atest FrameworksNetTests ImsPhoneCallTrackerTest TetheringTests
Fix: 148895143
Change-Id: I9495a198cf247e6c79100f7ac1edcea370b071de
2020-03-17 14:59:59 +00:00
junyulai
02a6340ca0 [SP24] Rename functions that add Entry unconditionally
Currently, in NetworkStats, there are many methods to manipulate
the records. However, some methods are similar and ambiguous,
such as addEntry, addValues, setValues, addIfaceValues,
combineValues and combineAllValues.

Thus, properly grouping and renaming methods are necessary.
In this change, for methods that add one record unconditionally,
name them insertEntry.
  setIfaceValues -> insertEntry
  addEntry -> insertEntry

Test: atest FrameworksNetTests ImsPhoneCallTrackerTest TetheringTests
Test: m doc-comment-check-docs
Bug: 148895143
Change-Id: I801ddc49e283a254b9586700c9b597c0adb0d459
Merged-In: I801ddc49e283a254b9586700c9b597c0adb0d459
(cherry picked from aosp/1256352)
2020-03-17 14:59:31 +00:00