Commit Graph

250 Commits

Author SHA1 Message Date
Jack Yu
05cca1a4cb Do not print misleading debug messages in some scenarios.
When the mobile network is not active, querying the network
information might trigger the misleading debug messages. Added
some condition checks to prevent this.

bug: 30850733
Change-Id: Ice6d548a56f98bac7fe2ca6a06148350b505533d
2016-08-23 16:09:36 -07:00
Jeremy Joslin
12255e3655 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
Change-Id: I62a75a0c0c0111e052b7903baa9f5d6d94ef57fd
2016-08-16 15:53:57 -07:00
Jeff Sharkey
bed14ecfc5 Avoid caching services with missing binders.
When fetching system services early during boot, if the underlying
binder interface hasn't been published yet, we end up caching a
manager class that is broken for the remainder of the process
lifetime, and innocent downstream callers end up using the broken
cached manager.

Fix this by using an explicit exception to quickly abort manager
creation when the underlying binder is missing.  The exception is
only used to skip the remainder of the manager creation, and it
doesn't actually crash the process.

Bug: 28634953
Change-Id: I0cb62261e6d6833660704b93a11185aa11a2ac97
2016-08-11 09:44:30 -06:00
Antonio Cansado
02f3b13b51 Merge \\\"Fix infinite loop when registering data usage callback.\\\" into nyc-dev am: 55e82ab60f am: 13cf0e7d54
am: 1d4fd3ed27

Change-Id: I5140373d930726e0b93fa62ac03315a37c581b5b
2016-06-20 22:44:51 +00:00
Antonio Cansado
320e313d2c Fix infinite loop when registering data usage callback.
Trivial fix is to call the method that takes the handler as a param.

Bug: 29508547
Change-Id: I75ba30a1663be265eed56b24deda82e83fd47a43
2016-06-20 15:03:03 -07:00
Antonio Cansado
dccb76c3de Merge "Cleaning up NetworkStatsManager." into nyc-dev am: c45f0aea71 am: f49cbec84c
am: cc1524eded

* commit 'cc1524edede07e2139cd072d6256fa96952f4004':
  Cleaning up NetworkStatsManager.

Change-Id: I3f669191e7c7739870dc098d5d6357d1d3ceb6dd
2016-05-25 22:43:26 +00:00
Antonio Cansado
bfd4e42c8d Cleaning up NetworkStatsManager.
- Throwing SecurityExceptionand and IllegalArgumentException instead of null for new APIs
- removing @removed APIs

Bug:27530098,27379882
Change-Id: Ifbe65bfc5051aa33aff2baa22cfa8e67b0f7c358
2016-05-25 11:07:41 -07:00
Antonio Cansado
e68d6ff96b Merge "Addressing API council comments on NetworkStatsManager." into nyc-dev am: dc5f558640 am: 7598ac2aa7
am: 8b2dd44f2f

* commit '8b2dd44f2f30a9dd22799ee30dd4b9c5a093aae5':
  Addressing API council comments on NetworkStatsManager.

Change-Id: Ie6455799758f0bdb67440f72c266effaf412e22f
2016-05-10 21:14:09 +00:00
Antonio Cansado
fe78ecbb2c Addressing API council comments on NetworkStatsManager.
Callbacks
 - DataUsageCallback renamed to UsageCallback
 - DataUsagePolicy removed; passing in params directly to register method
 - making it an abstract class
 - passing in (networkType, subscriberId) that reached its threshold
 - renaming onLimitReached to onThresholdReached to match existing naming
 - only monitor single network,subscriberId
 - no monitoring of specific uids; using device or user wide instead

Tags
 - only owner uid can read its tags
 - exposing only TAG_NONE to match service side

BUG: 27530098

Change-Id: I2b2664da71806868a1e937d2bf4d1f234637509b
2016-05-10 13:24:16 -07:00
Philip P. Moltmann
79a3c031a0 Indicate the NsdServiceInfo attributes are only filled in for a resolved service.
Fixes: 28530428
Change-Id: Ic90bcf4eec10c7db0fd4a4acc8436dda6bab4ba8
2016-05-05 22:34:00 +00:00
Antonio Cansado
84a92fd256 Fixing network tags.
- History was not populating the tag, so all of them appeared as tag 0x0.

