85 Commits

Author SHA1 Message Date
Jeff Sharkey
bfdd680ab4 Migrate to @Override to remove warnings.
Bug: 6303344
Change-Id: I0d33b2ed448467379d576ccd71fb5ae20c878852
2012-04-09 10:57:21 -07:00
Jeff Sharkey
b52e3e5509 INetworkStatsSession with lifecycle for caching.
Users outside system_server now explicitly communicate their
lifecycle, which keeps a strong-reference chain to any fully loaded
NetworkStatsCollection histories.

Bug: 6236498
Change-Id: I8e22739b6e89a626b676967a736d7117fd000778
2012-04-06 13:38:29 -07:00
Jeff Sharkey
8fc27e8b87 Support metered Wi-Fi NetworkPolicy.
Add networkId field to NetworkIdentity to identify Wi-Fi networks by
SSID.  Add support for policies without usage cycles.

Only apply mobile policies when SIM state is ready, which is cleaner
than just checking for airplane mode.  Also avoids creating no-op
default policies when subscriberId is null.

Bug: 3001465, 3291052
Change-Id: I1f8aaa49a5db306df022c402ea7f3f5d4bc0cfc7
2012-04-05 16:02:25 -07:00
Amith Yamasani
135936072b User management and switching
Broadcast intents that get sent out when users are added/removed/switched.

More work on generating user-specific information in package manager queries.
APIs to update user name and query a user by id.
Removed Package.mSetStopped and mSetEnabled, since they're not user specific.

User removal:
- Cleanup ActivityManager, PackageManager, WallpaperManager, AppWidgetService
  and AccountManager.
- Shutdown processes belonging to the user.

Don't show vibrate option in long-press power if there's no vibrator.

Lock the screen when switching users, to force unlocking.

Change-Id: Ib23a721cb75285eef5fd6ba8c7272462764038fa
2012-03-27 11:23:01 -07:00
Jeff Sharkey
6143f31537 Merge "NetworkPolicy multi-user tests." 2012-03-22 15:29:40 -07:00
Jeff Sharkey
cae04a29da NetworkPolicy multi-user tests.
Bug: 6214004
Change-Id: If13023a689dadfefe1475e0ef2f192922f2e7753
2012-03-22 15:18:57 -07:00
Amith Yamasani
ad812a23df Merge "Package restrictions per user" 2012-03-22 15:11:51 -07:00
Jeff Sharkey
4b63d69759 Fix test breakage.
Change-Id: I2c5fc8c3bf7795ccdd474caa3f858e9a56f026ed
2012-03-22 12:36:45 -07:00
Amith Yamasani
483f3b06ea Package restrictions per user
Packages can be enabled/disabled per user.
This requires maintaining stopped/launched states and
enabled / disabled components and packages per user.

Refactored pm.Settings and PackageSettingsBase to keep
track of states per user.

Migrated the stopped-packages.xml to users/<u>/package-restrictions.xml

Changed intent resolution to handle individual user restrictions.
Bunch of IPackageManager calls now have a userId argument.
Make AppWidgetService handle removals of packages.

Added some tests for pm.Settings and PackageManager.

Change-Id: Ia83b529e1df88dbcb3bd55ebfc952a6e9b20e861
2012-03-22 10:08:24 -07:00
Jeff Sharkey
9bf3150cfa Save timezone when setting data cycle reset date.
Instead of cycle reset at midnight UTC, use midnight of timezone
active when user last set cycle reset date.  Tests to verify, and
also to test leap year behavior.

Bug: 5938567
Change-Id: Ie06f7f0fa242d23110f9586a3f4f7037af87b31b
2012-03-09 17:10:05 -08:00
Jeff Sharkey
241dde2306 Unify shorthand for byte-based units.
Change-Id: If990859dee3f0973e1d4c48f05312c84071b3328
2012-02-03 14:50:13 -08:00
Jeff Sharkey
0e2e5f8b56 Support snoozing of data warning notification.
Introduce second snooze timestamp to support dismissal of data usage
warning notification.  Also explicitly set notification "when" to
avoid fighting with other notifications, such as ongoing downloads.

