Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 725024bb authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Name specific app for rapid data usage."

parents f6ff0f88 e0c2995d
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -39,9 +39,6 @@ interface INetworkStatsService {
     */
    INetworkStatsSession openSessionForUsageStats(int flags, String callingPackage);

    /** Return network layer usage total for traffic that matches template. */
    long getNetworkTotalBytes(in NetworkTemplate template, long start, long end);

    /** Return data layer snapshot of UID network usage. */
    NetworkStats getDataLayerSnapshotForUid(int uid);
    /** Return set of any ifaces associated with mobile networks since boot. */
@@ -50,17 +47,11 @@ interface INetworkStatsService {
    /** Increment data layer count of operations performed for UID and tag. */
    void incrementOperationCount(int uid, int tag, int operationCount);

    /** Mark given UID as being in foreground for stats purposes. */
    void setUidForeground(int uid, boolean uidForeground);

    /** Force update of ifaces. */
    void forceUpdateIfaces(in Network[] defaultNetworks);
    /** Force update of statistics. */
    void forceUpdate();

    /** Advise persistance threshold; may be overridden internally. */
    void advisePersistThreshold(long thresholdBytes);

    /** Registers a callback on data usage. */
    DataUsageRequest registerUsageCallback(String callingPackage,
            in DataUsageRequest request, in Messenger messenger, in IBinder binder);
+21 −14
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ public class NetworkStats implements Parcelable {
    public NetworkStats(long elapsedRealtime, int initialSize) {
        this.elapsedRealtime = elapsedRealtime;
        this.size = 0;
        if (initialSize >= 0) {
        if (initialSize > 0) {
            this.capacity = initialSize;
            this.iface = new String[initialSize];
            this.uid = new int[initialSize];
@@ -250,19 +250,7 @@ public class NetworkStats implements Parcelable {
            this.operations = new long[initialSize];
        } else {
            // Special case for use by NetworkStatsFactory to start out *really* empty.
            this.capacity = 0;
            this.iface = EmptyArray.STRING;
            this.uid = EmptyArray.INT;
            this.set = EmptyArray.INT;
            this.tag = EmptyArray.INT;
            this.metered = EmptyArray.INT;
            this.roaming = EmptyArray.INT;
            this.defaultNetwork = EmptyArray.INT;
            this.rxBytes = EmptyArray.LONG;
            this.rxPackets = EmptyArray.LONG;
            this.txBytes = EmptyArray.LONG;
            this.txPackets = EmptyArray.LONG;
            this.operations = EmptyArray.LONG;
            clear();
        }
    }

@@ -314,6 +302,25 @@ public class NetworkStats implements Parcelable {
        return clone;
    }

    /**
     * Clear all data stored in this object.
     */
    public void clear() {
        this.capacity = 0;
        this.iface = EmptyArray.STRING;
        this.uid = EmptyArray.INT;
        this.set = EmptyArray.INT;
        this.tag = EmptyArray.INT;
        this.metered = EmptyArray.INT;
        this.roaming = EmptyArray.INT;
        this.defaultNetwork = EmptyArray.INT;
        this.rxBytes = EmptyArray.LONG;
        this.rxPackets = EmptyArray.LONG;
        this.txBytes = EmptyArray.LONG;
        this.txPackets = EmptyArray.LONG;
        this.operations = EmptyArray.LONG;
    }

    @VisibleForTesting
    public NetworkStats addIfaceValues(
            String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) {
+17 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import android.util.proto.ProtoOutputStream;

import com.android.internal.util.IndentingPrintWriter;

import libcore.util.EmptyArray;

import java.io.CharArrayWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -458,6 +460,21 @@ public class NetworkStatsHistory implements Parcelable {
        bucketCount++;
    }

    /**
     * Clear all data stored in this object.
     */
    public void clear() {
        bucketStart = EmptyArray.LONG;
        if (activeTime != null) activeTime = EmptyArray.LONG;
        if (rxBytes != null) rxBytes = EmptyArray.LONG;
        if (rxPackets != null) rxPackets = EmptyArray.LONG;
        if (txBytes != null) txBytes = EmptyArray.LONG;
        if (txPackets != null) txPackets = EmptyArray.LONG;
        if (operations != null) operations = EmptyArray.LONG;
        bucketCount = 0;
        totalBytes = 0;
    }

    /**
     * Remove buckets older than requested cutoff.
     */
+9 −95
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static android.net.ConnectivityManager.TYPE_PROXY;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.ConnectivityManager.TYPE_WIFI_P2P;
import static android.net.ConnectivityManager.TYPE_WIMAX;
import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED;
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
import static android.net.NetworkStats.DEFAULT_NETWORK_NO;
import static android.net.NetworkStats.DEFAULT_NETWORK_YES;
@@ -34,11 +33,6 @@ import static android.net.NetworkStats.ROAMING_ALL;
import static android.net.NetworkStats.ROAMING_NO;
import static android.net.NetworkStats.ROAMING_YES;
import static android.net.wifi.WifiInfo.removeDoubleQuotes;
import static android.telephony.TelephonyManager.NETWORK_CLASS_2_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_3_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_4_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_UNKNOWN;
import static android.telephony.TelephonyManager.getNetworkClass;

import android.os.Parcel;
import android.os.Parcelable;
@@ -55,8 +49,8 @@ import java.util.Arrays;
import java.util.Objects;

/**
 * Template definition used to generically match {@link NetworkIdentity},
 * usually when collecting statistics.
 * Predicate used to match {@link NetworkIdentity}, usually when collecting
 * statistics. (It should probably have been named {@code NetworkPredicate}.)
 *
 * @hide
 */
@@ -68,13 +62,7 @@ public class NetworkTemplate implements Parcelable {
     */
    private static final int BACKUP_VERSION = 1;

    public static final int MATCH_MOBILE_ALL = 1;
    /** @deprecated don't use this any more */
    @Deprecated
    public static final int MATCH_MOBILE_3G_LOWER = 2;
    /** @deprecated don't use this any more */
    @Deprecated
    public static final int MATCH_MOBILE_4G = 3;
    public static final int MATCH_MOBILE = 1;
    public static final int MATCH_WIFI = 4;
    public static final int MATCH_ETHERNET = 5;
    public static final int MATCH_MOBILE_WILDCARD = 6;
@@ -84,9 +72,7 @@ public class NetworkTemplate implements Parcelable {

    private static boolean isKnownMatchRule(final int rule) {
        switch (rule) {
            case MATCH_MOBILE_ALL:
            case MATCH_MOBILE_3G_LOWER:
            case MATCH_MOBILE_4G:
            case MATCH_MOBILE:
            case MATCH_WIFI:
            case MATCH_ETHERNET:
            case MATCH_MOBILE_WILDCARD:
@@ -111,25 +97,7 @@ public class NetworkTemplate implements Parcelable {
     * the given IMSI.
     */
    public static NetworkTemplate buildTemplateMobileAll(String subscriberId) {
        return new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId, null);
    }

    /**
     * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
     * the given IMSI that roughly meet a "3G" definition, or lower.
     */
    @Deprecated
    public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) {
        return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId, null);
    }

    /**
     * Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
     * the given IMSI that roughly meet a "4G" definition.
     */
    @Deprecated
    public static NetworkTemplate buildTemplateMobile4g(String subscriberId) {
        return new NetworkTemplate(MATCH_MOBILE_4G, subscriberId, null);
        return new NetworkTemplate(MATCH_MOBILE, subscriberId, null);
    }

    /**
@@ -307,9 +275,7 @@ public class NetworkTemplate implements Parcelable {

    public boolean isMatchRuleMobile() {
        switch (mMatchRule) {
            case MATCH_MOBILE_3G_LOWER:
            case MATCH_MOBILE_4G:
            case MATCH_MOBILE_ALL:
            case MATCH_MOBILE:
            case MATCH_MOBILE_WILDCARD:
                return true;
            default:
@@ -348,12 +314,8 @@ public class NetworkTemplate implements Parcelable {
        if (!matchesDefaultNetwork(ident)) return false;

        switch (mMatchRule) {
            case MATCH_MOBILE_ALL:
            case MATCH_MOBILE:
                return matchesMobile(ident);
            case MATCH_MOBILE_3G_LOWER:
                return matchesMobile3gLower(ident);
            case MATCH_MOBILE_4G:
                return matchesMobile4g(ident);
            case MATCH_WIFI:
                return matchesWifi(ident);
            case MATCH_ETHERNET:
@@ -409,43 +371,6 @@ public class NetworkTemplate implements Parcelable {
        }
    }

    /**
     * Check if mobile network classified 3G or lower with matching IMSI.
     */
    @Deprecated
    private boolean matchesMobile3gLower(NetworkIdentity ident) {
        ensureSubtypeAvailable();
        if (ident.mType == TYPE_WIMAX) {
            return false;
        } else if (matchesMobile(ident)) {
            switch (getNetworkClass(ident.mSubType)) {
                case NETWORK_CLASS_UNKNOWN:
                case NETWORK_CLASS_2_G:
                case NETWORK_CLASS_3_G:
                    return true;
            }
        }
        return false;
    }

    /**
     * Check if mobile network classified 4G with matching IMSI.
     */
    @Deprecated
    private boolean matchesMobile4g(NetworkIdentity ident) {
        ensureSubtypeAvailable();
        if (ident.mType == TYPE_WIMAX) {
            // TODO: consider matching against WiMAX subscriber identity
            return true;
        } else if (matchesMobile(ident)) {
            switch (getNetworkClass(ident.mSubType)) {
                case NETWORK_CLASS_4_G:
                    return true;
            }
        }
        return false;
    }

    /**
     * Check if matches Wi-Fi network template.
     */
@@ -506,12 +431,8 @@ public class NetworkTemplate implements Parcelable {

    private static String getMatchRuleName(int matchRule) {
        switch (matchRule) {
            case MATCH_MOBILE_3G_LOWER:
                return "MOBILE_3G_LOWER";
            case MATCH_MOBILE_4G:
                return "MOBILE_4G";
            case MATCH_MOBILE_ALL:
                return "MOBILE_ALL";
            case MATCH_MOBILE:
                return "MOBILE";
            case MATCH_WIFI:
                return "WIFI";
            case MATCH_ETHERNET:
@@ -529,13 +450,6 @@ public class NetworkTemplate implements Parcelable {
        }
    }

    private static void ensureSubtypeAvailable() {
        if (COMBINE_SUBTYPE_ENABLED) {
            throw new IllegalArgumentException(
                    "Unable to enforce 3G_LOWER template on combined data.");
        }
    }

    /**
     * Examine the given template and normalize if it refers to a "merged"
     * mobile subscriber. We pick the "lowest" merged subscriber as the primary
+10 −16
Original line number Diff line number Diff line
@@ -3772,31 +3772,23 @@
    <string name="extract_edit_menu_button">Edit</string>

    <!-- Notification title when data usage has exceeded warning threshold. [CHAR LIMIT=50] -->
    <string name="data_usage_warning_title">Data usage alert</string>
    <string name="data_usage_warning_title">Data warning</string>
    <!-- Notification body when data usage has exceeded warning threshold. [CHAR LIMIT=32] -->
    <string name="data_usage_warning_body">Tap to view usage and settings.</string>
    <string name="data_usage_warning_body">You've used <xliff:g id="app" example="3.8GB">%s</xliff:g> of data</string>

    <!-- Notification title when 2G-3G data usage has exceeded limit threshold, and has been disabled. [CHAR LIMIT=32] -->
    <string name="data_usage_3g_limit_title">2G-3G data limit reached</string>
    <!-- Notification title when 4G data usage has exceeded limit threshold, and has been disabled. [CHAR LIMIT=32] -->
    <string name="data_usage_4g_limit_title">4G data limit reached</string>
    <!-- Notification title when mobile data usage has exceeded limit threshold, and has been disabled. [CHAR LIMIT=50] -->
    <string name="data_usage_mobile_limit_title">Mobile data limit reached</string>
    <!-- Notification title when Wi-Fi data usage has exceeded limit threshold, and has been disabled. [CHAR LIMIT=32] -->
    <string name="data_usage_wifi_limit_title">Wi-Fi data limit reached</string>
    <!-- Notification body when data usage has exceeded limit threshold, and has been disabled. -->
    <string name="data_usage_limit_body">Data paused for rest of cycle</string>
    <string name="data_usage_limit_body">Data paused for the rest of your cycle</string>

    <!-- Notification title when 2G-3G data usage has exceeded limit threshold. [CHAR LIMIT=32] -->
    <string name="data_usage_3g_limit_snoozed_title">2G-3G data limit exceeded</string>
    <!-- Notification title when 4G data usage has exceeded limit threshold. [CHAR LIMIT=32] -->
    <string name="data_usage_4g_limit_snoozed_title">4G data limit exceeded</string>
    <!-- Notification title when mobile data usage has exceeded limit threshold. [CHAR LIMIT=32] -->
    <string name="data_usage_mobile_limit_snoozed_title">Mobile data limit exceeded</string>
    <string name="data_usage_mobile_limit_snoozed_title">Over your mobile data limit</string>
    <!-- Notification title when Wi-Fi data usage has exceeded limit threshold. [CHAR LIMIT=32] -->
    <string name="data_usage_wifi_limit_snoozed_title">Wi-Fi data limit exceeded</string>
    <string name="data_usage_wifi_limit_snoozed_title">Over your Wi-Fi data limit</string>
    <!-- Notification body when data usage has exceeded limit threshold. -->
    <string name="data_usage_limit_snoozed_body"><xliff:g id="size" example="3.8GB">%s</xliff:g> over specified limit.</string>
    <string name="data_usage_limit_snoozed_body">You've gone <xliff:g id="size" example="3.8GB">%s</xliff:g> over your set limit</string>

    <!-- Notification title when background data usage is limited. [CHAR LIMIT=32] -->
    <string name="data_usage_restricted_title">Background data restricted</string>
@@ -3804,9 +3796,11 @@
    <string name="data_usage_restricted_body">Tap to remove restriction.</string>

    <!-- Notification title when there has been recent excessive data usage. [CHAR LIMIT=32] -->
    <string name="data_usage_rapid_title">Large data usage</string>
    <string name="data_usage_rapid_title">High mobile data usage</string>
    <!-- Notification body when there has been recent excessive data usage. [CHAR LIMIT=128] -->
    <string name="data_usage_rapid_body">Your data usage over the last few days is larger than normal. Tap to view usage and settings.</string>
    <string name="data_usage_rapid_body">Your apps have used more data than usual</string>
    <!-- Notification body when there has been recent excessive data usage by a specific app. [CHAR LIMIT=128] -->
    <string name="data_usage_rapid_app_body"><xliff:g id="app" example="Calculator">%s</xliff:g> has used more data than usual</string>

    <!-- SSL Certificate dialogs -->
    <!-- Title for an SSL Certificate dialog -->
Loading