Commit Graph

975 Commits

Author SHA1 Message Date
Hugo Benichi
624e54f225 NetworkStats: more robust subtraction for deltas
This patch ensures that subtract() between two NetworkStats object will
return a delta with no negative entries in all cases.

When the stats delta contains some negative values, there are clamped to
0. Some logging is added when this happens.

This is what's expected by NetworkStatsHistory#recordData().

Bug: 64365917
Bug: 65439160
Test: runtest frameworks-net
Merged-In: I16e97e73f600225f80e0ce517e80c07c6f399196
Merged-In: I2ac0bc3914cb65ae8ee27921856d698dc59624b2
Merged-In: I67d5dc4b52b254748ff17fe1e16c2eeb1d03c30d
Merged-In: Ib488fb034f72c92f19916490981342a3ef2eb33b

(cherry picked from commit d78311f267)

Change-Id: Ic86b65a65a2517c871221f8784088ec1de18f534
2017-09-08 13:39:44 +09:00
Hugo Benichi
619ce0a8f4 Merge "Network Service Discovery test: properly release resources" am: c9d24d203d am: 3a2e98b3ce
am: f467db29f9

Change-Id: Id9be284a16112f999d752751a7972fd735573cda
2017-09-04 12:42:56 +00:00
Hugo Benichi
3a2e98b3ce Merge "Network Service Discovery test: properly release resources"
am: c9d24d203d

Change-Id: If34b3770a5c0fef65d124201e0ca1374cc6b1eca
2017-09-04 12:14:11 +00:00
Hugo Benichi
fa8a0bb61f Network Service Discovery test: properly release resources
Bug: 32561414
Bug: 62918393
Bug: 62044295
Test: runtest frameworks-net
Change-Id: If23993b5e391947ecbdc01677f0a643144794b2b
2017-09-02 14:54:29 +09:00
Jeff Sharkey
4aa35f8d1b Merge "Gracefully handle integer overflows." into oc-mr1-dev
am: a7c5d0b053

Change-Id: I6ed70a40ad3e6df55e7669fedfe5b34faf95bd9f
2017-09-02 02:07:25 +00:00
TreeHugger Robot
a7c5d0b053 Merge "Gracefully handle integer overflows." into oc-mr1-dev 2017-09-02 01:54:58 +00:00
Jeff Sharkey
121a1fcbb2 Gracefully handle integer overflows.
Try sticking with integer-based math as much as possible for speed,
but switch to double-based math if we detect that we'd end up
causing an overflow.

New tests to verify.

Test: bit FrameworksNetTests:com.android.server.net.NetworkStatsCollectionTest
Bug: 65257769
Change-Id: I1ae35599be134f81850c0a3d86928b057fba1eff
2017-09-01 17:13:01 -06:00
Jeff Sharkey
f4dd66f12c Merge "Don't over-acquire NPMS locks." into oc-mr1-dev
am: 4576171c33

Change-Id: I2d23f8b238b8386958c0fd7348542713abb355dd
2017-09-01 22:03:47 +00:00
Jeff Sharkey
5f1befb42e Don't over-acquire NPMS locks.
We only need to hold mNetworkPoliciesSecondLock when working with
subscription plans; before this CL we could end up acquiring the two
NPMS locks out of order, resulting in a deadlock.

Also annotate objects in NSS that require mStatsLock to be held.

Test: builds, boots
Bug: 65268076
Change-Id: I06497564424316ef895dc8dceba72ae784781dc3
2017-09-01 12:36:20 -06:00
Jeff Sharkey
488cf28ae9 Merge "Augment network stats based on SubscriptionPlan." into oc-mr1-dev
am: f31cf45e82

Change-Id: Ia6c6d5893d841f21d181363dc01f77efa6579a8f
2017-08-30 19:14:21 +00:00
Jeff Sharkey
2f0f8f418f Augment network stats based on SubscriptionPlan.
When a carrier provides an "anchor" of data usage at a specific
moment in time, augment the network statistics used by warning/limit
thresholds and Settings UI.  For example, if the OS measured 500MB
of usage, but the carrier says only 400MB has been used, we "squish"
down the OS measured usage to match that anchor.