Bug: 28345240
Change-Id: I9c898695bbe8d18531f7ea432ebb8f02d72e5d27
2016-04-26 22:18:52 +00:00
Robin Lee
8bad0f4646 Move UidRange aidl declaration to system/netd
Which owns the native UidRange.cpp, so it makes more sense for the
declaration to live there since frameworks/base depends on netd but not
vice versa.

Bug: 26694104
Change-Id: I0efda77713ee6f0ec8070fb0e09a694b95f6cd25
2016-04-18 15:26:47 +01:00
Jeff Sharkey
3616d5e826 Fix broken javadoc.
Change-Id: I9f2050fd6040234bb1d759ab346f79fc41247aa9
2016-04-12 15:22:57 -06:00
Jack Yu
7e3859251f Excluded certain APNs (e.g. IMS) from mobile data usage.
Added not_metered capability to a mobile network if none
of its associated APN types are metered. Also used not_metered
capability to determine if a network should be accounted for
data usage or not instead of using network type, which is
always MOBILE after refactoring. Will add VT usage support
in next phase.

bug: 20888836
Change-Id: Id692cb856be9a47d0e918371112630128965b1bb
2016-04-07 10:07:31 -07:00
Philip P. Moltmann
bbb41dd3bd Parse and validate txt records.
Bug: 27696905
Change-Id: I9affcf02a51c92a2be1c2bfc5efbd09065e100bc
2016-03-30 20:33:31 -07:00
Sharvil Nanavati
74895614da Add a NetworkTemplate matcher for ConnectivityManager#TYPE_PROXY.
Change-Id: I48c0a7bc39e2efcc5b4120a4fa2ecf6dfd54ac27
2016-03-23 16:19:34 -07:00
Jeff Sharkey
f759159b62 Update TrafficStats SystemApi docs.
Bug: 25726690
Change-Id: I221d62eaaf1e0fca8c26e4f19cb25d306710a849
2016-03-22 10:20:35 -06:00
Jeff Sharkey
f28f2820ab Ignore wildcard network policies.
They never should have been persisted to disk in the first place.

Bug: 24972775
Change-Id: If9254f74455823f9fda9545fdf543fc7250a4016
2016-03-21 13:13:28 -06:00
Jeff Davidson
082ceb1679 NetworkStats.Bucket API polish.
-Add @IntDef constants for STATE_ and ROAMING_.
-Expand docs for ROAMING_ constants.
-Use ROAMING_NO/YES instead of ROAMING_DEFAULT/ROAMING.

Bug: 27531260
Change-Id: I54ecfb4148caa549214df0bee9983036ffa4cb55
2016-03-14 11:24:12 -07:00
Jeff Sharkey
27c8a07be6 Restrict TrafficStats due to privacy concerns.
Granular per-UID network statistics can be used to infer user
behavior over time, so they fall under the umbrella of the
PACKAGE_USAGE_STATS permission.

Since we can't check app-ops based permissions in the kernel, the
best we can do is redirect users to the NetworkStatsManager class,
which offers a much more robust historical data set.

Bug: 27577101
Change-Id: I696bdc5e0b3d7e24acf35f388d0ab13617ed8af3
2016-03-09 16:49:45 -07:00
Jeff Sharkey
f713828f74 When system server goes down, crash apps more.
Apps making calls into the system server may end up persisting
internal state or making security decisions based on the perceived
success or failure of a call, or the default values returned.

The reality is that if the system process just died, init will be
along shortly to kill all running apps, so we should have no problem
rethrowing the RemoteException as a RuntimeException.

Bug: 27364859
Change-Id: Ife0bcb079636c88d54c44d17eb580409fd79028b
2016-03-01 19:29:16 -07:00
Jeff Sharkey
89a344fe60 Parcelable classes should always be final.
Also hide ConnectivityMetricsEvent which isn't being used yet.

Bug: 27415331
Change-Id: Iacdccddda504f3f669185f807b4f35b8dc2b0212
2016-02-29 16:46:09 -07:00
Jeff Sharkey
bc08d071ba When system server goes down, crash apps more.
Similar to first patch, but now using new "rethrowFromSystemServer()"
method which internally translates DeadObjectException into
DeadSystemException.  New logic over in Log.printlns() now
suppresses the DeadSystemException stack traces, since they're
misleading and just added pressure to the precious log buffer space.

Add some extra RuntimeInit checks to suppress logging-about-logging
when the system server is dead.

Bug: 27364859
Change-Id: I05316b3e8e42416b30a56a76c09cd3113a018123
2016-02-27 17:17:01 -07:00
Antonio Cansado
7a6536383d Implementation of data usage callbacks.
NetworkStatsService will register data usage requests
and keep data usage stats scoped to the request.