Bug: 5443756, 5262414
Change-Id: I03342c25b0410b1b2db84de9a40884f04cb1d8ae
2012-02-02 16:22:33 -08:00
Jeff Sharkey
63abc37356 Move network stats to FileRotator pattern.
Split existing network stats into two separate classes: a recorder
which generates historical data based on periodic counter snapshots,
and a collection of historical data with persistance logic.

Recorder keeps a pending history in memory until outstanding data
crosses a specific threshold.  Persisting is handled through a given
FileRotator.  This pattern significantly reduces disk churn and
memory overhead.  Separate UID data from UID tag data, enabling a
shorter rotation cycle.  Migrate existing stats into new structure.

Remove "xt" stats until iptables hooks are ready.  Avoid consuming
Entry values when recording into NetworkStatsHistory.  Assign
operation counts to default route interface.

Introduce "Rewriter" interface in FileRotator with methods to enable
rewriteAll().  Introduce IndentingPrintWriter to handle indenting in
dump() methods.

Bug: 5386531
Change-Id: Ibe086230a17999a197206ca62d45f266225fdff1
2012-01-24 11:13:14 -08:00
Jeff Sharkey
f60d0afd1e Restrict app data on metered networks.
This separates the definition of "metered network" and "network with
limit."  For now, all mobile networks are considered metered.

Bug: 5571454
Change-Id: I394cd385bd33add75e53bfc9cf2fefd06a00208a
2011-12-15 14:30:04 -08:00
Makoto Onuki
f9165b7e43 MCC detection fixes for CountryDetector
- Don't get and cache phone tpe at the initialization time.  At this point
TelephonyManager is probably not ready yet.

- Refresh MCC whenever we get the service state changed callback, even when
the state hasn't actually changed, in order to make sure we get refresh
country properly when MCC changes.

- Also remove the initialization of mPhoneStateListener, which prevented us from
registering phone state listener properly.

- Also fix tests which were already failing.

Bug 5670680

Change-Id: Id45abeba1b1e843053ac2c946861b439ca568de4
2011-12-09 17:55:18 -08:00
Jeff Sharkey
31c6e4817f Move NativeDaemonConnector to varargs.
Perform uniform argument escaping inside NativeDaemonConnector, using
varargs to separate boundaries.  Also move to parsed NativeDaemonEvent
instances instead of raw Strings.

Bug: 5472606
Change-Id: I1270733e2b2eeb2f6b810240df82ab24d38ebf40
2011-11-29 12:09:06 -08:00
Nick Kralevich
8549aeea0a Merge "Rename EntropyService to EntropyMixer" 2011-11-17 15:30:46 -08:00
Nick Kralevich
6967cbc959 Rename EntropyService to EntropyMixer
EntropyService implies that this program provides entropy to other
programs, and is misleading. The EntropyMixer class is designed purely
to stir the existing entropy pool with some possibily random-ish data,
and carryover entropy across device reboots.

Change-Id: I086cd339a3b652d32371521e61e1b1f555ce2280
2011-11-17 13:29:58 -08:00
Jeff Sharkey
c506ff6150 Only write network stats when already loaded.
Bug: 5584564
Change-Id: Ife2a68804bf3691e9bccdc167807204bce8a85b2
2011-11-17 12:05:46 -08:00
Jeff Sharkey
7ee8658453 Conservatively trim data usage stats.
Instead of trusting NTP time alone, use the most-conservative of
system clock and NTP.

Bug: 5584564
Change-Id: I5dd87fc009959b1cf0a7d660e385a0b1a8be238b
2011-11-14 20:11:38 -08:00
Jeff Sharkey
163e6443f2 Correct proc file reader, optimizations.
Moved away from BufferedReader, which only reads the first 8KB of
some proc files because it aggresively fills its buffer.  Optimized
proc parsing, now double the speed.  Tests to cover.

