Commit Graph

622 Commits

Author SHA1 Message Date
junyulai
084485bcb9 Add 5G NSA to collapsed RAT types list
Currently, getAllCollapsedRatTypes is used to retrieve
all RAT types which will be recorded into NetworkStatsService.
However, there is a missing part that 5G NSA virtual RAT type
is not added into this list. This makes callers such as statsd
do not aware of 5G NSA RAT type and missed to collect data
usage of it.

Test: atest NetworkStatsSubscriptionsMonitorTest#test5g
Test: adb shell cmd stats pull-source 10082
Test: ./out/host/linux-x86/bin/statsd_testdrive 10082
Test: atest UidAtomTests#testMobileBytesTransfer \
      UidAtomTests#testMobileBytesTransferByFgBg \
      UidAtomTests#testDataUsageBytesTransfer
Bug: 163021464
Change-Id: I0faeda20f0506a48ac1131b234c5fc40d95dfbe0
Merged-In: I0faeda20f0506a48ac1131b234c5fc40d95dfbe0
(cherry-picked from ag/12355984)
2020-08-12 10:12:48 +00:00
junyulai
064b6915aa Add getAllCollapsedRatTypes to NetworkTemplate
This is a partial cherry-pick of ag/10293594

Test: TH
Bug: 129082217

Merged-In: I726e74f5c63a6ed456cb13ea259b58c7a33bec76
Change-Id: I726e74f5c63a6ed456cb13ea259b58c7a33bec76
2020-08-12 18:01:13 +08:00
Pavan Kumar M
f4e77ac570 Gracefully handle integer overflows.
Avoid recording negative data by doing integer-based
math as much as possible, but switch to double-based
math if we detect that we'd end up causing an overflow.

Test :

    - Builds, Boots
    - High data throughput scenarios
    - NetworkStatsHistoryTest, NetworkStatsCollectionTest,
      NetworkStatsTest

Bug: 119527458
Change-Id: I55d4aa649bea3ae201ad513074ff2b71cb918dad
2020-07-28 11:36:49 +05:30
junyulai
7fd64dee0f 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 18:22:09 +08:00
Robin Lee
6bdfba28ab ITetheredInterfaceCallback is a oneway interface
This is sent from the system server, and the system server doesn't like
being blocked by apps.

