Commit Graph

748 Commits

Author SHA1 Message Date
Automerger Merge Worker
6c530816c0 Merge "[SP01] Add NetworkStats to system API" am: a113464439 am: b340068a3e am: cc0ae82905
Change-Id: I1bb272727cbaec0102669b3f3b8141994f8e1f9a
2020-01-09 09:37:50 +00:00
junyulai
55041a4ad2 [SP01] Add NetworkStats to system API
In order to let external module report their network stats,
expose necessary APIs to construct NetworkStats object.

Test: atest FrameworksNetTests CtsUsageStatsTestCases
Test: m doc-comment-check-docs
Bug: 130855321
Change-Id: Id3ec8aaff3df67948c25eac2319a74cf33a27979
2020-01-09 03:11:22 +00:00
Maciej Żenczykowski
ed3ee3702b minor change to keep it building
This is part of 3 commits in 3 diff git repos, the main one is:
  https://android-review.googlesource.com/c/platform/system/netd/+/1200479
  "share eBPF struct definitions between ebpf and C++ netd"

as a side effect of which 'android::bpf::Stats' becomes simply '::Stats'

Test: builds
Bug: 146787904
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8548b27d1d8a7938f96c9fd9a185dae882e406f6
2020-01-06 23:25:49 +00:00
Automerger Merge Worker
6b709bab9b Merge "convert 'Stats stats; memset(&stats, 0, sizeof(Stats));' to 'Stats stats = {};'" am: 30bf98b239 am: d872904d2c am: 166e658c00
Change-Id: I270c321969d85ff5ae97627a6ecdb9c70d668247
2020-01-06 15:33:26 +00:00
Automerger Merge Worker
380559e9b8 Merge "remove spurious 'struct' on Stats" am: fa88e27173 am: 39b66243ee am: 16605fc29d
Change-Id: I7d6cb9ec24cb3012f445a46c746c5f8009bacc35
2020-01-06 15:32:32 +00:00
Treehugger Robot
30bf98b239 Merge "convert 'Stats stats; memset(&stats, 0, sizeof(Stats));' to 'Stats stats = {};'" 2020-01-06 14:12:26 +00:00
Treehugger Robot
fa88e27173 Merge "remove spurious 'struct' on Stats" 2020-01-06 14:12:21 +00:00
Tobias Thierer
190a471c2c Merge "Replace com.android.internal.util.Preconditions.checkNotNull with java.util.Objects.requireNonNull" 2020-01-03 17:53:55 +00:00
Daulet Zhanguzin
c120601182 Replace com.android.internal.util.Preconditions.checkNotNull with
java.util.Objects.requireNonNull

Bug: 126528330

Test: Treehugger
Exempt-From-Owner-Approval: Global refactoring.
Change-Id: Idb1b6ba41af3b52f3376b1157259af3c30328c4e
2020-01-03 17:53:30 +00:00
Automerger Merge Worker
c67821916c Merge "Replace com.android.internal.util.Preconditions.checkNotNull with java.util.Objects.requireNonNull" am: 2ee360b058 am: 5727033c3a am: af83fe4801
Change-Id: I54b4c3268878a10583dc6a4cf07f07588f0ca6cf
2020-01-03 16:31:22 +00:00
Daulet Zhanguzin
4461754bd5 Replace com.android.internal.util.Preconditions.checkNotNull with
java.util.Objects.requireNonNull

Bug: 126528330

Test: Treehugger
Change-Id: I978d5d0959f7800e859bfb384458ba52adc0c2b0
2020-01-03 14:42:32 +00:00
Maciej Żenczykowski
4421b2b9c2 convert 'Stats stats; memset(&stats, 0, sizeof(Stats));' to 'Stats stats = {};'
Not only is it more concise, but it's also just a tad more correct:
since it really should have been 'sizeof(stats)' not 'sizeof(Stats)'.

Test: builds, atest
Bug: 146787904
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6cf0295878c7b34cedfe3ae44ff7410ef419f8b9
2019-12-30 20:49:36 +00:00
Maciej Żenczykowski
3a4cc11de3 remove spurious 'struct' on Stats
Test: builds, atest
Bug: 146787904
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I824daf0ebdddbac1b11cabfcb248ee4134586768
2019-12-30 20:49:27 +00:00
Automerger Merge Worker
a8ebc95eb4 Merge "Update interface quota limit when network stats updated" am: 2dcf4c0227 am: a992b3aa83 am: 661741804d
Change-Id: I118f05adf0d5fc4aa665d45b3896d898dfeb3924
2019-12-19 10:37:39 +00:00
junyulai
d7efd7ba07 Update interface quota limit when network stats updated
In previous design, interface quota limit does not changed
when network stats are updated. However, this is incorrect
today since there are some offloaded traffic that cannot
be seen by kernel. If the limit is not updated, the offloaded
traffic might still be able to use whole quota as if there is
no embedded traffic.

