Program: 193208
Project: 193208
Buggy source:
private final int computeOomAdjLocked(ProcessRecord app,int cachedAdj,ProcessRecord TOP_APP,boolean doingAll,long now){
  if (mAdjSeq == app.adjSeq) {
    return app.curRawAdj;
  }
  if (app.thread == null) {
    app.adjSeq=mAdjSeq;
    app.curSchedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.curProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
    return (app.curAdj=app.curRawAdj=ProcessList.CACHED_APP_MAX_ADJ);
  }
  app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN;
  app.adjSource=null;
  app.adjTarget=null;
  app.empty=false;
  app.cached=false;
  final int activitiesSize=app.activities.size();
  if (app.maxAdj <= ProcessList.FOREGROUND_APP_ADJ) {
    app.adjType="String_Node_Str";
    app.adjSeq=mAdjSeq;
    app.curRawAdj=app.maxAdj;
    app.foregroundActivities=false;
    app.curSchedGroup=Process.THREAD_GROUP_DEFAULT;
    app.curProcState=ActivityManager.PROCESS_STATE_PERSISTENT;
    app.systemNoUi=true;
    if (app == TOP_APP) {
      app.systemNoUi=false;
    }
 else     if (activitiesSize > 0) {
      for (int j=0; j < activitiesSize; j++) {
        final ActivityRecord r=app.activities.get(j);
        if (r.visible) {
          app.systemNoUi=false;
        }
      }
    }
    if (!app.systemNoUi) {
      app.curProcState=ActivityManager.PROCESS_STATE_PERSISTENT_UI;
    }
    return (app.curAdj=app.maxAdj);
  }
  app.systemNoUi=false;
  final int PROCESS_STATE_TOP=mTopProcessState;
  int adj;
  int schedGroup;
  int procState;
  boolean foregroundActivities=false;
  BroadcastQueue queue;
  if (app == TOP_APP) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    foregroundActivities=true;
    procState=PROCESS_STATE_TOP;
  }
 else   if (app.instrumentationClass != null) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    procState=ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
  }
 else   if ((queue=isReceivingBroadcast(app)) != null) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=(queue == mFgBroadcastQueue) ? Process.THREAD_GROUP_DEFAULT : Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.adjType="String_Node_Str";
    procState=ActivityManager.PROCESS_STATE_RECEIVER;
  }
 else   if (app.executingServices.size() > 0) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=app.execServicesFg ? Process.THREAD_GROUP_DEFAULT : Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.adjType="String_Node_Str";
    procState=ActivityManager.PROCESS_STATE_SERVICE;
  }
 else {
    schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    adj=cachedAdj;
    procState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
    app.cached=true;
    app.empty=true;
    app.adjType="String_Node_Str";
  }
  if (!foregroundActivities && activitiesSize > 0) {
    int minLayer=ProcessList.VISIBLE_APP_LAYER_MAX;
    for (int j=0; j < activitiesSize; j++) {
      final ActivityRecord r=app.activities.get(j);
      if (r.app != app) {
        Slog.w(TAG,"String_Node_Str" + r + "String_Node_Str"+ app+ "String_Node_Str"+ r.app+ "String_Node_Str");
        continue;
      }
      if (r.visible) {
        if (adj > ProcessList.VISIBLE_APP_ADJ) {
          adj=ProcessList.VISIBLE_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        if (procState > PROCESS_STATE_TOP) {
          procState=PROCESS_STATE_TOP;
        }
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.cached=false;
        app.empty=false;
        foregroundActivities=true;
        if (r.task != null && minLayer > 0) {
          final int layer=r.task.mLayerRank;
          if (layer >= 0 && minLayer > layer) {
            minLayer=layer;
          }
        }
        break;
      }
 else       if (r.state == ActivityState.PAUSING || r.state == ActivityState.PAUSED) {
        if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
          adj=ProcessList.PERCEPTIBLE_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        if (procState > PROCESS_STATE_TOP) {
          procState=PROCESS_STATE_TOP;
        }
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.cached=false;
        app.empty=false;
        foregroundActivities=true;
      }
 else       if (r.state == ActivityState.STOPPING) {
        if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
          adj=ProcessList.PERCEPTIBLE_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        if (!r.finishing) {
          if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
            procState=ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
          }
        }
        app.cached=false;
        app.empty=false;
        foregroundActivities=true;
      }
 else {
        if (procState > ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
          procState=ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
          app.adjType="String_Node_Str";
        }
      }
    }
    if (adj == ProcessList.VISIBLE_APP_ADJ) {
      adj+=minLayer;
    }
  }
  if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
    if (app.foregroundServices) {
      adj=ProcessList.PERCEPTIBLE_APP_ADJ;
      procState=ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
      app.cached=false;
      app.adjType="String_Node_Str";
      schedGroup=Process.THREAD_GROUP_DEFAULT;
    }
 else     if (app.forcingToForeground != null) {
      adj=ProcessList.PERCEPTIBLE_APP_ADJ;
      procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      app.cached=false;
      app.adjType="String_Node_Str";
      app.adjSource=app.forcingToForeground;
      schedGroup=Process.THREAD_GROUP_DEFAULT;
    }
  }
  if (app == mHeavyWeightProcess) {
    if (adj > ProcessList.HEAVY_WEIGHT_APP_ADJ) {
      adj=ProcessList.HEAVY_WEIGHT_APP_ADJ;
      schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
      app.cached=false;
      app.adjType="String_Node_Str";
    }
    if (procState > ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) {
      procState=ActivityManager.PROCESS_STATE_HEAVY_WEIGHT;
    }
  }
  if (app == mHomeProcess) {
    if (adj > ProcessList.HOME_APP_ADJ) {
      adj=ProcessList.HOME_APP_ADJ;
      schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
      app.cached=false;
      app.adjType="String_Node_Str";
    }
    if (procState > ActivityManager.PROCESS_STATE_HOME) {
      procState=ActivityManager.PROCESS_STATE_HOME;
    }
  }
  if (app == mPreviousProcess && app.activities.size() > 0) {
    if (adj > ProcessList.PREVIOUS_APP_ADJ) {
      adj=ProcessList.PREVIOUS_APP_ADJ;
      schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
      app.cached=false;
      app.adjType="String_Node_Str";
    }
    if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
      procState=ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
    }
  }
  if (false)   Slog.i(TAG,"String_Node_Str" + app + "String_Node_Str"+ adj+ "String_Node_Str"+ app.adjType);
  app.adjSeq=mAdjSeq;
  app.curRawAdj=adj;
  app.hasStartedServices=false;
  if (mBackupTarget != null && app == mBackupTarget.app) {
    if (adj > ProcessList.BACKUP_APP_ADJ) {
      if (DEBUG_BACKUP)       Slog.v(TAG_BACKUP,"String_Node_Str" + app);
      adj=ProcessList.BACKUP_APP_ADJ;
      if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
        procState=ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND;
      }
      app.adjType="String_Node_Str";
      app.cached=false;
    }
    if (procState > ActivityManager.PROCESS_STATE_BACKUP) {
      procState=ActivityManager.PROCESS_STATE_BACKUP;
    }
  }
  boolean mayBeTop=false;
  for (int is=app.services.size() - 1; is >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); is--) {
    ServiceRecord s=app.services.valueAt(is);
    if (s.startRequested) {
      app.hasStartedServices=true;
      if (procState > ActivityManager.PROCESS_STATE_SERVICE) {
        procState=ActivityManager.PROCESS_STATE_SERVICE;
      }
      if (app.hasShownUi && app != mHomeProcess) {
        if (adj > ProcessList.SERVICE_ADJ) {
          app.adjType="String_Node_Str";
        }
      }
 else {
        if (now < (s.lastActivity + ActiveServices.MAX_SERVICE_INACTIVITY)) {
          if (adj > ProcessList.SERVICE_ADJ) {
            adj=ProcessList.SERVICE_ADJ;
            app.adjType="String_Node_Str";
            app.cached=false;
          }
        }
        if (adj > ProcessList.SERVICE_ADJ) {
          app.adjType="String_Node_Str";
        }
      }
    }
    for (int conni=s.connections.size() - 1; conni >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); conni--) {
      ArrayList<ConnectionRecord> clist=s.connections.valueAt(conni);
      for (int i=0; i < clist.size() && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); i++) {
        ConnectionRecord cr=clist.get(i);
        if (cr.binding.client == app) {
          continue;
        }
        if ((cr.flags & Context.BIND_WAIVE_PRIORITY) == 0) {
          ProcessRecord client=cr.binding.client;
          int clientAdj=computeOomAdjLocked(client,cachedAdj,TOP_APP,doingAll,now);
          int clientProcState=client.curProcState;
          if (clientProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
            clientProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
          }
          String adjType=null;
          if ((cr.flags & Context.BIND_ALLOW_OOM_MANAGEMENT) != 0) {
            if (app.hasShownUi && app != mHomeProcess) {
              if (adj > clientAdj) {
                adjType="String_Node_Str";
              }
              app.cached=false;
              clientAdj=adj;
              clientProcState=procState;
            }
 else {
              if (now >= (s.lastActivity + ActiveServices.MAX_SERVICE_INACTIVITY)) {
                if (adj > clientAdj) {
                  adjType="String_Node_Str";
                }
                clientAdj=adj;
              }
            }
          }
          if (adj > clientAdj) {
            if (app.hasShownUi && app != mHomeProcess && clientAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
              adjType="String_Node_Str";
            }
 else {
              if ((cr.flags & (Context.BIND_ABOVE_CLIENT | Context.BIND_IMPORTANT)) != 0) {
                adj=clientAdj >= ProcessList.PERSISTENT_SERVICE_ADJ ? clientAdj : ProcessList.PERSISTENT_SERVICE_ADJ;
              }
 else               if ((cr.flags & Context.BIND_NOT_VISIBLE) != 0 && clientAdj < ProcessList.PERCEPTIBLE_APP_ADJ && adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
                adj=ProcessList.PERCEPTIBLE_APP_ADJ;
              }
 else               if (clientAdj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
                adj=clientAdj;
              }
 else {
                if (adj > ProcessList.VISIBLE_APP_ADJ) {
                  adj=Math.max(clientAdj,ProcessList.VISIBLE_APP_ADJ);
                }
              }
              if (!client.cached) {
                app.cached=false;
              }
              adjType="String_Node_Str";
            }
          }
          if ((cr.flags & Context.BIND_NOT_FOREGROUND) == 0) {
            if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
              schedGroup=Process.THREAD_GROUP_DEFAULT;
            }
            if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
              if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
                mayBeTop=true;
                clientProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
              }
 else {
                if ((cr.flags & Context.BIND_FOREGROUND_SERVICE) != 0) {
                  clientProcState=ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
                }
 else                 if (mWakefulness == PowerManagerInternal.WAKEFULNESS_AWAKE && (cr.flags & Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE) != 0) {
                  clientProcState=ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
                }
 else {
                  clientProcState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
                }
              }
            }
          }
 else {
            if (clientProcState < ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
              clientProcState=ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND;
            }
          }
          if (procState > clientProcState) {
            procState=clientProcState;
          }
          if (procState < ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND && (cr.flags & Context.BIND_SHOWING_UI) != 0) {
            app.pendingUiClean=true;
          }
          if (adjType != null) {
            app.adjType=adjType;
            app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
            app.adjSource=cr.binding.client;
            app.adjSourceProcState=clientProcState;
            app.adjTarget=s.name;
          }
        }
        if ((cr.flags & Context.BIND_TREAT_LIKE_ACTIVITY) != 0) {
          app.treatLikeActivity=true;
        }
        final ActivityRecord a=cr.activity;
        if ((cr.flags & Context.BIND_ADJUST_WITH_ACTIVITY) != 0) {
          if (a != null && adj > ProcessList.FOREGROUND_APP_ADJ && (a.visible || a.state == ActivityState.RESUMED || a.state == ActivityState.PAUSING)) {
            adj=ProcessList.FOREGROUND_APP_ADJ;
            if ((cr.flags & Context.BIND_NOT_FOREGROUND) == 0) {
              schedGroup=Process.THREAD_GROUP_DEFAULT;
            }
            app.cached=false;
            app.adjType="String_Node_Str";
            app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
            app.adjSource=a;
            app.adjSourceProcState=procState;
            app.adjTarget=s.name;
          }
        }
      }
    }
  }
  for (int provi=app.pubProviders.size() - 1; provi >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); provi--) {
    ContentProviderRecord cpr=app.pubProviders.valueAt(provi);
    for (int i=cpr.connections.size() - 1; i >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); i--) {
      ContentProviderConnection conn=cpr.connections.get(i);
      ProcessRecord client=conn.client;
      if (client == app) {
        continue;
      }
      int clientAdj=computeOomAdjLocked(client,cachedAdj,TOP_APP,doingAll,now);
      int clientProcState=client.curProcState;
      if (clientProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
        clientProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
      }
      if (adj > clientAdj) {
        if (app.hasShownUi && app != mHomeProcess && clientAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
          app.adjType="String_Node_Str";
        }
 else {
          adj=clientAdj > ProcessList.FOREGROUND_APP_ADJ ? clientAdj : ProcessList.FOREGROUND_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        app.cached&=client.cached;
        app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE;
        app.adjSource=client;
        app.adjSourceProcState=clientProcState;
        app.adjTarget=cpr.name;
      }
      if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
        if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
          mayBeTop=true;
          clientProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
        }
 else {
          clientProcState=ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
        }
      }
      if (procState > clientProcState) {
        procState=clientProcState;
      }
      if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
        schedGroup=Process.THREAD_GROUP_DEFAULT;
      }
    }
    if (cpr.hasExternalProcessHandles()) {
      if (adj > ProcessList.FOREGROUND_APP_ADJ) {
        adj=ProcessList.FOREGROUND_APP_ADJ;
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.cached=false;
        app.adjType="String_Node_Str";
        app.adjTarget=cpr.name;
      }
      if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
        procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      }
    }
  }
  if (app.lastProviderTime > 0 && (app.lastProviderTime + CONTENT_PROVIDER_RETAIN_TIME) > now) {
    if (adj > ProcessList.PREVIOUS_APP_ADJ) {
      adj=ProcessList.PREVIOUS_APP_ADJ;
      schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
      app.cached=false;
      app.adjType="String_Node_Str";
    }
    if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
      procState=ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
    }
  }
  if (mayBeTop && procState > ActivityManager.PROCESS_STATE_TOP) {
switch (procState) {
case ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND:
case ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND:
case ActivityManager.PROCESS_STATE_SERVICE:
      procState=ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
    break;
default :
  procState=ActivityManager.PROCESS_STATE_TOP;
break;
}
}
if (procState >= ActivityManager.PROCESS_STATE_CACHED_EMPTY) {
if (app.hasClientActivities) {
procState=ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
app.adjType="String_Node_Str";
}
 else if (app.treatLikeActivity) {
procState=ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
app.adjType="String_Node_Str";
}
}
if (adj == ProcessList.SERVICE_ADJ) {
if (doingAll) {
app.serviceb=mNewNumAServiceProcs > (mNumServiceProcs / 3);
mNewNumServiceProcs++;
if (!app.serviceb) {
if (mLastMemoryLevel > ProcessStats.ADJ_MEM_FACTOR_NORMAL && app.lastPss >= mProcessList.getCachedRestoreThresholdKb()) {
  app.serviceHighRam=true;
  app.serviceb=true;
}
 else {
  mNewNumAServiceProcs++;
}
}
 else {
app.serviceHighRam=false;
}
}
if (app.serviceb) {
adj=ProcessList.SERVICE_B_ADJ;
}
}
app.curRawAdj=adj;
if (adj > app.maxAdj) {
adj=app.maxAdj;
if (app.maxAdj <= ProcessList.PERCEPTIBLE_APP_ADJ) {
schedGroup=Process.THREAD_GROUP_DEFAULT;
}
}
app.curAdj=app.modifyRawOomAdj(adj);
app.curSchedGroup=schedGroup;
app.curProcState=procState;
app.foregroundActivities=foregroundActivities;
return app.curRawAdj;
}

