Commit Graph

2258 Commits

Author SHA1 Message Date
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
4bbc0d2449 Merge "NetworkStats: Fix race condition causing system server crashes" am: 08b928e8ed am: f37da9a879 am: c993c0c45f
am: f126a7e923

Change-Id: Ia4adc58a4c8baef92e204bedd914b5e041e071a6
2019-06-25 03:31:52 -07: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
f126a7e923 Merge "NetworkStats: Fix race condition causing system server crashes" am: 08b928e8ed am: f37da9a879
am: c993c0c45f

Change-Id: Ieb9f17b6e3eed82c450a5b90dd67a00e4ede8b3f
2019-06-25 02:21:15 -07: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
Lorenzo Colitti
3233bc2613 [automerger skipped] Merge changes If7d41052,I66f263d7,Id45ae956,Iba752fed,I575a7e4f, ... into qt-r1-dev am: f80234a9b0 -s ours
am: 85c6ebcce9 -s ours
am skip reason: change_id If2ef8d8f038f32c8cf974aa02cfc1dc7e44dbad3 with SHA1 d749767f44 is in history

Change-Id: I2081b6633b1d0f61bff7531a082e0b6856c23b5b
2019-06-24 09:09:35 -07:00
Lorenzo Colitti
85c6ebcce9 [automerger skipped] Merge changes If7d41052,I66f263d7,Id45ae956,Iba752fed,I575a7e4f, ... into qt-r1-dev
am: f80234a9b0 -s ours
am skip reason: change_id If2ef8d8f038f32c8cf974aa02cfc1dc7e44dbad3 with SHA1 d749767f44 is in history

Change-Id: I5b525feb1e7df2a89dea4f38b521973ccaac0746
2019-06-24 08:17:26 -07:00
Benedict Wong
0768aa7770 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
Merged-In: If2ef8d8f038f32c8cf974aa02cfc1dc7e44dbad3
Change-Id: If7d41052115ed145da8a610d676f6ed33c8d5e63
(cherry picked from commit 8c9d8c5e05cd35a340c4224c61f7fa9e95b5c861)
2019-06-21 01:12:41 +00:00
Benedict Wong
4d326f96cc 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.
Merged-In: Ieb8645acc400fdaeb0df7092c5369b96f9f35af9
Change-Id: I66f263d7e12bce7668901306c0c2ecdda634abaf
(cherry picked from commit 833603caabb1a850a63a970fc285b4c8ed7401f8)
2019-06-21 01:12:34 +00:00
Benedict Wong
dedb6bb0e5 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.
Merged-In: I6466ec1411fc5ed6954125d27d353b6cd1be719e
Change-Id: Id45ae956ad7165be346ecc010e17d260563ac1c0
(cherry picked from commit 9fbbdebc61513982a6775460e1d400956f803bde)
2019-06-21 01:12:27 +00:00
Benedict Wong
a3da62f5a1 Remove unused lastStats parameter
This change removes an unused parameter that is always null in
getNetworkStatsUidDetail

Bug: 113122541
Bug: 134244752
Test: FrameworksNetTest passing
Merged-In: I995b108ef30e1fbd6190131ed4db40a3d9327eb5
Change-Id: I575a7e4fa145f2c93537f33a2bfe952aeafd0e69
(cherry picked from commit 5823e8d3c69b10ad2a458e491c146631457ca86d)
2019-06-21 01:12:10 +00:00
Benedict Wong
2cca1ef390 Revert "Revert "Take all VPN underlying networks into account when migrating traffic for""
This reverts commit d8220c20507f0c346f517d715c7b9826b04d64e2.

Reason for revert: Fix available for deadlocks.

Bug: 113122541
Bug: 134244752
Merged-In: Ib65214598837289bd39dbf040b56ab7835f893ba
Change-Id: Ia90bf2c72ef686e80800d113d03548e0efcadb66
(cherry picked from commit a84d9fa57247cf78a9297b0c6dbd3d81b69e235f)
2019-06-21 01:09:49 +00:00
Benedict Wong
20b7556bcf Merge "Inline readNetworkStatsDetailInternal, make mUseBpfStats final" am: b8f3f2446e am: df3deaf33d am: bdcf776874
am: 720bf37264

