154 Commits

Author SHA1 Message Date
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
Jeff Sharkey
afb60c36b7 Merge "Push interface quota rules from NetworkPolicyManager to kernel." 2011-06-29 10:53:06 -07:00
Ashish Sharma
50fd36d7c3 Push interface quota rules from NetworkPolicyManager to kernel.
Change-Id: Id2b758f561820b44839f69bf5fbd676cae771fe3
2011-06-29 10:51:06 -07:00
Jesse Wilson
8568db5341 Move socket tagging from libcore.
Change-Id: I7515896936c5bbd212c88e2801b831914219a925
2011-06-28 23:43:51 -07:00
Jeff Sharkey
4414cea139 Better network stats parsing, integer tags, async.
Change NMS parsing to handle extended /proc/ stats formats by pairing
values with header keys.  Move TrafficStats to integer tags to match
kernel internals, and offer well-known tags for system services.

Async policy event dispatch from NPMS, and update tests to block for
event dispatch.  Narrow app policy to exclude apps signed with system
key, which are usually critical.

Bug: 4948913, 4903489, 4585280

Change-Id: Idb357227ccaa617906411f309371cea18d7bc519
2011-06-28 17:59:00 -07:00
Jeff Sharkey
d03fd3f004 Persist "tagged" network stats along with UIDs.
Now stores tags other than TAG_NONE (0x0), which are useful for app
debugging.  Combine UID and tag together into single long key, and
expose tag data through AIDL when requested.  Change NMS to track
TAG_NONE as total UID traffic, matching the kernel definition.

Added TAG_MAX_HISTORY to control how long tag-granularity statistics
are stored; overall UID usage is still kept for UID_MAX_HISTORY.  Fix
bug to trim NetworkStatsHistory outside normal polling loops to catch
non-active networks and UIDs.

Test to verify UID and tag packing, and to verify that UID traffic on
two networks are combined to match MOBILE_ALL template.

Change-Id: If0e039416d9e7f63b1a39e04cddfb1133b5a78ee
2011-06-19 21:58:39 -07:00
Jeff Sharkey
b09540f33a Handle removed UIDs in network stats and policy.
When UID_REMOVED, clean up any existing UID network policy so it
doesn't linger for future apps.  Also move any NetworkStatsHistory
to special UID_REMOVED tracking bucket.

Tests for new removal code.  Also test detailed UID stats, including
network changes to verify template matching logic.

Bug: 4584212
Change-Id: I9faadf6b6f3830eb45d86c7f1980a27cdbcdb11e
2011-06-19 01:08:12 -07:00
Jeff Sharkey
1b5a2a96f7 Read "qtaguid" network stats, refactor templates.
Teach NMS to read qtaguid stats from kernel, but fall back to older
stats when kernel doesn't support.  Add "tags" to NetworkStats entries
to support qtaguid.  To work around double-reporting bug, subtract
tagged stats from TAG_NONE entry.

Flesh out stronger NetworkTemplate.  All NetworkStatsService requests
now require a template, and moved matching logic into template.

Record UID stats keyed on complete NetworkIdentitySet definition,
similar to how interface stats are stored.  Since previous UID stats
didn't have iface breakdown, discard during file format upgrade.

Change-Id: I0447b5e7d205d73d28e71c889c568e536e91b8e4
2011-06-18 22:23:11 -07:00
Jeff Sharkey
fdfef57f49 Notify policy listeners about metered ifaces.
Currently, kernel definition of metered networks is applied at the
interface level.  This change maintain list of those metered ifaces
and notifies policy listeners, like ConnectivityService.  (This gives
us a consistent picture of when a network would be blocked.)

Bug: 4601393
Change-Id: I277d5ca96ab967a1c1c3f1da8f9587557cd6d74c
2011-06-17 16:49:21 -07:00
Jeff Sharkey
2242af25df Add permission to fix NetworkPolicy tests.
Change-Id: I4d5265b2b08c1ec0c42b71ad0ceeb9952094caa0
2011-06-16 14:03:43 -07:00
Jeff Sharkey
2ef2aeb18d Fix NetworkPolicy tests after notifications.
Change-Id: I569e9ceba6d89459b347ed151fd9bda2909dc892
2011-06-15 11:01:31 -07:00
Jeff Sharkey
af11d48595 Fix test-related build breakage.
Change-Id: I48a3dbbdc49d742d6ad19cff34ee8da4b3949bb8
2011-06-13 00:14:31 -07:00
Jeff Sharkey
4a97122ebf Growable NetworkStats object instead of builder.
NetworkStats now grows in place with arraycopy() instead of callers
needing to know record count a priori.  Better growth calculation for
both NetworkStats and NetworkStatsHistory; 50% each time.  Better
estimates of buckets needed in calling services.

