Program: 199635
Project: 199635
Buggy source:
private void updateNetworkActivityLocked(int which,long elapsedRealtimeMs){
  if (!SystemProperties.getBoolean(PROP_QTAGUID_ENABLED,false))   return;
  if ((which & NET_UPDATE_MOBILE) != 0 && 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;
    if (mOnBatteryInternal) {
      final NetworkStats delta=NetworkStats.subtract(snapshot,last,null,null,mTmpNetworkStats);
      mTmpNetworkStats=delta;
      long radioTime=mMobileRadioActivePerAppTimer.checkpointRunningLocked(elapsedRealtimeMs);
      long totalPackets=delta.getTotalPackets();
      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);
        if (radioTime > 0) {
          long appPackets=entry.rxPackets + entry.txPackets;
          long appRadioTime=(radioTime * appPackets) / totalPackets;
          u.noteMobileRadioActiveTimeLocked(appRadioTime);
          radioTime-=appRadioTime;
          totalPackets-=appPackets;
        }
        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 (radioTime > 0) {
        mMobileRadioActiveUnknownTime.addCountLocked(radioTime);
        mMobileRadioActiveUnknownCount.addCountLocked(1);
      }
    }
  }
  if ((which & NET_UPDATE_WIFI) != 0 && 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;
    if (mOnBatteryInternal) {
      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 (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);
      }
    }
  }
}

Fixed version (ground truth):
private void updateNetworkActivityLocked(int which,long elapsedRealtimeMs){
  if (!SystemProperties.getBoolean(PROP_QTAGUID_ENABLED,false))   return;
  if ((which & NET_UPDATE_MOBILE) != 0 && 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;
    if (mOnBatteryInternal) {
      final NetworkStats delta=NetworkStats.subtract(snapshot,last,null,null,mTmpNetworkStats);
      mTmpNetworkStats=delta;
      long radioTime=mMobileRadioActivePerAppTimer.checkpointRunningLocked(elapsedRealtimeMs);
      long totalPackets=delta.getTotalPackets();
      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(mapUid(entry.uid));
        u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA,entry.rxBytes,entry.rxPackets);
        u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA,entry.txBytes,entry.txPackets);
        if (radioTime > 0) {
          long appPackets=entry.rxPackets + entry.txPackets;
          long appRadioTime=(radioTime * appPackets) / totalPackets;
          u.noteMobileRadioActiveTimeLocked(appRadioTime);
          radioTime-=appRadioTime;
          totalPackets-=appPackets;
        }
        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 (radioTime > 0) {
        mMobileRadioActiveUnknownTime.addCountLocked(radioTime);
        mMobileRadioActiveUnknownCount.addCountLocked(1);
      }
    }
  }
  if ((which & NET_UPDATE_WIFI) != 0 && 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;
    if (mOnBatteryInternal) {
      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 (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(mapUid(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);
      }
    }
  }
}