Program: 196869
Project: 196869
Buggy source:
public boolean setMemFactorLocked(int memFactor,boolean screenOn,long now){
  mMemFactorLowered=memFactor < mLastMemOnlyState;
  mLastMemOnlyState=memFactor;
  if (screenOn) {
    memFactor+=ProcessStats.ADJ_SCREEN_ON;
  }
  if (memFactor != mProcessStats.mMemFactor) {
    if (mProcessStats.mMemFactor != ProcessStats.STATE_NOTHING) {
      mProcessStats.mMemFactorDurations[mProcessStats.mMemFactor]+=now - mProcessStats.mStartTime;
    }
    mProcessStats.mMemFactor=memFactor;
    mProcessStats.mStartTime=now;
    final ArrayMap<String,SparseArray<SparseArray<ProcessStats.PackageState>>> pmap=mProcessStats.mPackages.getMap();
    for (int ipkg=pmap.size() - 1; ipkg >= 0; ipkg--) {
      final SparseArray<SparseArray<ProcessStats.PackageState>> uids=pmap.valueAt(ipkg);
      for (int iuid=uids.size() - 1; iuid >= 0; iuid--) {
        final SparseArray<ProcessStats.PackageState> vers=uids.valueAt(iuid);
        for (int iver=vers.size() - 1; iver >= 0; iver--) {
          final ProcessStats.PackageState pkg=vers.valueAt(iver);
          final ArrayMap<String,ProcessStats.ServiceState> services=pkg.mServices;
          for (int isvc=services.size() - 1; isvc >= 0; isvc--) {
            final ProcessStats.ServiceState service=services.valueAt(isvc);
            if (service.isInUse()) {
              if (service.mStartedState != ProcessStats.STATE_NOTHING) {
                service.setStarted(true,memFactor,now);
              }
              if (service.mBoundState != ProcessStats.STATE_NOTHING) {
                service.setBound(true,memFactor,now);
              }
              if (service.mExecState != ProcessStats.STATE_NOTHING) {
                service.setExecuting(true,memFactor,now);
              }
            }
          }
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
public boolean setMemFactorLocked(int memFactor,boolean screenOn,long now){
  mMemFactorLowered=memFactor < mLastMemOnlyState;
  mLastMemOnlyState=memFactor;
  if (screenOn) {
    memFactor+=ProcessStats.ADJ_SCREEN_ON;
  }
  if (memFactor != mProcessStats.mMemFactor) {
    if (mProcessStats.mMemFactor != ProcessStats.STATE_NOTHING) {
      mProcessStats.mMemFactorDurations[mProcessStats.mMemFactor]+=now - mProcessStats.mStartTime;
    }
    mProcessStats.mMemFactor=memFactor;
    mProcessStats.mStartTime=now;
    final ArrayMap<String,SparseArray<SparseArray<ProcessStats.PackageState>>> pmap=mProcessStats.mPackages.getMap();
    for (int ipkg=pmap.size() - 1; ipkg >= 0; ipkg--) {
      final SparseArray<SparseArray<ProcessStats.PackageState>> uids=pmap.valueAt(ipkg);
      for (int iuid=uids.size() - 1; iuid >= 0; iuid--) {
        final SparseArray<ProcessStats.PackageState> vers=uids.valueAt(iuid);
        for (int iver=vers.size() - 1; iver >= 0; iver--) {
          final ProcessStats.PackageState pkg=vers.valueAt(iver);
          final ArrayMap<String,ProcessStats.ServiceState> services=pkg.mServices;
          for (int isvc=services.size() - 1; isvc >= 0; isvc--) {
            final ProcessStats.ServiceState service=services.valueAt(isvc);
            if (service.isRestarting()) {
              service.setRestarting(true,memFactor,now);
            }
 else             if (service.isInUse()) {
              if (service.mStartedState != ProcessStats.STATE_NOTHING) {
                service.setStarted(true,memFactor,now);
              }
              if (service.mBoundState != ProcessStats.STATE_NOTHING) {
                service.setBound(true,memFactor,now);
              }
              if (service.mExecState != ProcessStats.STATE_NOTHING) {
                service.setExecuting(true,memFactor,now);
              }
            }
          }
        }
      }
    }
    return true;
  }
  return false;
}