Program: 193343
Project: 193343
Buggy source:
private final boolean applyOomAdjLocked(ProcessRecord app,boolean doingAll,long now){
  boolean success=true;
  if (app.curRawAdj != app.setRawAdj) {
    app.setRawAdj=app.curRawAdj;
  }
  int changes=0;
  if (app.curAdj != app.setAdj) {
    ProcessList.setOomAdj(app.pid,app.info.uid,app.curAdj);
    if (DEBUG_SWITCH || DEBUG_OOM_ADJ)     Slog.v(TAG_OOM_ADJ,"String_Node_Str" + app.pid + "String_Node_Str"+ app.processName+ "String_Node_Str"+ app.curAdj+ "String_Node_Str"+ app.adjType);
    app.setAdj=app.curAdj;
  }
  if (app.setSchedGroup != app.curSchedGroup) {
    app.setSchedGroup=app.curSchedGroup;
    if (DEBUG_SWITCH || DEBUG_OOM_ADJ)     Slog.v(TAG_OOM_ADJ,"String_Node_Str" + app.processName + "String_Node_Str"+ app.curSchedGroup);
    if (app.waitingToKill != null && app.curReceiver == null && app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
      app.kill(app.waitingToKill,true);
      success=false;
    }
 else {
      if (true) {
        long oldId=Binder.clearCallingIdentity();
        try {
          Process.setProcessGroup(app.pid,app.curSchedGroup);
        }
 catch (        Exception e) {
          Slog.w(TAG,"String_Node_Str" + app.pid + "String_Node_Str"+ app.curSchedGroup);
          e.printStackTrace();
        }
 finally {
          Binder.restoreCallingIdentity(oldId);
        }
      }
 else {
        if (app.thread != null) {
          try {
            app.thread.setSchedulingGroup(app.curSchedGroup);
          }
 catch (          RemoteException e) {
          }
        }
      }
      Process.setSwappiness(app.pid,app.curSchedGroup <= Process.THREAD_GROUP_BG_NONINTERACTIVE);
    }
  }
  if (app.repForegroundActivities != app.foregroundActivities) {
    app.repForegroundActivities=app.foregroundActivities;
    changes|=ProcessChangeItem.CHANGE_ACTIVITIES;
  }
  if (app.repProcState != app.curProcState) {
    app.repProcState=app.curProcState;
    changes|=ProcessChangeItem.CHANGE_PROCESS_STATE;
    if (app.thread != null) {
      try {
        if (false) {
          Slog.i(TAG,"String_Node_Str" + app.repProcState + "String_Node_Str"+ app);
        }
        app.thread.setProcessState(app.repProcState);
      }
 catch (      RemoteException e) {
      }
    }
  }
  if (app.setProcState == ActivityManager.PROCESS_STATE_NONEXISTENT || ProcessList.procStatesDifferForMem(app.curProcState,app.setProcState)) {
    if (false && mTestPssMode && app.setProcState >= 0 && app.lastStateTime <= (now - 200)) {
      long start=SystemClock.uptimeMillis();
      long pss=Debug.getPss(app.pid,mTmpLong,null);
      recordPssSampleLocked(app,app.curProcState,pss,mTmpLong[0],now);
      mPendingPssProcesses.remove(app);
      Slog.i(TAG,"String_Node_Str" + app + "String_Node_Str"+ app.setProcState+ "String_Node_Str"+ app.curProcState+ "String_Node_Str"+ (SystemClock.uptimeMillis() - start)+ "String_Node_Str");
    }
    app.lastStateTime=now;
    app.nextPssTime=ProcessList.computeNextPssTime(app.curProcState,true,mTestPssMode,isSleeping(),now);
    if (DEBUG_PSS)     Slog.d(TAG_PSS,"String_Node_Str" + ProcessList.makeProcStateString(app.setProcState) + "String_Node_Str"+ ProcessList.makeProcStateString(app.curProcState)+ "String_Node_Str"+ (app.nextPssTime - now)+ "String_Node_Str"+ app);
  }
 else {
    if (now > app.nextPssTime || (now > (app.lastPssTime + ProcessList.PSS_MAX_INTERVAL) && now > (app.lastStateTime + ProcessList.minTimeFromStateChange(mTestPssMode)))) {
      requestPssLocked(app,app.setProcState);
      app.nextPssTime=ProcessList.computeNextPssTime(app.curProcState,false,mTestPssMode,isSleeping(),now);
    }
 else     if (false && DEBUG_PSS)     Slog.d(TAG_PSS,"String_Node_Str" + app + "String_Node_Str"+ (app.nextPssTime - now));
  }
  if (app.setProcState != app.curProcState) {
    if (DEBUG_SWITCH || DEBUG_OOM_ADJ)     Slog.v(TAG_OOM_ADJ,"String_Node_Str" + app.processName + "String_Node_Str"+ app.curProcState);
    boolean setImportant=app.setProcState < ActivityManager.PROCESS_STATE_SERVICE;
    boolean curImportant=app.curProcState < ActivityManager.PROCESS_STATE_SERVICE;
    if (setImportant && !curImportant) {
      BatteryStatsImpl stats=mBatteryStatsService.getActiveStatistics();
synchronized (stats) {
        app.lastWakeTime=stats.getProcessWakeTime(app.info.uid,app.pid,SystemClock.elapsedRealtime());
      }
      app.lastCpuTime=app.curCpuTime;
    }
    maybeUpdateUsageStatsLocked(app);
    app.setProcState=app.curProcState;
    if (app.setProcState >= ActivityManager.PROCESS_STATE_HOME) {
      app.notCachedSinceIdle=false;
    }
    if (!doingAll) {
      setProcessTrackerStateLocked(app,mProcessStats.getMemFactorLocked(),now);
    }
 else {
      app.procStateChanged=true;
    }
  }
  if (changes != 0) {
    if (DEBUG_PROCESS_OBSERVERS)     Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + app + "String_Node_Str"+ changes);
    int i=mPendingProcessChanges.size() - 1;
    ProcessChangeItem item=null;
    while (i >= 0) {
      item=mPendingProcessChanges.get(i);
      if (item.pid == app.pid) {
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + item);
        break;
      }
      i--;
    }
    if (i < 0) {
      final int NA=mAvailProcessChanges.size();
      if (NA > 0) {
        item=mAvailProcessChanges.remove(NA - 1);
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + item);
      }
 else {
        item=new ProcessChangeItem();
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + item);
      }
      item.changes=0;
      item.pid=app.pid;
      item.uid=app.info.uid;
      if (mPendingProcessChanges.size() == 0) {
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str");
        mUiHandler.obtainMessage(DISPATCH_PROCESSES_CHANGED).sendToTarget();
      }
      mPendingProcessChanges.add(item);
    }
    item.changes|=changes;
    item.processState=app.repProcState;
    item.foregroundActivities=app.repForegroundActivities;
    if (DEBUG_PROCESS_OBSERVERS)     Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + Integer.toHexString(System.identityHashCode(item)) + "String_Node_Str"+ app.toShortString()+ "String_Node_Str"+ item.changes+ "String_Node_Str"+ item.processState+ "String_Node_Str"+ item.foregroundActivities+ "String_Node_Str"+ app.adjType+ "String_Node_Str"+ app.adjSource+ "String_Node_Str"+ app.adjTarget);
  }
  return success;
}