Callers using the hidden API will have their data augmented by
default, and the public API offers a way to opt-into augmentation.

Thorough testing to verify behavior.

Test: bit FrameworksNetTests:android.net.,com.android.server.net.
Test: cts-tradefed run commandAndExit cts-dev -m CtsUsageStatsTestCases -t android.app.usage.cts.NetworkUsageStatsTest
Bug: 64534190
Change-Id: Id3d4d7625bbf04f57643e51dbf376e3fa0ea8eca
2017-08-30 10:01:10 -06:00
Lorenzo Colitti
1d1d06f8dd Merge changes I325b13d5,I89719fe7 am: 31cb4583e5 am: d1800f3e6f am: 4fa0187015
am: 4187540d39  -s ours

Change-Id: Iddb0b4e22d942c9b399e57e17328b6911f473064
2017-08-19 03:47:59 +00:00
Lorenzo Colitti
4187540d39 Merge changes I325b13d5,I89719fe7 am: 31cb4583e5 am: d1800f3e6f
am: 4fa0187015

Change-Id: Ib980879b0e50ffe1c8209339df22da4a50d5b74e
2017-08-19 03:38:10 +00:00
Lorenzo Colitti
d1800f3e6f Merge changes I325b13d5,I89719fe7
am: 31cb4583e5

Change-Id: Iaced543ab17ea87c8f701975764d957bc1b17fc7
2017-08-19 03:15:08 +00:00
Treehugger Robot
31cb4583e5 Merge changes I325b13d5,I89719fe7
* changes:
  Add tether offload traffic to interface stats as well.
  Tell the system when tethering offload hits a limit.
2017-08-19 03:05:14 +00:00
Lorenzo Colitti
c2f8a8dda3 Add tether offload traffic to interface stats as well.
Currently, we only count add tethering traffic to per-UID
stats, but not to total data usage (i.e., dev and XT stats). This
is correct for software tethering, because all software forwarded
packets are already included in interface counters, but it is
incorrect for hardware offload, because such packets do not
increment interface counters.

To fix this:
1. Add an argument to ITetheringStatsProvider#getTetherStats to
   indicate whether per-UID stats are requested. For clarity,
   define integer constants STATS_PER_IFACE and STATS_PER_UID
   to represent these operations.
2. Make NetdTetheringStatsProvider return stats only if per-UID
   stats are requested. (Otherwise tethering traffic would be
   double-counted).
3. Make OffloadController's stats provider return the same
   stats regardless of whether per-UID stats were requested or
   not.
4. Make NetworkStatsService add non-per-UID tethering stats to
   the dev and XT snapshots. The per-UID snapshots were already
   correctly adding in per-UID stats.

(cherry picked from commit f31c942e89)

Bug: 29337859
Bug: 32163131
Test: runtest frameworks-net
Test: runtest frameworks-telephony
Change-Id: I325b13d50e88841dfb0db4c35e7e27f163ee72fe
Merged-In: I4e8e923d68dce1a4a68608dbd6c75a91165aa4ee
2017-08-19 10:12:05 +09:00
Lorenzo Colitti
45ab5640ef Merge "Add tether offload traffic to interface stats as well." into oc-mr1-dev
am: 21bc3a39a4

Change-Id: I4e8e923d68dce1a4a68608dbd6c75a91165aa4ee
2017-08-19 01:02:33 +00:00
Lorenzo Colitti
f31c942e89 Add tether offload traffic to interface stats as well.
Currently, we only count add tethering traffic to per-UID
stats, but not to total data usage (i.e., dev and XT stats). This
is correct for software tethering, because all software forwarded
packets are already included in interface counters, but it is
incorrect for hardware offload, because such packets do not
increment interface counters.

