Commit Graph

740 Commits

Author SHA1 Message Date
Jeff Sharkey
ad1cebe58e Annotate @SystemApi with required permissions.
Most @SystemApi methods should be protected with system (or higher)
permissions, so annotate common methods with @RequiresPermission to
make automatic verification easier.

Verification is really only relevant when calling into system
services (where permissions checking can happen on the other side of
a Binder call), so annotate managers with the new @SystemService
annotation, which is now automatically documented.

This is purely a docs change; no logic changes are being made.

Test: make -j32 update-api && make -j32 offline-sdk-docs
Bug: 62263906
Change-Id: I2554227202d84465676aa4ab0dd336b5c45fc651
2017-06-05 13:27:11 -06:00
Hugo Benichi
b15ed2c488 NetworkStatsFactory: fix double accounting on IPv6 only networks
For 464xlat scenarios on IPv6 networks, the clatd interface setup
introduces double counting of apps ipv4 traffic. NetworkStatsFactory was
accounting for this on the tx path, but not on the rx path. Also it did
not accounted for the 20 bytes added by the IPv6 header.

This patch subtract correctly the rx and tx traffic from the root uid on
the underlying interface, and also adds correctly the 20 bytes cost per
packet on the stacked interface for 464xlat traffic.

Test: added several new unit tests, based on synthetic data and real
      data also.
Bug: 33681750
Change-Id: I4867fe181938d94b5594b3d88896a3c4e01d895c
Merged-In: I2675643b220acbc6110179fa937d4c313b6f5e32

(cherry picked from commit e1bb3a14d1ee1aba2f92e5bccf659774699eaffe)
2017-05-10 09:19:12 +09:00
Nathan Harold
7194bb9bf9 Hide IpSecManager, IpSecTransform, and IpSecAlgorithm
These classes, originally planned to be part of the
public API, are not ready for public consumption.
They are planned to be un-hidden in a future release.

Bug: 37681043
Test: make update-api and make
Merged-In: I8caccd3f8455341cb56a2256354eacbadedff047
Change-Id: I8caccd3f8455341cb56a2256354eacbadedff047
(cherry picked from commit e38565fc74ee19e27175782be3cf2f0dffefd3a6)
2017-04-25 16:53:50 -07:00
Hugo Benichi
4a786f94c2 Merge changes Ic029cc9f,Id917f3a2 into oc-dev
* changes:
  NsdService: minor cleanups
  Nsdmanager/NsdService: add logging
2017-04-20 04:27:50 +00:00
Hugo Benichi
5d4c5a2f5c NsdService: minor cleanups
Minor cleanups in switches of processMessage and handleNativeEvent.

Test: no functional changes
Bug: 33074219

(cherry picked from commit 23dba85fff01a9f51beea8ce811fc98b582f8e71)

Merged-In: I9ad4ce812c0d2c02a671a7a871ad427e4ce29b4a
Change-Id: Ic029cc9fa007d8c485f64f4afcbd4dc10da1ae29
2017-04-20 01:36:30 +00:00
Nathan Harold
b2b85df5d6 Hide Socket+DatagramSocket IpSecTransform methods
These methods do not currently work for IPv4 sockets,
so they need to be hidden until the underlying kernel
code can be made to work properly in a dual-stack
environment.

Bug: 36073210
Test: compilation
Merged-In: Idce367f638a42da374a7f1dc5ebb8931c9555e06
Change-Id: Idce367f638a42da374a7f1dc5ebb8931c9555e06
(cherry picked from commit da18b028f85e9a2c969c636aea6abf7f4bac3922)
2017-04-17 20:23:51 -07:00
Nathan Harold
2528c66a66 Consistenly Throw IOExceptions from IpSecManager
Bug: 36073210
Test: api-update
Change-Id: Ia3825e85b09b6330f1326a26cf9e1cadf9dacf71
Merged-In: Ia3825e85b09b6330f1326a26cf9e1cadf9dacf71
(cherry picked from commit c2fd6cfdc9dce33d57a3c2780e0527dd4b1bfeb9)
2017-04-17 20:23:34 -07:00
Hugo Benichi
b6389543d4 Nsdmanager/NsdService: add logging
This patch adds basic logging to NsdManager and NsdService, and improves
the facilities for pretty printing the event ids defined in NsdManager.