This change also removes the re-arm global alert after
advising persist threshold if not changed, given that it will
cause an additional alert while updating interface quota limit.

Bug: 145792619
Test: 1. atest NetworkStatsServiceTest
      2. atest NetworkPolicyManagerServiceTest
      3. manual test: run speedtest, check dumpsys netd

Change-Id: I8d2203e713730d536430a234b1aa8b2468badee3
2019-12-18 10:57:29 +08:00
Jeffrey Huang
f9f6d87ced Rename writeToProto to be dumpDebug
We want to eventually migrate some of these APIs to be @SystemApi for mainline modules.
The #dumpDebug name is more appropriate than #writeToProto.

Bug: 142279786
Test: Manual
Change-Id: I60793e91cedf6b720d4ecef6a8484f4fed4ff30f
2019-12-05 11:28:11 -08:00
paulhu
a262cc1154 Replace the permission of internal connectivity checks
A number of connectivity checks that protect system-only methods
check for CONNECTIVITY_INTERNAL, but CONNECTIVITY_INTERNAL is a
signature|privileged permission. We should audit the permission
checks, and convert checks that protect code that should not be
called outside the system to a signature permission. So replace
all CONNECTIVITY_INTERNAL to other proper permissions.

Bug: 32963470
Test: atest FrameworksNetTests NetworkPolicyManagerServiceTest
Change-Id: I8f2dd1cd0609056494eaf612d39820e273ae093f
2019-12-04 11:45:51 +08:00
paulhu
6569cef6a6 Replace the permission of internal connectivity checks
A number of connectivity checks that protect system-only methods
check for CONNECTIVITY_INTERNAL, but CONNECTIVITY_INTERNAL is a
signature|privileged permission. We should audit the permission
checks, and convert checks that protect code that should not be
called outside the system to a signature permission. So replace
all CONNECTIVITY_INTERNAL to other proper permissions.

Bug: 32963470
Test: atest FrameworksNetTests NetworkPolicyManagerServiceTest
Change-Id: I8f2dd1cd0609056494eaf612d39820e273ae093f
Merged-In: I8f2dd1cd0609056494eaf612d39820e273ae093f
2019-12-04 11:44:45 +08:00
markchien
4686dd8958 [Tether07] Migrate Tethering into module
Now tethering would be run in dedicated service.
TetheringManager is the interface used to communicate with
TetheringService. The new call flow would be: ConnectivityManager
-> ConnectivityService -> TetheringManager -> TetheringService.
Note: the return value of #tether(), #untether() and #setUsbTethering()
APIs would always be no error. Client can use #getLastTetherError()
or #getTetheredIfaces or listen tether state change to check
status of corresponding interface.

Bug: 136040414
Bug: 144742179
Test: -build, flash, boot
      -atest TetheringTests
      -atest FrameworksNetTests

Change-Id: I7e78c0e0a3e70f940a749ba2a39ece7c7ec5b9b3
Merged-In: I7e78c0e0a3e70f940a749ba2a39ece7c7ec5b9b3
2019-11-30 10:03:08 +00:00
markchien
87f0b94f3b [Tether07] Migrate Tethering into module
Now tethering would be run in dedicated service.
TetheringManager is the interface used to communicate with
TetheringService. The new call flow would be: ConnectivityManager
-> ConnectivityService -> TetheringManager -> TetheringService.
Note: the return value of #tether(), #untether() and #setUsbTethering()
APIs would always be no error. Client can use #getLastTetherError()
or #getTetheredIfaces or listen tether state change to check
status of corresponding interface.

Bug: 136040414
Bug: 144742179
Test: -build, flash, boot
      -atest TetheringTests
      -atest FrameworksNetTests

Change-Id: I7e78c0e0a3e70f940a749ba2a39ece7c7ec5b9b3
2019-11-29 07:05:21 +00:00
Jayachandran C
270197bc8d Remove usage of Telephonymanager getDefault() and from() hidden APIs
This CL replaces with getSystemService(TelephonyManager.class)

