Search in sources :

Example 21 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by DirtyUnicorns.

the class NetworkPolicyManagerShellCommand method newPolicy.

private NetworkPolicy newPolicy(String ssid) {
    final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(ssid);
    final NetworkPolicy policy = newWifiPolicy(template, false);
    return policy;
}
Also used : NetworkTemplate(android.net.NetworkTemplate) NetworkPolicy(android.net.NetworkPolicy)

Example 22 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by DirtyUnicorns.

the class DataUsageController method getDataUsageInfo.

public DataUsageInfo getDataUsageInfo() {
    final String subscriberId = getActiveSubscriberId(mContext);
    if (subscriberId == null) {
        return warn("no subscriber id");
    }
    NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);
    template = NetworkTemplate.normalize(template, mTelephonyManager.getMergedSubscriberIds());
    return getDataUsageInfo(template);
}
Also used : NetworkTemplate(android.net.NetworkTemplate)

Example 23 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by DirtyUnicorns.

the class ChartDataLoader method loadInBackground.

@Override
public ChartData loadInBackground() {
    final NetworkTemplate template = mArgs.getParcelable(KEY_TEMPLATE);
    final AppItem app = mArgs.getParcelable(KEY_APP);
    final int fields = mArgs.getInt(KEY_FIELDS);
    try {
        return loadInBackground(template, app, fields);
    } catch (RemoteException e) {
        // leave with half-baked UI, we bail hard.
        throw new RuntimeException("problem reading network stats", e);
    }
}
Also used : NetworkTemplate(android.net.NetworkTemplate) AppItem(com.android.settingslib.AppItem) RemoteException(android.os.RemoteException)

Example 24 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by DirtyUnicorns.

the class NetworkStatsManager method querySummaryForDevice.

/**
     * Query network usage statistics summaries. Result is summarised data usage for the whole
     * device. Result is a single Bucket aggregated over time, state, uid, tag and roaming. This
     * means the bucket's start and end timestamp are going to be the same as the 'startTime' and
     * 'endTime' parameters. State is going to be {@link NetworkStats.Bucket#STATE_ALL}, uid
     * {@link NetworkStats.Bucket#UID_ALL}, tag {@link NetworkStats.Bucket#TAG_NONE}
     * and roaming {@link NetworkStats.Bucket#ROAMING_ALL}.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
     *            etc.
     * @param subscriberId If applicable, the subscriber id of the network interface.
     * @param startTime Start of period. Defined in terms of "Unix time", see
     *            {@link java.lang.System#currentTimeMillis}.
     * @param endTime End of period. Defined in terms of "Unix time", see
     *            {@link java.lang.System#currentTimeMillis}.
     * @return Bucket object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
public Bucket querySummaryForDevice(int networkType, String subscriberId, long startTime, long endTime) throws SecurityException, RemoteException {
    NetworkTemplate template;
    try {
        template = createTemplate(networkType, subscriberId);
    } catch (IllegalArgumentException e) {
        if (DBG)
            Log.e(TAG, "Cannot create template", e);
        return null;
    }
    Bucket bucket = null;
    NetworkStats stats = new NetworkStats(mContext, template, startTime, endTime);
    bucket = stats.getDeviceSummaryForNetwork();
    stats.close();
    return bucket;
}
Also used : NetworkTemplate(android.net.NetworkTemplate) Bucket(android.app.usage.NetworkStats.Bucket)

Example 25 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by DirtyUnicorns.

the class NetworkStatsManager method querySummaryForUser.

/**
     * Query network usage statistics summaries. Result is summarised data usage for all uids
     * belonging to calling user. Result is a single Bucket aggregated over time, state and uid.
     * This means the bucket's start and end timestamp are going to be the same as the 'startTime'
     * and 'endTime' parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid
     * {@link NetworkStats.Bucket#UID_ALL}.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
     *            etc.
     * @param subscriberId If applicable, the subscriber id of the network interface.
     * @param startTime Start of period. Defined in terms of "Unix time", see
     *            {@link java.lang.System#currentTimeMillis}.
     * @param endTime End of period. Defined in terms of "Unix time", see
     *            {@link java.lang.System#currentTimeMillis}.
     * @return Bucket object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
public Bucket querySummaryForUser(int networkType, String subscriberId, long startTime, long endTime) throws SecurityException, RemoteException {
    NetworkTemplate template;
    try {
        template = createTemplate(networkType, subscriberId);
    } catch (IllegalArgumentException e) {
        if (DBG)
            Log.e(TAG, "Cannot create template", e);
        return null;
    }
    NetworkStats stats;
    stats = new NetworkStats(mContext, template, startTime, endTime);
    stats.startSummaryEnumeration();
    stats.close();
    return stats.getSummaryAggregate();
}
Also used : NetworkTemplate(android.net.NetworkTemplate)

Aggregations

NetworkTemplate (android.net.NetworkTemplate)111 NetworkPolicy (android.net.NetworkPolicy)33 RemoteException (android.os.RemoteException)21 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 NetworkStats (android.net.NetworkStats)12 IOException (java.io.IOException)12 AlertDialog (android.app.AlertDialog)6 Dialog (android.app.Dialog)6 DialogInterface (android.content.DialogInterface)6 NetworkIdentity (android.net.NetworkIdentity)6 Time (android.text.format.Time)6 NtpTrustedTime (android.util.NtpTrustedTime)6 TrustedTime (android.util.TrustedTime)6 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)6 AppItem (com.android.settingslib.AppItem)6 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)6 Bucket (android.app.usage.NetworkStats.Bucket)5