To fix this:
1. Add an argument to ITetheringStatsProvider#getTetherStats to
   indicate whether per-UID stats are requested. For clarity,
   define integer constants STATS_PER_IFACE and STATS_PER_UID
   to represent these operations.
2. Make NetdTetheringStatsProvider return stats only if per-UID
   stats are requested. (Otherwise tethering traffic would be
   double-counted).
3. Make OffloadController's stats provider return the same
   stats regardless of whether per-UID stats were requested or
   not.
4. Make NetworkStatsService add non-per-UID tethering stats to
   the dev and XT snapshots. The per-UID snapshots were already
   correctly adding in per-UID stats.

Bug: 29337859
Bug: 32163131
Test: runtest frameworks-net
Test: runtest frameworks-telephony
Change-Id: I7a4d04ab47694d754874136179f8edad71099638
2017-08-19 00:21:56 +09:00
Di Lu
635d3f5345 Merge "Add user quota information into the IpSecService dump" am: fedd856546 am: 318ca31081 am: 759696c47c
am: aa32c400ce

Change-Id: Iecd820e12495121f991bb00fa65cda07bf0f2abe
2017-08-16 17:25:30 +00:00
Di Lu
aa32c400ce Merge "Add user quota information into the IpSecService dump" am: fedd856546 am: 318ca31081
am: 759696c47c

Change-Id: I8f958d4967e02a58d8baf7b4a4058cf15ca50cc6
2017-08-16 17:12:05 +00:00
Di Lu
318ca31081 Merge "Add user quota information into the IpSecService dump"
am: fedd856546

Change-Id: I1f64ab03918ece154fe31a07b698825315d39c0f
2017-08-16 16:33:18 +00:00
ludi
529fdecc4c Add user quota information into the IpSecService dump
Bug: 64093788
Test: runtest frameworks-net
Change-Id: I6c5fc9e2db4ba57e0db4f6380a1251c4e444951b
2017-08-14 16:10:55 -07:00
Jeff Sharkey
b050a094a0 Merge "Rename API to match StorageStats." into oc-mr1-dev
am: 74f7a1425f

Change-Id: I87815da4f2f96c476fcdfdb3361d0f43b895e909
2017-08-12 00:45:19 +00:00
Jeff Sharkey
b1f97acf19 Rename API to match StorageStats.
Since they're both measuring app code (APKs), name this API
consistently with StorageStats.getAppBytes().

Bug: 64331226
Test: builds, boots
Change-Id: I1b00427b619a78c043b1b5fac2d0e6406b51d454
2017-08-11 15:10:38 -06:00
nharold
07ab65cc3b Merge "Add UserQuotaTracker to IpSecService" am: a0c97b3ddb am: b1d39a7aff am: 31e299220a
am: c83a829a57

Change-Id: I9ff32634ac098238dd826ececa59547788db15fc
2017-08-09 22:12:36 +00:00
nharold
c83a829a57 Merge "Add UserQuotaTracker to IpSecService" am: a0c97b3ddb am: b1d39a7aff
am: 31e299220a

Change-Id: Icc10cf54879e8f5b103392418edc1947593a8b39
2017-08-09 18:36:13 +00:00
nharold
b1d39a7aff Merge "Add UserQuotaTracker to IpSecService"
am: a0c97b3ddb

Change-Id: I43a9617b077ecd5fc2b445a1ade8b76c00562640
2017-08-09 17:49:42 +00:00
Nathan Harold
6e4681c7e2 Add UserQuotaTracker to IpSecService
Add a small tracking object to enforce maximum
quotas for SPIs, Transforms, and Encap sockets. The
current quota limits are intentionally conservative
with the expectation that we can relax them more
easily than we can shrink them.

