@@ -806,9 +806,7 @@ private void performPollLocked(int flags) {
806806 final NetworkStats networkDevSnapshot ;
807807 try {
808808 // collect any tethering stats
809- final String [] tetheredIfacePairs = mConnManager .getTetheredIfacePairs ();
810- final NetworkStats tetherSnapshot = mNetworkManager .getNetworkStatsTethering (
811- tetheredIfacePairs );
809+ final NetworkStats tetherSnapshot = getNetworkStatsTethering ();
812810
813811 // record uid stats, folding in tethering stats
814812 uidSnapshot = mNetworkManager .getNetworkStatsUidDetail (UID_ALL );
@@ -1505,7 +1503,7 @@ private NetworkStats computeStatsDelta(
15051503 NetworkStats before , NetworkStats current , boolean collectStale , String type ) {
15061504 if (before != null ) {
15071505 try {
1508- return current .subtract (before );
1506+ return current .subtract (before , false );
15091507 } catch (NonMonotonicException e ) {
15101508 Log .w (TAG , "found non-monotonic values; saving to dropbox" );
15111509
@@ -1517,8 +1515,13 @@ private NetworkStats computeStatsDelta(
15171515 builder .append ("right=" ).append (e .right ).append ('\n' );
15181516 mDropBox .addText (TAG_NETSTATS_ERROR , builder .toString ());
15191517
1520- // return empty delta to avoid recording broken stats
1521- return new NetworkStats (0L , 10 );
1518+ try {
1519+ // return clamped delta to help recover
1520+ return current .subtract (before , true );
1521+ } catch (NonMonotonicException e1 ) {
1522+ Log .wtf (TAG , "found non-monotonic values; returning empty delta" , e1 );
1523+ return new NetworkStats (0L , 10 );
1524+ }
15221525 }
15231526 } else if (collectStale ) {
15241527 // caller is okay collecting stale stats for first call.
@@ -1530,6 +1533,20 @@ private NetworkStats computeStatsDelta(
15301533 }
15311534 }
15321535
1536+ /**
1537+ * Return snapshot of current tethering statistics. Will return empty
1538+ * {@link NetworkStats} if any problems are encountered.
1539+ */
1540+ private NetworkStats getNetworkStatsTethering () throws RemoteException {
1541+ try {
1542+ final String [] tetheredIfacePairs = mConnManager .getTetheredIfacePairs ();
1543+ return mNetworkManager .getNetworkStatsTethering (tetheredIfacePairs );
1544+ } catch (IllegalStateException e ) {
1545+ Log .wtf (TAG , "problem reading network stats" , e );
1546+ return new NetworkStats (0L , 10 );
1547+ }
1548+ }
1549+
15331550 private static NetworkStats computeNetworkXtSnapshotFromUid (NetworkStats uidSnapshot ) {
15341551 return uidSnapshot .groupedByIface ();
15351552 }
0 commit comments