Commit Graph

3969 Commits

Author SHA1 Message Date
Jeff Sharkey
92313e436a 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
Hugo Benichi
b3dec17660 Merge "Revert "Nat464Xlat: interface notification handler on ConnectivityService"" into oc-mr1-dev 2017-09-01 02:49:17 +00:00
Hugo Benichi
2984496383 Revert "Nat464Xlat: interface notification handler on ConnectivityService"
This reverts commit 39e10e2111.

Bug: 65225023
Change-Id: Id6c21682cafa86d87f66480237dd731b21f917c5
2017-08-31 14:32:54 +00:00
Jeff Sharkey
cf84220710 Merge "Augment network stats based on SubscriptionPlan." into oc-mr1-dev 2017-08-30 19:01:18 +00:00
Jeff Sharkey
3c8f96ef4a 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
Hugo Benichi
39e10e2111 Nat464Xlat: interface notification handler on ConnectivityService
This patch adds a layer of asynchonicity to the NetworkBaseObserver
callbacks implemented by Nat464Xlat in order to allow these callbacks
to run on the main ConnectivityService handler.

This allows to run interfaceLinkStateChanged and interfaceRemoved
callbacks in the same thread context as other Nat464Xlat methods and
solves the following issues:
  - NPE risk due to race between fixupLinkProperties called on the
    ConnectivityService thread and interfaceRemoved called as a
    callback by NetworkManagementService.
  - stale LinkProperties reads in both callbacks not called on
    ConnectivityService handler.
  - removes the race between stop() and interfaceRemoved().

This patch also:
  - removes/simplifies comments related to the threading
    model which are no obsolete.
  - extract clatd management logic from ConnectivityService into
    NetworkAgentInfo

Bug: 62997041
Bug: 64571917
Test:  runtest frameworks-net
       manually connected to ipv6 network and went to test-ipv6.com
Merged-In: I889d98e47423ff3d4746d6ed8015b265286e7c52
Merged-In: I2f002cd197e2eeaaadadd747a6b33d264cd34433
Merged-In: Id3ab064cf9f4417c0e8988fff4167b65b3c8c414
Merged-In: Ib224392c9a185f6bd79fd60cd5cb5549f2a7851e
Merged-In: I9116a493ca1cbdf6a25664a1b0017aa6c9b38eb4
Merged-In: I12918d208364eef55067ae9d59fbc38477e1f1c6

(cherry picked from commit 771d5c2f0126ba692897c9716f4098ae6e3a870c)

Change-Id: I34c4a0c32ce7c9b7bd7acf8f87b932e15c573bd8
2017-08-29 15:12:32 +09:00
Hugo Benichi
9cd15c7f2e Nat464Xlat: internal state guards cleanup + state enum
This patch does some cleanup of Nat464Xlat internal state guards
against the Nat464Xlat state Idle | Started | Running, which reduces
code nesting.

It also replaces introspection of internal state for distinguishing
between different stages in 464xlat lifecycle with an enum explicitly
introducing these three Idle | Started | Running states.

Bug: 62997041
Bug: 64571917
Test:  runtest frameworks-net
       manually connected to ipv6 network and went to test-ipv6.com
Merged-In: I6efc9fed2420ca488731a2b9b9c3c025b16eca10
Merged-In: I188ac4c367db11cb33b67fe92df3a120e3c6fbce
Merged-In: I7e2c5db8d537fb0ab47cde37158b7f04d7786942
Merged-In: Ic2246a97618c596dbdbf48cda39c2f5b66e3bfb6
Merged-In: Ib04b9a3d56e9daf61b299a30e24a3c8839819a00
Merged-In: Icc1558a0f0e7c299270f550897347458e2bd3188

(cherry pick from commit 4f6f139869ddadf6f9ed50967c106a10a2e8ce3f)

Change-Id: Iebc7d153d8cd0b90d074d8d6eed821fbc3f1370d
2017-08-29 10:02:24 +09:00
Hugo Benichi
5a5c1bb116 Nat464Xlat: clat management cleanup
This patch does some minor refactoring of clat starting/stopping code:
 - remove unused LinkProperties arguments in updateClat
 - remove unused Context argument in Nat464Xlat ctor
 - introduce ensureClatIsStarted and ensureClatIsStopped methods and
   simplify updateClat
 - add clatd to NetworkAgentInfo toString() method
 - clarify some comments

This changes prepare for moving BaseNetworkObserver callbacks to
ConnectivityService.

Bug: 62997041
Bug: 64571917
Test: runtest frameworks-net
      manually connected to IPv6 only network and went to test-ipv6.com

