Program: 1806
Project: 1806
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;
  app.hasClientActivities=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.hasActivities=false;
    app.foregroundActivities=false;
    app.keeping=true;
    app.curSchedGroup=Process.THREAD_GROUP_DEFAULT;
    app.curProcState=ActivityManager.PROCESS_STATE_PERSISTENT;
    app.systemNoUi=true;
    if (app == TOP_APP) {
      app.systemNoUi=false;
      app.hasActivities=true;
    }
 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 (r.app == app) {
          app.hasActivities=true;
        }
      }
    }
    if (!app.systemNoUi) {
      app.curProcState=ActivityManager.PROCESS_STATE_PERSISTENT_UI;
    }
    return (app.curAdj=app.maxAdj);
  }
  app.keeping=false;
  app.systemNoUi=false;
  app.hasActivities=false;
  int adj;
  int schedGroup;
  int procState;
  boolean foregroundActivities=false;
  boolean interesting=false;
  BroadcastQueue queue;
  if (app == TOP_APP) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    foregroundActivities=true;
    interesting=true;
    app.hasActivities=true;
    procState=ActivityManager.PROCESS_STATE_TOP;
  }
 else   if (app.instrumentationClass != null) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    interesting=true;
    procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
  }
 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=Process.THREAD_GROUP_DEFAULT;
    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) {
    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");
        continue;
      }
      app.hasActivities=true;
      if (r.visible) {
        if (adj > ProcessList.VISIBLE_APP_ADJ) {
          adj=ProcessList.VISIBLE_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        if (procState > ActivityManager.PROCESS_STATE_TOP) {
          procState=ActivityManager.PROCESS_STATE_TOP;
        }
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.cached=false;
        app.empty=false;
        foregroundActivities=true;
        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 > ActivityManager.PROCESS_STATE_TOP) {
          procState=ActivityManager.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_CACHED_ACTIVITY) {
            procState=ActivityManager.PROCESS_STATE_CACHED_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.PERCEPTIBLE_APP_ADJ) {
    if (app.foregroundServices) {
      adj=ProcessList.PERCEPTIBLE_APP_ADJ;
      procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      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.foregroundServices) {
    interesting=true;
  }
  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,"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;
    }
  }
  for (int is=app.services.size() - 1; is >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); 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";
        }
      }
      app.keeping=true;
    }
    for (int conni=s.connections.size() - 1; conni >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); 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_IMPORTANT_FOREGROUND); 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;
          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;
              }
            }
          }
 else           if ((cr.flags & Context.BIND_AUTO_CREATE) != 0) {
            if ((cr.flags & Context.BIND_NOT_VISIBLE) == 0) {
              if (client.hasActivities) {
                if (procState > ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT) {
                  procState=ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
                  app.adjType="String_Node_Str";
                }
              }
              app.hasClientActivities|=client.hasActivities;
            }
          }
          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;
              }
 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.VISIBLE_APP_ADJ) {
                adj=clientAdj;
              }
 else {
                if (adj > ProcessList.VISIBLE_APP_ADJ) {
                  adj=ProcessList.VISIBLE_APP_ADJ;
                }
              }
              if (!client.cached) {
                app.cached=false;
              }
              if (client.keeping) {
                app.keeping=true;
              }
              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_IMPORTANT_FOREGROUND) {
              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.adjSourceOom=clientAdj;
            app.adjTarget=s.name;
          }
        }
        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.adjSourceOom=adj;
            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_IMPORTANT_FOREGROUND); 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_IMPORTANT_FOREGROUND); i--) {
      ContentProviderConnection conn=cpr.connections.get(i);
      ProcessRecord client=conn.client;
      if (client == app) {
        continue;
      }
      int clientAdj=computeOomAdjLocked(client,cachedAdj,TOP_APP,doingAll,now);
      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.keeping|=client.keeping;
        app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE;
        app.adjSource=client;
        app.adjSourceOom=clientAdj;
        app.adjTarget=cpr.name;
      }
      if (procState > client.curProcState) {
        procState=client.curProcState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND ? client.curProcState : ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      }
      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.keeping=true;
        app.adjType="String_Node_Str";
        app.adjTarget=cpr.name;
      }
      if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
        procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      }
    }
  }
  if (adj == ProcessList.SERVICE_ADJ) {
    if (doingAll) {
      app.serviceb=mNewNumServiceProcs > (mNumServiceProcs / 3);
      mNewNumServiceProcs++;
    }
    if (app.serviceb) {
      adj=ProcessList.SERVICE_B_ADJ;
    }
  }
 else {
    app.serviceb=false;
  }
  app.curRawAdj=adj;
  if (adj > app.maxAdj) {
    adj=app.maxAdj;
    if (app.maxAdj <= ProcessList.PERCEPTIBLE_APP_ADJ) {
      schedGroup=Process.THREAD_GROUP_DEFAULT;
    }
  }
  if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
    app.keeping=true;
  }
  adj=app.modifyRawOomAdj(adj);
  app.curProcState=procState;
  int importance=app.memImportance;
  if (importance == 0 || adj != app.curAdj || schedGroup != app.curSchedGroup) {
    app.curAdj=adj;
    app.curSchedGroup=schedGroup;
    if (!interesting) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
    }
 else     if (adj >= ProcessList.CACHED_APP_MIN_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
    }
 else     if (adj >= ProcessList.SERVICE_B_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
    }
 else     if (adj >= ProcessList.HOME_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
    }
 else     if (adj >= ProcessList.SERVICE_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
    }
 else     if (adj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE;
    }
 else     if (adj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
    }
 else     if (adj >= ProcessList.VISIBLE_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
    }
 else     if (adj >= ProcessList.FOREGROUND_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
    }
 else {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERSISTENT;
    }
  }
  int changes=importance != app.memImportance ? ProcessChangeItem.CHANGE_IMPORTANCE : 0;
  if (foregroundActivities != app.foregroundActivities) {
    changes|=ProcessChangeItem.CHANGE_ACTIVITIES;
  }
  if (changes != 0) {
    if (DEBUG_PROCESS_OBSERVERS)     Slog.i(TAG,"String_Node_Str" + app + "String_Node_Str"+ changes);
    app.memImportance=importance;
    app.foregroundActivities=foregroundActivities;
    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,"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,"String_Node_Str" + item);
      }
 else {
        item=new ProcessChangeItem();
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG,"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,"String_Node_Str");
        mHandler.obtainMessage(DISPATCH_PROCESSES_CHANGED).sendToTarget();
      }
      mPendingProcessChanges.add(item);
    }
    item.changes|=changes;
    item.importance=importance;
    item.foregroundActivities=foregroundActivities;
    if (DEBUG_PROCESS_OBSERVERS)     Slog.i(TAG,"String_Node_Str" + Integer.toHexString(System.identityHashCode(item)) + "String_Node_Str"+ app.toShortString()+ "String_Node_Str"+ item.changes+ "String_Node_Str"+ item.importance+ "String_Node_Str"+ item.foregroundActivities+ "String_Node_Str"+ app.adjType+ "String_Node_Str"+ app.adjSource+ "String_Node_Str"+ app.adjTarget);
  }
  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;
  app.hasClientActivities=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.hasActivities=false;
    app.foregroundActivities=false;
    app.keeping=true;
    app.curSchedGroup=Process.THREAD_GROUP_DEFAULT;
    app.curProcState=ActivityManager.PROCESS_STATE_PERSISTENT;
    app.systemNoUi=true;
    if (app == TOP_APP) {
      app.systemNoUi=false;
      app.hasActivities=true;
    }
 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 (r.app == app) {
          app.hasActivities=true;
        }
      }
    }
    if (!app.systemNoUi) {
      app.curProcState=ActivityManager.PROCESS_STATE_PERSISTENT_UI;
    }
    return (app.curAdj=app.maxAdj);
  }
  app.keeping=false;
  app.systemNoUi=false;
  app.hasActivities=false;
  int adj;
  int schedGroup;
  int procState;
  boolean foregroundActivities=false;
  boolean interesting=false;
  BroadcastQueue queue;
  if (app == TOP_APP) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    foregroundActivities=true;
    interesting=true;
    app.hasActivities=true;
    procState=ActivityManager.PROCESS_STATE_TOP;
  }
 else   if (app.instrumentationClass != null) {
    adj=ProcessList.FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    interesting=true;
    procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
  }
 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=Process.THREAD_GROUP_DEFAULT;
    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) {
    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");
        continue;
      }
      app.hasActivities=true;
      if (r.visible) {
        if (adj > ProcessList.VISIBLE_APP_ADJ) {
          adj=ProcessList.VISIBLE_APP_ADJ;
          app.adjType="String_Node_Str";
        }
        if (procState > ActivityManager.PROCESS_STATE_TOP) {
          procState=ActivityManager.PROCESS_STATE_TOP;
        }
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.cached=false;
        app.empty=false;
        foregroundActivities=true;
        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 > ActivityManager.PROCESS_STATE_TOP) {
          procState=ActivityManager.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_CACHED_ACTIVITY) {
            procState=ActivityManager.PROCESS_STATE_CACHED_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.PERCEPTIBLE_APP_ADJ) {
    if (app.foregroundServices) {
      adj=ProcessList.PERCEPTIBLE_APP_ADJ;
      procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      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.foregroundServices) {
    interesting=true;
  }
  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,"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;
    }
  }
  for (int is=app.services.size() - 1; is >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); 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";
        }
      }
      app.keeping=true;
    }
    for (int conni=s.connections.size() - 1; conni >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE || procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); 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_IMPORTANT_FOREGROUND); 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;
              }
            }
          }
 else           if ((cr.flags & Context.BIND_AUTO_CREATE) != 0) {
            if ((cr.flags & Context.BIND_NOT_VISIBLE) == 0) {
              if (client.hasActivities) {
                if (procState > ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT) {
                  procState=ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
                  app.adjType="String_Node_Str";
                }
                app.hasClientActivities=true;
              }
            }
          }
          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;
              }
 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.VISIBLE_APP_ADJ) {
                adj=clientAdj;
              }
 else {
                if (adj > ProcessList.VISIBLE_APP_ADJ) {
                  adj=ProcessList.VISIBLE_APP_ADJ;
                }
              }
              if (!client.cached) {
                app.cached=false;
              }
              if (client.keeping) {
                app.keeping=true;
              }
              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_IMPORTANT_FOREGROUND) {
              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.adjSourceOom=clientAdj;
            app.adjTarget=s.name;
          }
        }
        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.adjSourceOom=adj;
            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_IMPORTANT_FOREGROUND); 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_IMPORTANT_FOREGROUND); 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.keeping|=client.keeping;
        app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE;
        app.adjSource=client;
        app.adjSourceOom=clientAdj;
        app.adjTarget=cpr.name;
      }
      if (procState > clientProcState) {
        procState=clientProcState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND ? clientProcState : ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      }
      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.keeping=true;
        app.adjType="String_Node_Str";
        app.adjTarget=cpr.name;
      }
      if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
        procState=ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
      }
    }
  }
  if (adj == ProcessList.SERVICE_ADJ) {
    if (doingAll) {
      app.serviceb=mNewNumServiceProcs > (mNumServiceProcs / 3);
      mNewNumServiceProcs++;
    }
    if (app.serviceb) {
      adj=ProcessList.SERVICE_B_ADJ;
    }
  }
 else {
    app.serviceb=false;
  }
  app.curRawAdj=adj;
  if (adj > app.maxAdj) {
    adj=app.maxAdj;
    if (app.maxAdj <= ProcessList.PERCEPTIBLE_APP_ADJ) {
      schedGroup=Process.THREAD_GROUP_DEFAULT;
    }
  }
  if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
    app.keeping=true;
  }
  adj=app.modifyRawOomAdj(adj);
  app.curProcState=procState;
  int importance=app.memImportance;
  if (importance == 0 || adj != app.curAdj || schedGroup != app.curSchedGroup) {
    app.curAdj=adj;
    app.curSchedGroup=schedGroup;
    if (!interesting) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
    }
 else     if (adj >= ProcessList.CACHED_APP_MIN_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
    }
 else     if (adj >= ProcessList.SERVICE_B_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
    }
 else     if (adj >= ProcessList.HOME_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
    }
 else     if (adj >= ProcessList.SERVICE_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
    }
 else     if (adj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE;
    }
 else     if (adj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
    }
 else     if (adj >= ProcessList.VISIBLE_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
    }
 else     if (adj >= ProcessList.FOREGROUND_APP_ADJ) {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
    }
 else {
      importance=ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERSISTENT;
    }
  }
  int changes=importance != app.memImportance ? ProcessChangeItem.CHANGE_IMPORTANCE : 0;
  if (foregroundActivities != app.foregroundActivities) {
    changes|=ProcessChangeItem.CHANGE_ACTIVITIES;
  }
  if (changes != 0) {
    if (DEBUG_PROCESS_OBSERVERS)     Slog.i(TAG,"String_Node_Str" + app + "String_Node_Str"+ changes);
    app.memImportance=importance;
    app.foregroundActivities=foregroundActivities;
    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,"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,"String_Node_Str" + item);
      }
 else {
        item=new ProcessChangeItem();
        if (DEBUG_PROCESS_OBSERVERS)         Slog.i(TAG,"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,"String_Node_Str");
        mHandler.obtainMessage(DISPATCH_PROCESSES_CHANGED).sendToTarget();
      }
      mPendingProcessChanges.add(item);
    }
    item.changes|=changes;
    item.importance=importance;
    item.foregroundActivities=foregroundActivities;
    if (DEBUG_PROCESS_OBSERVERS)     Slog.i(TAG,"String_Node_Str" + Integer.toHexString(System.identityHashCode(item)) + "String_Node_Str"+ app.toShortString()+ "String_Node_Str"+ item.changes+ "String_Node_Str"+ item.importance+ "String_Node_Str"+ item.foregroundActivities+ "String_Node_Str"+ app.adjType+ "String_Node_Str"+ app.adjSource+ "String_Node_Str"+ app.adjTarget);
  }
  return app.curRawAdj;
}