Program: 199977
Project: 199977
Buggy source:
ComponentName startServiceLocked(IApplicationThread caller,Intent service,String resolvedType,int callingPid,int callingUid,int userId){
  if (DEBUG_DELAYED_STATS)   Slog.v(TAG,"String_Node_Str" + service + "String_Node_Str"+ resolvedType+ "String_Node_Str"+ service.getExtras());
  final boolean callerFg;
  if (caller != null) {
    final ProcessRecord callerApp=mAm.getRecordForAppLocked(caller);
    if (callerApp == null) {
      throw new SecurityException("String_Node_Str" + caller + "String_Node_Str"+ Binder.getCallingPid()+ "String_Node_Str"+ service);
    }
    callerFg=callerApp.setSchedGroup != Process.THREAD_GROUP_BG_NONINTERACTIVE;
  }
 else {
    callerFg=true;
  }
  ServiceLookupResult res=retrieveServiceLocked(service,resolvedType,callingPid,callingUid,userId,true,callerFg);
  if (res == null) {
    return null;
  }
  if (res.record == null) {
    return new ComponentName("String_Node_Str",res.permission != null ? res.permission : "String_Node_Str");
  }
  ServiceRecord r=res.record;
  NeededUriGrants neededGrants=mAm.checkGrantUriPermissionFromIntentLocked(callingUid,r.packageName,service,service.getFlags(),null);
  if (unscheduleServiceRestartLocked(r,callingUid,false)) {
    if (DEBUG_SERVICE)     Slog.v(TAG,"String_Node_Str" + r);
  }
  r.lastActivity=SystemClock.uptimeMillis();
  r.startRequested=true;
  r.delayedStop=false;
  r.pendingStarts.add(new ServiceRecord.StartItem(r,false,r.makeNextStartId(),service,neededGrants));
  final ServiceMap smap=getServiceMap(r.userId);
  boolean addToStarting=false;
  if (!callerFg && r.app == null && mAm.mStartedUsers.get(r.userId) != null) {
    ProcessRecord proc=mAm.getProcessRecordLocked(r.processName,r.appInfo.uid,false);
    if (proc == null || proc.curProcState > ActivityManager.PROCESS_STATE_RECEIVER) {
      if (DEBUG_DELAYED_SERVICE)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ proc);
      if (r.delayed) {
        if (DEBUG_DELAYED_STATS)         Slog.v(TAG,"String_Node_Str" + r);
        return r.name;
      }
      if (smap.mStartingBackground.size() >= mMaxStartingBackground) {
        Slog.i(TAG,"String_Node_Str" + r);
        smap.mDelayedStartList.add(r);
        r.delayed=true;
        return r.name;
      }
      if (DEBUG_DELAYED_STATS)       Slog.v(TAG,"String_Node_Str" + r);
      addToStarting=true;
    }
 else     if (proc.curProcState >= ActivityManager.PROCESS_STATE_SERVICE) {
      addToStarting=true;
      if (DEBUG_DELAYED_STATS)       Slog.v(TAG,"String_Node_Str" + r);
    }
 else     if (DEBUG_DELAYED_STATS) {
      StringBuilder sb=new StringBuilder(128);
      sb.append("String_Node_Str").append(proc.curProcState).append(' ').append(proc.adjType);
      String reason=proc.makeAdjReason();
      if (reason != null) {
        sb.append(' ');
        sb.append(reason);
      }
      sb.append("String_Node_Str");
      sb.append(r.toString());
      Slog.v(TAG,sb.toString());
    }
  }
 else   if (DEBUG_DELAYED_STATS) {
    if (callerFg) {
      Slog.v(TAG,"String_Node_Str" + callerFg + "String_Node_Str"+ callingUid+ "String_Node_Str"+ callingPid+ "String_Node_Str"+ r);
    }
 else     if (r.app != null) {
      Slog.v(TAG,"String_Node_Str" + r.app + "String_Node_Str"+ r);
    }
 else {
      Slog.v(TAG,"String_Node_Str" + r.userId + "String_Node_Str"+ r);
    }
  }
  return startServiceInnerLocked(smap,service,r,callerFg,addToStarting);
}