Change-Id: I5ddc834a7c50ae260704ce9d53c954cfb55bec7b
2019-06-20 14:46:35 -07:00
Chalard Jean
5baf78c082 Merge "Factorize custom asserts." am: 6c176efa3d am: 99fbb40990 am: b4dd87625b
am: dc168b63fb

Change-Id: I1eecc5dd9f8c77287b8cca76f5d647a23a9a2f7a
2019-06-20 14:29:43 -07:00
Benedict Wong
720bf37264 Merge "Inline readNetworkStatsDetailInternal, make mUseBpfStats final" am: b8f3f2446e am: df3deaf33d
am: bdcf776874

Change-Id: I9125dc1aa39189a43b3c68618853e0a7a7298fe2
2019-06-20 14:23:25 -07: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
Chalard Jean
dc168b63fb Merge "Factorize custom asserts." am: 6c176efa3d am: 99fbb40990
am: b4dd87625b

Change-Id: I8774ea64f004999ddb46223a76a671388687d455
2019-06-20 14:06:58 -07:00
Chalard Jean
b4dd87625b Merge "Factorize custom asserts." am: 6c176efa3d
am: 99fbb40990

Change-Id: I65ea7497abb8b77ebd10ba622075ef3b6c49b2a8
2019-06-20 14:01:31 -07:00
Benedict Wong
b8f3f2446e Merge "Inline readNetworkStatsDetailInternal, make mUseBpfStats final" 2019-06-20 20:25:31 +00: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
Chalard Jean
812ffea029 Factorize custom asserts.
Also a few utilities that were in the way, and some opportunistic
cleanups.

Test: FrameworksNetTest NetworkStackTest
Change-Id: I385070e2044fd967cb18f1ffea9a86a4627b742e
2019-06-20 16:24:25 +09:00
Varun Anand
1c608de218 Merge changes Ieb8645ac,I6466ec14,I87deb82b,I995b108e,Ib6521459 am: f4c10e8bc2 am: 48f59a0fdf am: a87d30ba9a
am: 82c57bcb79

Change-Id: I8415a7c91158cce99e91e6054ed4f40e44563b89
2019-06-17 10:59:29 -07:00
Varun Anand
82c57bcb79 Merge changes Ieb8645ac,I6466ec14,I87deb82b,I995b108e,Ib6521459 am: f4c10e8bc2 am: 48f59a0fdf
am: a87d30ba9a

Change-Id: I16884eef6e2b8d64031363cfb4adacc4a0a9ead7
2019-06-17 10:43:22 -07: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
d1eed13f49 [automerger skipped] Merge changes from topic "vpn_data_accnt_revert" am: 8af90ce15b am: 39f9c1c212 -s ours am: d7ca6e7dc7 -s ours
am: 8249d4ac1e -s ours
am skip reason: change_id Ibdaad3a4cbf0d8ef1ed53cfab1e454b9b878bae9 with SHA1 612ac19261 is in history

Change-Id: I476f1bf69f0cceaeadbe6dbdd93b5dfa096e955a
2019-06-11 19:22:30 -07:00
Varun Anand
8249d4ac1e [automerger skipped] Merge changes from topic "vpn_data_accnt_revert" am: 8af90ce15b am: 39f9c1c212 -s ours
am: d7ca6e7dc7 -s ours
am skip reason: change_id Ibdaad3a4cbf0d8ef1ed53cfab1e454b9b878bae9 with SHA1 612ac19261 is in history

Change-Id: I48f805c08d46e03a837173f59f411506c9748951
2019-06-11 19:11:23 -07:00
Varun Anand
d7ca6e7dc7 [automerger skipped] Merge changes from topic "vpn_data_accnt_revert" am: 8af90ce15b
am: 39f9c1c212 -s ours
am skip reason: change_id Ibdaad3a4cbf0d8ef1ed53cfab1e454b9b878bae9 with SHA1 612ac19261 is in history