Change-Id: I3adbffa0b7407612cc6349d9135a8b4eb63cd440
2011-06-11 22:17:17 -07:00
Jeff Sharkey
39ebc2195e Persist UID stats, lazy loading, resize buckets.
Persisting detailed UID stats in separate "netstats_detail.bin" file
to enable different schedules for summary and detail polling.  Only
load detailed UID history on demand, since it's not needed during
boot.  Add test to verify UID stats are persisted across simulated
reboot.

Move external settings into well-named interface, which is still
backed by Settings.Secure.  During periodic poll events, resize any
history to match current bucket duration setting.  Test to verify.

Change-Id: I6366f3583a591f8ba859b0e5987daf8cafa4e95a
2011-06-11 17:55:56 -07:00
Jeff Sharkey
cd2ca4038a Move data cycle methods to framework object.
Moved so they can be used by both system service and Settings UI, since
they both work with data usage cycles.  Still covered by tests.

Change-Id: I01c0c4db6da9457dd867c9167d31a5f9f8e5f5d9
2011-06-10 19:45:34 -07:00
Jeff Sharkey
21c9c45e5c Interface-level network policy, persist policies.
Define NetworkPolicy as cycle-reset day and warning/limit values, and
set/get through NetworkPolicyManager.  Watch ConnectivityManager for
network connection events, and apply quota rules based on matching
interfaces.  Policy service matches based on strong identity to support
IMSI-specific policy values.

Calculates remaining quota based on current stats recorded since the
last reset cycle day.  Tests to verify edge cases around February.

Persist network and UID policies in XML, and restore on boot.

Change-Id: Id40ba7d6eed6094fbd5e18e6331286c606880d80
2011-06-10 19:35:20 -07:00
Jeff Sharkey
3f3913550c Persist network stats using AtomicFile.
Implements read/write of network stats using AtomicFile, along with
magic number and versioning.  Stores in "/data/system/netstats.bin"
for now.  Tests to verify that stats are persisted across a simulated
reboot, and to verify that TEMPLATE_WIFI is working.

Fixed bug where kernel counters rolling backwards would cause negative
stats to be recorded; now we clamp deltas at 0.

Change-Id: I53bce26fc8fd3f4ab1e34ce135d302edfa34db34
2011-06-09 10:14:13 -07:00
Jeff Sharkey
7527990420 Collect historical network stats.
Periodically records delta network traffic into historical buckets to
support other services, such NetworkPolicyManager and Settings UI.

Introduces NetworkStatsHistory structure which contains sparse, uniform
buckets of data usage defined by timestamps.  Service periodically
polls NetworkStats and records changes into buckets.  It only persists
to disk when substantial changes have occured.  Current parameters
create 4 buckets each day, and persist for 90 days, resulting in about
8kB of data per network.

Only records stats for "well known" network interfaces that have been
claimed by Telephony or Wi-Fi subsystems.  Historical stats are also
keyed off identity (such as IMSI) to support SIM swapping.

Change-Id: Ia27d1289556a2bf9545fbc4f3b789425a01be53a
2011-06-01 17:44:52 -07:00
Jeff Sharkey
9599cc5f21 Tests for NetworkPolicyManager rule generation.
Verifies that policy changes trigger rule updates that respect current
foregroundActivities status.  Also verifies logic that promotes a UID
based on its most-foreground PID.  Verifies that policy changes result
in immediate rule changes.

Also verifies that BACKGROUND_DATA_SETTING_CHANGED broadcasts are sent
by policy changes.

Change-Id: I4fd0dad9e1dbccee2c5968244bb1814e6cb2c6e1
2011-06-01 17:26:30 -07:00
Svetoslav Ganov
cc4053e031 Accessibility serviceconfiguration via meta-data
Note: This is a part of two CL change and contains the
      system changes without updates to the settings.

1. Added a mechanism for configuring an accessibility service via
   XML file specified in a meta-data tag (similar to IMEs).

2. Added property for specifying a settings activity for an
   accessibility service.

3. Refactored the APIs in AccessibilityManager to return
   lists of AccessiblityServiceInfo instead ServiceInfo
   since the former describes an AccessibilityService in
   particular (similar to IMEs).

Change-Id: Ie8781bb7e0cdb329e583b6702a612a507367ad7b
2011-05-31 12:04:18 -07:00
Jeff Sharkey
eedcb9525b APIs to profile network usage for current UID.
Added startDataProfiling() and stopDataProfiling() to TrafficStats,
which can be used by apps to measure network usage delta between two
points in time.  Currently takes two NetworkStats snapshots and returns
delta, which will eventually include tag-level granularity.  Added
tests for NetworkStats delta subtraction.

Added NMS.getNetworkStatsUidDetail() that returns stats for specific
UID.  Always gives stats access for the calling UID, otherwise enforces
that caller has permission.  Fix readSingleLongFromFile(), since
/proc/ files don't have well-defined lengths.