Bug: 140768340
Test: atest frameworks/base/tests/net
Change-Id: I0f14cc5440fa85c81ab90f3199e9e91c1b00f5e1
2019-11-15 19:26:33 -08:00
Benedict Wong
ec2e2e2174 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
2019-10-18 21:04:59 +00:00
Remi NGUYEN VAN
b374d3953c Merge "Extract test utilities for ConnectivityService"
am: b7d270a73e

Change-Id: I0ac2a480f961bb6fd1d83dedad6a7942ee03858f
2019-08-06 14:58:43 -07:00
Remi NGUYEN VAN
a18a355536 Extract test utilities for ConnectivityService
The utilities help using ConnectivityService in tests, and will be used
to write integration tests for ConnectivityService.

Test: atest FrameworksNetTests
Change-Id: Ie895ad05139cd5768d3d8a9bd5589d72571f47e6
2019-08-01 16:32:30 +09:00
TreeHugger Robot
3f1f8d1315 Merge "DO NOT MERGE - Merge qt-dev-plus-aosp-without-vendor (5699924) into stage-aosp-master" into stage-aosp-master 2019-07-02 07:41:13 +00:00
junyulai
e5e15aee20 Fix mobile data usage didn't get increased for xlat464 traffic
Interface stats on stacked interfaces is usually clatd. For
xt_qtaguid supported device, the stats is already accounted
against its final egress interface by the kernel.
Framework side does not need to handle stats on statcked
interface at all.

However, on devices that support BPF offload, xlat464
packets are seen by the iptables rules as arriving on stack
interface only. Thus, add stack interface into accounting is
needed.

Bug: 136193260
Test: 1. atest FrameworksNetTests
      2. atest android.app.usage.cts.NetworkUsageStatsTest
      3. manual test on ipv6-only wifi network

Change-Id: I8ebbefbe4df00e40f4896a17fa52c8438d41286e
2019-07-01 14:17:47 -07:00
Lorenzo Colitti
05f0587ca2 Merge "Remove all static members from NetworkStatsFactory." am: 63f94f411b
am: 5409264cee

Change-Id: Iada14a1fea74197014e75a1112c7a5b35d6b1a1d
2019-06-27 19:40:01 -07:00
Lorenzo Colitti
bcaf1f959b Remove all static members from NetworkStatsFactory.
NetworkStatsFactory is owned by NetworkStatsService, and any
accesses to NSF data should go through NSS.

Test: atest FrameworksNetTests
Change-Id: Idbd0dbbaeb11313f63474e7ec0e01f974349fc89
2019-06-27 17:39:05 +09:00
Lorenzo Colitti
f189d8ee94 Merge "Transfer ownership of NetworkStatsFactory to NetworkStatsService." am: bd94f0afd2
am: 92292f556b

Change-Id: If897c9c95fc8571949183c45a99a5c28cb032ebb
2019-06-27 01:31:46 -07:00
Lorenzo Colitti
1bb38318b4 Merge "Synchronize the NetworkStatsFactory constructor." am: f2bd2bbfd8
am: e6193f4086

Change-Id: I521cd368a611bedaf9e6e5af4b8d71c040b502ac
2019-06-27 01:23:07 -07:00
Lorenzo Colitti
8b6fdeca3f Transfer ownership of NetworkStatsFactory to NetworkStatsService.
NetworkStatsService is the only consumer of the data coming from
NetworkStatsFactory, but the factory itself is instantiated and
owned by NetworkManagementService.

Move it into NetworkStatsService instead.

Test: atest FrameworksNetTests
Change-Id: I52df1e545c646927952579da22845a12d1d7563b
2019-06-26 19:29:51 +09:00
Lorenzo Colitti
ebfdc7c4e7 Synchronize the NetworkStatsFactory constructor.
This ensures the constructor takes the necessary lock before
accessing memmber variables.

Bug: 113122541
Test: atest FrameworksNetTests
Change-Id: Ibd324ed922c738b8d77d4eb74f45b75c6645bdc7
2019-06-25 18:58:42 +09:00
Lorenzo Colitti
c993c0c45f Merge "NetworkStats: Fix race condition causing system server crashes" am: 08b928e8ed
am: f37da9a879

Change-Id: I0ab308d5215ddb174ffb115e36948685d68da3ec
2019-06-25 01:53:11 -07:00
Hugo Benichi
0308b3971d NetworkStats: Fix race condition causing system server crashes
NetworkStatsService uses an internal boolean to know when it has
started for the purpose of preventing access to other internal
variables before they are initialized.

However that boolean is set to true in systemReady() non-atomically
with respect to the initialization of the other variables it guards,
which can cause the system server to crash.