Bug: 37688603
Test: tbd
Change-Id: Iee59ac59ef9f4a7ab75a2e04f9ca72da82fc3229
2017-08-08 18:28:47 -07:00
Hugo Benichi
7065f9f393 Merge "Merge "NetworkStats: more robust subtraction for deltas" into oc-dr1-dev am: 5e24152e33" into oc-mr1-dev
am: 279c26fa24

Change-Id: Id85a409a2d3cc12e53f977f94f7b5a306115a09a
2017-08-08 16:16:06 +00:00
Hugo Benichi
ae3ee131d2 Merge "NetworkStats: more robust subtraction for deltas" into oc-dr1-dev am: 5e24152e33
am: b9d28344e0

Change-Id: I67d5dc4b52b254748ff17fe1e16c2eeb1d03c30d
2017-08-08 16:10:52 +00:00
Hugo Benichi
f062d08360 Merge "NetworkStats: more robust subtraction for deltas" into oc-dr1-dev
am: 5e24152e33

Change-Id: Id6040a899653c585d298b7be7208f5cba997f665
2017-08-08 16:01:10 +00:00
Hugo Benichi
b9d28344e0 Merge "NetworkStats: more robust subtraction for deltas" into oc-dr1-dev
am: 5e24152e33

Change-Id: I2ac0bc3914cb65ae8ee27921856d698dc59624b2
2017-08-08 16:01:07 +00:00
Hugo Benichi
d78311f267 NetworkStats: more robust subtraction for deltas
This patch ensures that subtract() between two NetworkStats object will
return a delta with no negative entries in all cases.

When the stats delta contains some negative values, there are clamped to
0. Some logging is added when this happens.

This is what's expected by NetworkStatsHistory#recordData().

Bug: 64365917
Test: runtest frameworks-net
Change-Id: I16e97e73f600225f80e0ce517e80c07c6f399196
2017-08-08 09:19:05 +09:00
Hugo Benichi
37d178c71e NsdManager: remove duplicated argument validation
am: 38e4783a60

Change-Id: I3cad605d34cd9612b6073e689dc4af04b1717413
2017-08-03 07:28:16 +00:00
Hugo Benichi
38e4783a60 NsdManager: remove duplicated argument validation
This patch simplifies argument validation in NsdManager public api and
regroup duplicated validation into common methods.

This makes stack traces more actionable as now specific errors will
cause the api to throw exception from specific methods, whereas before
IllegalArgumentException would be thrown from inside the same api method
for different reasons.

This patch also includes a couple of other small cleanups.

Test: $ runtest -x frameworks/base/tests/net/../NsdManagerTest.java
Bug: 37013369

(cherry picked from commit f2c64f8725)

Change-Id: Icf047532aa551fbe0a70721cfb95507eaa84d51e
2017-08-03 14:19:43 +09:00
Tetsutoki Shiozawa
a00d4b0bf4 Abort connecting to native daemon during shutdown
Symptom:
System_server crashed due to unsolved "netd" service.

Root cause:
Init intentionally killed services when shutdown was triggered.
NativeDaemonConnector unnecessarily tried to reconnect the killed
daemon and NetworkManagemantService got a callback of connection.
Finally, NetworkManagemantService failed to get netd service and it
crashed with NPE.

Solution:
Do not retry connecting to the target native daemon when the device
is in the middle of shutdown.

Bug: 64237349
Change-Id: I2514cdc47b3eea785b5ffe5bd8bb27609bcc1726
2017-08-01 08:40:22 +00:00
Hugo Benichi
4d457931cc Merge "NsdManager: remove duplicated argument validation" into oc-mr1-dev
am: 4f48862d0f  -s ours

Change-Id: I66aa7d2d7128272bedc04568dbdcb759a3be8afe
2017-08-01 05:27:59 +00:00
Hugo Benichi
e71cc98cb1 NsdManager: remove duplicated argument validation
This patch simplifies argument validation in NsdManager public api and
regroup duplicated validation into common methods.

This makes stack traces more actionable as now specific errors will
cause the api to throw exception from specific methods, whereas before
IllegalArgumentException would be thrown from inside the same api method
for different reasons.