It also includes a few minor cleanups:
  - adding 'final' on effectively final instance variables of NsdManager
  and NsdService.
  - similarly, adding 'static' on effectively static class fields.
  - regrouping instance variables together.

Test: no functional changes
Bug: 33074219

(cherry picked from commit 2183ba9b5f8eb54c74cd198a7506b21319794e99)

Merged-In: I360d539e73cc8e4b45d4e0d20b2e345455fdb10c
Change-Id: Id917f3a2085d17f277850af36a2cf859e3614a0f
2017-04-17 10:07:05 +09:00
Nathan Harold
0bb49fc68c Add FileDescriptor Versions of applyTransportModeTransform()
Because there is no way using the Java sockets API to actually
get a socket of AF_INET on mode machines, it is necessary to
provide a way to apply transforms to sockets made using the
native wrapper API, which uses POSIX APIs and will create a
socket that is AF_INET.

Bug: 36073210
Test: b/34811227
Change-Id: I28ac7cc4f36045ce523a54111e5be975b0331356
2017-04-13 15:05:13 -07:00
Nathan Harold
ed0fcf1faf IpSecManager and IpSecAlgorithm API Tweaks
-Add a reserveSecurityParamterIndex() function that allows the
 system to select an SPI.
-Disallow INVALID_SECURITY_PARAMETER_INDEX from being passed as
 an explicit SPI request.
-Remove the ALGO_ prefix from constants in IpSecAlgorithm

Bug: 36073210
Test: Updated CTS tests still pass on bullhead
Change-Id: Ic94809996076b0718f153f550b82192fe7048a2e
2017-04-13 15:04:47 -07:00
Nathan Harold
7c30d6b8f2 Add Initial IPsec APIs to IpSecService
-Plumb IpSecManager APIs to NetD
-Add Resource Management to IpSecService