Log when NetworkStats counters roll backwards when subtracting, and
optimizations around findIndex().  When system removes UID, also
remove from last stats snapshot to avoid xt counters from rolling
backwards.

Bug: 5472949, 5458380
Change-Id: I07c08fe5233156fac2b84450f6291868bf9bfaf2
2011-11-02 15:14:11 -07:00
Jeff Sharkey
1059c3c30a Move battery stats to xt_qtaguid for data stats.
Replace TrafficStats calls by reading values from xt_qtaguid kernel
module. To keep BatteryStatsImpl changes lightweight, cache recently
parsed stats. Tracks mobile ifaces from ConnectivityService.

Refactor xt_qtaguid parsing into factory outside of NMS. Add stats
grouping based on UID, and total based on limiting filters like iface
prefix and UID.

Bug: 4902271
Change-Id: I533f116c434b77f93355bf95b839e7478528505b
2011-10-09 13:49:08 -07:00
Jeff Sharkey
ae2c181083 Read iface stats from single proc file.
When available, use single "iface_stat_all" file instead of reading
values from dozens of files scattered across proc.  Tests to verify.

Bug: 5397840
Change-Id: I0247be518436c1f79b32c4b72216739f49a9e8cc
2011-10-04 13:22:39 -07:00
Jeff Sharkey
905b5891d2 Track xtables summary, move tether stats, time.
Begin tracking xtables summary of data usage to compare with values
reported from /proc/net/dev.  Roll tethering directly into UID stats
to trigger UID stats persisting when crossing threshold.

Include xtables summary and authoritative time in samples.

Bug: 5373561, 5397882, 5381980
Change-Id: Ib7945522caadfbe0864fdf391582dc820f4f371e
2011-10-03 17:21:05 -07:00
Kenny Root
8a663c89a3 Merge "Allow non-required package verifiers" 2011-09-26 09:53:06 -07:00
Kenny Root
05ca4c9064 Allow non-required package verifiers
* Verifiers can be specified in the AndroidManifest.xml

* Those verifiers can respond to the new Intent action

* PackageManager API for those verifiers: verifyPendingInstall

Change-Id: I4892bce2e6984871e6e93c60a1ca0dae145f5df5
2011-09-23 16:03:03 -07:00
Jeff Sharkey
367d15ab1a Watch network subtype, tethering teardown, empty.
Watch for changes to telephony network subtype, and update iface
mapping to persist stats under correct type.  Update network stats
before removing tethering NAT rules.

Skip recording that would create empty historical buckets.  Query UID
stats before iface stats to always skew positive when counters are
actively rolling forward.

Bug: 5360042, 5359860, 5335674, 5334448
Change-Id: I8aa37b568e8ffb70647218aa1aff5195d3e44d5a
2011-09-22 16:19:06 -07:00
Jeff Sharkey
34c73acf88 Sample atomic network stats buckets, full poll.
When sampling network stats, always use atomic buckets instead of
interpolating.  Always poll iface and UID together so we distribute
into buckets equally.  Move stale bucket trimming to just before
writing stats.

Bug: 5321340
Change-Id: I78a2226778a79c875f3668336e39ea24a7b4d5c4
2011-09-18 16:27:21 -07:00
JP Abgrall
98a4f7e7e1 NetworkManagement SocketTagger: Migrate QTagUid support to JNI.
* Instead of javaland trying to write commands to
   /proc/net/xt_qtaguid/ctrl
use the libcutils/qtaguid.c support via JNI.
* Get rid of tagToKernel() handled by qtaguid library.

Requires libcutils changes from c/132538/