Fixed version (ground truth):
private final int computeOomAdjLocked(ProcessRecord app,int cachedAdj,ProcessRecord TOP_APP,boolean doingAll,long now){
  if (mAdjSeq == app.adjSeq) {
    return app.curRawAdj;
  }
  if (app.thread == null) {
    app.adjSeq=mAdjSeq;
    app.curSchedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.curProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
    return (app.curAdj=app.curRawAdj=ProcessList.CACHED_APP_MAX_ADJ);
  }
  app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN;
  app.adjSource=null;
  app.adjTarget=null;
  app.empty=false;
  app.cached=false;
  final int activitiesSize=app.activities.size();
  if (app.maxAdj <= ProcessList.FOREGROUND_APP_ADJ) {
    app.adjType="String_Node_Str";
    app.adjSeq=mAdjSeq;
    app.curRawAdj=app.maxAdj;
    app.foregroundActivities=false;
    app.curSchedGroup=Process.THREAD_GROUP_DEFAULT;
    app.curProcState=ActivityManager.PROCESS_STATE_PERSISTENT;
    app.systemNoUi=true;
    if (app == TOP_APP) {
      app.systemNoUi=false;
    }
 else     if (activitiesSize > 0) {
      for (int j=0; j < activitiesSize; j++) {
        final ActivityRecord r=app.activities.get(j);
        if (r.visible) {
          app.systemNoUi=false;
        }
      }
    }
    if (!app.systemNoUi) {
      app.curProcState=ActivityManager.PROCESS_STATE_PERSISTENT_UI;
    }
    return (app.curAdj=app.maxAdj);
  }
  app.systemNoUi=false;
  final int PROCESS_STATE_CUR_TOP=mTopProcessState;
  int adj;
  int schedGroup;
  int procState;
  boolean foregroundActivities=false;
  BroadcastQueue queue;
  if (app == TOP_APP) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    foregroundActivities=true;
    procState=PROCESS_STATE_CUR_TOP;
  }
 else   if (app.instrumentationClass != null) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    procState=ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
  }
 else   if ((queue=isReceivingBroadcast(app)) != null) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=(queue == mFgBroadcastQueue) ? Process.THREAD_GROUP_DEFAULT : Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.adjType="String_Node_Str";
    procState=ActivityManager.PROCESS_STATE_RECEIVER;
  }
 else   if (app.executingServices.size() > 0) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=app.execServicesFg ? Process.THREAD_GROUP_DEFAULT : Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.adjType="String_Node_Str";
    procState=ActivityManager.PROCESS_STATE_SERVICE;
  }
 else {
    schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    adj=cachedAdj;
    procState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
    app.cached=true;
    app.empty=true;
    app.adjType="String_Node_Str";
  }
  if (!foregroundActivities && activitiesSize > 0) {
    int minLayer=ProcessList.VISIBLE_APP_LAYER_MAX;
    for (int j=0; j < activitiesSize; j++) {
      final ActivityRecord r=app.activities.get(j);
      if (r.app != app) {
        Slog.w(TAG,"String_Node_Str" + r + "String_Node_Str"+ app+ "String_Node_Str"+ r.app+ "String_Node_Str");
        continue;
      }
      if (r.visible) {
        if (adj > ProcessList.VISIBLE_APP_ADJ) {
          adj=ProcessList.VISIBLE_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        if (procState > PROCESS_STATE_CUR_TOP) {
          procState=PROCESS_STATE_CUR_TOP;
        }
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.cached=false;
        app.empty=false;
        foregroundActivities=true;
        if (r.task != null && minLayer > 0) {
          final int layer=r.task.mLayerRank;
          if (layer >= 0 && minLayer > layer) {
            minLayer=layer;
          }
        }
        break;
      }
 else       if (r.state == ActivityState.PAUSING || r.state == ActivityState.PAUSED) {
        if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
          adj=ProcessList.PERCEPTIBLE_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        if (procState > PROCESS_STATE_CUR_TOP) {
          procState=PROCESS_STATE_CUR_TOP;
        }
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.cached=false;
        app.empty=false;
        foregroundActivities=true;
      }
 else       if (r.state == ActivityState.STOPPING) {
        if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
          adj=ProcessList.PERCEPTIBLE_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        if (!r.finishing) {
          if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
            procState=ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
          }
        }
        app.cached=false;
        app.empty=false;
        foregroundActivities=true;
      }
 else {
        if (procState > ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
          procState=ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
          app.adjType="String_Node_Str";
        }
      }
    }
    if (adj == ProcessList.VISIBLE_APP_ADJ) {
      adj+=minLayer;
    }
  }
  if (adj > ProcessList.PERCEPTIBLE_APP_ADJ || procState > ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) {
    if (app.foregroundServices) {
      adj=ProcessList.PERCEPTIBLE_APP_ADJ;
      procState=ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
      app.cached=false;
      app.adjType="String_Node_Str";
      schedGroup=Process.THREAD_GROUP_DEFAULT;
    }
 else     if (app.forcingToForeground != null) {
      adj=ProcessList.PERCEPTIBLE_APP_ADJ;
      procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      app.cached=false;
      app.adjType="String_Node_Str";
      app.adjSource=app.forcingToForeground;
      schedGroup=Process.THREAD_GROUP_DEFAULT;
    }
  }
  if (app == mHeavyWeightProcess) {
    if (adj > ProcessList.HEAVY_WEIGHT_APP_ADJ) {
      adj=ProcessList.HEAVY_WEIGHT_APP_ADJ;
      schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
      app.cached=false;
      app.adjType="String_Node_Str";
    }
    if (procState > ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) {
      procState=ActivityManager.PROCESS_STATE_HEAVY_WEIGHT;
    }
  }
  if (app == mHomeProcess) {
    if (adj > ProcessList.HOME_APP_ADJ) {
      adj=ProcessList.HOME_APP_ADJ;
      schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
      app.cached=false;
      app.adjType="String_Node_Str";
    }
    if (procState > ActivityManager.PROCESS_STATE_HOME) {
      procState=ActivityManager.PROCESS_STATE_HOME;
    }
  }
  if (app == mPreviousProcess && app.activities.size() > 0) {
    if (adj > ProcessList.PREVIOUS_APP_ADJ) {
      adj=ProcessList.PREVIOUS_APP_ADJ;
      schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
      app.cached=false;
      app.adjType="String_Node_Str";
    }
    if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
      procState=ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
    }
  }
  if (false)   Slog.i(TAG,"String_Node_Str" + app + "String_Node_Str"+ adj+ "String_Node_Str"+ app.adjType);
  app.adjSeq=mAdjSeq;
  app.curRawAdj=adj;
  app.hasStartedServices=false;
  if (mBackupTarget != null && app == mBackupTarget.app) {
    if (adj > ProcessList.BACKUP_APP_ADJ) {
      if (DEBUG_BACKUP)       Slog.v(TAG_BACKUP,"String_Node_Str" + app);
      adj=ProcessList.BACKUP_APP_ADJ;
      if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
        procState=ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND;
      }
      app.adjType="String_Node_Str";
      app.cached=false;
    }
    if (procState > ActivityManager.PROCESS_STATE_BACKUP) {
      procState=ActivityManager.PROCESS_STATE_BACKUP;
    }
  }
  boolean mayBeTop=false;
  for (int is=app.services.size() - 1; is >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); is--) {
    ServiceRecord s=app.services.valueAt(is);
    if (s.startRequested) {
      app.hasStartedServices=true;
      if (procState > ActivityManager.PROCESS_STATE_SERVICE) {
        procState=ActivityManager.PROCESS_STATE_SERVICE;
      }
      if (app.hasShownUi && app != mHomeProcess) {
        if (adj > ProcessList.SERVICE_ADJ) {
          app.adjType="String_Node_Str";
        }
      }
 else {
        if (now < (s.lastActivity + ActiveServices.MAX_SERVICE_INACTIVITY)) {
          if (adj > ProcessList.SERVICE_ADJ) {
            adj=ProcessList.SERVICE_ADJ;
            app.adjType="String_Node_Str";
            app.cached=false;
          }
        }
        if (adj > ProcessList.SERVICE_ADJ) {
          app.adjType="String_Node_Str";
        }
      }
    }
    for (int conni=s.connections.size() - 1; conni >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); conni--) {
      ArrayList<ConnectionRecord> clist=s.connections.valueAt(conni);
      for (int i=0; i < clist.size() && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); i++) {
        ConnectionRecord cr=clist.get(i);
        if (cr.binding.client == app) {
          continue;
        }
        if ((cr.flags & Context.BIND_WAIVE_PRIORITY) == 0) {
          ProcessRecord client=cr.binding.client;
          int clientAdj=computeOomAdjLocked(client,cachedAdj,TOP_APP,doingAll,now);
          int clientProcState=client.curProcState;
          if (clientProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
            clientProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
          }
          String adjType=null;
          if ((cr.flags & Context.BIND_ALLOW_OOM_MANAGEMENT) != 0) {
            if (app.hasShownUi && app != mHomeProcess) {
              if (adj > clientAdj) {
                adjType="String_Node_Str";
              }
              app.cached=false;
              clientAdj=adj;
              clientProcState=procState;
            }
 else {
              if (now >= (s.lastActivity + ActiveServices.MAX_SERVICE_INACTIVITY)) {
                if (adj > clientAdj) {
                  adjType="String_Node_Str";
                }
                clientAdj=adj;
              }
            }
          }
          if (adj > clientAdj) {
            if (app.hasShownUi && app != mHomeProcess && clientAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
              adjType="String_Node_Str";
            }
 else {
              if ((cr.flags & (Context.BIND_ABOVE_CLIENT | Context.BIND_IMPORTANT)) != 0) {
                adj=clientAdj >= ProcessList.PERSISTENT_SERVICE_ADJ ? clientAdj : ProcessList.PERSISTENT_SERVICE_ADJ;
              }
 else               if ((cr.flags & Context.BIND_NOT_VISIBLE) != 0 && clientAdj < ProcessList.PERCEPTIBLE_APP_ADJ && adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
                adj=ProcessList.PERCEPTIBLE_APP_ADJ;
              }
 else               if (clientAdj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
                adj=clientAdj;
              }
 else {
                if (adj > ProcessList.VISIBLE_APP_ADJ) {
                  adj=Math.max(clientAdj,ProcessList.VISIBLE_APP_ADJ);
                }
              }
              if (!client.cached) {
                app.cached=false;
              }
              adjType="String_Node_Str";
            }
          }
          if ((cr.flags & Context.BIND_NOT_FOREGROUND) == 0) {
            if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
              schedGroup=Process.THREAD_GROUP_DEFAULT;
            }
            if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
              if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
                mayBeTop=true;
                clientProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
              }
 else {
                if ((cr.flags & Context.BIND_FOREGROUND_SERVICE) != 0) {
                  clientProcState=ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
                }
 else                 if (mWakefulness == PowerManagerInternal.WAKEFULNESS_AWAKE && (cr.flags & Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE) != 0) {
                  clientProcState=ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
                }
 else {
                  clientProcState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
                }
              }
            }
          }
 else {
            if (clientProcState < ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
              clientProcState=ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND;
            }
          }
          if (procState > clientProcState) {
            procState=clientProcState;
          }
          if (procState < ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND && (cr.flags & Context.BIND_SHOWING_UI) != 0) {
            app.pendingUiClean=true;
          }
          if (adjType != null) {
            app.adjType=adjType;
            app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
            app.adjSource=cr.binding.client;
            app.adjSourceProcState=clientProcState;
            app.adjTarget=s.name;
          }
        }
        if ((cr.flags & Context.BIND_TREAT_LIKE_ACTIVITY) != 0) {
          app.treatLikeActivity=true;
        }
        final ActivityRecord a=cr.activity;
        if ((cr.flags & Context.BIND_ADJUST_WITH_ACTIVITY) != 0) {
          if (a != null && adj > ProcessList.FOREGROUND_APP_ADJ && (a.visible || a.state == ActivityState.RESUMED || a.state == ActivityState.PAUSING)) {
            adj=ProcessList.FOREGROUND_APP_ADJ;
            if ((cr.flags & Context.BIND_NOT_FOREGROUND) == 0) {
              schedGroup=Process.THREAD_GROUP_DEFAULT;
            }
            app.cached=false;
            app.adjType="String_Node_Str";
            app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
            app.adjSource=a;
            app.adjSourceProcState=procState;
            app.adjTarget=s.name;
          }
        }
      }
    }
  }
  for (int provi=app.pubProviders.size() - 1; provi >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); provi--) {
    ContentProviderRecord cpr=app.pubProviders.valueAt(provi);
    for (int i=cpr.connections.size() - 1; i >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_TOP); i--) {
      ContentProviderConnection conn=cpr.connections.get(i);
      ProcessRecord client=conn.client;
      if (client == app) {
        continue;
      }
      int clientAdj=computeOomAdjLocked(client,cachedAdj,TOP_APP,doingAll,now);
      int clientProcState=client.curProcState;
      if (clientProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
        clientProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
      }
      if (adj > clientAdj) {
        if (app.hasShownUi && app != mHomeProcess && clientAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
          app.adjType="String_Node_Str";
        }
 else {
          adj=clientAdj > ProcessList.FOREGROUND_APP_ADJ ? clientAdj : ProcessList.FOREGROUND_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        app.cached&=client.cached;
        app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE;
        app.adjSource=client;
        app.adjSourceProcState=clientProcState;
        app.adjTarget=cpr.name;
      }
      if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
        if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
          mayBeTop=true;
          clientProcState=ActivityManager.PROCESS_STATE_CACHED_EMPTY;
        }
 else {
          clientProcState=ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
        }
      }
      if (procState > clientProcState) {
        procState=clientProcState;
      }
      if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
        schedGroup=Process.THREAD_GROUP_DEFAULT;
      }
    }
    if (cpr.hasExternalProcessHandles()) {
      if (adj > ProcessList.FOREGROUND_APP_ADJ) {
        adj=ProcessList.FOREGROUND_APP_ADJ;
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.cached=false;
        app.adjType="String_Node_Str";
        app.adjTarget=cpr.name;
      }
      if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
        procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      }
    }
  }
  if (app.lastProviderTime > 0 && (app.lastProviderTime + CONTENT_PROVIDER_RETAIN_TIME) > now) {
    if (adj > ProcessList.PREVIOUS_APP_ADJ) {
      adj=ProcessList.PREVIOUS_APP_ADJ;
      schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
      app.cached=false;
      app.adjType="String_Node_Str";
    }
    if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
      procState=ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
    }
  }
  if (mayBeTop && procState > ActivityManager.PROCESS_STATE_TOP) {
switch (procState) {
case ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND:
case ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND:
case ActivityManager.PROCESS_STATE_SERVICE:
      procState=ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
    break;
default :
  procState=ActivityManager.PROCESS_STATE_TOP;
break;
}
}
if (procState >= ActivityManager.PROCESS_STATE_CACHED_EMPTY) {
if (app.hasClientActivities) {
procState=ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
app.adjType="String_Node_Str";
}
 else if (app.treatLikeActivity) {
procState=ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
app.adjType="String_Node_Str";
}
}
if (adj == ProcessList.SERVICE_ADJ) {
if (doingAll) {
app.serviceb=mNewNumAServiceProcs > (mNumServiceProcs / 3);
mNewNumServiceProcs++;
if (!app.serviceb) {
if (mLastMemoryLevel > ProcessStats.ADJ_MEM_FACTOR_NORMAL && app.lastPss >= mProcessList.getCachedRestoreThresholdKb()) {
  app.serviceHighRam=true;
  app.serviceb=true;
}
 else {
  mNewNumAServiceProcs++;
}
}
 else {
app.serviceHighRam=false;
}
}
if (app.serviceb) {
adj=ProcessList.SERVICE_B_ADJ;
}
}
app.curRawAdj=adj;
if (adj > app.maxAdj) {
adj=app.maxAdj;
if (app.maxAdj <= ProcessList.PERCEPTIBLE_APP_ADJ) {
schedGroup=Process.THREAD_GROUP_DEFAULT;
}
}
app.curAdj=app.modifyRawOomAdj(adj);
app.curSchedGroup=schedGroup;
app.curProcState=procState;
app.foregroundActivities=foregroundActivities;
return app.curRawAdj;
}