Loading services/core/java/com/android/server/net/NetworkPolicyManagerService.java +9 −0 Original line number Original line Diff line number Diff line Loading @@ -71,6 +71,7 @@ import static android.net.NetworkTemplate.MATCH_MOBILE; import static android.net.NetworkTemplate.MATCH_WIFI; import static android.net.NetworkTemplate.MATCH_WIFI; import static android.net.NetworkTemplate.buildTemplateMobileAll; import static android.net.NetworkTemplate.buildTemplateMobileAll; import static android.net.TrafficStats.MB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES; import static android.os.Trace.TRACE_TAG_NETWORK; import static android.provider.Settings.Global.NETPOLICY_OVERRIDE_ENABLED; import static android.provider.Settings.Global.NETPOLICY_OVERRIDE_ENABLED; import static android.provider.Settings.Global.NETPOLICY_QUOTA_ENABLED; import static android.provider.Settings.Global.NETPOLICY_QUOTA_ENABLED; import static android.provider.Settings.Global.NETPOLICY_QUOTA_FRAC_JOBS; import static android.provider.Settings.Global.NETPOLICY_QUOTA_FRAC_JOBS; Loading Loading @@ -1100,6 +1101,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { */ */ void updateNotificationsNL() { void updateNotificationsNL() { if (LOGV) Slog.v(TAG, "updateNotificationsNL()"); if (LOGV) Slog.v(TAG, "updateNotificationsNL()"); Trace.traceBegin(TRACE_TAG_NETWORK, "updateNotificationsNL"); // keep track of previously active notifications // keep track of previously active notifications final ArraySet<NotificationId> beforeNotifs = new ArraySet<NotificationId>(mActiveNotifs); final ArraySet<NotificationId> beforeNotifs = new ArraySet<NotificationId>(mActiveNotifs); Loading Loading @@ -1191,6 +1193,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { cancelNotification(notificationId); cancelNotification(notificationId); } } } } Trace.traceEnd(TRACE_TAG_NETWORK); } } /** /** Loading Loading @@ -1604,6 +1608,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { */ */ void updateNetworkEnabledNL() { void updateNetworkEnabledNL() { if (LOGV) Slog.v(TAG, "updateNetworkEnabledNL()"); if (LOGV) Slog.v(TAG, "updateNetworkEnabledNL()"); Trace.traceBegin(TRACE_TAG_NETWORK, "updateNetworkEnabledNL"); // TODO: reset any policy-disabled networks when any policy is removed // TODO: reset any policy-disabled networks when any policy is removed // completely, which is currently rare case. // completely, which is currently rare case. Loading Loading @@ -1633,6 +1638,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { } } mStatLogger.logDurationStat(Stats.UPDATE_NETWORK_ENABLED, startTime); mStatLogger.logDurationStat(Stats.UPDATE_NETWORK_ENABLED, startTime); Trace.traceEnd(TRACE_TAG_NETWORK); } } /** /** Loading Loading @@ -1693,6 +1699,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { */ */ void updateNetworkRulesNL() { void updateNetworkRulesNL() { if (LOGV) Slog.v(TAG, "updateNetworkRulesNL()"); if (LOGV) Slog.v(TAG, "updateNetworkRulesNL()"); Trace.traceBegin(TRACE_TAG_NETWORK, "updateNetworkRulesNL"); final NetworkState[] states; final NetworkState[] states; try { try { Loading Loading @@ -1866,6 +1873,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget(); mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget(); mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget(); mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget(); Trace.traceEnd(TRACE_TAG_NETWORK); } } /** /** Loading services/core/java/com/android/server/net/NetworkStatsService.java +35 −9 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,7 @@ import static android.net.NetworkTemplate.buildTemplateMobileWildcard; import static android.net.NetworkTemplate.buildTemplateWifiWildcard; import static android.net.NetworkTemplate.buildTemplateWifiWildcard; import static android.net.TrafficStats.KB_IN_BYTES; import static android.net.TrafficStats.KB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES; import static android.os.Trace.TRACE_TAG_NETWORK; import static android.provider.Settings.Global.NETSTATS_AUGMENT_ENABLED; import static android.provider.Settings.Global.NETSTATS_AUGMENT_ENABLED; import static android.provider.Settings.Global.NETSTATS_DEV_BUCKET_DURATION; import static android.provider.Settings.Global.NETSTATS_DEV_BUCKET_DURATION; import static android.provider.Settings.Global.NETSTATS_DEV_DELETE_AGE; import static android.provider.Settings.Global.NETSTATS_DEV_DELETE_AGE; Loading Loading @@ -109,6 +110,7 @@ import android.os.Messenger; import android.os.PowerManager; import android.os.PowerManager; import android.os.RemoteException; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemClock; import android.os.Trace; import android.os.UserHandle; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings; import android.provider.Settings.Global; import android.provider.Settings.Global; Loading Loading @@ -1189,27 +1191,43 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private void recordSnapshotLocked(long currentTime) throws RemoteException { private void recordSnapshotLocked(long currentTime) throws RemoteException { // snapshot and record current counters; read UID stats first to // snapshot and record current counters; read UID stats first to // avoid over counting dev stats. // avoid over counting dev stats. Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotUid"); final NetworkStats uidSnapshot = getNetworkStatsUidDetail(INTERFACES_ALL); final NetworkStats uidSnapshot = getNetworkStatsUidDetail(INTERFACES_ALL); Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotXt"); final NetworkStats xtSnapshot = getNetworkStatsXt(); final NetworkStats xtSnapshot = getNetworkStatsXt(); Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotDev"); final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev(); final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev(); Trace.traceEnd(TRACE_TAG_NETWORK); // Tethering snapshot for dev and xt stats. Counts per-interface data from tethering stats // Tethering snapshot for dev and xt stats. Counts per-interface data from tethering stats // providers that isn't already counted by dev and XT stats. // providers that isn't already counted by dev and XT stats. Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotTether"); final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_IFACE); final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_IFACE); Trace.traceEnd(TRACE_TAG_NETWORK); xtSnapshot.combineAllValues(tetherSnapshot); xtSnapshot.combineAllValues(tetherSnapshot); devSnapshot.combineAllValues(tetherSnapshot); devSnapshot.combineAllValues(tetherSnapshot); // For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic // For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic // can't be reattributed to responsible apps. // can't be reattributed to responsible apps. Trace.traceBegin(TRACE_TAG_NETWORK, "recordDev"); mDevRecorder.recordSnapshotLocked( mDevRecorder.recordSnapshotLocked( devSnapshot, mActiveIfaces, null /* vpnArray */, currentTime); devSnapshot, mActiveIfaces, null /* vpnArray */, currentTime); Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceBegin(TRACE_TAG_NETWORK, "recordXt"); mXtRecorder.recordSnapshotLocked( mXtRecorder.recordSnapshotLocked( xtSnapshot, mActiveIfaces, null /* vpnArray */, currentTime); xtSnapshot, mActiveIfaces, null /* vpnArray */, currentTime); Trace.traceEnd(TRACE_TAG_NETWORK); // For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps. // For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps. VpnInfo[] vpnArray = mConnManager.getAllVpnInfo(); VpnInfo[] vpnArray = mConnManager.getAllVpnInfo(); Trace.traceBegin(TRACE_TAG_NETWORK, "recordUid"); mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceBegin(TRACE_TAG_NETWORK, "recordUidTag"); mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); Trace.traceEnd(TRACE_TAG_NETWORK); // We need to make copies of member fields that are sent to the observer to avoid // We need to make copies of member fields that are sent to the observer to avoid // a race condition between the service handler thread and the observer's // a race condition between the service handler thread and the observer's Loading Loading @@ -1254,8 +1272,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private void performPollLocked(int flags) { private void performPollLocked(int flags) { if (!mSystemReady) return; if (!mSystemReady) return; if (LOGV) Slog.v(TAG, "performPollLocked(flags=0x" + Integer.toHexString(flags) + ")"); if (LOGV) Slog.v(TAG, "performPollLocked(flags=0x" + Integer.toHexString(flags) + ")"); Trace.traceBegin(TRACE_TAG_NETWORK, "performPollLocked"); final long startRealtime = SystemClock.elapsedRealtime(); final boolean persistNetwork = (flags & FLAG_PERSIST_NETWORK) != 0; final boolean persistNetwork = (flags & FLAG_PERSIST_NETWORK) != 0; final boolean persistUid = (flags & FLAG_PERSIST_UID) != 0; final boolean persistUid = (flags & FLAG_PERSIST_UID) != 0; Loading @@ -1275,6 +1292,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } // persist any pending data depending on requested flags // persist any pending data depending on requested flags Trace.traceBegin(TRACE_TAG_NETWORK, "[persisting]"); if (persistForce) { if (persistForce) { mDevRecorder.forcePersistLocked(currentTime); mDevRecorder.forcePersistLocked(currentTime); mXtRecorder.forcePersistLocked(currentTime); mXtRecorder.forcePersistLocked(currentTime); Loading @@ -1290,11 +1308,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { mUidTagRecorder.maybePersistLocked(currentTime); mUidTagRecorder.maybePersistLocked(currentTime); } } } } Trace.traceEnd(TRACE_TAG_NETWORK); if (LOGV) { final long duration = SystemClock.elapsedRealtime() - startRealtime; Slog.v(TAG, "performPollLocked() took " + duration + "ms"); } if (mSettings.getSampleEnabled()) { if (mSettings.getSampleEnabled()) { // sample stats after each full poll // sample stats after each full poll Loading @@ -1306,6 +1320,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { updatedIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); updatedIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); mContext.sendBroadcastAsUser(updatedIntent, UserHandle.ALL, mContext.sendBroadcastAsUser(updatedIntent, UserHandle.ALL, READ_NETWORK_USAGE_HISTORY); READ_NETWORK_USAGE_HISTORY); Trace.traceEnd(TRACE_TAG_NETWORK); } } /** /** Loading Loading @@ -1388,12 +1404,22 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private class NetworkStatsManagerInternalImpl extends NetworkStatsManagerInternal { private class NetworkStatsManagerInternalImpl extends NetworkStatsManagerInternal { @Override @Override public long getNetworkTotalBytes(NetworkTemplate template, long start, long end) { public long getNetworkTotalBytes(NetworkTemplate template, long start, long end) { Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkTotalBytes"); try { return NetworkStatsService.this.getNetworkTotalBytes(template, start, end); return NetworkStatsService.this.getNetworkTotalBytes(template, start, end); } finally { Trace.traceEnd(TRACE_TAG_NETWORK); } } } @Override @Override public NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) { public NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) { Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkUidBytes"); try { return NetworkStatsService.this.getNetworkUidBytes(template, start, end); return NetworkStatsService.this.getNetworkUidBytes(template, start, end); } finally { Trace.traceEnd(TRACE_TAG_NETWORK); } } } @Override @Override Loading Loading
services/core/java/com/android/server/net/NetworkPolicyManagerService.java +9 −0 Original line number Original line Diff line number Diff line Loading @@ -71,6 +71,7 @@ import static android.net.NetworkTemplate.MATCH_MOBILE; import static android.net.NetworkTemplate.MATCH_WIFI; import static android.net.NetworkTemplate.MATCH_WIFI; import static android.net.NetworkTemplate.buildTemplateMobileAll; import static android.net.NetworkTemplate.buildTemplateMobileAll; import static android.net.TrafficStats.MB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES; import static android.os.Trace.TRACE_TAG_NETWORK; import static android.provider.Settings.Global.NETPOLICY_OVERRIDE_ENABLED; import static android.provider.Settings.Global.NETPOLICY_OVERRIDE_ENABLED; import static android.provider.Settings.Global.NETPOLICY_QUOTA_ENABLED; import static android.provider.Settings.Global.NETPOLICY_QUOTA_ENABLED; import static android.provider.Settings.Global.NETPOLICY_QUOTA_FRAC_JOBS; import static android.provider.Settings.Global.NETPOLICY_QUOTA_FRAC_JOBS; Loading Loading @@ -1100,6 +1101,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { */ */ void updateNotificationsNL() { void updateNotificationsNL() { if (LOGV) Slog.v(TAG, "updateNotificationsNL()"); if (LOGV) Slog.v(TAG, "updateNotificationsNL()"); Trace.traceBegin(TRACE_TAG_NETWORK, "updateNotificationsNL"); // keep track of previously active notifications // keep track of previously active notifications final ArraySet<NotificationId> beforeNotifs = new ArraySet<NotificationId>(mActiveNotifs); final ArraySet<NotificationId> beforeNotifs = new ArraySet<NotificationId>(mActiveNotifs); Loading Loading @@ -1191,6 +1193,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { cancelNotification(notificationId); cancelNotification(notificationId); } } } } Trace.traceEnd(TRACE_TAG_NETWORK); } } /** /** Loading Loading @@ -1604,6 +1608,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { */ */ void updateNetworkEnabledNL() { void updateNetworkEnabledNL() { if (LOGV) Slog.v(TAG, "updateNetworkEnabledNL()"); if (LOGV) Slog.v(TAG, "updateNetworkEnabledNL()"); Trace.traceBegin(TRACE_TAG_NETWORK, "updateNetworkEnabledNL"); // TODO: reset any policy-disabled networks when any policy is removed // TODO: reset any policy-disabled networks when any policy is removed // completely, which is currently rare case. // completely, which is currently rare case. Loading Loading @@ -1633,6 +1638,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { } } mStatLogger.logDurationStat(Stats.UPDATE_NETWORK_ENABLED, startTime); mStatLogger.logDurationStat(Stats.UPDATE_NETWORK_ENABLED, startTime); Trace.traceEnd(TRACE_TAG_NETWORK); } } /** /** Loading Loading @@ -1693,6 +1699,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { */ */ void updateNetworkRulesNL() { void updateNetworkRulesNL() { if (LOGV) Slog.v(TAG, "updateNetworkRulesNL()"); if (LOGV) Slog.v(TAG, "updateNetworkRulesNL()"); Trace.traceBegin(TRACE_TAG_NETWORK, "updateNetworkRulesNL"); final NetworkState[] states; final NetworkState[] states; try { try { Loading Loading @@ -1866,6 +1873,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget(); mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget(); mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget(); mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget(); Trace.traceEnd(TRACE_TAG_NETWORK); } } /** /** Loading
services/core/java/com/android/server/net/NetworkStatsService.java +35 −9 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,7 @@ import static android.net.NetworkTemplate.buildTemplateMobileWildcard; import static android.net.NetworkTemplate.buildTemplateWifiWildcard; import static android.net.NetworkTemplate.buildTemplateWifiWildcard; import static android.net.TrafficStats.KB_IN_BYTES; import static android.net.TrafficStats.KB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES; import static android.os.Trace.TRACE_TAG_NETWORK; import static android.provider.Settings.Global.NETSTATS_AUGMENT_ENABLED; import static android.provider.Settings.Global.NETSTATS_AUGMENT_ENABLED; import static android.provider.Settings.Global.NETSTATS_DEV_BUCKET_DURATION; import static android.provider.Settings.Global.NETSTATS_DEV_BUCKET_DURATION; import static android.provider.Settings.Global.NETSTATS_DEV_DELETE_AGE; import static android.provider.Settings.Global.NETSTATS_DEV_DELETE_AGE; Loading Loading @@ -109,6 +110,7 @@ import android.os.Messenger; import android.os.PowerManager; import android.os.PowerManager; import android.os.RemoteException; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemClock; import android.os.Trace; import android.os.UserHandle; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings; import android.provider.Settings.Global; import android.provider.Settings.Global; Loading Loading @@ -1189,27 +1191,43 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private void recordSnapshotLocked(long currentTime) throws RemoteException { private void recordSnapshotLocked(long currentTime) throws RemoteException { // snapshot and record current counters; read UID stats first to // snapshot and record current counters; read UID stats first to // avoid over counting dev stats. // avoid over counting dev stats. Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotUid"); final NetworkStats uidSnapshot = getNetworkStatsUidDetail(INTERFACES_ALL); final NetworkStats uidSnapshot = getNetworkStatsUidDetail(INTERFACES_ALL); Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotXt"); final NetworkStats xtSnapshot = getNetworkStatsXt(); final NetworkStats xtSnapshot = getNetworkStatsXt(); Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotDev"); final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev(); final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev(); Trace.traceEnd(TRACE_TAG_NETWORK); // Tethering snapshot for dev and xt stats. Counts per-interface data from tethering stats // Tethering snapshot for dev and xt stats. Counts per-interface data from tethering stats // providers that isn't already counted by dev and XT stats. // providers that isn't already counted by dev and XT stats. Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotTether"); final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_IFACE); final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_IFACE); Trace.traceEnd(TRACE_TAG_NETWORK); xtSnapshot.combineAllValues(tetherSnapshot); xtSnapshot.combineAllValues(tetherSnapshot); devSnapshot.combineAllValues(tetherSnapshot); devSnapshot.combineAllValues(tetherSnapshot); // For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic // For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic // can't be reattributed to responsible apps. // can't be reattributed to responsible apps. Trace.traceBegin(TRACE_TAG_NETWORK, "recordDev"); mDevRecorder.recordSnapshotLocked( mDevRecorder.recordSnapshotLocked( devSnapshot, mActiveIfaces, null /* vpnArray */, currentTime); devSnapshot, mActiveIfaces, null /* vpnArray */, currentTime); Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceBegin(TRACE_TAG_NETWORK, "recordXt"); mXtRecorder.recordSnapshotLocked( mXtRecorder.recordSnapshotLocked( xtSnapshot, mActiveIfaces, null /* vpnArray */, currentTime); xtSnapshot, mActiveIfaces, null /* vpnArray */, currentTime); Trace.traceEnd(TRACE_TAG_NETWORK); // For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps. // For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps. VpnInfo[] vpnArray = mConnManager.getAllVpnInfo(); VpnInfo[] vpnArray = mConnManager.getAllVpnInfo(); Trace.traceBegin(TRACE_TAG_NETWORK, "recordUid"); mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceBegin(TRACE_TAG_NETWORK, "recordUidTag"); mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); Trace.traceEnd(TRACE_TAG_NETWORK); // We need to make copies of member fields that are sent to the observer to avoid // We need to make copies of member fields that are sent to the observer to avoid // a race condition between the service handler thread and the observer's // a race condition between the service handler thread and the observer's Loading Loading @@ -1254,8 +1272,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private void performPollLocked(int flags) { private void performPollLocked(int flags) { if (!mSystemReady) return; if (!mSystemReady) return; if (LOGV) Slog.v(TAG, "performPollLocked(flags=0x" + Integer.toHexString(flags) + ")"); if (LOGV) Slog.v(TAG, "performPollLocked(flags=0x" + Integer.toHexString(flags) + ")"); Trace.traceBegin(TRACE_TAG_NETWORK, "performPollLocked"); final long startRealtime = SystemClock.elapsedRealtime(); final boolean persistNetwork = (flags & FLAG_PERSIST_NETWORK) != 0; final boolean persistNetwork = (flags & FLAG_PERSIST_NETWORK) != 0; final boolean persistUid = (flags & FLAG_PERSIST_UID) != 0; final boolean persistUid = (flags & FLAG_PERSIST_UID) != 0; Loading @@ -1275,6 +1292,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } // persist any pending data depending on requested flags // persist any pending data depending on requested flags Trace.traceBegin(TRACE_TAG_NETWORK, "[persisting]"); if (persistForce) { if (persistForce) { mDevRecorder.forcePersistLocked(currentTime); mDevRecorder.forcePersistLocked(currentTime); mXtRecorder.forcePersistLocked(currentTime); mXtRecorder.forcePersistLocked(currentTime); Loading @@ -1290,11 +1308,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { mUidTagRecorder.maybePersistLocked(currentTime); mUidTagRecorder.maybePersistLocked(currentTime); } } } } Trace.traceEnd(TRACE_TAG_NETWORK); if (LOGV) { final long duration = SystemClock.elapsedRealtime() - startRealtime; Slog.v(TAG, "performPollLocked() took " + duration + "ms"); } if (mSettings.getSampleEnabled()) { if (mSettings.getSampleEnabled()) { // sample stats after each full poll // sample stats after each full poll Loading @@ -1306,6 +1320,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { updatedIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); updatedIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); mContext.sendBroadcastAsUser(updatedIntent, UserHandle.ALL, mContext.sendBroadcastAsUser(updatedIntent, UserHandle.ALL, READ_NETWORK_USAGE_HISTORY); READ_NETWORK_USAGE_HISTORY); Trace.traceEnd(TRACE_TAG_NETWORK); } } /** /** Loading Loading @@ -1388,12 +1404,22 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private class NetworkStatsManagerInternalImpl extends NetworkStatsManagerInternal { private class NetworkStatsManagerInternalImpl extends NetworkStatsManagerInternal { @Override @Override public long getNetworkTotalBytes(NetworkTemplate template, long start, long end) { public long getNetworkTotalBytes(NetworkTemplate template, long start, long end) { Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkTotalBytes"); try { return NetworkStatsService.this.getNetworkTotalBytes(template, start, end); return NetworkStatsService.this.getNetworkTotalBytes(template, start, end); } finally { Trace.traceEnd(TRACE_TAG_NETWORK); } } } @Override @Override public NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) { public NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) { Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkUidBytes"); try { return NetworkStatsService.this.getNetworkUidBytes(template, start, end); return NetworkStatsService.this.getNetworkUidBytes(template, start, end); } finally { Trace.traceEnd(TRACE_TAG_NETWORK); } } } @Override @Override Loading