Fixed version (ground truth):
private final boolean applyOomAdjLocked(ProcessRecord app,boolean doingAll,long now,long nowElapsed){
  boolean success=true;
  if (app.curRawAdj != app.setRawAdj) {
    app.setRawAdj=app.curRawAdj;
  }
  int changes=0;
  if (app.curAdj != app.setAdj) {
    ProcessList.setOomAdj(app.pid,app.info.uid,app.curAdj);
    if (DEBUG_SWITCH || DEBUG_OOM_ADJ)     Slog.v(TAG_OOM_ADJ,"String_Node_Str" + app.pid + "String_Node_Str"+ app.processName+ "String_Node_Str"+ app.curAdj+ "String_Node_Str"+ app.adjType);
    app.setAdj=app.curAdj;
  }
  if (app.setSchedGroup != app.curSchedGroup) {
    app.setSchedGroup=app.curSchedGroup;
    if (DEBUG_SWITCH || DEBUG_OOM_ADJ)     Slog.v(TAG_OOM_ADJ,"String_Node_Str" + app.processName + "String_Node_Str"+ app.curSchedGroup);
    if (app.waitingToKill != null && app.curReceiver == null && app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
      app.kill(app.waitingToKill,true);
      success=false;
    }
 else {
      if (true) {
        long oldId=Binder.clearCallingIdentity();
        try {
          Process.setProcessGroup(app.pid,app.curSchedGroup);
        }
 catch (        Exception e) {
          Slog.w(TAG,"String_Node_Str" + app.pid + "String_Node_Str"+ app.curSchedGroup);
          e.printStackTrace();
        }
 finally {
          Binder.restoreCallingIdentity(oldId);
        }
      }
 else {
        if (app.thread != null) {
          try {
            app.thread.setSchedulingGroup(app.curSchedGroup);
          }
 catch (          RemoteException e) {
          }
        }
      }
      Process.setSwappiness(app.pid,app.curSchedGroup <= Process.THREAD_GROUP_BG_NONINTERACTIVE);
    }
  }
  if (app.repForegroundActivities != app.foregroundActivities) {
    app.repForegroundActivities=app.foregroundActivities;
    changes|=ProcessChangeItem.CHANGE_ACTIVITIES;
  }
  if (app.repProcState != app.curProcState) {
    app.repProcState=app.curProcState;
    changes|=ProcessChangeItem.CHANGE_PROCESS_STATE;
    if (app.thread != null) {
      try {
        if (false) {
          Slog.i(TAG,"String_Node_Str" + app.repProcState + "String_Node_Str"+ app);
        }
        app.thread.setProcessState(app.repProcState);
      }
 catch (      RemoteException e) {
      }
    }
  }
  if (app.setProcState == ActivityManager.PROCESS_STATE_NONEXISTENT || ProcessList.procStatesDifferForMem(app.curProcState,app.setProcState)) {
    if (false && mTestPssMode && app.setProcState >= 0 && app.lastStateTime <= (now - 200)) {
      long start=SystemClock.uptimeMillis();
      long pss=Debug.getPss(app.pid,mTmpLong,null);
      recordPssSampleLocked(app,app.curProcState,pss,mTmpLong[0],now);
      mPendingPssProcesses.remove(app);
      Slog.i(TAG,"String_Node_Str" + app + "String_Node_Str"+ app.setProcState+ "String_Node_Str"+ app.curProcState+ "String_Node_Str"+ (SystemClock.uptimeMillis() - start)+ "String_Node_Str");
    }
    app.lastStateTime=now;
    app.nextPssTime=ProcessList.computeNextPssTime(app.curProcState,true,mTestPssMode,isSleeping(),now);
    if (DEBUG_PSS)     Slog.d(TAG_PSS,"String_Node_Str" + ProcessList.makeProcStateString(app.setProcState) + "String_Node_Str"+ ProcessList.makeProcStateString(app.curProcState)+ "String_Node_Str"+ (app.nextPssTime - now)+ "String_Node_Str"+ app);
  }
 else {
    if (now > app.nextPssTime || (now > (app.lastPssTime + ProcessList.PSS_MAX_INTERVAL) && now > (app.lastStateTime + ProcessList.minTimeFromStateChange(mTestPssMode)))) {
      requestPssLocked(app,app.setProcState);
      app.nextPssTime=ProcessList.computeNextPssTime(app.curProcState,false,mTestPssMode,isSleeping(),now);
    }
 else     if (false && DEBUG_PSS)     Slog.d(TAG_PSS,"String_Node_Str" + app + "String_Node_Str"+ (app.nextPssTime - now));
  }
  if (app.setProcState != app.curProcState) {
    if (DEBUG_SWITCH || DEBUG_OOM_ADJ)     Slog.v(TAG_OOM_ADJ,"String_Node_Str" + app.processName + "String_Node_Str"+ app.curProcState);
    boolean setImportant=app.setProcState < ActivityManager.PROCESS_STATE_SERVICE;
    boolean curImportant=app.curProcState < ActivityManager.PROCESS_STATE_SERVICE;
    if (setImportant && !curImportant) {
      BatteryStatsImpl stats=mBatteryStatsService.getActiveStatistics();
synchronized (stats) {
        app.lastWakeTime=stats.getProcessWakeTime(app.info.uid,app.pid,nowElapsed);
      }
      app.lastCpuTime=app.curCpuTime;
    }
    maybeUpdateUsageStatsLocked(app,nowElapsed);
    app.setProcState=app.curProcState;
    if (app.setProcState >= ActivityManager.PROCESS_STATE_HOME) {
      app.notCachedSinceIdle=false;
    }
    if (!doingAll) {
      setProcessTrackerStateLocked(app,mProcessStats.getMemFactorLocked(),now);
    }
 else {
      app.procStateChanged=true;
    }
  }
 else   if (app.reportedInteraction && (nowElapsed - app.interactionEventTime) > USAGE_STATS_INTERACTION_INTERVAL) {
    maybeUpdateUsageStatsLocked(app,nowElapsed);
  }
  if (changes != 0) {
    if (DEBUG_PROCESS_OBSERVERS)     Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + app + "String_Node_Str"+ changes);
    int i=mPendingProcessChanges.size() - 1;
    ProcessChangeItem item=null;
    while (i >= 0) {
      item=mPendingProcessChanges.get(i);
      if (item.pid == app.pid) {
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + item);
        break;
      }
      i--;
    }
    if (i < 0) {
      final int NA=mAvailProcessChanges.size();
      if (NA > 0) {
        item=mAvailProcessChanges.remove(NA - 1);
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + item);
      }
 else {
        item=new ProcessChangeItem();
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + item);
      }
      item.changes=0;
      item.pid=app.pid;
      item.uid=app.info.uid;
      if (mPendingProcessChanges.size() == 0) {
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str");
        mUiHandler.obtainMessage(DISPATCH_PROCESSES_CHANGED).sendToTarget();
      }
      mPendingProcessChanges.add(item);
    }
    item.changes|=changes;
    item.processState=app.repProcState;
    item.foregroundActivities=app.repForegroundActivities;
    if (DEBUG_PROCESS_OBSERVERS)     Slog.i(TAG_PROCESS_OBSERVERS,"String_Node_Str" + Integer.toHexString(System.identityHashCode(item)) + "String_Node_Str"+ app.toShortString()+ "String_Node_Str"+ item.changes+ "String_Node_Str"+ item.processState+ "String_Node_Str"+ item.foregroundActivities+ "String_Node_Str"+ app.adjType+ "String_Node_Str"+ app.adjSource+ "String_Node_Str"+ app.adjTarget);
  }
  return success;
}