There are different types of data usage requests
- scoped to a set of NetworkTemplate; these are restrictred to
device owners and carrier apps and allow the caller to monitor
all activity on the specified interfaces.
- scoped to all uids visible to the user, if the user has
android.Manifest.permission#PACKAGE_USAGE_STATS permission.
The set of uids may change over time, so we keep track of that.
- scoped to a set of uids given by the caller, granted that
the caller has access to those uids.
- scoped to the caller's own data usage. This doesn't require
PACKAGE_USAGE_STATS.

Bug: 25812785
Change-Id: Ie11f35fc1f29d0dbe82f7fc924b169bb55c76708
2016-02-17 18:43:53 -08:00
Ritesh Reddy
118b392565 Merge "Enabled Network Policy Backup/Restore." into mm-wireless-dev
am: d9c4bc0c4d

* commit 'd9c4bc0c4db7a8b16d8ea0f58ed0615efc167f47':
  Enabled Network Policy Backup/Restore.
2016-02-10 19:46:20 +00:00
Ritesh Reddy
ca9d62d08d Enabled Network Policy Backup/Restore.
Added Backup Restore specific NetworkPolicySerializer
to NetworkPolicy Class and related classes.

Change-Id: I2a11e2afae8dd9e0ee0c3356e669a73f6a1361af
2016-02-08 10:41:21 +00:00
Antonio Cansado
fb502108b4 Adding a callback to notify data usage.
Allow holders of android.Manifest.permission#PACKAGE_USAGE_STATS
to be notified when data usage has exceeded a given threshold.
This allows an app to update its data usage metrics without
polling.

Bug: 25812785
Change-Id: I3a4904a97f3c7fbaf8071b460f9ee6ca9c1ba4ed
2016-02-02 15:18:41 -08:00
Antonio Cansado
2bb66f5d48 Retuning tag information through NetworkStatsManager.
Network tags could be set since ICS but was not exposed
through the SDK. This CL extends existing functionality
of NetworkStatsManager to return network tags.

Bug: 25813338
Change-Id: I414b98193249ba88a3f2d64cb2e0d2633f64fa3f
2016-02-01 14:13:20 -08:00
Jeff Davidson
3bbf8f320d Revert Network Stats API stub for tracking of metered networks.
Bug: 25813958
Change-Id: I9d2835b7bacfffef05b1588f1301afc70f5f582f
2016-01-29 10:36:52 -08:00
Zoltan Szatmary-Ban
4ff8b948b0 Introduce DEVICESUMMARY access level to NetworkStatsAccess.
Apps with PACKAGE_USAGE_STATS app op or READ_NETWORK_USAGE_HISTORY
granted can query the summarized device data usage (but not individual
uids running in other users or profiles).

Bug:26677052
Change-Id: Id51631638f338a8cf48172c9b41746228a335084
2016-01-26 13:59:52 +00:00
Jeff Davidson
131806f111 Implement roaming tracking in NetworkStats summary queries.
Whether a network is deemed roaming or not was already being tracked
as part of the NetworkIdentitySet, so the underlying data store
already tracks roaming and native data separately. However, this data
was being aggregated together in NetworkStatsCollection#getSummary,
since the NetworkIdentitySet is converted to an iface name for the
purposes of matching, and the iface name will be identical whether or
not the iface is considered roaming. Now it is separated.

Also fixes a long-standing bug in NetworkIdentitySet where an identity
read from a saved file would always be considered roaming == false,
even if it wasn't at the time it was written.

Bug: 25813438
Change-Id: I11ab5b51182ed8da7af8fde468df065f9fdc3dad
2016-01-19 16:57:51 -08:00
Jeff Davidson
b7ab1f9da6 Define new APIs for metering and roaming network stats buckets.
These are analagous to the state buckets for tracking whether usage is
incurred while the app is in the foreground or background. We will
additionally track whether data usage is incurred over a metered or
unmetered network, and whether it is incurred over a roaming or native
network.

The APIs are not implemented in this CL; the existing buckets are
still returned with METERING_ALL and ROAMING_ALL to indicate that this
is not yet being tracked.

