Program: 41216
Project: 41216
Buggy source:
final int startActivityMayWait(IApplicationThread caller,Intent intent,String resolvedType,Uri[] grantedUriPermissions,int grantedMode,IBinder resultTo,String resultWho,int requestCode,boolean onlyIfNeeded,boolean debug,WaitResult outResult,Configuration config){
  if (intent != null && intent.hasFileDescriptors()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  boolean componentSpecified=intent.getComponent() != null;
  intent=new Intent(intent);
  ActivityInfo aInfo;
  try {
    ResolveInfo rInfo=AppGlobals.getPackageManager().resolveIntent(intent,resolvedType,PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS);
    aInfo=rInfo != null ? rInfo.activityInfo : null;
  }
 catch (  RemoteException e) {
    aInfo=null;
  }
  if (aInfo != null) {
    intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName,aInfo.name));
    if (debug) {
      if (!aInfo.processName.equals("String_Node_Str")) {
        mService.setDebugApp(aInfo.processName,true,false);
      }
    }
  }
synchronized (mService) {
    int callingPid;
    int callingUid;
    if (caller == null) {
      callingPid=Binder.getCallingPid();
      callingUid=Binder.getCallingUid();
    }
 else {
      callingPid=callingUid=-1;
    }
    mConfigWillChange=config != null && mService.mConfiguration.diff(config) != 0;
    if (DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + mConfigWillChange);
    final long origId=Binder.clearCallingIdentity();
    if (mMainStack && aInfo != null && (aInfo.applicationInfo.flags & ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
      if (aInfo.processName.equals(aInfo.applicationInfo.packageName)) {
        if (mService.mHeavyWeightProcess != null && (mService.mHeavyWeightProcess.info.uid != aInfo.applicationInfo.uid || !mService.mHeavyWeightProcess.processName.equals(aInfo.processName))) {
          int realCallingPid=callingPid;
          int realCallingUid=callingUid;
          if (caller != null) {
            ProcessRecord callerApp=mService.getRecordForAppLocked(caller);
            if (callerApp != null) {
              realCallingPid=callerApp.pid;
              realCallingUid=callerApp.info.uid;
            }
 else {
              Slog.w(TAG,"String_Node_Str" + caller + "String_Node_Str"+ realCallingPid+ "String_Node_Str"+ intent.toString());
              return START_PERMISSION_DENIED;
            }
          }
          IIntentSender target=mService.getIntentSenderLocked(IActivityManager.INTENT_SENDER_ACTIVITY,"String_Node_Str",realCallingUid,null,null,0,intent,resolvedType,PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
          Intent newIntent=new Intent();
          if (requestCode >= 0) {
            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_HAS_RESULT,true);
          }
          newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_INTENT,new IntentSender(target));
          if (mService.mHeavyWeightProcess.activities.size() > 0) {
            ActivityRecord hist=mService.mHeavyWeightProcess.activities.get(0);
            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_APP,hist.packageName);
            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_TASK,hist.task.taskId);
          }
          newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_NEW_APP,aInfo.packageName);
          newIntent.setFlags(intent.getFlags());
          newIntent.setClassName("String_Node_Str",HeavyWeightSwitcherActivity.class.getName());
          intent=newIntent;
          resolvedType=null;
          caller=null;
          callingUid=Binder.getCallingUid();
          callingPid=Binder.getCallingPid();
          componentSpecified=true;
          try {
            ResolveInfo rInfo=AppGlobals.getPackageManager().resolveIntent(intent,null,PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS);
            aInfo=rInfo != null ? rInfo.activityInfo : null;
          }
 catch (          RemoteException e) {
            aInfo=null;
          }
        }
      }
    }
    int res=startActivityLocked(caller,intent,resolvedType,grantedUriPermissions,grantedMode,aInfo,resultTo,resultWho,requestCode,callingPid,callingUid,onlyIfNeeded,componentSpecified);
    if (mConfigWillChange && mMainStack) {
      mService.enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,"String_Node_Str");
      mConfigWillChange=false;
      if (DEBUG_CONFIGURATION)       Slog.v(TAG,"String_Node_Str");
      mService.updateConfigurationLocked(config,null);
    }
    Binder.restoreCallingIdentity(origId);
    if (outResult != null) {
      outResult.result=res;
      if (res == IActivityManager.START_SUCCESS) {
        mWaitingActivityLaunched.add(outResult);
        do {
          try {
            wait();
          }
 catch (          InterruptedException e) {
          }
        }
 while (!outResult.timeout && outResult.who == null);
      }
 else       if (res == IActivityManager.START_TASK_TO_FRONT) {
        ActivityRecord r=this.topRunningActivityLocked(null);
        if (r.nowVisible) {
          outResult.timeout=false;
          outResult.who=new ComponentName(r.info.packageName,r.info.name);
          outResult.totalTime=0;
          outResult.thisTime=0;
        }
 else {
          outResult.thisTime=SystemClock.uptimeMillis();
          mWaitingActivityVisible.add(outResult);
          do {
            try {
              wait();
            }
 catch (            InterruptedException e) {
            }
          }
 while (!outResult.timeout && outResult.who == null);
        }
      }
    }
    return res;
  }
}