Change-Id: I47d22d76e3525efc7771e6b514ebadc9b2c75e22
2019-06-11 19:03:04 -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
Varun Anand
2099b09982 Revert "Addressing comments for http://ag/7700679."
This reverts commit 6018f64055.

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

Bug: 134244752
Change-Id: I12ab724e2ef8a5c1b42078330ba74713ff86fdd1
Merged-In: I5fbb3443a39a21fc9d96442726cd10d20e8d61cd
2019-06-10 16:00:28 -07:00
Benedict Wong
f3d23e1b88 Merge changes from topic "am-9a435ce648dc47d49fc32dc2680fa5b7" into qt-r1-dev-plus-aosp
am: 102c6a2a35

Change-Id: I46aebe74e24d39b7fce0c7eb835e282d59f2c169
2019-06-07 02:50:31 -07:00
Benedict Wong
26a85da7aa Revert "Take all VPN underlying networks into account when migrating traffic for" am: 612ac19261 am: 1951779616
am: 27e91edd6b

Change-Id: I5306f76761ce4ae3c8a0ec89b6bdea3e004a1d73
2019-06-07 02:48:37 -07:00
Benedict Wong
b3a7169e82 Revert "NetworkStatsService: Fix getDetailedUidStats to take VPNs into account." am: 75fc9e4e15 am: a2e0879840
am: 4c78fb4c61

Change-Id: I6e9f5b04bbb036c13eedee6e8d079a48f14f5685
2019-06-07 02:48:33 -07:00
Benedict Wong
46938fcd73 Revert "Addressing comments for http://ag/7700679." am: bebb34732d am: 251f7ac812
am: 0adc53072c

Change-Id: If2c644ab4b69f385a6e939ca4760530c196f098d
2019-06-07 02:48:29 -07:00
Android Build Merger (Role)
102c6a2a35 Merge changes from topic "am-9a435ce648dc47d49fc32dc2680fa5b7" into qt-r1-dev-plus-aosp
* changes:
  Revert "Take all VPN underlying networks into account when migrating traffic for" am: 612ac19261 am: 3e9726c69c
  Revert "NetworkStatsService: Fix getDetailedUidStats to take VPNs into account." am: 75fc9e4e15 am: 9b8282b7ba
  Revert "Addressing comments for http://ag/7700679." am: bebb34732d am: 25f881d116
  Revert "Add one more test for VPN usage stats." am: 54a08a686d am: 469ee82902
2019-06-07 09:44:50 +00:00
Benedict Wong
392e82a09d Revert "Take all VPN underlying networks into account when migrating traffic for" am: 612ac19261
am: 3e9726c69c

Change-Id: Ia6598f3550d1dcdd42e04f846ac6cfcce18ce7c1
2019-06-07 02:43:37 -07:00
Benedict Wong
8eb19b9ead Revert "NetworkStatsService: Fix getDetailedUidStats to take VPNs into account." am: 75fc9e4e15
am: 9b8282b7ba

Change-Id: I799bbaed92dfce20690ae5a8b59241d22e5dc6d6
2019-06-07 02:43:33 -07:00
Benedict Wong
f886ba8635 Revert "Addressing comments for http://ag/7700679." am: bebb34732d
am: 25f881d116

Change-Id: Ib986a6e4bf6f9a66722c612fcae6f79c1cce91b6
2019-06-07 02:43:29 -07:00
Benedict Wong
1951779616 Revert "Take all VPN underlying networks into account when migrating traffic for"
am: 612ac19261

Change-Id: Ie9e830962e702c5e66faa7239e6c5037ed3d791d
2019-06-07 02:33:33 -07:00
Benedict Wong
a2e0879840 Revert "NetworkStatsService: Fix getDetailedUidStats to take VPNs into account."
am: 75fc9e4e15

Change-Id: I9bf180aca56a8b5e2c5262beabac3ceaa9b00315
2019-06-07 02:33:30 -07:00
Benedict Wong
251f7ac812 Revert "Addressing comments for http://ag/7700679."
am: bebb34732d

Change-Id: I56e7736ced431a5dcd78a6a258abfad09745d25e
2019-06-07 02:33:26 -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