Bug: 25813438
Bug: 25813958
Change-Id: I76dd3dd063ed28ef5579ca3a978570532e7836bc
2016-01-06 14:15:46 -08:00
Jeff Davidson
8dc22e3e90 Relax permissions around NetworkStatsManager APIs.
Currently, access to network usage history and statistics requires a
signature|privileged permission, an AppOps bit (associated with the
PACKAGE_USAGE_STATS permission), or device/profile ownership. Once
access is granted via one of these mechanisms, it generally applies to
any UID running in the same user as the caller.

This CL expands access as follows:

-Any app can access its own usage history with no extra requirements.
-Carrier-privileged applications can access usage history for the
entire device.
-Device owners can access per-UID breakdowns for usage. Previously
they could access the summary for the whole device, but not the
individual breakdowns.

We simplify the permission model by defining three access levels -
DEFAULT (own app only), USER (all apps in the same user), and DEVICE
(all apps on the device), and propagate these levels throughout.

Finally, this CL fixes an apparent bug in
NetworkStatsSerice#hasAppOpsPermissions - if the AppOp bit was in
MODE_DEFAULT, hasAppOpsPermission would always return false instead of
falling back to the PackageManager permission check.

Bug: 25812859
Bug: 25813856
Change-Id: Ic96e0776e2a4215a400163872acea1ededfaced9
2015-12-14 17:16:37 -08:00
Jeff Sharkey
7b124cb8e6 Add tagging variants for DatagramSocket.
Oops, we missed these along the way.

Bug: 25799174
Change-Id: I4ad368f9faee4b1996d605534dce4c2b23dbe200
2015-12-04 15:32:07 -07:00
Christopher Tate
c1c71fdff5 Introduce socket stats tag for restore traffic
As well as system API for emplacing it.

Change-Id: If33fbd23552261efe3b00d75c22ff823564f43e6
2015-11-10 11:13:12 -08:00
Jeff Sharkey
385f839a2c Merge "Ignore network policies with missing IMSI." into mnc-dr-dev am: 38463bb950 am: 5d7604323f
am: 3b30aae6e7

* commit '3b30aae6e702cbdad4ada69b76e4bc50fa2e161c':
  Ignore network policies with missing IMSI.
2015-10-20 18:33:48 +00:00
Jeff Sharkey
32933d6da3 Ignore network policies with missing IMSI.
In rare cases, we might have created a network policy before an IMSI
was available.  Because this policy is persisted, and we incorrectly
think that it always applies, we end up annoying the user when data
usage goes over the 2GB default warning threshold.

This patch fixes the network matching logic to ignore these empty
network policies when present.

Bug: 24972775
Change-Id: Id26499b6716121dddf0f2c05b848b0bed5995e72
2015-10-19 16:52:08 -07:00
Elliott Hughes
8dc3833e83 resolved conflicts for a884d81e to stage-aosp-master
Change-Id: Ice485967fa96f13786024b6939b826638e906ff0
2015-09-24 10:01:32 -07:00
Daniel Micay
aa49801a92 constify JNINativeMethod function pointer tables
Change-Id: I4036c924958221cbc644724f8eb01c5de3cd7954
2015-09-22 17:10:35 -04:00
Zoltan Szatmary-Ban
06a45679aa Remove uids with empty history from NetworkStats uid enumeration
Bug: 23018174
Change-Id: I1a482280599e0f5da18a208e727653d4bd4107ec
2015-08-14 16:21:52 +01:00
Zoltan Szatmary-Ban
f34946fabb Expose time-interval detail query on INetworkStatsSession
Also, force polling when a session is opened for NetworkStatsManager.

Bug: 21864554
Bug: 21754685
Change-Id: I24ea822c2d5bc1421ec7ee65d0cfe27cf02dd69e
2015-07-07 17:36:54 +01:00
Jeff Sharkey
8806907cc9 Update file size formatting.
Per UX, default strings should have space between value and units
resulting in "12.3 GB".  Add a formatting variant that returns the
various components for callers who want to build their own strings.

For now there is only one mounted emulated volume at a time, and
it's always the primary storage, so give it the default rootId to
keep old Uris working.

Change-Id: Ifcc72a91a6b397ee65dc92642153286186eb64ac
2015-06-15 21:39:28 -07:00
Zoltan Szatmary-Ban
567b6f86e7 Replace renamed reference to NetworkStats in javadoc
Bug: 21572680
Change-Id: Iad43af4d8a6d178f3396f23a74f1568e6faed311
2015-06-04 14:15:47 +01:00
Zoltan Szatmary-Ban
43a69f7a67 Rename NetworkUsageStats -> NetworkStats
Also making other changes to Data Usage API as requested by API review.