Fixed version (ground truth):
ComponentName startServiceLocked(IApplicationThread caller,Intent service,String resolvedType,int callingPid,int callingUid,int userId){
  if (DEBUG_DELAYED_STARTS)   Slog.v(TAG,"String_Node_Str" + service + "String_Node_Str"+ resolvedType+ "String_Node_Str"+ service.getExtras());
  final boolean callerFg;
  if (caller != null) {
    final ProcessRecord callerApp=mAm.getRecordForAppLocked(caller);
    if (callerApp == null) {
      throw new SecurityException("String_Node_Str" + caller + "String_Node_Str"+ Binder.getCallingPid()+ "String_Node_Str"+ service);
    }
    callerFg=callerApp.setSchedGroup != Process.THREAD_GROUP_BG_NONINTERACTIVE;
  }
 else {
    callerFg=true;
  }
  ServiceLookupResult res=retrieveServiceLocked(service,resolvedType,callingPid,callingUid,userId,true,callerFg);
  if (res == null) {
    return null;
  }
  if (res.record == null) {
    return new ComponentName("String_Node_Str",res.permission != null ? res.permission : "String_Node_Str");
  }
  ServiceRecord r=res.record;
  NeededUriGrants neededGrants=mAm.checkGrantUriPermissionFromIntentLocked(callingUid,r.packageName,service,service.getFlags(),null);
  if (unscheduleServiceRestartLocked(r,callingUid,false)) {
    if (DEBUG_SERVICE)     Slog.v(TAG,"String_Node_Str" + r);
  }
  r.lastActivity=SystemClock.uptimeMillis();
  r.startRequested=true;
  r.delayedStop=false;
  r.pendingStarts.add(new ServiceRecord.StartItem(r,false,r.makeNextStartId(),service,neededGrants));
  final ServiceMap smap=getServiceMap(r.userId);
  boolean addToStarting=false;
  if (!callerFg && r.app == null && mAm.mStartedUsers.get(r.userId) != null) {
    ProcessRecord proc=mAm.getProcessRecordLocked(r.processName,r.appInfo.uid,false);
    if (proc == null || proc.curProcState > ActivityManager.PROCESS_STATE_RECEIVER) {
      if (DEBUG_DELAYED_SERVICE)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ proc);
      if (r.delayed) {
        if (DEBUG_DELAYED_STARTS)         Slog.v(TAG,"String_Node_Str" + r);
        return r.name;
      }
      if (smap.mStartingBackground.size() >= mMaxStartingBackground) {
        Slog.i(TAG,"String_Node_Str" + r);
        smap.mDelayedStartList.add(r);
        r.delayed=true;
        return r.name;
      }
      if (DEBUG_DELAYED_STARTS)       Slog.v(TAG,"String_Node_Str" + r);
      addToStarting=true;
    }
 else     if (proc.curProcState >= ActivityManager.PROCESS_STATE_SERVICE) {
      addToStarting=true;
      if (DEBUG_DELAYED_STARTS)       Slog.v(TAG,"String_Node_Str" + r);
    }
 else     if (DEBUG_DELAYED_STARTS) {
      StringBuilder sb=new StringBuilder(128);
      sb.append("String_Node_Str").append(proc.curProcState).append(' ').append(proc.adjType);
      String reason=proc.makeAdjReason();
      if (reason != null) {
        sb.append(' ');
        sb.append(reason);
      }
      sb.append("String_Node_Str");
      sb.append(r.toString());
      Slog.v(TAG,sb.toString());
    }
  }
 else   if (DEBUG_DELAYED_STARTS) {
    if (callerFg) {
      Slog.v(TAG,"String_Node_Str" + callerFg + "String_Node_Str"+ callingUid+ "String_Node_Str"+ callingPid+ "String_Node_Str"+ r);
    }
 else     if (r.app != null) {
      Slog.v(TAG,"String_Node_Str" + r.app + "String_Node_Str"+ r);
    }
 else {
      Slog.v(TAG,"String_Node_Str" + r.userId + "String_Node_Str"+ r);
    }
  }
  return startServiceInnerLocked(smap,service,r,callerFg,addToStarting);
}