Search in sources :

Example 1 with NetworkTemplate

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

the class NetworkStatsService method openSession.

@Override
public INetworkStatsSession openSession() {
    mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
    assertBandwidthControlEnabled();
    return new INetworkStatsSession.Stub() {

        private NetworkStatsCollection mUidComplete;

        private NetworkStatsCollection mUidTagComplete;

        private NetworkStatsCollection getUidComplete() {
            if (mUidComplete == null) {
                synchronized (mStatsLock) {
                    mUidComplete = mUidRecorder.getOrLoadCompleteLocked();
                }
            }
            return mUidComplete;
        }

        private NetworkStatsCollection getUidTagComplete() {
            if (mUidTagComplete == null) {
                synchronized (mStatsLock) {
                    mUidTagComplete = mUidTagRecorder.getOrLoadCompleteLocked();
                }
            }
            return mUidTagComplete;
        }

        @Override
        public NetworkStats getSummaryForNetwork(NetworkTemplate template, long start, long end) {
            return internalGetSummaryForNetwork(template, start, end);
        }

        @Override
        public NetworkStatsHistory getHistoryForNetwork(NetworkTemplate template, int fields) {
            return internalGetHistoryForNetwork(template, fields);
        }

        @Override
        public NetworkStats getSummaryForAllUid(NetworkTemplate template, long start, long end, boolean includeTags) {
            final NetworkStats stats = getUidComplete().getSummary(template, start, end);
            if (includeTags) {
                final NetworkStats tagStats = getUidTagComplete().getSummary(template, start, end);
                stats.combineAllValues(tagStats);
            }
            return stats;
        }

        @Override
        public NetworkStatsHistory getHistoryForUid(NetworkTemplate template, int uid, int set, int tag, int fields) {
            if (tag == TAG_NONE) {
                return getUidComplete().getHistory(template, uid, set, tag, fields);
            } else {
                return getUidTagComplete().getHistory(template, uid, set, tag, fields);
            }
        }

        @Override
        public void close() {
            mUidComplete = null;
            mUidTagComplete = null;
        }
    };
}
Also used : NetworkTemplate(android.net.NetworkTemplate) NetworkStats(android.net.NetworkStats)

Example 2 with NetworkTemplate

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

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 3 with NetworkTemplate

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

the class DataIdleTest method testMobile.

/**
     * Test that dumps all the data usage metrics for all mobile to instrumentation out.
     */
public void testMobile() {
    String subscriberId = mTelephonyManager.getSubscriberId();
    NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);
    fetchStats(template);
}
Also used : NetworkTemplate(android.net.NetworkTemplate)

Example 4 with NetworkTemplate

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

the class DataIdleTest method testWifiIdle.

/**
     * Test that dumps all the data usage metrics for wifi to instrumentation out.
     */
public void testWifiIdle() {
    NetworkTemplate template = NetworkTemplate.buildTemplateWifiWildcard();
    fetchStats(template);
}
Also used : NetworkTemplate(android.net.NetworkTemplate)

Example 5 with NetworkTemplate

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

the class DataIdleTest method testMobile.

/**
     * Test that dumps all the data usage metrics for all mobile to instrumentation out.
     */
public void testMobile() {
    String subscriberId = mTelephonyManager.getSubscriberId();
    NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);
    fetchStats(template);
}
Also used : NetworkTemplate(android.net.NetworkTemplate)

Aggregations

NetworkTemplate (android.net.NetworkTemplate)151 NetworkPolicy (android.net.NetworkPolicy)40 RemoteException (android.os.RemoteException)26 TelephonyManager (android.telephony.TelephonyManager)23 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 Intent (android.content.Intent)14 Context (android.content.Context)13 PackageManager (android.content.pm.PackageManager)13 NetworkStats (android.net.NetworkStats)12 AppItem (com.android.settingslib.AppItem)12 IOException (java.io.IOException)12 Bundle (android.os.Bundle)8 SubscriptionManager (android.telephony.SubscriptionManager)8 DataUsageController (com.android.settingslib.net.DataUsageController)8 ApplicationInfo (android.content.pm.ApplicationInfo)7 ConnectivityManager (android.net.ConnectivityManager)7 SubscriptionInfo (android.telephony.SubscriptionInfo)7 UidDetail (com.android.settingslib.net.UidDetail)7 UidDetailProvider (com.android.settingslib.net.UidDetailProvider)7 JSONArray (org.json.JSONArray)7