Change-Id: I9de5b3fa4a596c56835024c6d376769a0eea7db1
2011-09-15 02:29:03 -07:00
Jeff Sharkey
991d1b1b3f Network stats flag to force complete poll.
Devices currently delay collecting UID stats during common operations
like global alerts to reduce parsing load.  Here we introduce a flag
to always collect UID and iface stats together to aid debugging.

Bug: 5321340
Change-Id: Ia8e1daf1a6f9d5f5cf1f64a04b6b6766ee965ab6
2011-09-14 19:47:05 -07:00
Jeff Sharkey
69b0f63af2 Data usage structure optimizations.
Driven by traceview hotspots found in Settings UI.

Change-Id: I614a049523c526b7fcd12fffdf53a3e4723623e4
2011-09-12 16:13:20 -07:00
Jeff Sharkey
b3d5957604 Poll UID stats during iface changes, enforce idx.
When ifaces change, poll UID stats without persisting, since they
depend on knowing active iface to store correctly.  Log dropped UID
stats when iface is unknown.  Switch to using flags when calling
performPoll().

Enforce that "idx" values are consistent from xt_qtaguid.  Transition
to using Log.wtf() for important checks, mostly around file I/O,
kernel stats parsing, and kernel module control.  Increase stats
persist threshold to 2MB to reduce churn.

Bug: 5269476, 5270106
Change-Id: I721215bfb65127f95775c71cf135e907cd567e92
2011-09-07 18:06:30 -07:00
Jeff Sharkey
0fea823673 Selectively add stats based on iface active state.
Only combine /proc/net/dev and xt_qtaguid stats when iface is marked
as active.  When inactive, only return xt_qtaguid stats.  When iface
is unknown to xt_qtaguid, always pass through /proc/net/dev stats.

Bug: 5242730
Change-Id: I469fc6abe45309f794afebca814cbb39e4f13af5
2011-09-01 15:23:38 -07:00
Jeff Sharkey
961e304583 Introduce immediate CONNECTIVITY_ACTION variant.
New broadcast that is dispatched immediately after connectivity
changes have been handled by ConnectivityService, bypassing any
applicable CONNECTIVITY_CHANGE_DELAY.

Also protect CONNECTIVITY_CHANGE broadcasts, since they should only
be sent by system.

Bug: 5198167
Change-Id: I75f1fb44b21da1879f0ab960bcaa481126d70fde
2011-08-29 16:10:43 -07:00
Jeff Sharkey
47eb102b40 Always splice historical data stats, debug info.
When reading network counters, always splice in xt_qtaguid values
to avoid counting backwards. Test to verify.

Remove verbose logging around global alerts, and add dumpsys debug
info for NMS and MDST. Also fix subtle bug around stats persisting
and dumping.

Bug: 5212893, 5211028
Change-Id: I783e5286637a67ee2dd2b09878198711a926d0cb
2011-08-26 14:19:54 -07:00
Jeff Sharkey
8e9992ae50 Register for kernel global data usage alerts.
Instead of polling every 15 minutes, register for alerts that trigger
when system-wide traffic passes a threshold.  Still mixed with polling
to persist UID stats, but relaxed to 30 minutes.  Currently watches
for every 512kB.

Make persistence decision separately for network versus UID, and use
total delta bytes when making decision.  Use light bootstrap during
systemReady() instead of heavy poll, which had been force-loading all
UID data unnecessarily.

Bug: 5023631
Change-Id: I04b723d6c4bf872fb1028071122dba66a8e1b576
2011-08-23 18:46:14 -07:00
Jeff Sharkey
8e28b7d782 Proactively disable data when over policy limit.
Add policy controls to NetworkStateTracker which are combined with
other user preference and internal flags to decide if data connection
should be established.  Better locking around enabled flags.

When data network would be over limit, proactively disable data on
that network.  Enable when policy is snoozed or when cycle resets.

Track and dismiss notifications from now-stale policies.

