Search in sources :

Example 36 with NetworkTemplate

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

the class NetworkStatsService method performSampleLocked.

/**
     * Sample recent statistics summary into {@link EventLog}.
     */
private void performSampleLocked() {
    // TODO: migrate trustedtime fixes to separate binary log events
    final long trustedTime = mTime.hasCache() ? mTime.currentTimeMillis() : -1;
    NetworkTemplate template;
    NetworkStats.Entry devTotal;
    NetworkStats.Entry xtTotal;
    NetworkStats.Entry uidTotal;
    // collect mobile sample
    template = buildTemplateMobileWildcard();
    devTotal = mDevRecorder.getTotalSinceBootLocked(template);
    xtTotal = mXtRecorder.getTotalSinceBootLocked(template);
    uidTotal = mUidRecorder.getTotalSinceBootLocked(template);
    EventLogTags.writeNetstatsMobileSample(devTotal.rxBytes, devTotal.rxPackets, devTotal.txBytes, devTotal.txPackets, xtTotal.rxBytes, xtTotal.rxPackets, xtTotal.txBytes, xtTotal.txPackets, uidTotal.rxBytes, uidTotal.rxPackets, uidTotal.txBytes, uidTotal.txPackets, trustedTime);
    // collect wifi sample
    template = buildTemplateWifiWildcard();
    devTotal = mDevRecorder.getTotalSinceBootLocked(template);
    xtTotal = mXtRecorder.getTotalSinceBootLocked(template);
    uidTotal = mUidRecorder.getTotalSinceBootLocked(template);
    EventLogTags.writeNetstatsWifiSample(devTotal.rxBytes, devTotal.rxPackets, devTotal.txBytes, devTotal.txPackets, xtTotal.rxBytes, xtTotal.rxPackets, xtTotal.txBytes, xtTotal.txPackets, uidTotal.rxBytes, uidTotal.rxPackets, uidTotal.txBytes, uidTotal.txPackets, trustedTime);
}
Also used : NetworkTemplate(android.net.NetworkTemplate) NetworkStats(android.net.NetworkStats)

Example 37 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 38 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 39 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 40 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)

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