Fixed version (ground truth):
final int startActivityMayWait(IApplicationThread caller,Intent intent,String resolvedType,Uri[] grantedUriPermissions,int grantedMode,IBinder resultTo,String resultWho,int requestCode,boolean onlyIfNeeded,boolean debug,WaitResult outResult,Configuration config){
  if (intent != null && intent.hasFileDescriptors()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  boolean componentSpecified=intent.getComponent() != null;
  intent=new Intent(intent);
  ActivityInfo aInfo;
  try {
    ResolveInfo rInfo=AppGlobals.getPackageManager().resolveIntent(intent,resolvedType,PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS);
    aInfo=rInfo != null ? rInfo.activityInfo : null;
  }
 catch (  RemoteException e) {
    aInfo=null;
  }
  if (aInfo != null) {
    intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName,aInfo.name));
    if (debug) {
      if (!aInfo.processName.equals("String_Node_Str")) {
        mService.setDebugApp(aInfo.processName,true,false);
      }
    }
  }
synchronized (mService) {
    int callingPid;
    int callingUid;
    if (caller == null) {
      callingPid=Binder.getCallingPid();
      callingUid=Binder.getCallingUid();
    }
 else {
      callingPid=callingUid=-1;
    }
    mConfigWillChange=config != null && mService.mConfiguration.diff(config) != 0;
    if (DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + mConfigWillChange);
    final long origId=Binder.clearCallingIdentity();
    if (mMainStack && aInfo != null && (aInfo.applicationInfo.flags & ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
      if (aInfo.processName.equals(aInfo.applicationInfo.packageName)) {
        if (mService.mHeavyWeightProcess != null && (mService.mHeavyWeightProcess.info.uid != aInfo.applicationInfo.uid || !mService.mHeavyWeightProcess.processName.equals(aInfo.processName))) {
          int realCallingPid=callingPid;
          int realCallingUid=callingUid;
          if (caller != null) {
            ProcessRecord callerApp=mService.getRecordForAppLocked(caller);
            if (callerApp != null) {
              realCallingPid=callerApp.pid;
              realCallingUid=callerApp.info.uid;
            }
 else {
              Slog.w(TAG,"String_Node_Str" + caller + "String_Node_Str"+ realCallingPid+ "String_Node_Str"+ intent.toString());
              return START_PERMISSION_DENIED;
            }
          }
          IIntentSender target=mService.getIntentSenderLocked(IActivityManager.INTENT_SENDER_ACTIVITY,"String_Node_Str",realCallingUid,null,null,0,intent,resolvedType,PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
          Intent newIntent=new Intent();
          if (requestCode >= 0) {
            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_HAS_RESULT,true);
          }
          newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_INTENT,new IntentSender(target));
          if (mService.mHeavyWeightProcess.activities.size() > 0) {
            ActivityRecord hist=mService.mHeavyWeightProcess.activities.get(0);
            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_APP,hist.packageName);
            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_TASK,hist.task.taskId);
          }
          newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_NEW_APP,aInfo.packageName);
          newIntent.setFlags(intent.getFlags());
          newIntent.setClassName("String_Node_Str",HeavyWeightSwitcherActivity.class.getName());
          intent=newIntent;
          resolvedType=null;
          caller=null;
          callingUid=Binder.getCallingUid();
          callingPid=Binder.getCallingPid();
          componentSpecified=true;
          try {
            ResolveInfo rInfo=AppGlobals.getPackageManager().resolveIntent(intent,null,PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS);
            aInfo=rInfo != null ? rInfo.activityInfo : null;
          }
 catch (          RemoteException e) {
            aInfo=null;
          }
        }
      }
    }
    int res=startActivityLocked(caller,intent,resolvedType,grantedUriPermissions,grantedMode,aInfo,resultTo,resultWho,requestCode,callingPid,callingUid,onlyIfNeeded,componentSpecified);
    if (mConfigWillChange && mMainStack) {
      mService.enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,"String_Node_Str");
      mConfigWillChange=false;
      if (DEBUG_CONFIGURATION)       Slog.v(TAG,"String_Node_Str");
      mService.updateConfigurationLocked(config,null);
    }
    Binder.restoreCallingIdentity(origId);
    if (outResult != null) {
      outResult.result=res;
      if (res == IActivityManager.START_SUCCESS) {
        mWaitingActivityLaunched.add(outResult);
        do {
          try {
            mService.wait();
          }
 catch (          InterruptedException e) {
          }
        }
 while (!outResult.timeout && outResult.who == null);
      }
 else       if (res == IActivityManager.START_TASK_TO_FRONT) {
        ActivityRecord r=this.topRunningActivityLocked(null);
        if (r.nowVisible) {
          outResult.timeout=false;
          outResult.who=new ComponentName(r.info.packageName,r.info.name);
          outResult.totalTime=0;
          outResult.thisTime=0;
        }
 else {
          outResult.thisTime=SystemClock.uptimeMillis();
          mWaitingActivityVisible.add(outResult);
          do {
            try {
              mService.wait();
            }
 catch (            InterruptedException e) {
            }
          }
 while (!outResult.timeout && outResult.who == null);
        }
      }
    }
    return res;
  }
}