Merged-In: Idb204784614cfe700f73255a7a7b78c5e9ee6eca
Merged-In: Ic3808a1afe48efac745b1b378fb12cc5678918ec
Merged-In: Ia769aef6ef8b258f44f8979003d271c96264f1b5
Merged-In: I1a19e6fbb0cb13262e90b171d861062469078fb6
Merged-In: I06661bd6bd1456ba34a3bbdb52c120ac01da9d61
Merged-In: Ifccff9f3cfccdb2cdddf2f07561f0787a48bc0f8

(cherry picked from commit b577d65825e623a9868664486482ed137b98b504)

Change-Id: Ibb02888633df9643030336c4dbea6c569a47554c
2017-08-28 22:32:11 +09:00
Baligh Uddin
4a46108d0f DO NOT MERGE ANYWHERE Revert "Merge "Remove gender-specific pronouns from documentation" into oc-dev" am: e811770999 -s ours
am: 0a92e1584e  -s ours

Change-Id: I3bc8768f4790abe57ed64bb516db5dadd9a7dd9c
2017-08-21 21:52:56 +00:00
Tyler Freeman
20eaf1b908 DO NOT MERGE ANYWHERE Manually merge commit 'fd35d7c0a284' into oc-dr1-dev
am: 27b9dd89db  -s ours

Change-Id: I6ac35f90d62b08cb6cae66b9ed001265a7496aea
2017-08-21 21:41:25 +00:00
Baligh Uddin
0a92e1584e DO NOT MERGE ANYWHERE Revert "Merge "Remove gender-specific pronouns from documentation" into oc-dev"
am: e811770999  -s ours

Change-Id: Ida80fe80780bf4f811aa54e0163f5c936f4d16a6
2017-08-21 21:40:53 +00:00
The Android Automerger
27b9dd89db DO NOT MERGE ANYWHERE Manually merge commit 'fd35d7c0a284' into oc-dr1-dev
BUG:64864568
2017-08-21 21:28:42 +00:00
Hugo Benichi
39b6912019 Merge "Really allow NetworkAgent immutable updates to NetworkCapabilities" into oc-mr1-dev 2017-08-21 03:24:06 +00:00
Baligh Uddin
e811770999 DO NOT MERGE ANYWHERE Revert "Merge "Remove gender-specific pronouns from documentation" into oc-dev"
Bug: 64864568

This reverts commit fd35d7c0a284e31231e2f424cade864be695965b, reversing
changes made to 07a21754f45672b27e765d8c7677c9663c6dce91.
2017-08-19 15:49:05 -07:00
Lorenzo Colitti
2d10195128 Merge "Add tether offload traffic to interface stats as well." into oc-mr1-dev 2017-08-19 00:54:59 +00:00
Lorenzo Colitti
49ab263c0b 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
Hugo Benichi
b319377255 Really allow NetworkAgent immutable updates to NetworkCapabilities
This patch completes commit bae105a5ccd11430bab14721d1325e2303a673da to
really allow updates of immutable capabilities to NetworkCapabilities of
NetworkAgents by using satisfiedByImmutableNetworkCapabilities instead
satisfiedByNetworkCapabilities.

Bug: 64125969
Test: runtest frameworks-net
Merged-In: I9beeb623792f0ee31abcd4ba9d0ba2451304fb2e
Merged-In: Ifbdd005576b3f0fbf278ecec81ce3e4308c6276d
Merged-In: Id352fdb6da21a2150d3e8d062d7eba11878f6919
Merged-In: If3742ea0e2151b9b710eda2fed280c31f7960393
Merged-In: Icd8e328e3c810a644bfb83798bd42fed8dc70425

(cherry picked from commit a60c6eab42cd904faaf26c23100939d397b80c39)

Change-Id: I737494117d7f1e0198f0ad4d3c41019c9295fe09
2017-08-18 12:44:26 +00:00
Hugo Benichi
3f04e31eee Merge "Allow NetworkAgent "immutable updates" to NetworkCapabilities" into oc-mr1-dev 2017-08-18 11:46:22 +00:00
Hugo Benichi
de7117d3fe Merge "Add convenience methods to IpPrefix and LinkAddress" into oc-mr1-dev 2017-08-17 22:31:59 +00:00
Hugo Benichi
f2ccd7a219 Add convenience methods to IpPrefix and LinkAddress
Also moving relevant test files into tests/net as part of runtest
framworks-net.

Also removes testHashCode in LinkAddress() because this test relies on
the assumption that hashCode() is stable across releases or jdk
versions, which is absolutely not true.

This creates maintenance work for little benefit since hashCode is
already tested as part of the equality test.