Bug: 4587023, 5178147
Change-Id: Ibfcc9f73cda7c369209af701b46eddd3d1943f2d
2011-08-23 18:45:44 -07:00
Jeff Sharkey
b5d55e302d Foreground/background network stats using sets.
Teach NetworkStats about "counter sets" coming from kernel, and use
them to track usage in foreground/background.  Add AID_NET_BW_ACCT to
system_server so it can control counter sets.

Move to composite key of NetworkIdentitySet, UID, set, and tag when
recording historical usage.  Persisting still clusters by identity,
since that is heaviest object.

Request async stats poll during systemReady() to bootstrap later
delta calculations. Reset kernel counters when UID removed. Update
various tests.

Bug: 5105592, 5146067
Change-Id: Idabec9e3ffcaf212879821515602ecde0a03de8c
2011-08-15 17:30:25 -07:00
Jeff Sharkey
af82ea2abf Data cycle ends on last second of month.
When data cycle resets on a day invalid in given month, snap the
cycle to last second of month.  Previous behavior was to bump fully
into next month, but that causes cycle loops.

Includes tests to verify.

Bug: 4623124
Change-Id: I2f233091f6f1df33a2814284519cbc04532874e9
2011-08-04 17:07:08 -07:00
Jeff Sharkey
63d27a9233 Network stats with varint, omit parcel fields.
Persist NetworkStatsHistory using variable-length encoding; since
most buckets have small numbers, we can encode them tighter. Initial
test showed 44% space savings. Also persist packet and operation
counters.

Let NetworkStatsHistory consumers request which fields they actually
need to reduce parcel overhead.

Tests for verify varint and history field requests, also verify end-
to-end by persisting history into byte[] and restoring. Expose
bandwidth control enabled state. Extend random generation to create
packet and operation counts. Moved operation counts to long.

Fix bug that miscalculated bytes since last persist, which would
cause partial stats loss when battery pulled.

Bug: 4581977, 5023706, 5023635, 5096903
Change-Id: If61e89f681ffa11fe5711471fd9f7c238d3d37b0
2011-08-03 17:21:07 -07:00
Jeff Sharkey
a63ba59260 Add operation counts to network statistics.
Provide API to increment "operation counts" for a UID and tag, used
to eventually derive bytes/operation stats.  Internally is stored at
network layer, but should belong at data layer.  Switch profiling
to use data layer stats, which are emulated by summarizing network
layer details.

Read packet counts from new /proc/ columns and collect them into
NetworkStatsHistory.  Prevent double-counting by ignoring values from
first snapshot.  Watch for duplicate /proc/ entries.  Update tests
to verify packet and operation counters.

Bug: 5052136, 5097392
Change-Id: I1832f65a2b8a9188f8088f253474a667c21a2f09
2011-07-29 22:24:01 -07:00
Jeff Sharkey
41ff7ec824 Revise data limit notifs, watch kernel alerts.
Teach NetworkPolicy limits to "snooze" when requested by user, and
notify with both dialog and notification.  Register for network alerts
through NMS to trigger updates immediately instead of waiting for
next stats update.

Enforce that all NetworkPolicy are unique on a template basis, and
move SCREEN_ON/OFF broadcasts to background thread.  Launch SystemUI
and Settings directly instead of using actions, and include full
NetworkTemplate in extras.

Tests to verify notification and snooze behavior.

Bug: 5057979, 5023579, 4723336, 5045721
Change-Id: I03724beff94a7c0547cb5220431ba8d4cd44d077
2011-07-27 09:31:39 -07:00
Svetoslav Ganov
00aabf7d18 Touch exploration state set to clients asynchronously and depended on talking service being enabled.
1. Upon registration of an accessibility client the latter received only
   the accessiiblity state and waiting for the touch exploration state
   to be sent by the system in async manner. This led the very first
   check of touch exploration state is checked a wrong value to be reported.
   Now a state of the accessibility layer is returned to the client
   upon registration.

