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)
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)
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
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
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
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)
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
Merged-In: Id1b8f41be79f847ad73197ff0e18258b6ee8a730
(cherry picked from aosp/1256351)
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: Iaecbf10a7610461bd52e315659006c7332c416e6
Merged-In: Iaecbf10a7610461bd52e315659006c7332c416e6
Merged-In: Idfebd0a1988c3dcfd812d87e30f6a2034d6fbf6b
(cherry picked from commit e9e8d8f9ff096c1723eba1d74b17bb7cade7f23b)
This is shameless copied from ConnectivityService and plan to be
used in follow-up change. For long term perspective we should
have a permission util that contains those util in one place.
Test: m -j
Change-Id: If70e6e831c0386b604d0151cc0650f68457b6e5f
Merged-In: If70e6e831c0386b604d0151cc0650f68457b6e5f
Merged-In: I837545b54f36c8f21c878cbb1fd028ff23be6cb8
Bug: 149652079
(cherry picked from commit 4da7af7e7e4a0d3360cd41e98e4d6fa731d21515)
The method requires NETWORK_STACK or MAINLINE_NETWORK_STACK permissions,
but the annotation was missing.
Test: m
Fixes: 150877670
Merged-In: I2af74cbcfa642f05f5e7bf85b2a8e8c38595f6ca
(cherry picked from commit e45d3ff849695977cb063cc59550c505b220bd6c)
Change-Id: Ia215b74df99ae60be2e380917be68a272d658ef4
=====
Remove the need of accessing handler in NSS unit test
Currently, to wait for handler becomes idle, specific message
is used and the test would wait for condition variable to be
open when the message is processed.
However, this is already done in the HandlerUtils. Thus,
there is no need to post such message manually in the handler.
Test: atest FrameworksNetTests
Bug: 150664039
Change-Id: Iab32b2dbab01634ca159dcb90fc9f929d1fed1a2
=====
Remove setHandler in NetworkStatsService
Currently, internal handler is set by setHandler after
constructing NSS object. This was introduced in ag/866187 to
access the handler in the unit test.
However, the design put NSS in a bad situation where all classes
that need handler or executor could not be final and need to be
dynamically allocated in order to get a valid handler.
Thus, since the usage of handler is removed in previous patch,
this change eliminate setHandler by initializing the handler in
the constructor.
Test: atest FrameworksNetTests
Bug: 150664039
Change-Id: I794a24d00b0ca9fdc78091e7b9ab7307e0f034b7
=====
Bug: 150664039
Change-Id: If256ed4437ddcbcc72a6f766cff2f4cc512ee3f7
Merged-In: If256ed4437ddcbcc72a6f766cff2f4cc512ee3f7
(cherry picked from commit 2a6439d7e2a3926e10a0b9a4dc730b1a022d8138)
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: Ibd3ea6bc6751bd65647ff381f9b0124bc3395c09
Merged-In: I7c5127e96d80d077735010d2e62c7227805ccb10
Merged-In: Ibd3ea6bc6751bd65647ff381f9b0124bc3395c09
(cherry picked from commit 72702b979654234c18045f04270040056a74cf90)
From current design, the traffic accounted by stats providers
will be updated asynchronously when force polling. When upper
layer make two subsequently queries. They will get stale
stats upon the first query, and may get newest/stale stats
base on the result of race.
Thus, wait for a bit of time to allow asynchronous stats update
complete to reduce the chance of race. In pratice, it would
be finished in ~2ms when testing.
Test: systrace.py network
Test: atest FrameworksNetTests
Bug: 147460444
Change-Id: I22a00fc4049cddf77fd578e25769ae1979f2cc6d
Currently NetworkStatsService holding a lock when invoking
getVtDataUsage, which causes a lot of deadlock problems since
Phone will also have binder calls to system_server.
Thus, this change uses a new set of API to break such situation,
that allows VT to report stats asynchronously.
Test: atest FrameworksNetTests FrameworksTelephonyTests
Bug: 130855321
Fix: 143923500
Change-Id: Ifdb8599c3bade09208b4730710fc99da1afad71d