Program: 199856
Project: 199856
Buggy source:
private void updateNetworkActivityLocked(){
  if (!SystemProperties.getBoolean(PROP_QTAGUID_ENABLED,false))   return;
  if (mMobileIfaces.length > 0) {
    final NetworkStats snapshot;
    try {
      snapshot=mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL,mMobileIfaces,NetworkStats.TAG_NONE,mLastMobileSnapshot);
    }
 catch (    IOException e) {
      Log.wtf(TAG,"String_Node_Str",e);
      return;
    }
    if (mLastMobileSnapshot == null) {
      mLastMobileSnapshot=snapshot;
      return;
    }
    final NetworkStats delta=NetworkStats.subtract(snapshot,mLastMobileSnapshot,null,null,mTmpNetworkStats);
    mTmpNetworkStats=delta;
    mLastMobileSnapshot=snapshot;
    final int size=delta.size();
    for (int i=0; i < size; i++) {
      final NetworkStats.Entry entry=delta.getValues(i,mTmpNetworkStatsEntry);
      if (entry.rxBytes == 0 || entry.txBytes == 0)       continue;
      final Uid u=getUidStatsLocked(entry.uid);
      u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA,entry.rxBytes,entry.rxPackets);
      u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA,entry.txBytes,entry.txPackets);
      mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked(entry.rxBytes);
      mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked(entry.txBytes);
      mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked(entry.rxPackets);
      mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked(entry.txPackets);
    }
  }
  if (mWifiIfaces.length > 0) {
    final NetworkStats snapshot;
    try {
      snapshot=mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL,mWifiIfaces,NetworkStats.TAG_NONE,mLastWifiSnapshot);
    }
 catch (    IOException e) {
      Log.wtf(TAG,"String_Node_Str",e);
      return;
    }
    if (mLastWifiSnapshot == null) {
      mLastWifiSnapshot=snapshot;
      return;
    }
    final NetworkStats delta=NetworkStats.subtract(snapshot,mLastWifiSnapshot,null,null,mTmpNetworkStats);
    mTmpNetworkStats=delta;
    mLastWifiSnapshot=snapshot;
    final int size=delta.size();
    for (int i=0; i < size; i++) {
      final NetworkStats.Entry entry=delta.getValues(i,mTmpNetworkStatsEntry);
      if (entry.rxBytes == 0 || entry.txBytes == 0)       continue;
      final Uid u=getUidStatsLocked(entry.uid);
      u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA,entry.rxBytes,entry.rxPackets);
      u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA,entry.txBytes,entry.txPackets);
      mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(entry.rxBytes);
      mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked(entry.txBytes);
      mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(entry.rxPackets);
      mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked(entry.txPackets);
    }
  }
}

Fixed version (ground truth):
private void updateNetworkActivityLocked(){
  if (!SystemProperties.getBoolean(PROP_QTAGUID_ENABLED,false))   return;
  if (mMobileIfaces.length > 0) {
    final NetworkStats snapshot;
    final NetworkStats last=mCurMobileSnapshot;
    try {
      snapshot=mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL,mMobileIfaces,NetworkStats.TAG_NONE,mLastMobileSnapshot);
    }
 catch (    IOException e) {
      Log.wtf(TAG,"String_Node_Str",e);
      return;
    }
    mCurMobileSnapshot=snapshot;
    mLastMobileSnapshot=last;
    final NetworkStats delta=NetworkStats.subtract(snapshot,last,null,null,mTmpNetworkStats);
    mTmpNetworkStats=delta;
    final int size=delta.size();
    for (int i=0; i < size; i++) {
      final NetworkStats.Entry entry=delta.getValues(i,mTmpNetworkStatsEntry);
      if (entry.rxBytes == 0 || entry.txBytes == 0)       continue;
      final Uid u=getUidStatsLocked(entry.uid);
      u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA,entry.rxBytes,entry.rxPackets);
      u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA,entry.txBytes,entry.txPackets);
      mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked(entry.rxBytes);
      mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked(entry.txBytes);
      mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked(entry.rxPackets);
      mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked(entry.txPackets);
    }
  }
  if (mWifiIfaces.length > 0) {
    final NetworkStats snapshot;
    final NetworkStats last=mCurWifiSnapshot;
    try {
      snapshot=mNetworkStatsFactory.readNetworkStatsDetail(UID_ALL,mWifiIfaces,NetworkStats.TAG_NONE,mLastWifiSnapshot);
    }
 catch (    IOException e) {
      Log.wtf(TAG,"String_Node_Str",e);
      return;
    }
    mCurWifiSnapshot=snapshot;
    mLastWifiSnapshot=last;
    final NetworkStats delta=NetworkStats.subtract(snapshot,last,null,null,mTmpNetworkStats);
    mTmpNetworkStats=delta;
    mLastWifiSnapshot=snapshot;
    final int size=delta.size();
    for (int i=0; i < size; i++) {
      final NetworkStats.Entry entry=delta.getValues(i,mTmpNetworkStatsEntry);
      if (DEBUG) {
        final NetworkStats.Entry cur=snapshot.getValues(i,null);
        Slog.d(TAG,"String_Node_Str" + entry.uid + "String_Node_Str"+ entry.rxBytes+ "String_Node_Str"+ entry.txBytes+ "String_Node_Str"+ cur.rxBytes+ "String_Node_Str"+ cur.txBytes);
      }
      if (entry.rxBytes == 0 || entry.txBytes == 0)       continue;
      final Uid u=getUidStatsLocked(entry.uid);
      u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA,entry.rxBytes,entry.rxPackets);
      u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA,entry.txBytes,entry.txPackets);
      mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(entry.rxBytes);
      mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked(entry.txBytes);
      mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(entry.rxPackets);
      mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked(entry.txPackets);
    }
  }
}