For instance this test is now broken because hashing for InetAddress
changed.

Bug: 62988545
Bug: 62918393
Test: runtest frameworks-net, added coverage in tests
Merged-In: I695bc3f0e801bf13bc4fc0706565758f12b775b4
Merged-In: I6d3f3c50eaec44e3a0787e849ab28e89f6f4a72d
Merged-In: Iddfec82a08f845e728adadfa6ec58a60a078d6af
Merged-In: I8d6dd5efd226a8b1c4b05d1e1102362b58e094a1
Merged-In: Ied0cc53ac34c7c5f5539507b1979cbf9c215262e
Merged-In: I3b2b7dcb1a9a194fc08643b27bbb5a0e84e01412

(cherry picked from commit 1dfb6b67555d04973dfb9d1100dfc1c6a5200633)

Change-Id: I9a17094bfdc54b9dec671306618e132a4beb59fc
2017-08-17 11:03:24 +09:00
Hugo Benichi
9712eb35b9 Allow NetworkAgent "immutable updates" to NetworkCapabilities
This patch loosens the validation checks when a NetworkAgent updates it
NetworkCapabilities: instead of checking that capabilities labeled as
"immutable" stay identical across updates, it is now accepted to change
immutable capabilities in a way that the new NetworkCapabilities
satisfies the old NetworkCapabilities.

This allows a NetworkAgent to update itself in order to match more
requests, but will still catch NetworkAgents that sends degradation
updates causing potentially requests to not match anymore.

Bug: 64125969
Test: runtest frameworks-net
Merged-In: I2a1b3f9c0be6415e40edc989d0c1b03b5631f7b1
Merged-In: I0ab76de59e87c46a6961229399ff7200bce49838
Merged-In: Ied592bf6112574399a1e808da337004e1c35f244
Merged-In: I01e287b4df82a53a522566d33b3166f7801badca
Merged-In: I7ee60daa9c4266e9b9179032815dd7267e06377f
Merged-In: I31ef741eb83d64c476e5930d5762514b5d4cb16f

(cherry picked from commit bae105a5ccd11430bab14721d1325e2303a673da)

Change-Id: I9d630d63336f4db69f3eb52faa8483f1b1e35d16
2017-08-17 10:48:41 +09:00
Charles He
d681363fd1 Opt-out for always-on VPN: rename API.
Rename the opt-out flag in AndroidManifest to
SERVICE_META_DATA_SUPPORTS_ALWAYS_ON
as directed by the API Council.

Bug: 64331776
Bug: 36650087
Test: runtest --path java/com/android/server/connectivity/VpnTest.java
Change-Id: I24326fad7a89083a2409134640bda81ee0359d08
2017-08-15 15:52:39 +01:00
Hugo Benichi
6ecf87a88a Merge "NetworkCapabilities: fix describeImmutableDifferences" into oc-dr1-dev
am: 1b3877a965

Change-Id: I50748aa0c9332787797f91265afccf82ceabf332
2017-08-07 05:49:25 +00:00
Hugo Benichi
dec642b9b3 NetworkCapabilities: fix describeImmutableDifferences
This patch fixes the mask used in describeImmutableDifferences which did
not correctly turn NET_CAPABILITY_NOT_METERED into bit flag.

Bug: 63326103
Test: added unit tests, runtest frameworks-net
Merged-In: Ib6b390b1daef5912859302692af7dcd6cfd3e39a
Merged-In: If38efacdeec8476880835657938e435f9b598525
Merged-In: Ieccad46fcffcaf748f5644b04617e9a82527000e
Merged-In: I533ef8fe369cec19d283ff2950314fce6e28cffd
Merged-In: I12636c6699ff60487a28570208e819ea0b66fa2e
Merged-In: Ie5df14e0ea1c12e0cfabe87978ac6c9b744353b2

(cherry picked from commit 2ecb9408f4102687f20f9ca19c13071ac6098cc6)

Change-Id: I74ecf34a2c079c74152d00caea2c220e9c6d1fa5
2017-08-05 11:37:10 +09:00
Hugo Benichi
b1701a2d29 DO NOT MERGE ANYWHERE ConnectivityService: move reportNetworkConnectivity to handler am: 1681f064ff -s ours am: 552b3aae6e -s ours am: e22c6cd56a -s ours
am: ae00616f2f  -s ours

Change-Id: I5b252535638054e87fb3cc6069d51a6c4da7dce0
2017-08-01 15:10:35 +00:00
Hugo Benichi
ae00616f2f DO NOT MERGE ANYWHERE ConnectivityService: move reportNetworkConnectivity to handler am: 1681f064ff -s ours am: 552b3aae6e -s ours
am: e22c6cd56a  -s ours

