Program: 21842
Project: 21842
Buggy source:
private final int computeOomAdjLocked(ProcessRecord app,int hiddenAdj,ProcessRecord TOP_APP,boolean recursed){
  if (mAdjSeq == app.adjSeq) {
    if (!recursed && app.hidden) {
      app.curAdj=hiddenAdj;
    }
    return app.curAdj;
  }
  if (app.thread == null) {
    app.adjSeq=mAdjSeq;
    app.curSchedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    return (app.curAdj=EMPTY_APP_ADJ);
  }
  if (app.maxAdj <= FOREGROUND_APP_ADJ) {
    app.adjType="String_Node_Str";
    app.adjSeq=mAdjSeq;
    app.curRawAdj=app.maxAdj;
    app.keeping=true;
    app.curSchedGroup=Process.THREAD_GROUP_DEFAULT;
    return (app.curAdj=app.maxAdj);
  }
  app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN;
  app.adjSource=null;
  app.adjTarget=null;
  app.keeping=false;
  app.empty=false;
  app.hidden=false;
  int adj;
  int schedGroup;
  int N;
  if (app == TOP_APP) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.instrumentationClass != null) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.persistentActivities > 0) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.curReceiver != null || (mPendingBroadcast != null && mPendingBroadcast.curApp == app)) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.executingServices.size() > 0) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.foregroundServices) {
    adj=PERCEPTIBLE_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.forcingToForeground != null) {
    adj=PERCEPTIBLE_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    app.adjSource=app.forcingToForeground;
  }
 else   if (app == mHeavyWeightProcess) {
    adj=HEAVY_WEIGHT_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app == mHomeProcess) {
    adj=HOME_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.adjType="String_Node_Str";
  }
 else   if ((N=app.activities.size()) != 0) {
    app.hidden=true;
    adj=hiddenAdj;
    schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.adjType="String_Node_Str";
    N=app.activities.size();
    for (int j=0; j < N; j++) {
      if (app.activities.get(j).visible) {
        app.hidden=false;
        adj=VISIBLE_APP_ADJ;
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.adjType="String_Node_Str";
        break;
      }
    }
  }
 else {
    app.hidden=true;
    app.empty=true;
    schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    adj=hiddenAdj;
    app.adjType="String_Node_Str";
  }
  app.adjSeq=mAdjSeq;
  app.curRawAdj=adj;
  if (mBackupTarget != null && app == mBackupTarget.app) {
    if (adj > BACKUP_APP_ADJ) {
      if (DEBUG_BACKUP)       Slog.v(TAG,"String_Node_Str" + app);
      adj=BACKUP_APP_ADJ;
      app.adjType="String_Node_Str";
      app.hidden=false;
    }
  }
  if (app.services.size() != 0 && (adj > FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
    final long now=SystemClock.uptimeMillis();
    Iterator<ServiceRecord> jt=app.services.iterator();
    while (jt.hasNext() && adj > FOREGROUND_APP_ADJ) {
      ServiceRecord s=jt.next();
      if (s.startRequested) {
        if (now < (s.lastActivity + MAX_SERVICE_INACTIVITY)) {
          if (adj > SECONDARY_SERVER_ADJ) {
            adj=SECONDARY_SERVER_ADJ;
            app.adjType="String_Node_Str";
            app.hidden=false;
          }
        }
        if (adj > SECONDARY_SERVER_ADJ) {
          app.adjType="String_Node_Str";
        }
        app.keeping=true;
      }
      if (s.connections.size() > 0 && (adj > FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
        Iterator<ArrayList<ConnectionRecord>> kt=s.connections.values().iterator();
        while (kt.hasNext() && adj > FOREGROUND_APP_ADJ) {
          ArrayList<ConnectionRecord> clist=kt.next();
          for (int i=0; i < clist.size() && adj > FOREGROUND_APP_ADJ; i++) {
            ConnectionRecord cr=clist.get(i);
            if (cr.binding.client == app) {
              continue;
            }
            if ((cr.flags & Context.BIND_AUTO_CREATE) != 0) {
              ProcessRecord client=cr.binding.client;
              int myHiddenAdj=hiddenAdj;
              if (myHiddenAdj > client.hiddenAdj) {
                if (client.hiddenAdj >= VISIBLE_APP_ADJ) {
                  myHiddenAdj=client.hiddenAdj;
                }
 else {
                  myHiddenAdj=VISIBLE_APP_ADJ;
                }
              }
              int clientAdj=computeOomAdjLocked(client,myHiddenAdj,TOP_APP,true);
              if (adj > clientAdj) {
                adj=clientAdj >= VISIBLE_APP_ADJ ? clientAdj : VISIBLE_APP_ADJ;
                if (!client.hidden) {
                  app.hidden=false;
                }
                if (client.keeping) {
                  app.keeping=true;
                }
                app.adjType="String_Node_Str";
                app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
                app.adjSource=cr.binding.client;
                app.adjTarget=s.name;
              }
              if ((cr.flags & Context.BIND_NOT_FOREGROUND) == 0) {
                if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
                  schedGroup=Process.THREAD_GROUP_DEFAULT;
                }
              }
            }
            ActivityRecord a=cr.activity;
            if (a != null && adj > FOREGROUND_APP_ADJ && (a.state == ActivityState.RESUMED || a.state == ActivityState.PAUSING)) {
              adj=FOREGROUND_APP_ADJ;
              schedGroup=Process.THREAD_GROUP_DEFAULT;
              app.hidden=false;
              app.adjType="String_Node_Str";
              app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
              app.adjSource=a;
              app.adjTarget=s.name;
            }
          }
        }
      }
    }
    if (adj > hiddenAdj) {
      adj=hiddenAdj;
      app.hidden=false;
      app.adjType="String_Node_Str";
    }
  }
  if (app.pubProviders.size() != 0 && (adj > FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
    Iterator<ContentProviderRecord> jt=app.pubProviders.values().iterator();
    while (jt.hasNext() && (adj > FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
      ContentProviderRecord cpr=jt.next();
      if (cpr.clients.size() != 0) {
        Iterator<ProcessRecord> kt=cpr.clients.iterator();
        while (kt.hasNext() && adj > FOREGROUND_APP_ADJ) {
          ProcessRecord client=kt.next();
          if (client == app) {
            continue;
          }
          int myHiddenAdj=hiddenAdj;
          if (myHiddenAdj > client.hiddenAdj) {
            if (client.hiddenAdj > FOREGROUND_APP_ADJ) {
              myHiddenAdj=client.hiddenAdj;
            }
 else {
              myHiddenAdj=FOREGROUND_APP_ADJ;
            }
          }
          int clientAdj=computeOomAdjLocked(client,myHiddenAdj,TOP_APP,true);
          if (adj > clientAdj) {
            adj=clientAdj > FOREGROUND_APP_ADJ ? clientAdj : FOREGROUND_APP_ADJ;
            if (!client.hidden) {
              app.hidden=false;
            }
            if (client.keeping) {
              app.keeping=true;
            }
            app.adjType="String_Node_Str";
            app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE;
            app.adjSource=client;
            app.adjTarget=cpr.name;
          }
          if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
            schedGroup=Process.THREAD_GROUP_DEFAULT;
          }
        }
      }
      if (cpr.externals != 0) {
        if (adj > FOREGROUND_APP_ADJ) {
          adj=FOREGROUND_APP_ADJ;
          schedGroup=Process.THREAD_GROUP_DEFAULT;
          app.hidden=false;
          app.keeping=true;
          app.adjType="String_Node_Str";
          app.adjTarget=cpr.name;
        }
      }
    }
  }
  app.curRawAdj=adj;
  if (adj > app.maxAdj) {
    adj=app.maxAdj;
    if (app.maxAdj <= PERCEPTIBLE_APP_ADJ) {
      schedGroup=Process.THREAD_GROUP_DEFAULT;
    }
  }
  if (adj < HIDDEN_APP_MIN_ADJ) {
    app.keeping=true;
  }
  app.curAdj=adj;
  app.curSchedGroup=schedGroup;
  return adj;
}

Fixed version (ground truth):
private final int computeOomAdjLocked(ProcessRecord app,int hiddenAdj,ProcessRecord TOP_APP,boolean recursed){
  if (mAdjSeq == app.adjSeq) {
    if (!recursed && app.hidden) {
      app.curAdj=hiddenAdj;
    }
    return app.curAdj;
  }
  if (app.thread == null) {
    app.adjSeq=mAdjSeq;
    app.curSchedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    return (app.curAdj=EMPTY_APP_ADJ);
  }
  if (app.maxAdj <= FOREGROUND_APP_ADJ) {
    app.adjType="String_Node_Str";
    app.adjSeq=mAdjSeq;
    app.curRawAdj=app.maxAdj;
    app.keeping=true;
    app.curSchedGroup=Process.THREAD_GROUP_DEFAULT;
    return (app.curAdj=app.maxAdj);
  }
  app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN;
  app.adjSource=null;
  app.adjTarget=null;
  app.keeping=false;
  app.empty=false;
  app.hidden=false;
  int adj;
  int schedGroup;
  int N;
  if (app == TOP_APP) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.instrumentationClass != null) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.curReceiver != null || (mPendingBroadcast != null && mPendingBroadcast.curApp == app)) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.executingServices.size() > 0) {
    adj=FOREGROUND_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.foregroundServices) {
    adj=PERCEPTIBLE_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app.forcingToForeground != null) {
    adj=PERCEPTIBLE_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
    app.adjSource=app.forcingToForeground;
  }
 else   if (app == mHeavyWeightProcess) {
    adj=HEAVY_WEIGHT_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_DEFAULT;
    app.adjType="String_Node_Str";
  }
 else   if (app == mHomeProcess) {
    adj=HOME_APP_ADJ;
    schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.adjType="String_Node_Str";
  }
 else   if ((N=app.activities.size()) != 0) {
    app.hidden=true;
    adj=hiddenAdj;
    schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    app.adjType="String_Node_Str";
    N=app.activities.size();
    for (int j=0; j < N; j++) {
      if (app.activities.get(j).visible) {
        app.hidden=false;
        adj=VISIBLE_APP_ADJ;
        schedGroup=Process.THREAD_GROUP_DEFAULT;
        app.adjType="String_Node_Str";
        break;
      }
    }
  }
 else {
    app.hidden=true;
    app.empty=true;
    schedGroup=Process.THREAD_GROUP_BG_NONINTERACTIVE;
    adj=hiddenAdj;
    app.adjType="String_Node_Str";
  }
  app.adjSeq=mAdjSeq;
  app.curRawAdj=adj;
  if (mBackupTarget != null && app == mBackupTarget.app) {
    if (adj > BACKUP_APP_ADJ) {
      if (DEBUG_BACKUP)       Slog.v(TAG,"String_Node_Str" + app);
      adj=BACKUP_APP_ADJ;
      app.adjType="String_Node_Str";
      app.hidden=false;
    }
  }
  if (app.services.size() != 0 && (adj > FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
    final long now=SystemClock.uptimeMillis();
    Iterator<ServiceRecord> jt=app.services.iterator();
    while (jt.hasNext() && adj > FOREGROUND_APP_ADJ) {
      ServiceRecord s=jt.next();
      if (s.startRequested) {
        if (now < (s.lastActivity + MAX_SERVICE_INACTIVITY)) {
          if (adj > SECONDARY_SERVER_ADJ) {
            adj=SECONDARY_SERVER_ADJ;
            app.adjType="String_Node_Str";
            app.hidden=false;
          }
        }
        if (adj > SECONDARY_SERVER_ADJ) {
          app.adjType="String_Node_Str";
        }
        app.keeping=true;
      }
      if (s.connections.size() > 0 && (adj > FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
        Iterator<ArrayList<ConnectionRecord>> kt=s.connections.values().iterator();
        while (kt.hasNext() && adj > FOREGROUND_APP_ADJ) {
          ArrayList<ConnectionRecord> clist=kt.next();
          for (int i=0; i < clist.size() && adj > FOREGROUND_APP_ADJ; i++) {
            ConnectionRecord cr=clist.get(i);
            if (cr.binding.client == app) {
              continue;
            }
            if ((cr.flags & Context.BIND_AUTO_CREATE) != 0) {
              ProcessRecord client=cr.binding.client;
              int myHiddenAdj=hiddenAdj;
              if (myHiddenAdj > client.hiddenAdj) {
                if (client.hiddenAdj >= VISIBLE_APP_ADJ) {
                  myHiddenAdj=client.hiddenAdj;
                }
 else {
                  myHiddenAdj=VISIBLE_APP_ADJ;
                }
              }
              int clientAdj=computeOomAdjLocked(client,myHiddenAdj,TOP_APP,true);
              if (adj > clientAdj) {
                adj=clientAdj >= VISIBLE_APP_ADJ ? clientAdj : VISIBLE_APP_ADJ;
                if (!client.hidden) {
                  app.hidden=false;
                }
                if (client.keeping) {
                  app.keeping=true;
                }
                app.adjType="String_Node_Str";
                app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
                app.adjSource=cr.binding.client;
                app.adjTarget=s.name;
              }
              if ((cr.flags & Context.BIND_NOT_FOREGROUND) == 0) {
                if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
                  schedGroup=Process.THREAD_GROUP_DEFAULT;
                }
              }
            }
            ActivityRecord a=cr.activity;
            if (a != null && adj > FOREGROUND_APP_ADJ && (a.state == ActivityState.RESUMED || a.state == ActivityState.PAUSING)) {
              adj=FOREGROUND_APP_ADJ;
              schedGroup=Process.THREAD_GROUP_DEFAULT;
              app.hidden=false;
              app.adjType="String_Node_Str";
              app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_USE;
              app.adjSource=a;
              app.adjTarget=s.name;
            }
          }
        }
      }
    }
    if (adj > hiddenAdj) {
      adj=hiddenAdj;
      app.hidden=false;
      app.adjType="String_Node_Str";
    }
  }
  if (app.pubProviders.size() != 0 && (adj > FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
    Iterator<ContentProviderRecord> jt=app.pubProviders.values().iterator();
    while (jt.hasNext() && (adj > FOREGROUND_APP_ADJ || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE)) {
      ContentProviderRecord cpr=jt.next();
      if (cpr.clients.size() != 0) {
        Iterator<ProcessRecord> kt=cpr.clients.iterator();
        while (kt.hasNext() && adj > FOREGROUND_APP_ADJ) {
          ProcessRecord client=kt.next();
          if (client == app) {
            continue;
          }
          int myHiddenAdj=hiddenAdj;
          if (myHiddenAdj > client.hiddenAdj) {
            if (client.hiddenAdj > FOREGROUND_APP_ADJ) {
              myHiddenAdj=client.hiddenAdj;
            }
 else {
              myHiddenAdj=FOREGROUND_APP_ADJ;
            }
          }
          int clientAdj=computeOomAdjLocked(client,myHiddenAdj,TOP_APP,true);
          if (adj > clientAdj) {
            adj=clientAdj > FOREGROUND_APP_ADJ ? clientAdj : FOREGROUND_APP_ADJ;
            if (!client.hidden) {
              app.hidden=false;
            }
            if (client.keeping) {
              app.keeping=true;
            }
            app.adjType="String_Node_Str";
            app.adjTypeCode=ActivityManager.RunningAppProcessInfo.REASON_PROVIDER_IN_USE;
            app.adjSource=client;
            app.adjTarget=cpr.name;
          }
          if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
            schedGroup=Process.THREAD_GROUP_DEFAULT;
          }
        }
      }
      if (cpr.externals != 0) {
        if (adj > FOREGROUND_APP_ADJ) {
          adj=FOREGROUND_APP_ADJ;
          schedGroup=Process.THREAD_GROUP_DEFAULT;
          app.hidden=false;
          app.keeping=true;
          app.adjType="String_Node_Str";
          app.adjTarget=cpr.name;
        }
      }
    }
  }
  app.curRawAdj=adj;
  if (adj > app.maxAdj) {
    adj=app.maxAdj;
    if (app.maxAdj <= PERCEPTIBLE_APP_ADJ) {
      schedGroup=Process.THREAD_GROUP_DEFAULT;
    }
  }
  if (adj < HIDDEN_APP_MIN_ADJ) {
    app.keeping=true;
  }
  app.curAdj=adj;
  app.curSchedGroup=schedGroup;
  return adj;
}