Change-Id: I603be3038831974baf1dc392ff0d062e9db91b63
Test: atest CtsTetheringTest
Bug: 160389275
2020-07-02 17:59:28 +02:00
Maciej Żenczykowski
d03416842c 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
2020-05-28 01:47:30 -07:00
Maciej Żenczykowski
7c8b7b14ea NetworkStats: apply464xlatAdjustments - remove useBpfStats parameter.
Test: atest NetworkStatsTest NetworkStatsFactoryTest
Bug: 150738490
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0121a4ac7ee824adc5930bab786d550b2f00b05b
2020-05-28 01:33:25 -07:00
Maciej Żenczykowski
7b964ba2c0 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
2020-05-28 00:26:17 -07:00
junyulai
110e2b8da4 [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
2020-04-01 16:46:08 +08:00
Lorenzo Colitti
0cd8f32e1d Merge "Make Ethernet interfaces more testable." 2020-03-19 11:12:09 +00:00
junyulai
f6f863428e [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 1227f32c58 and
 fix merge conflict in SettingsBackupTest)
2020-03-19 10:10:07 +08:00
junyulai
b2067520a2 [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 8413d3c1af)
2020-03-19 10:10:07 +08:00
junyulai
d83a0e0d1e [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 82d9f7cbb0)
2020-03-19 10:10:07 +08:00
junyulai
55962ad9cb [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 96105f0d21)
2020-03-19 10:10:07 +08:00
Lorenzo Colitti
187a7b1ad8 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
2020-03-19 09:46:37 +09:00
junyulai
4ceb6470bd [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
Merged-In: I9495a198cf247e6c79100f7ac1edcea370b071de
(cherry picked from ag/10700816)
2020-03-18 00:29:15 +00:00
junyulai
f27a3cd08f [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
2020-03-16 14:27:45 +08:00
junyulai
05b2fc2283 [SP23] Address misc API review comment about NetworkStats
This change add several javadoc for NetworkStats and its Entry
class. Also remove IFACE_ALL constant accordlingly.

Test: atest FrameworkNetTests
Test: m doc-comment-check-docs
Bug: 148895143
Change-Id: Id1b8f41be79f847ad73197ff0e18258b6ee8a730
2020-03-16 14:27:45 +08:00
junyulai
6b65a8484b [SP21] Address comments for API council review about aosp/1172143
Test: atest FrameworksNetTests ImsPhoneCallTrackerTest
Test: atest TetheringTests NetworkStackTests
Test: m doc-comment-check-docs
Fix: 148552904

Change-Id: I141393f229e772d2eb9f7c156849e379bd71b845
2020-03-12 21:34:17 +08:00
Junyu Lai
60c2b54b11 Merge changes from topic "sp20-stats-provider-permission"
* changes:
  [SP20] Check signature permission when accessing network stats provider
  Add permission check functions to NetworkStatsService
2020-03-12 08:19:24 +00:00
Remi NGUYEN VAN
f94a6010c0 Add missing RequiresPermission to EthernetManager
The method requires NETWORK_STACK or MAINLINE_NETWORK_STACK permissions,
but the annotation was missing.

Test: m
Fixes: 150877670
Change-Id: I2af74cbcfa642f05f5e7bf85b2a8e8c38595f6ca
2020-03-09 14:18:55 +09:00
Automerger Merge Worker
d139692366 Merge "Fix crash and duplicated ethernet tethering request" am: 41c82c99df
Change-Id: Idd4eca225909f88ef6d57fd8952ae497ec82115b
2020-02-28 02:49:58 +00:00
markchien
e3576345d6 Fix crash and duplicated ethernet tethering request
This change fix two things:
1. Handle ethernet callback in internal thread to avoid crash. IpServer
should be created from tethering thread, otherwise mIpNeighborMonitor of
IpServer would throw
   IllegalStateException("start() called from off-thread")
2. Ethernet tethering request may be duplicated if multiple
startTethering is called but no stopTethering

Bug: 130840861
Bug: 148824036
Test: ON/OFF ethernet tehtering manually
      atest TetheringTests

Change-Id: I7c5127e96d80d077735010d2e62c7227805ccb10
2020-02-27 14:50:16 +08:00
junyulai
1c20161672 [SP20] Check signature permission when accessing network stats provider
Currently, registerNetworkStatsProvider requires the
UPDATE_DEVICE_STATS permission. This is a privileged permission
so it can be granted to preinstalled apps. Thus, apps like
GmsCore, or preinstalled apps will be able to update network stats.

This change checks for a new permission that would only allow
signature apps to declare that. Also check
MAINLINE_NETWORK_STACK permission to allow NetworkStack process
to use it.

Test: adb shell dumpsys netstats
Test: atest FrameworksNetTests
Bug: 149652079
Change-Id: Idfebd0a1988c3dcfd812d87e30f6a2034d6fbf6b
2020-02-24 20:22:48 +08:00
Junyu Lai
9a035a6f07 Merge "[SP16] Address comments on aosp/1172143" am: 64f520db50
Change-Id: I9c826c08320e112466dea0d2628f3447ebcb7d02
2020-02-15 02:35:42 +00:00
junyulai
0d16cdde0f [SP16] Address comments on aosp/1172143
Test: atest FrameworksNetTests
Test: atest NetworkPolicyManagerServiceTest
Test: m doc-comment-check-docs
Bug: 130855321
Change-Id: Iccaab09f5b9668ec4a7249737c64a69cecb08d15
2020-02-14 16:53:40 +08:00
Benedict Wong
b370dc111c Merge "Implement Ikev2VpnRunner" am: 08d5c632c3
Change-Id: I9b966b52f78fa54dca9d8c3032ec26ed853ad572
2020-02-13 21:31:28 +00:00
Benedict Wong
08d5c632c3 Merge "Implement Ikev2VpnRunner" 2020-02-13 21:15:24 +00:00
Benedict Wong
514983cc3e Implement Ikev2VpnRunner
This change adds the implementation for IKEv2/IPsec VPNs.

Bug: 144246767
Test: Manually tested
Change-Id: I5ccec756cec49ccf57ccc4d5ad800eeb5d595a76
Merged-In: I5ccec756cec49ccf57ccc4d5ad800eeb5d595a76
2020-02-13 18:37:06 +00:00
Automerger Merge Worker
730d964d04 Merge "Fix incorrect interpolation of active bucket for partial requests." am: 740fb7e003
Change-Id: Ibfaf1e3d13ce758323c30381ba44702b6016d9eb
2020-02-13 07:53:18 +00:00
Maciej Żenczykowski
740fb7e003 Merge "Fix incorrect interpolation of active bucket for partial requests." 2020-02-13 07:37:57 +00:00
Automerger Merge Worker
5afc0ef0ff Merge "[SP10] Add IntDef annotations for system api of NetworkStats" am: de345df19b
Change-Id: I4d352ed54671ce77ebbcaa9f0808a0ef703d3c6f
2020-02-12 04:54:02 +00:00
Treehugger Robot
de345df19b Merge "[SP10] Add IntDef annotations for system api of NetworkStats" 2020-02-12 04:37:55 +00:00
junyulai
950d79e145 [SP10] Add IntDef annotations for system api of NetworkStats
Test: m -j
Bug: 130855321
Change-Id: I8855ec95d5d086fc14e2eb71558bc2dcd9a830e5
2020-02-11 09:47:03 +00:00
Automerger Merge Worker
c2263368f8 Merge changes Iaa6f0d65,I68a16b64 am: 744d94b96f
Change-Id: I687e59f2c25d5c5e2cb5b1574dbcf6f32ec8c817
2020-01-31 16:37:49 +00:00
David Su
744d94b96f Merge changes Iaa6f0d65,I68a16b64
* changes:
  Networking: Rename removeDoubleQuotes to sanitizeSsid
  Wifi: Rename removeDoubleQuotes to sanitizeSsid
2020-01-30 22:42:16 +00:00
Lorenzo Colitti
11b91ef861 Merge changes I34842acd,Icc6c4d6b
am: 06fea00173

Change-Id: I38f5452905216ebf9e0b28311d34ad0667243274
2020-01-28 02:53:38 -08:00
Remi NGUYEN VAN
07b469658f Add support for Ethernet tethering
Ethernet tethering can be started via
startTethering(TETHERING_ETHERNET).

Test: flashed, enabled ethernet tethering, verified internet access on
      downstream.
Bug: 130840861

Merged-In: I34842acd94b972e440c3622f7617df10c18acf65
Change-Id: I34842acd94b972e440c3622f7617df10c18acf65
(cherry-pick with conflicts in test-current.txt)
2020-01-28 17:52:06 +09:00
Remi NGUYEN VAN
f151eb517c Merge "Support putting one Ethernet interface in server mode."
am: e7e38501e8

Change-Id: Ib1c26821880daa118b1911d4f98ebbd970c3c1b4
2020-01-28 00:37:20 -08:00
Lorenzo Colitti
22a02a7422 Support putting one Ethernet interface in server mode.
requestTetheredInterface can be used to put an interface in server mode,
which will persist until release() is called on the returned request, or
until the requesting process dies.

Test: Enabled ethernet tethering with change on top
Bug: 130840861
Merged-In: Id96d581acb3fa4e52ca62dd94ec257f56bd3a1ce
Change-Id: Id96d581acb3fa4e52ca62dd94ec257f56bd3a1ce
(clean cherry-pick from internal branch)
2020-01-28 16:25:43 +09:00
Maciej Żenczykowski
c359926d90 Fix incorrect interpolation of active bucket for partial requests.
Just because the bucket is active (ie. overlaps with 'now') doesn't
mean the request necessarily covers the entire bucket.

For example a bucketDuration=5 with a bucket from curStart=1 to
curEnd=6 with now=4 and requests:
- from start=0 to end=3 --> overlap=[1,3] --> bucketSpan=2
- from start=2 to end=3 --> overlap=[2,3] --> bucketSpan=1
- from start=2 to end=5 --> overlap=[2,4] --> bucketSpan=2
- from start=2 to end=7 --> overlap=[2,4] --> bucketSpan=2
and the previously correctly handled cases:
- from start=0 to end=5 --> overlap=[1,4] --> bucketSpan=3
- from start=0 to end=7 --> overlap=[1,4] --> bucketSpan=3

We fix this by bounding the end of buckets to now, this means
that bucketDuration is no longer a constant, but it simplifies
all the rest of the logic.

Test: builds, atest
Bug: 143338233
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I642b57f7b8486071ad7808fd9b901859923b6d25
2020-01-27 18:39:15 -08:00
David Su
b13338a8e3 Networking: Rename removeDoubleQuotes to sanitizeSsid
Bug: 145745815
Test: compiles
Change-Id: Iaa6f0d65cab556c24b0a9010427de8e6a02836c1
Merged-In: Iaa6f0d65cab556c24b0a9010427de8e6a02836c1
(clean cherry-pick from internal branch)
2020-01-27 13:51:56 -08:00
Xin Li
a4b9008f4c DO NOT MERGE - Merge qt-qpr1-dev-plus-aosp-without-vendor (6129114) into stage-aosp-master
Bug: 146167222
Change-Id: Ifeb003ec9b3bf824f04d31a117aea65d517241fb
2020-01-15 16:15:41 -08:00
junyulai
0935e710d7 [SP03] support registerNetworkStatsProvider API
am: b3f085c5a8

Change-Id: Id3a21676b6063048124c54035207a1c070df7a8c
2020-01-13 06:12:41 -08:00
junyulai
99dc88756d [SP03.1] Replace com.android.internal.util.Preconditions.checkNotNull
am: 892e3bf7b6

Change-Id: I17550a2191ccd33a53a195df3cd178d93fbfe952
2020-01-13 06:12:31 -08:00
Junyu Lai
9ccc0c05d8 Merge changes from topic "sp04"
* changes:
  [SP05] add unit test for onStatsProviderLimitReached in NPMS
  [SP04] add unit test for NetworkStatsProvider
  [SP03] support registerNetworkStatsProvider API
  [SP03.1] Replace com.android.internal.util.Preconditions.checkNotNull
2020-01-13 14:09:52 +00:00
Artur Satayev
ea0a0c347f Use new UnsupportedAppUsage annotation.
Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library.

Bug: 145132366
Test: m && diff unsupportedappusage_index.csv
Change-Id: I534e3fd1305e2f4af076986770033478448a665c
Merged-In: I534e3fd1305e2f4af076986770033478448a665c
2020-01-13 12:39:59 +00:00
junyulai
b3f085c5a8 [SP03] support registerNetworkStatsProvider API
This change provides an API that allow external modules to
register a custom provider of NetworkStats to merge the
network statistics that cannot be seen by the kernel to system.

Test: atest FrameworksNetTests CtsUsageStatsTestCases
Test: atest NetworkPolicyManagerServiceTest
Test: m doc-comment-check-docs
Bug: 130855321

Change-Id: I265bc637c40666cde505fde5056d2d9bfc5fb204
2020-01-13 14:43:03 +08:00
junyulai
892e3bf7b6 [SP03.1] Replace com.android.internal.util.Preconditions.checkNotNull
Extracted from ag/9990011 to make NetworkStatsManager sync with internal
line, given that it is missing in aosp/1198084.

Bug: 126528330

Test: Treehugger
Change-Id: I77f50326869799f51d4636cb7c6d7c97daf531e6
Merged-In: I42117ebfb640e3b0b133183e5e146860bed8471a
2020-01-13 14:42:37 +08:00
Automerger Merge Worker
4605390760 Merge "Allow mainline IPsec(IKE) to statically include @PolicyDirection" am: 287b253564 am: b5189ed2d9
Change-Id: I40382746ab54ed21fe9d8fc68b2c81bdf2b4e464
2020-01-10 00:16:11 +00:00