Change-Id: Ic5b6414d8effbd66846e275b00d4b8a82c74589d
2011-05-21 15:02:58 -07:00
Jeff Sharkey
9a13f36cdd Return NetworkStats bundle from NM service.
Introduce NetworkStats which is a collection of network statistics,
which should match the structure communicated by kernel module through
netd.  Will introduce tags and fg/bg stats later.  Kept entirely in a
flat data structure to optimize parcel speed.

Initial pass at returning NetworkStats from NetworkManagementService,
both summary and details.  Will eventually pull data from kernel module
over netd connection.

Change-Id: I92d9f61678ec8c22e2ce26775fb035a0cf32413f
2011-05-04 16:07:21 -07:00
Daisuke Miyakawa
a550bdc84a Use passive provider for location based country detection
Bug: 4345419
Change-Id: Ia3e071b97c6971538ea994fdee6029db928201d6
2011-04-28 16:18:19 -07:00
Jeff Sharkey
b7342acebc Tests for ThrottleService, NTP into TrustedTime.
Wrote initial suite of tests for ThrottleService, checking a variety
of edge cases.  Checks going over limits, updating policies, and reset
after cycle elapses.

Moved NTP code in ThrottleService into new TrustedTime interface,
which makes it easier to understand, and allows tests to provide custom
clocks.

Change-Id: I0d62b8b3a169516a2ab2d33025f6fe30dc792be8
2011-04-28 12:28:36 -07:00
Amith Yamasani
0b285499db Plumbing in PackageManager and installd for multi-user support.
- Create /data/user directory and symlink /data/user/0 -> /data/data for
  backward compatibility
- Create data directories for all packages for new user

- Remove data directories when removing a user

- Create data directories for all users when a package is created

- Clear / Remove data for multiple users

- Fixed a bug in verifying the location of a system app

- pm commands for createUser and removeUser (will be disabled later)

- symlink duplicate lib directories to the original lib directory

Change-Id: Id9fdfcf0e62406a8896aa811314dfc08d5f6ed95
2011-04-15 15:15:27 -07:00
Amith Yamasani
4b2e934928 Package manager changes to store and update user information.
Some API stubs for managing users and storing their details.
List of users is stored in an xml file.
Each user's properties are stored in a separate xml file.

Some unit tests for modifying the XML files.

Change-Id: If2ce2420723111bd426f6762def3c2afc19a0ae5
2011-04-11 12:12:58 -07:00
Svetoslav Ganov
383742c16d 3205857 java.lang.ExceptionInInitializerError at java.lang.Class.newInstanceImpl(Native Method)
Change-Id: I72ab33da2f5cc0bbaa89f3b996ff4ac48deadf73
2010-12-09 11:52:47 -08:00
Bai Tao
a58a8751b4 Add new system service CountryDetector
a. The CountryDetector detects the country the user is in
   in order of mobile network, location, sim card or locale.
   It will be used by contact and contact provider.

b. All added APIs are hidden at this stage.

Change-Id: I4ba278571ffb6ab6ded0996d4f440a18534f8ed4
2010-07-28 09:45:57 +08:00
Dan Egnor
3300b6f41e am 7da38863: am 3685db7f: am e8605af5: Merge "Avoid leaking file descriptors when returning drop box events." into froyo
Merge commit '7da38863d4382746090bf50413b1774ab04f6bc1'

* commit '7da38863d4382746090bf50413b1774ab04f6bc1':
  Avoid leaking file descriptors when returning drop box events.
2010-07-21 15:00:27 -07:00
Dan Egnor
6e6d60d4c8 Avoid leaking file descriptors when returning drop box events.
We can't use Parcel.writeValue() to write the ParcelFileDescriptor, otherwise
it leaks when returning the value to the caller (the flag gets lost).  Change
the way DropBoxManager.Entry gets serialized so that it uses a bit of its own
flags value to track whether the data is a byte[] or a ParcelFileDescriptor.

Modify the dropbox unit test to add extensive checking of Entry serialization
and deserialization under various circumstances, and to include a regression
test to ensure that FD leaking doesn't happen.

Bug: 2847738
Change-Id: I4ccd17dd03ffab234340cd359e6f3510fdf81193
2010-07-21 12:52:21 -07:00
Svetoslav Ganov
5637745e59 2744878 com.android.server.AccessibilityManagerServiceTest:testInterrupt is failing
Change-Id: I73d056c7dcf8edddae2ef9cb28ec7d2b3203bb9b
2010-06-07 14:27:39 -07:00
Svetoslav Ganov
0b29a58714 2604226 Add test cases for the internal accessibility infrastructure.
Change-Id: Iaeb2c11b6c2167632086b50d9c79e6459cc072b8
2010-04-26 21:23:54 -07:00