Bug: 20823478
Change-Id: Id766c5a725c856da9d8883d73ae788fc1472440a
2015-05-13 17:53:17 +01:00
Jeff Sharkey
6f2ba5ec43 Progress towards dynamic storage support.
Storage devices are no longer hard-coded, and instead bubble up from
whatever Disk and VolumeBase that vold uncovered, turning into
sibling Java objects in MountService.  We now treat vold events as
the source-of-truth for state, and synchronize our state by asking
vold to "reset" whenever we reconnect.

We've now moved to a model where all storage devices are mounted in
the root mount namespace (user boundaries protected with GIDs), so
we no longer need app-to-vold path translation.  This also means that
zygote only needs to bind mount the user-specific /mnt/user/n/ path
onto /storage/self/ to make legacy paths like /sdcard work.  This
grealy simplifies a lot of system code.

Many parts of the platform depend on a primary storage device always
being present, so we hack together a stub StorageVolume when vold
doesn't have a volume ready yet.

StorageVolume isn't really a volume anymore; it's the user-specific
view onto a volume, so MountService now filters and builds them
based on the calling user.  StorageVolume is now immutable, making
it easier to reason about.

Environment now builds all of its paths dynamically based on active
volumes.  Adds utility methods to turn int types and flags into
user-readable strings for debugging purposes.

Remove UMS sharing support for now, since no current devices support
it; MTP is the recommended solution going forward because it offers
better multi-user support.

Simplify unmount logic, since vold will now gladly trigger EJECTING
broadcast and kill stubborn processes.

Bug: 19993667
Change-Id: I9842280e61974c91bae15d764e386969aedcd338
2015-03-30 19:46:23 -07:00
Wenchao Tong
efd57ecab8 Keep debug information in NetworkStats files
Create two special SETs.

SET_DBG_VPN_IN is used by individual applications to know
how much traffic of the NetworkIdentity was actually moved
from a VPN app.
SET_DBG_VPN_OUT is used by the VPN app to know how much
traffic of the NetworkIdentity was deducted.

A debug application can restore the raw stats by these
entries.
  raw_traffic = recorded_entry (TAG_NONE, SET_ALL)
              + recorded_entry (TAG_NONE, SET_DBF_VPN_OUT)
              - recorded_entry (TAG_NONE, SET_DBF_VPN_IN)

The two debug SETs are not returned by
NetworkStatsService.openSession(). These debug entries are
retrieved by NetworkStatsCollection.dump().

Bug: 19536273
Change-Id: I03ef9f7667f5f2f48cbe3f6b11447fe7ead8ad3b
2015-03-27 13:49:13 -07:00
Zoltan Szatmary-Ban
b293e46f2c Data Usage public API
Added new API consisting of android.app.usage.NetworkUsageManager and
android.app.usage.NetworkUsageStats. Through them data usage on a
network interface can be programmatically queried. Both summary and
details are available.

Bug: 19208876
Change-Id: I0e0c4b37ae23ad1e589d4b0c955b93f28ba4333e
2015-03-25 15:53:38 +00:00
Wenchao Tong
fccef1da81 NetworkStatsService to adjust VPN stats before recording.
* Creates a new Parcelable class VpnInfo to hold required
  parameters for VPN stats adjustments.
* ConnectivityService to collect infomation and provide
  a list of VpnInfo, one for each user.
* NetworkStatsService passes the VpnInfo array to
  NetworkStatsRecorder.
* NetworkStatsRecorder calls NetworkStats.migrateTun()
  to do the math.
* Poll NetworkStats when the vpn application calls
  setUnderlyingNetworks().

Bug: 19536273
Change-Id: I7a4c7726b8243fead10416f7ec6eb5cf95f20183
2015-03-12 17:43:41 -07:00
Wenchao Tong
9ba4d7429b NetworkStats to support VPN accounting.
Create a new method to migrate underlying network traffic
from VPN app to other apps.

Bug: 19536273
Change-Id: I3434cad361592e26b01225edf8012f7b16afc98f
2015-03-09 11:38:10 -07:00
Jeff Sharkey
7639e76b81 am 2f1e953f: am 4df65bf1: Merge "Direct notification of network interface changes." into lmp-mr1-dev
* commit '2f1e953f8fd6d7ee32c00a680f887607f1005f62':
  Direct notification of network interface changes.
2014-12-09 00:18:01 +00:00