Change-Id: Ia38655a26410e9ea78e394e5c59e052739f041a6
2017-08-01 14:55:26 +00:00
Hugo Benichi
e9c2b802e5 DO NOT MERGE ANYWHERE ConnectivityService: move reportNetworkConnectivity to handler am: 1681f064ff -s ours am: 552b3aae6e -s ours
am: e22c6cd56a  -s ours

Change-Id: Ic8e234914839f9e98fed944638d85c2e795c0c9d
2017-08-01 14:55:23 +00:00
Hugo Benichi
e22c6cd56a DO NOT MERGE ANYWHERE ConnectivityService: move reportNetworkConnectivity to handler am: 1681f064ff -s ours
am: 552b3aae6e  -s ours

Change-Id: I6d788c5b7cd5c6877799e5a3e0ad865996147b70
2017-08-01 14:37:06 +00:00
Hugo Benichi
552b3aae6e DO NOT MERGE ANYWHERE ConnectivityService: move reportNetworkConnectivity to handler
am: 1681f064ff  -s ours

Change-Id: Ie54e0712dc83514ff3ddcd6cee1b0bd2e80c73ad
2017-08-01 14:30:02 +00:00
Hugo Benichi
3d722e38f3 Merge "Logging improvements when NetworkCapabilities change" into oc-dr1-dev
am: 8a8c295879

Change-Id: I4f6cbc0adb461cef6610460daeba72ca38b8f10c
2017-07-28 23:54:03 +00:00
Hugo Benichi
8a8c295879 Merge "Logging improvements when NetworkCapabilities change" into oc-dr1-dev 2017-07-28 23:42:59 +00:00
Hugo Benichi
d9806e8014 Logging improvements when NetworkCapabilities change
This patch improves the wtf() logging in updateCapabilities to
better distinguish between the cases of a changed specifiers, changed
transports, or changed capabilities. The case of NOT_METERED being added
or removed is ignored.

Bug: 63326103
Test: runtest frameworks-net, runtest frameworks-wifi
Change-Id: I05c6e78891e1eac658f1cf883223af520a9a4f8f
2017-07-28 15:25:54 +09:00
Hugo Benichi
7ae02714ae Merge "NetworkNotificationManager: correctly handle existing notifications" into oc-dr1-dev
am: a03bf7acd1

Change-Id: I4ca3dcc293be5408a6f207e1ac1a7229a915723a
2017-07-28 04:39:14 +00:00
Hugo Benichi
1681f064ff DO NOT MERGE ANYWHERE ConnectivityService: move reportNetworkConnectivity to handler
This patch moves reportNetworkConnectivity onto the handler of
ConnectivityService.

This allows:
  - to inspect NetworkAgentInfo on the ConnectivityService handler,
    which is always more correct than doing so on a Binder thread.
  - to improve locking policies around NetworkAgentInfo.

Test: $ runtest frameworks-net
Bug: 37119619, 36902662
Change-Id: I49a765826e65c29a1995242290e5e7544112c94e
2017-07-27 20:18:03 -07:00
Hugo Benichi
57af1a02a6 DO NOT MERGE ANYWHERE ConnectivityService: safer locking
This path changes a dangerous lock path in reportNetworkConnectivity().
This methods is called outside of the main ConnectivityService handler
and takes a lock on a specific NetworkAgentInfo whose connectivity
status is being reported.

While this lock is held, reportNetworkConnectivity() goes on and query
the network policy state for that network, which may ends into
NetworkPolicyManagerService.

Instead, the lock on NetworkAgentInfo is only held long enough to make a
copy of LinkProperties, which is then passed to
NetworkPolicyManagerService without that lock.

Bug: 36902662
Test: could not repro b/36902662, reportNetworkConnectivity() works.
      $ runtest frameworks-net

Change-Id: Iac4b75bcecbdddb0ac695c8b1a87ae755f62f47f
2017-07-27 20:17:25 -07:00
Hugo Benichi
900a3dbcc0 NetworkNotificationManager: correctly handle existing notifications
This patch corrects a regression added by commit fd35080555 that did
not take into account the case of multiple notifications shown for a
single network id. Given how network notifications are triggered, it can
happen that NO_INTERNET and SIGN_IN notifications are both triggered for
the same network when captive portal detection is slow.

Contrary to the situation before commit fd35080555, a notification
priority order is introduced so that SIGN_IN always overrides
NO_INTERNET, and NO_INTERNET is ignored if SIGN_IN is already present.

