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
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
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
For now, there is still too much breakage around the kernel's new
qtaguid netfilter.
So no netstats up front.
But enable on the device until wiped:
./vendor/google/tools/override-gservices secure:netstats_enabled=1
adb reboot
Bug: 4903513
Change-Id: I230bd2d4efab85cac5c9abaa7d638c94f5e0c7d6
Signed-off-by: JP Abgrall <jpa@google.com>
And catch the actual errors reported by the other side of NetworkManager.
Change-Id: I9a9393b659d6f896ee1bf40a8deaca7853ef8f94
Signed-off-by: JP Abgrall <jpa@google.com>
During systemReady(), tell netd to enable bandwidth tracking module,
which is used to provide detailed stats and controls.
Change-Id: Iecfd8b17a3b90f5a817d731fbe1c71777681ed6e
And correctly upgrade NetworkIdentitySet written to disk, assuming
that old values aren't roaming.
Bug: 4724762
Change-Id: Ic25897ebbaf43be2390174d8e5fd08386bc8a345
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
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
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
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
Handful of DownloadManager flags to record when a download was paused
because of NetworkPolicyManager rules.
Change-Id: I99fc47f529cb6c8a42dbeca049e0cd0f1556eac4
When launching warning/limit UI, include the template that triggered
the notification. Also move actions and extra into contract class.
Change-Id: Id2e63fd2d2e36a137a3fd8f889c7256038ca5f2e
Watch for network statistics to cross NetworkPolicy warning or limit,
and show notifications to user as needed. Currently checks during
any statistics update, but will eventually move to event registration
through netd when kernel supports.
Fixed accounting bug in getSummaryForNetwork(). Only apply UID policy
to applications; applying to system processes could break critical
services like RIL.
Change-Id: Iac0f20e910e205f3cbc54ec96395ff268b1aa379
Instead of embedding complex template coexistence rules into policy
service, rely on external editors to enforce, and offer atomic
get/set operations for full policy sets.
Generate default mobile policy when none exists, using default of 4GB
warning and cycle reset of current day. Dispatch listener events
through Handler when holding internal lock, and catch CLASS_UNKNOWN
networks in 3G_LOWER template.
Change-Id: I063cf1eaf330e32b75d0697b89fc04488e6dfaea
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
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
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
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
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
When given a start/end range, interpolate between buckets to return
the total network usage. Used to summarize detailed UID stats. Method
to combine NetworkStatsHistory regardless of bucket size. Used to
combine all histories matching a template.
Added tests for both methods.
Change-Id: Ia463910c0ecf7cf08dcf97c658ad99742bd6b882
Collect UID-granularity network stats during regular poll event. Add
dumpsys argument to generate fake historical data for debugging, and
move stats parameters to Settings.Secure.
Change-Id: I09b36a2955dc10c697d4b9c3ff23dcb3ac37bd70
Instead of deriving network identity based on raw subsystem broadcasts,
listen for updates from ConnectivityService. Added atomic view of all
active NetworkState, and build map from "iface" to NetworkIdentity set
for stats tracking.
To avoid exposing internal complexity, INetworkStatsService calls use
general templates. Added TelephonyManager mapping to classify network
types using broad labels like "3G" or "4G", used to drive templates.
Cleaned up Objects and Preconditions.
Change-Id: I1d4c1403f0503bc3635a59bb378841ba42239a91
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
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
Teach ConnectivityManager about UID-specific rules derived from policy,
such as rejecting network traffic on "paid" interfaces. Calls that
return NetworkInfo now filter based on any REJECT rules in effect for
the calling UID. (Added uid parameter if callers that still want all
interfaces.)
Changed NetworkPolicyManager to derive rules based on current policy
combined with PowerManager and ActivityManager status, which it passes
to ConnectivityService for eventual enforcement through netd. When
rules change the usability of a NetworkInfo for a specific UID, it also
dispatches CONNECTIVITY_ACTION broadcasts to that UID. Combined paid
and background policy together to match current working definition.
Change-Id: I797ea49439fcc487cfe2cbc16703d4b91ceb9af6
The POLICY_REJECT_BACKGROUND policy requires that network traffic be
blocked when a UID goes into the background. Even if the UID has an
activity in the foreground, it's considered "background" if the screen
is turned off.
This changes watches for SCREEN_ON/OFF broadcasts, and rule generation
now observes screen state. It also introduces an observer pattern so
that ActivityManager doesn't directly know about NetworkPolicy, and
moves the service management into SystemServer.
Change-Id: Ie7a84929d3ca60ae4578d47e19d5a8da10fd8d58
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
New system service that maintains low-level network policy rules and
collects statistics to drive those rules. Will eventually connect to
netfilter kernel module through NetworkManagementService and "netd".
Begin tracking foreground activities in ActivityManagerService, which
is updated as part of OOM adjustment. Eventually a network policy of
POLICY_REJECT_BACKGROUND will reject network traffic from background
processes.
Change-Id: I5ffbbaee1b9628e9c3eff6b9cb2145fc5316e64d