This patch fixes this concurrency bug by moving setting the internal
boolean flag and the variable it guards in one atomic synchronized
block.

This patch also removes code checking if bandwidth control is enabled,
because this is now always true.

Bug: 132767673
Test: Compiled.
Change-Id: Ia089b5767ce271d669879c975508654d4dd03429
2019-06-25 10:51:51 +09:00
Benedict Wong
bdcf776874 Merge "Inline readNetworkStatsDetailInternal, make mUseBpfStats final" am: b8f3f2446e
am: df3deaf33d

Change-Id: I8fc5e96150bc30ae87881feb5730be2fbb5891ac
2019-06-20 14:11:17 -07:00
Benedict Wong
d749767f44 Inline readNetworkStatsDetailInternal, make mUseBpfStats final
This change inlines the logic from readNetworkStatsDetailInternal, and
reduces reundant checks in mUseBpfStats

Bug: 113122541
Test: atest FrameworksNetTests run, passing
Change-Id: If2ef8d8f038f32c8cf974aa02cfc1dc7e44dbad3
2019-06-20 20:23:17 +00:00
Varun Anand
a87d30ba9a Merge changes Ieb8645ac,I6466ec14,I87deb82b,I995b108e,Ib6521459 am: f4c10e8bc2
am: 48f59a0fdf

Change-Id: I960e94b03b29282ae2b03f78a19ed2692bd88e05
2019-06-17 10:33:53 -07:00
Benedict Wong
13162aefb1 Remove VPN info arrays from NetworkStats(Observer|Recorder)
This change removes the now-unused VPN arrays in the network stats
observer and recorder classes. These are always null values in every
call site.

Bug: 113122541
Bug: 120145746
Bug: 129264869
Bug: 134244752
Test: FrameworksNetTest passing
Test: Manual tests show data usage fixes maintained.
Change-Id: Ieb8645acc400fdaeb0df7092c5369b96f9f35af9
2019-06-14 11:41:31 -07:00
Benedict Wong
44f698e1c7 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.
Change-Id: I6466ec1411fc5ed6954125d27d353b6cd1be719e
2019-06-14 11:41:31 -07:00
Benedict Wong
9491d3a253 Remove unused lastStats parameter
This change removes an unused parameter that is always null in
getNetworkStatsUidDetail

Bug: 134244752
Test: FrameworksNetTest passing
Change-Id: I995b108ef30e1fbd6190131ed4db40a3d9327eb5
2019-06-13 15:36:36 -07:00
Benedict Wong
9b2ad58eae Revert "Revert "Take all VPN underlying networks into account when migrating traffic for""
This reverts commit b8e4b5bbbd.

Reason for revert: Fix available for deadlocks.

Bug: 134244752
Change-Id: Ib65214598837289bd39dbf040b56ab7835f893ba
2019-06-13 15:36:27 -07:00
Varun Anand
b8e4b5bbbd Revert "Take all VPN underlying networks into account when migrating traffic for"
This reverts commit c8dbdf35de.

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

Bug: 134244752
Change-Id: I2f1839d7776a613ca571af8a542755ddc5fc8760
Merged-In: Ibdaad3a4cbf0d8ef1ed53cfab1e454b9b878bae9
2019-06-10 16:00:48 -07:00
Varun Anand
52ce558fef Revert "NetworkStatsService: Fix getDetailedUidStats to take VPNs into account."
This reverts commit 720133f79d.

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

Bug: 134244752
Change-Id: I37f75c2b243ea548a88ef1dae88287405c6ef55f
Merged-In: I0c00e8f0e30cee987b71b561079a97bf09d4dae4
2019-06-10 16:00:38 -07: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
TreeHugger Robot
1824c32a5d Merge "NetworkStatAccess Should checkCarrierPrivileges cross all subscriptions" into qt-dev 2019-05-30 01:00:44 +00:00
chen xu
3b8356c7ef NetworkStatAccess Should checkCarrierPrivileges cross all subscriptions
Bug: 133236378
Test: Manual
Change-Id: I49fbde1fe73b33aadcf8fd23ad224f363b137bf3
Merged-in: I49fbde1fe73b33aadcf8fd23ad224f363b137bf3
2019-05-29 17:16:54 +00: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
chen xu
47090f9dd0 NetworkStatAccess Should checkCarrierPrivileges cross all subscriptions
Bug: 133236378
Test: Manual
Change-Id: I49fbde1fe73b33aadcf8fd23ad224f363b137bf3
2019-05-28 23:28:56 -07:00