Bug: 63676954
Bug: 62503737
Test: runtest frameworks-net, added new unit tests
Merged-In: Ib8658601e8d4dc6c41b335ab7dd8caa0cccd9531
Merged-In: I4432f66067ea1ab02e1d2dfe42530bcdafa52df6
Merged-In: I74631b0bfd14daf18a1641ed7f2ec323d636ebbf
Merged-In: I73cc879e910d503946facdba498b300337f349fd
Merged-In: Ieed9e3e7755e0c5f89dc41ef66f47d4dbf4c66a9
Merged-In: I0aa590170f1bd4c37175c7e35e54d52f1fb21347

(cherry picked from commit 5fcd050e0ecd5985cf184f55ea3df4434da8f824)

Change-Id: I41675768ab59e9b23ca4275edf297b82595e5730
2017-07-28 09:17:20 +09:00
Steven Moreland
4f252f629f Merge "frameworks/base: use proper nativehelper headers" am: 80c9a74da8 am: d4a4d12451 am: c840945a78
am: bdf39c32ea

Change-Id: Ibe321dd4a8aae9342c76da0780edf94b90e8cd3a
2017-07-20 03:11:00 +00:00
Steven Moreland
bdf39c32ea Merge "frameworks/base: use proper nativehelper headers" am: 80c9a74da8 am: d4a4d12451
am: c840945a78

Change-Id: I654e14f0d1b495450db81592a2e564e308746350
2017-07-20 03:05:02 +00:00
Steven Moreland
d4a4d12451 Merge "frameworks/base: use proper nativehelper headers"
am: 80c9a74da8

Change-Id: I36f10ff4d963284a313f1cc5b368f82549a4adb2
2017-07-20 02:50:53 +00:00
Treehugger Robot
80c9a74da8 Merge "frameworks/base: use proper nativehelper headers" 2017-07-20 02:42:49 +00:00
Steven Moreland
b9e50d94d1 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
Hugo Benichi
90217e1808 Merge "ConnectivityServiceTest: fix testNetworkInfoOfTypeNone" am: 1f0d765378 am: 9efd050236 am: b1894abbc5
am: fecebf94a2

Change-Id: I7d3bfdf6d95d5db2d31439b5c3334569666864e1
2017-07-19 08:20:23 +00:00
Hugo Benichi
fecebf94a2 Merge "ConnectivityServiceTest: fix testNetworkInfoOfTypeNone" am: 1f0d765378 am: 9efd050236
am: b1894abbc5

Change-Id: I458a0fdae874039e0f1d5cd38ed8ad0a1754bba9
2017-07-19 08:15:12 +00:00
Hugo Benichi
9efd050236 Merge "ConnectivityServiceTest: fix testNetworkInfoOfTypeNone"
am: 1f0d765378

Change-Id: I4be1d2ce67871c1e01364beca886fdd3af374321
2017-07-19 08:04:48 +00:00
Treehugger Robot
1f0d765378 Merge "ConnectivityServiceTest: fix testNetworkInfoOfTypeNone" 2017-07-19 07:54:45 +00:00
Hugo Benichi
a6fe35a841 ConnectivityServiceTest: fix testNetworkInfoOfTypeNone
This patch fixes a couple of flakyness issues with
testNetworkInfoOfTypeNone. It also fixes some typos and naming issues.

Bug: 62918393, 62918393
Test: runtest frameworks-net
Change-Id: I1c56557ab113d3ef57dbc06a6e882634d03c5b09
2017-07-19 15:08:49 +09:00
The Android Automerger
260b8cec60 Manually merge commit '530b93aae428'
* commit '530b93aae428':
  NetworkCapabilities: Unhide TRANSPORT_LOWPAN

BUG:31038431
2017-07-19 00:27:08 +00:00
Robert Quattlebaum
6b6c6d45e2 Merge "NetworkCapabilities: Unhide TRANSPORT_LOWPAN" am: 1d4be0ece6 am: d1ce5a4ca7
am: dbc78509ae

Change-Id: I017036f8c63ea1e9c1934daad55ef087b3a83012
2017-07-18 23:51:04 +00:00
Robert Quattlebaum
d1ce5a4ca7 Merge "NetworkCapabilities: Unhide TRANSPORT_LOWPAN"
am: 1d4be0ece6

Change-Id: I3ae9566ca52b9dae87cace18b1e97897eb8de0ad
2017-07-18 23:33:08 +00:00
Treehugger Robot
1d4be0ece6 Merge "NetworkCapabilities: Unhide TRANSPORT_LOWPAN" 2017-07-18 23:09:58 +00:00