This patch also includes a couple of other small cleanups.

Test: $ runtest -x frameworks/base/tests/net/../NsdManagerTest.java
Bug: 35362108
Bug: 37013369
Bug: 62044295
Bug: 63826516
Merged-In: Iaad13e13976e9bf8f508d7188f823f8184ac414b

(cherry pick from commit f2c64f8725)

Change-Id: I5e6a1ecc6b98069ef0089bbceecf73f7692df227
2017-08-01 02:45:23 +00:00
ludi
2e438582ba Merge "Add dump info to IpSecService" am: ec5fc4872e am: b47cb8b03c am: c628b22fe5
am: 16853ff14c

Change-Id: Idbc0a6f0c88a023c3954b25cc66c8c65c70085c9
2017-07-25 03:36:41 +00:00
ludi
16853ff14c Merge "Add dump info to IpSecService" am: ec5fc4872e am: b47cb8b03c
am: c628b22fe5

Change-Id: I1a5d4c424a3c9e1638d86d177cbf98f0d1bce05d
2017-07-25 03:26:23 +00:00
ludi
b47cb8b03c Merge "Add dump info to IpSecService"
am: ec5fc4872e

Change-Id: Idd4c051e4536d32504718fdfd201c7effdeb62e3
2017-07-25 03:07:00 +00:00
ludi
89194d6e45 Add dump info to IpSecService
Bug:38350824

Test: runtest frameworks-net

Change-Id: Ifa11d55e9d337016ad865baada627db3aa8c2db3
2017-07-24 16:03:33 -07:00
Di Lu
48e3c86ea7 Merge "Add unit test for IpSecService" am: 9e3f886dca am: 8cdceb2fed am: 345db82674
am: cfb337087c

Change-Id: I788e4e8466a76f80d1f15330e6d3b91b73be1d32
2017-07-20 08:42:27 +00:00
Di Lu
cfb337087c Merge "Add unit test for IpSecService" am: 9e3f886dca am: 8cdceb2fed
am: 345db82674

Change-Id: Ia4d85bcf5c42774d7b48cb1cd648754b6dd16b69
2017-07-20 07:50:21 +00:00
Di Lu
8cdceb2fed Merge "Add unit test for IpSecService"
am: 9e3f886dca

Change-Id: I16fb89239e641ac39a8a7adeafd72b7fe03935ed
2017-07-20 07:36:19 +00:00
ludi
5e623eaa02 Add unit test for IpSecService
Test: runtest frameworks-net

Bug:38259578
Change-Id: I4a049d5fdec79e36692e3b12306bd0758c19ad75
2017-07-20 04:26:24 +00:00
Steven Moreland
ba133a202d Merge "frameworks/base: use proper nativehelper headers" am: 826eafd958 am: 4f846495a4 am: c840945a78
am: c79573c26d

Change-Id: Ibe321dd4a8aae9342c76da0780edf94b90e8cd3a
2017-07-20 03:11:00 +00:00
Steven Moreland
c79573c26d Merge "frameworks/base: use proper nativehelper headers" am: 826eafd958 am: 4f846495a4
am: c840945a78

Change-Id: I654e14f0d1b495450db81592a2e564e308746350
2017-07-20 03:05:02 +00:00
Steven Moreland
4f846495a4 Merge "frameworks/base: use proper nativehelper headers"
am: 826eafd958

Change-Id: I36f10ff4d963284a313f1cc5b368f82549a4adb2
2017-07-20 02:50:53 +00:00
Steven Moreland
881296fa45 frameworks/base: use proper nativehelper headers
libnativehelper exports headers under nativehelper. These were
available before incorrectly as global headers in order to give
access to jni.h.

Test: modules using frameworks/base find headers
Bug: 63762847
Change-Id: I0f9f231acdebe460f279135462f43d3e32eff64d
2017-07-19 10:06:40 -07:00