2. Removing the dependency on talking accessibility service to be enabled
   for getting into touch exploration mode. What if the user wants to use
   an accessibility service that shows a dialog with the text of the touched
   view?

bug:5051546

Change-Id: Ib377babb3f560929ee73bd3d8b0d277341ba23f7
2011-07-22 17:38:54 -07:00
Svetoslav Ganov
35bfedeaba Touch exploration separate setting and API to poll the latter state.
1. Seperated touch exploration to be a seperate setting rather being
   magically enabled by the system of accessiiblity is on the there
   is at leas one accessibility service that speaks enabled. Now
   there is a setting for requesting touch exploration but still the
   system will enabled it only if that makes sense i.e. accessibility
   is on and one accessibility service that speaks is enabled.

2. Added public API for checking of touch exploration is enabled.

3. Added description attribute in accessibility service declaration
   which will be shown to the user before enabling the service.

4. Added API for quick cloning of AccessibilityNodeInfo.

5. Added clone functionality to SparseArray, SparseIntArray, and
   SparseBooleanArray.

bug:5034010
bug:5033928

Change-Id: Ia442edbe55c20309244061cd9d24e0545c01b54f
2011-07-18 12:44:08 -07:00
Jeff Sharkey
4e814c348c Hide NetworkTemplate details, buffered stats I/O.
Move template matching to builder methods instead of exposing the
internal constants.  Also rule to match Ethernet usage.  Buffer
reading and writing of network stats, making operations 5x faster.

Change-Id: Iedb2d0ab3b26a976811c050f84a164e909eb74b6
2011-07-14 20:43:27 -07:00
Jeff Sharkey
434962e44e Include full network history around current time.
When requesting historical values with time ranges, always include
full values for buckets that span current time.  (It doesn't make
sense to interpolate partial data.)  Move getTotalData() to return
full Entry objects to prepare for packet counts.

Bug: 4691901
Change-Id: I717bd721be9f1d4a47c4121e46e07a56cb15bbf1
2011-07-12 20:20:56 -07:00
Jeff Sharkey
d37948f6ed Hide NetworkStatsHistory internals.
Instead of exposing internal storage details, offer getValues()
accessor which populates values into a recycled structure.

Change-Id: I5228d7099a8f61b2018a435a813435a67dae49b4
2011-07-12 13:57:06 -07:00
Jeff Sharkey
fd8be3e5e7 Return stats from inactive ifaces, packet counts.
When an iface goes inactive, xt_qtaguid maintains historical counters
instead of discarding.  Now reading and returning those values in
NetworkManagementService summary calls.  Tests to verify stats are
returned.

Modify NetworkStats to include rxPackets and txPackets values, and
move to Entry to eventually hide internal storage details.

Bug: 4984539
Change-Id: I1ba0bb5580c62e946d9dff2cc2a6f64aff403efc
2011-07-11 14:39:56 -07:00
Jeff Sharkey
350083e36b Migrate bandwidth control to NMS, omit history.
Both stats and policy make NMS calls that depend on bandwidth control
being enabled, so move enable/disable into NMS and drop calls when
disabled.  This avoids throwing heavy ISE exceptions when disabled.

Only include recent data when writing NetworkStatsHistory as part of
dumpsys call.  Introduce manual poll event for Settings UI.

Bug: 4982115, 4770435, 4515856
Change-Id: I257820b057af2f0f99c736fb4f61e55b9fdc3e66
2011-06-30 15:47:51 -07:00
Jeff Sharkey
b3f19ca36c Enforce background data flag, rules through netd.
Connect up netd penalty box through NMS, and enforce the existing
background data flag by putting all UIDs in penalty box.  Allow
platform applications to have policy applied.  Only dispatch unique
rules to netd, avoiding any repeats.

Bug: 4598463, 4965677
Change-Id: Ibf9beff998ba7a1ea92f5e2f7eeba7b483d4b918
2011-06-30 00:17:46 -07:00