Bug: 30984788
Test: b/34812052, b/34811227
Change-Id: Ic43965c6158f28cac53810adbf5cf50d2c54f920
(cherry picked from commit 93962f34ce21f5aac825afbcebf2f3e8c7a30910)
2017-04-05 10:24:45 -07:00
Nathan Harold
8e518b4255 IpSecManager and IpSecTransform API Cleanup
-Remove Int-based SPI usage from the IpSecTransform.Builder
 This is essentially a less-safe method overload, and it is both
 unnecessary and difficult to implement: the cross-validation
 between SPI and Transform is actually useful, and the kernel
 requires two different mechanisms to use an unreserved vs a
 reserved (alloc'd) SPI: CREATESA vs UPDATESA, which makes this
 hard to support. API Council has questioned the value of this,
 and they are right: everything points to "remove this". In the
 future, if we find that SPI reservation is overhead, we can
 always add it back.

-Hiding the TunnelMode builder method and application/remove
 methods. These will not land by the time the next API
 stabilizes, so better to hide them now that this is a
 near-certainty. Expectation is to un-hide them in the subsequent
 API bump.

Bug: 36073210
Test: Compilation, verified nobody is calling these stubs
Change-Id: Ic1a3f2cf7128633318ac175d6b56b45eb8d21cab
(cherry picked from commit 48b566557d5a66d4476008b3c59b815eb78cb373)
2017-04-05 10:24:23 -07:00
Nathan Harold
18fd608286 Change reserveSecurityParameterIndex() to take a remoteAddress
To make the SPI reservation more semantically consistent with the
transform creation API, and to ensure that we always create SPI
reservations relative to a well-known remote, we should take the
SPI request relative to a remote (rather than to a destination).
This necessitates that we now consider direction separately, which
is used for keying the SA-Id.

Bug: 36073210
Test: compilation
Change-Id: I81e955c20128c1f8e04fd68eb26669561f827a78
(cherry picked from commit c4f879925b58b1b5ca9a3cfdc898c20cbf56355a)
2017-04-05 10:24:03 -07:00
Nathan Harold
8ea66052f2 Add a Skeleton IpSecService
-Add IpSecService with the necessary glue to connect to netd
-Add code to retrieve IpSecService from System Server

Bug: 30984788
Test: b/34812052, b/34811227
Change-Id: I4cdcb643421141202f77a0e2f87a37012de0cd92
(cherry picked from commit 28084d89ec136b56f5012be33a0dea147962f9f6)
2017-04-05 10:23:27 -07:00
Jeff Sharkey
f1077c3095 Consistent dump() permission checking.
This change introduces new methods on DumpUtils that can check if the
caller has DUMP and/or PACKAGE_USAGE_STATS access.  It then moves all
existing dump() methods to use these checks so that we emit
consistent error messages.

Test: cts-tradefed run commandAndExit cts-dev -m CtsSecurityTestCases -t android.security.cts.ServicePermissionsTest
Bug: 32806790
Change-Id: Iaff6b9506818ee082b1e169c89ebe1001b3bfeca
2017-04-02 22:29:07 -06:00
Ryuki Nakamura
f8dd5d479a Merge "Fix NPE while performing NetworkStatsService.removeUidsLocked()" am: a6ce3f3021 am: 8d2a076b4e
am: 06659047f0

Change-Id: Ia7c8309f68d85a88e2a26169509d3e45d4d2ff69
2017-03-20 17:24:37 +00:00
Ryuki Nakamura
8d2a076b4e Merge "Fix NPE while performing NetworkStatsService.removeUidsLocked()"
am: a6ce3f3021

Change-Id: I3f43b25622e5052e6336983da84b92e12f3e06dc
2017-03-20 17:05:16 +00:00
Ryuki Nakamura
662a01236a Fix NPE while performing NetworkStatsService.removeUidsLocked()
Symptom:
NPE occurred while performing NetworkStatsService.removeUidsLocked().

Root cause:
NetworkStatsService refers to mUidRecorder at
NetworkStatsService.removeUidsLocked() when mUserReceiver received
Intent.ACTION_USER_REMOVED.
However NetworkStatsService sets mUidRecorder to null without
unregistering mUserReceiver when mShutdownReceiver received
Intent.ACTION_SHUTDOWN.
Therefore NPE occurred when mUserReceiver received
Intent.ACTION_USER_REMOVED after mShutdownReceiver received
Intent.ACTION_SHUTDOWN.

Solution:
Unregister mUserReceiver before setting mUidRecorder to null when
mShutdownReceiver received Intent.ACTION_SHUTDOWN.

Bug: 36015339

Change-Id: I9279e4c6ae07d94e7ec519c40b2d973c84d8fef1
2017-03-07 07:12:51 +00:00
Nathan Harold
fab5eff9a6 Merge "Add API Surface for creating IpSec Transforms" am: 7645fa2816 am: 5466fbdc27
am: 3ddaf3e6b0

Change-Id: Idceae0e5a1af2f357378b03fc0d257dab605b217
2017-03-01 14:22:57 +00:00
Nathan Harold
5466fbdc27 Merge "Add API Surface for creating IpSec Transforms"
am: 7645fa2816

Change-Id: Ibe70a60c5c5808a7877145cccefcc1f11bfacc51
2017-03-01 14:12:55 +00:00
Nathan Harold
b1f605fc33 Add API Surface for creating IpSec Transforms
This CL adds an API to set up an IPSec Security Association
and Security Policy to perform Transport-Mode and Tunnel-Mode encapuslation
of IP Packets.

Bug: 30984788
Bug: 34811752
Test: 34812052, 34811227
Change-Id: Ic9f63c7bb366302a24baa3e1b79020210910ac0a
2017-02-28 22:01:20 -08:00
Stephen Chen
a86d26ef4b Merge commit '29a9cf2250e0eaed062fd0f990a04b923896279b' into nyc-mr1-dev-plus-aosp am: 8aa88a533c
am: 30fb2f228b

Change-Id: I318efe59e1967150338a7bd8001c27d9ebe3cf75
2017-01-27 07:42:07 +00:00
Hugo Benichi
7ee689b582 Merge commit 'a19056c35d16ddb5a6c1d3343729701b8939f1e1' into nyc-mr1-dev-plus-aosp am: cf7d2e1221 -s ours
am: d44a2395e3

Change-Id: I7028ef23f597e6e82ecdb6c11a6c8dcdb1d1f77b
2017-01-27 07:40:56 +00:00
Stephen Chen
30fb2f228b Merge commit '29a9cf2250e0eaed062fd0f990a04b923896279b' into nyc-mr1-dev-plus-aosp
am: 8aa88a533c

Change-Id: I3de8f91b1c9d0160ec58be8347502769580e0159
2017-01-27 07:29:07 +00:00
Hugo Benichi
d44a2395e3 Merge commit 'a19056c35d16ddb5a6c1d3343729701b8939f1e1' into nyc-mr1-dev-plus-aosp
am: cf7d2e1221  -s ours

Change-Id: Ie2f8c1e18acf57238fe4816812562ecd1644cf51
2017-01-27 07:28:06 +00:00
The Android Automerger
8aa88a533c Merge commit '29a9cf2250e0eaed062fd0f990a04b923896279b' into nyc-mr1-dev-plus-aosp
* commit '29a9cf2250e0eaed062fd0f990a04b923896279b':
  Implement metered tracking for NetworkStats summary queries.
2017-01-27 06:39:41 +00:00
The Android Automerger
cf7d2e1221 Merge commit 'a19056c35d16ddb5a6c1d3343729701b8939f1e1' into nyc-mr1-dev-plus-aosp
* commit 'a19056c35d16ddb5a6c1d3343729701b8939f1e1': (35 commits)
  NetworkMonitor: send one DNS probe per web probe
  NetworkMonitor metrics: add first validation information
  APF: also drop any ICMPv6 RSs
  ConnectivityServiceTest: fix testAvoidBadWifiSettings
  Fix ConnectivityServiceTest testRequestBenchmark
  Switch over to new "time.android.com" NTP pool.
  Define API for metering network stats buckets.
  Refactored NetworkStatsServiceTest to use Mockito instead of EasyMock.
  Use @Ignore to explicitly disable a @Test method.
  Fixed NetworkStatsServiceTest and converted it to JUnit4.
  VPN network stat accounting changes.
  ConnectivityThread: use lazy holder idiom
  ConnectivityManager: use ConnectivityThread looper
  ConnectivityManager: a simpler CallbackHandler
  Indicate the NsdServiceInfo attributes are only filled in for a resolved service.
  Add a null check for the OnStartTetheringCallback.
  TokenBucket for rate-limiting and throttling
  IpConnectivityMetrics reads buffer size in settings
  CaptivePortalLogin: set mixed content policy to compatibility.
  Add IP conn metrics to dumpsys and bug reports
  ...
2017-01-27 06:39:05 +00:00
Stephen Chen
29a9cf2250 Implement metered tracking for NetworkStats summary queries.
Dependent on ag/1550196 where API is defined.

Bug: 31015360
Bug: 26545374
Test: runtest --path
frameworks/base/core/tests/coretests/src/android/net/NetworkStatsTest.java,
other test classes.

(cherry picked from commit 357f8fabc8)

Change-Id: I46da93ba4afa968facf98f7c3d844fd0c469095a
2017-01-26 18:52:32 +09:00
Stephen Chen
a471b1647e Define API for metering network stats buckets.
This is a continuation of b/26545374, since now we can also set the
metered bit with NetworkScorer. The tracking of metered state changes
will be implemented in a seperate CL.

Bug: 31015360
Bug: 26545374
Test: N/A

(cherry picked from commit ed7fcb4d26)

Change-Id: I6a2fcc8577d62daa8823dff9e0128a5cf39ede7b
2017-01-26 18:52:08 +09:00
Jeremy Joslin
921f6f6797 VPN network stat accounting changes.
Properly account for VPN apps that make heavy use of the tun
interface. Prior to this change a VPN app could be incorrectly charged
for more data than it actually used if it sent more traffic through
the tun interface than the underlying interface.

This change excludes VPN app traffic on the tun interface from the
adjustment pool and doesn't redistribute traffic to the VPN app.
Instead all of the redistributed traffic is deducted from the VPN app
which effectively represents any overhead incurred by the VPN app.

BUG: 30557871

(cherry picked from commit 12255e3655)

Change-Id: I06f01aa8fe5fdc06b2d36cfb9c68feb244c2e5de
2017-01-26 18:51:53 +09:00
Jeff Sharkey
289eac11a2 StrictMode to detect untagged network traffic.
Network usage is tracked by the kernel at the UID level, which is
granular enough for normal apps, but large components (such as the
system server) are impossible to debug without adding additional
socket tagging to help identify subsystems within a UID.

To help ensure that system components tag all their network traffic,
this change offers a new StrictMode option to detect and report
untagged sockets.

Test: builds, boots, all common traffic tagged
Bug: 30943431, 30414041
Change-Id: I825c7941076054732264690247de2863342638e2
2017-01-19 20:52:05 -07:00
Makoto Onuki
3f75b41a1c Merge "Support protofied dumpsys for NetStats" 2017-01-18 21:30:20 +00:00
Stephen Chen
ff7dba4721 DO NOT MERGE: Implement metered tracking for NetworkStats summary queries.
am: f57c4def50  -s ours

Change-Id: I970aed286a5bcc69d2ee69ea23b53af36dc2bbea
2017-01-18 10:48:16 +00:00
Stephen Chen
1390fbbed8 DO NOT MERGE: Define API for metering network stats buckets.
am: 88b52b25f7  -s ours

Change-Id: I03a015bbc76c762d48688b1c66562bbd599d4265
2017-01-18 10:44:12 +00:00
Philip P. Moltmann
ade5083d25 DO NOT MERGE: Indicate the NsdServiceInfo attributes are only filled in for a resolved service.
am: 8ad38f0f6c  -s ours

Change-Id: I7d66e82b940bd88c7e5da0d4a4f2008f14d98a2e
2017-01-18 10:37:37 +00:00
Stephen Chen
f57c4def50 DO NOT MERGE: Implement metered tracking for NetworkStats summary queries.
Dependent on ag/1550196 where API is defined.

Bug: 31015360
Bug: 26545374
Test: runtest --path
frameworks/base/core/tests/coretests/src/android/net/NetworkStatsTest.java,
other test classes.

(cherry picked from commit 357f8fabc8)

(cherry picked from commit 92b6175069)

Change-Id: I79e401fc4159264a075febba82bd8c295b8e677f
2017-01-18 19:08:41 +09:00
Stephen Chen
88b52b25f7 DO NOT MERGE: Define API for metering network stats buckets.
This is a continuation of b/26545374, since now we can also set the
metered bit with NetworkScorer. The tracking of metered state changes
will be implemented in a seperate CL.

Bug: 31015360
Bug: 26545374
Test: N/A

(cherry picked from commit ed7fcb4d26)

(cherry picked from commit ebace40092)

Change-Id: I01ebb270c5bf7f2383e8923cce72545ca1bee118
2017-01-18 19:08:32 +09:00
Philip P. Moltmann
8ad38f0f6c DO NOT MERGE: Indicate the NsdServiceInfo attributes are only filled in for a resolved service.
Fixes: 28530428

(cherry picked from commit 79a3c031a0)

(cherry picked from commit 2838d9bb56)

Change-Id: Ib8f8da947af804c8b203928e57ed6a8aedbf0684
2017-01-18 19:08:16 +09:00
Makoto Onuki
feb5df9814 Support protofied dumpsys for NetStats
Bug 34228873
Test: manual tests with "incident_report netstats"

Change-Id: I359b364c64d9798fd4229018a905658d5d46ea5c
2017-01-17 14:16:01 -08:00
Jeff Davidson
601bc9b9a7 Merge "Add Log.wtf when getSummaryForAllUid NPEs." 2016-12-14 19:29:15 +00:00
Jeff Davidson
ed23aa6ca4 Add Log.wtf when getSummaryForAllUid NPEs.
This will provide stack trace information from the system process
which should enable us to more easily track down where the crash is
occurring.

Test: Builds locally
Bug: 33427276
Change-Id: I584a568fc038771afb28a534e2eefe2f763ed5e1
2016-12-12 12:11:16 -08:00
Lorenzo Colitti
34af49bb01 Merge changes from topic 'framework-net-aosp' am: a79b99893c am: 1a2fa0f372 am: c1c6b379c4
am: 20b77883fa

Change-Id: Ic6ee235cfbe3eea990f729de36119f8ce12a6a17
2016-12-09 11:25:03 +00:00
Stephen Chen
0e271e1517 DO NOT MERGE: Implement metered tracking for NetworkStats summary queries. am: 92b6175069 -s ours am: 3f5785260e -s ours am: c8be8d5853
am: 9b8712a3a0  -s ours

Change-Id: I8d502d83e00fdc1cb295b32c557ab253f4b5c091
2016-12-09 11:10:40 +00:00
Stephen Chen
597d0445ce DO NOT MERGE: Define API for metering network stats buckets. am: ebace40092 -s ours am: 419a061017 -s ours am: f394f5c66f
am: c13d7998dc  -s ours

Change-Id: Ia147a494bf908d64d938355bd357d570ac783b76
2016-12-09 11:03:13 +00:00
Jeremy Joslin
ff852600b5 DO NOT MERGE: VPN network stat accounting changes. am: b135f1d5a8 -s ours am: 12bb3f057b -s ours am: 0e885ddad1
am: 483611214d  -s ours

Change-Id: I356877d99b1304777d3d9103e9e0d421b1bb112b
2016-12-09 10:59:11 +00:00
Philip P. Moltmann
473af6b8f1 DO NOT MERGE: Indicate the NsdServiceInfo attributes are only filled in for a resolved service. am: 2838d9bb56 -s ours am: 6e8a33a583 -s ours am: 4ede7f4df7
am: 6c6a790ddc  -s ours

Change-Id: Ie5b45503c2917340397abdbd6df5ecc407d90c26
2016-12-09 10:55:07 +00:00
Lorenzo Colitti
c1c6b379c4 Merge changes from topic 'framework-net-aosp' am: a79b99893c
am: 1a2fa0f372

Change-Id: I746ee7fd37946df2ba31ca8aee928fa3ef04591c
2016-12-09 10:18:11 +00:00
Stephen Chen
c8be8d5853 DO NOT MERGE: Implement metered tracking for NetworkStats summary queries. am: 92b6175069 -s ours
am: 3f5785260e  -s ours

Change-Id: Ib6f4a4af04c3f4e26028604c66f6cc4f1720a801
2016-12-09 10:04:41 +00:00
Stephen Chen
f394f5c66f DO NOT MERGE: Define API for metering network stats buckets. am: ebace40092 -s ours
am: 419a061017  -s ours

Change-Id: Ide68c11828a6473e330715bb4efe4d0ade9a46a2
2016-12-09 09:58:05 +00:00
Jeremy Joslin
0e885ddad1 DO NOT MERGE: VPN network stat accounting changes. am: b135f1d5a8 -s ours
am: 12bb3f057b  -s ours

Change-Id: Id9d26bf1b9512a85cd9b6a3253b86b77a6f62e77
2016-12-09 09:54:07 +00:00