Program: 197082
Project: 197082
Buggy source:
final int startActivityLocked(IApplicationThread caller,Intent intent,String resolvedType,ActivityInfo aInfo,IVoiceInteractionSession voiceSession,IVoiceInteractor voiceInteractor,IBinder resultTo,String resultWho,int requestCode,int callingPid,int callingUid,String callingPackage,int startFlags,Bundle options,boolean componentSpecified,ActivityRecord[] outActivity,ActivityContainer container,TaskRecord inTask){
  int err=ActivityManager.START_SUCCESS;
  ProcessRecord callerApp=null;
  if (caller != null) {
    callerApp=mService.getRecordForAppLocked(caller);
    if (callerApp != null) {
      callingPid=callerApp.pid;
      callingUid=callerApp.info.uid;
    }
 else {
      Slog.w(TAG,"String_Node_Str" + caller + "String_Node_Str"+ callingPid+ "String_Node_Str"+ intent.toString());
      err=ActivityManager.START_PERMISSION_DENIED;
    }
  }
  if (err == ActivityManager.START_SUCCESS) {
    final int userId=aInfo != null ? UserHandle.getUserId(aInfo.applicationInfo.uid) : 0;
    Slog.i(TAG,"String_Node_Str" + userId + "String_Node_Str"+ intent.toShortString(true,true,true,false)+ "String_Node_Str"+ callingUid+ "String_Node_Str"+ (container == null ? (mFocusedStack == null ? Display.DEFAULT_DISPLAY : mFocusedStack.mDisplayId) : (container.mActivityDisplay == null ? Display.DEFAULT_DISPLAY : container.mActivityDisplay.mDisplayId)));
  }
  ActivityRecord sourceRecord=null;
  ActivityRecord resultRecord=null;
  if (resultTo != null) {
    sourceRecord=isInAnyStackLocked(resultTo);
    if (DEBUG_RESULTS)     Slog.v(TAG,"String_Node_Str" + resultTo + "String_Node_Str"+ sourceRecord);
    if (sourceRecord != null) {
      if (requestCode >= 0 && !sourceRecord.finishing) {
        resultRecord=sourceRecord;
      }
    }
  }
  ActivityStack resultStack=resultRecord == null ? null : resultRecord.task.stack;
  final int launchFlags=intent.getFlags();
  if ((launchFlags & Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0 && sourceRecord != null) {
    if (requestCode >= 0) {
      ActivityOptions.abort(options);
      return ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT;
    }
    resultRecord=sourceRecord.resultTo;
    resultWho=sourceRecord.resultWho;
    requestCode=sourceRecord.requestCode;
    sourceRecord.resultTo=null;
    if (resultRecord != null) {
      resultRecord.removeResultsLocked(sourceRecord,resultWho,requestCode);
    }
    if (sourceRecord.launchedFromUid == callingUid) {
      callingPackage=sourceRecord.launchedFromPackage;
    }
  }
  if (err == ActivityManager.START_SUCCESS && intent.getComponent() == null) {
    err=ActivityManager.START_INTENT_NOT_RESOLVED;
  }
  if (err == ActivityManager.START_SUCCESS && aInfo == null) {
    err=ActivityManager.START_CLASS_NOT_FOUND;
  }
  if (err == ActivityManager.START_SUCCESS && sourceRecord != null && sourceRecord.task.voiceSession != null) {
    if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) == 0 && sourceRecord.info.applicationInfo.uid != aInfo.applicationInfo.uid) {
      try {
        if (!AppGlobals.getPackageManager().activitySupportsIntent(intent.getComponent(),intent,resolvedType)) {
          err=ActivityManager.START_NOT_VOICE_COMPATIBLE;
        }
      }
 catch (      RemoteException e) {
        err=ActivityManager.START_NOT_VOICE_COMPATIBLE;
      }
    }
  }
  if (err == ActivityManager.START_SUCCESS && voiceSession != null) {
    try {
      if (!AppGlobals.getPackageManager().activitySupportsIntent(intent.getComponent(),intent,resolvedType)) {
        err=ActivityManager.START_NOT_VOICE_COMPATIBLE;
      }
    }
 catch (    RemoteException e) {
      err=ActivityManager.START_NOT_VOICE_COMPATIBLE;
    }
  }
  if (err != ActivityManager.START_SUCCESS) {
    if (resultRecord != null) {
      resultStack.sendActivityResultLocked(-1,resultRecord,resultWho,requestCode,Activity.RESULT_CANCELED,null);
    }
    ActivityOptions.abort(options);
    return err;
  }
  final int startAnyPerm=mService.checkPermission(START_ANY_ACTIVITY,callingPid,callingUid);
  final int componentPerm=mService.checkComponentPermission(aInfo.permission,callingPid,callingUid,aInfo.applicationInfo.uid,aInfo.exported);
  if (startAnyPerm != PERMISSION_GRANTED && componentPerm != PERMISSION_GRANTED) {
    if (resultRecord != null) {
      resultStack.sendActivityResultLocked(-1,resultRecord,resultWho,requestCode,Activity.RESULT_CANCELED,null);
    }
    String msg;
    if (!aInfo.exported) {
      msg="String_Node_Str" + intent.toString() + "String_Node_Str"+ callerApp+ "String_Node_Str"+ callingPid+ "String_Node_Str"+ callingUid+ "String_Node_Str"+ "String_Node_Str"+ aInfo.applicationInfo.uid;
    }
 else {
      msg="String_Node_Str" + intent.toString() + "String_Node_Str"+ callerApp+ "String_Node_Str"+ callingPid+ "String_Node_Str"+ callingUid+ "String_Node_Str"+ "String_Node_Str"+ aInfo.permission;
    }
    Slog.w(TAG,msg);
    throw new SecurityException(msg);
  }
  boolean abort=!mService.mIntentFirewall.checkStartActivity(intent,callingUid,callingPid,resolvedType,aInfo.applicationInfo);
  if (mService.mController != null) {
    try {
      Intent watchIntent=intent.cloneFilter();
      abort|=!mService.mController.activityStarting(watchIntent,aInfo.applicationInfo.packageName);
    }
 catch (    RemoteException e) {
      mService.mController=null;
    }
  }
  if (abort) {
    if (resultRecord != null) {
      resultStack.sendActivityResultLocked(-1,resultRecord,resultWho,requestCode,Activity.RESULT_CANCELED,null);
    }
    ActivityOptions.abort(options);
    return ActivityManager.START_SUCCESS;
  }
  ActivityRecord r=new ActivityRecord(mService,callerApp,callingUid,callingPackage,intent,resolvedType,aInfo,mService.mConfiguration,resultRecord,resultWho,requestCode,componentSpecified,this,container,options);
  if (outActivity != null) {
    outActivity[0]=r;
  }
  final ActivityStack stack=getFocusedStack();
  if (voiceSession == null && (stack.mResumedActivity == null || stack.mResumedActivity.info.applicationInfo.uid != callingUid)) {
    if (!mService.checkAppSwitchAllowedLocked(callingPid,callingUid,"String_Node_Str")) {
      PendingActivityLaunch pal=new PendingActivityLaunch(r,sourceRecord,startFlags,stack);
      mPendingActivityLaunches.add(pal);
      ActivityOptions.abort(options);
      return ActivityManager.START_SWITCHES_CANCELED;
    }
  }
  if (mService.mDidAppSwitch) {
    mService.mAppSwitchesAllowedTime=0;
  }
 else {
    mService.mDidAppSwitch=true;
  }
  doPendingActivityLaunchesLocked(false);
  err=startActivityUncheckedLocked(r,sourceRecord,voiceSession,voiceInteractor,startFlags,true,options,inTask);
  if (err < 0) {
    notifyActivityDrawnForKeyguard();
  }
  return err;
}

Fixed version (ground truth):
final int startActivityLocked(IApplicationThread caller,Intent intent,String resolvedType,ActivityInfo aInfo,IVoiceInteractionSession voiceSession,IVoiceInteractor voiceInteractor,IBinder resultTo,String resultWho,int requestCode,int callingPid,int callingUid,String callingPackage,int realCallingPid,int realCallingUid,int startFlags,Bundle options,boolean componentSpecified,ActivityRecord[] outActivity,ActivityContainer container,TaskRecord inTask){
  int err=ActivityManager.START_SUCCESS;
  ProcessRecord callerApp=null;
  if (caller != null) {
    callerApp=mService.getRecordForAppLocked(caller);
    if (callerApp != null) {
      callingPid=callerApp.pid;
      callingUid=callerApp.info.uid;
    }
 else {
      Slog.w(TAG,"String_Node_Str" + caller + "String_Node_Str"+ callingPid+ "String_Node_Str"+ intent.toString());
      err=ActivityManager.START_PERMISSION_DENIED;
    }
  }
  if (err == ActivityManager.START_SUCCESS) {
    final int userId=aInfo != null ? UserHandle.getUserId(aInfo.applicationInfo.uid) : 0;
    Slog.i(TAG,"String_Node_Str" + userId + "String_Node_Str"+ intent.toShortString(true,true,true,false)+ "String_Node_Str"+ callingUid+ "String_Node_Str"+ (container == null ? (mFocusedStack == null ? Display.DEFAULT_DISPLAY : mFocusedStack.mDisplayId) : (container.mActivityDisplay == null ? Display.DEFAULT_DISPLAY : container.mActivityDisplay.mDisplayId)));
  }
  ActivityRecord sourceRecord=null;
  ActivityRecord resultRecord=null;
  if (resultTo != null) {
    sourceRecord=isInAnyStackLocked(resultTo);
    if (DEBUG_RESULTS)     Slog.v(TAG,"String_Node_Str" + resultTo + "String_Node_Str"+ sourceRecord);
    if (sourceRecord != null) {
      if (requestCode >= 0 && !sourceRecord.finishing) {
        resultRecord=sourceRecord;
      }
    }
  }
  ActivityStack resultStack=resultRecord == null ? null : resultRecord.task.stack;
  final int launchFlags=intent.getFlags();
  if ((launchFlags & Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0 && sourceRecord != null) {
    if (requestCode >= 0) {
      ActivityOptions.abort(options);
      return ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT;
    }
    resultRecord=sourceRecord.resultTo;
    resultWho=sourceRecord.resultWho;
    requestCode=sourceRecord.requestCode;
    sourceRecord.resultTo=null;
    if (resultRecord != null) {
      resultRecord.removeResultsLocked(sourceRecord,resultWho,requestCode);
    }
    if (sourceRecord.launchedFromUid == callingUid) {
      callingPackage=sourceRecord.launchedFromPackage;
    }
  }
  if (err == ActivityManager.START_SUCCESS && intent.getComponent() == null) {
    err=ActivityManager.START_INTENT_NOT_RESOLVED;
  }
  if (err == ActivityManager.START_SUCCESS && aInfo == null) {
    err=ActivityManager.START_CLASS_NOT_FOUND;
  }
  if (err == ActivityManager.START_SUCCESS && sourceRecord != null && sourceRecord.task.voiceSession != null) {
    if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) == 0 && sourceRecord.info.applicationInfo.uid != aInfo.applicationInfo.uid) {
      try {
        if (!AppGlobals.getPackageManager().activitySupportsIntent(intent.getComponent(),intent,resolvedType)) {
          err=ActivityManager.START_NOT_VOICE_COMPATIBLE;
        }
      }
 catch (      RemoteException e) {
        err=ActivityManager.START_NOT_VOICE_COMPATIBLE;
      }
    }
  }
  if (err == ActivityManager.START_SUCCESS && voiceSession != null) {
    try {
      if (!AppGlobals.getPackageManager().activitySupportsIntent(intent.getComponent(),intent,resolvedType)) {
        err=ActivityManager.START_NOT_VOICE_COMPATIBLE;
      }
    }
 catch (    RemoteException e) {
      err=ActivityManager.START_NOT_VOICE_COMPATIBLE;
    }
  }
  if (err != ActivityManager.START_SUCCESS) {
    if (resultRecord != null) {
      resultStack.sendActivityResultLocked(-1,resultRecord,resultWho,requestCode,Activity.RESULT_CANCELED,null);
    }
    ActivityOptions.abort(options);
    return err;
  }
  final int startAnyPerm=mService.checkPermission(START_ANY_ACTIVITY,callingPid,callingUid);
  final int componentPerm=mService.checkComponentPermission(aInfo.permission,callingPid,callingUid,aInfo.applicationInfo.uid,aInfo.exported);
  if (startAnyPerm != PERMISSION_GRANTED && componentPerm != PERMISSION_GRANTED) {
    if (resultRecord != null) {
      resultStack.sendActivityResultLocked(-1,resultRecord,resultWho,requestCode,Activity.RESULT_CANCELED,null);
    }
    String msg;
    if (!aInfo.exported) {
      msg="String_Node_Str" + intent.toString() + "String_Node_Str"+ callerApp+ "String_Node_Str"+ callingPid+ "String_Node_Str"+ callingUid+ "String_Node_Str"+ "String_Node_Str"+ aInfo.applicationInfo.uid;
    }
 else {
      msg="String_Node_Str" + intent.toString() + "String_Node_Str"+ callerApp+ "String_Node_Str"+ callingPid+ "String_Node_Str"+ callingUid+ "String_Node_Str"+ "String_Node_Str"+ aInfo.permission;
    }
    Slog.w(TAG,msg);
    throw new SecurityException(msg);
  }
  boolean abort=!mService.mIntentFirewall.checkStartActivity(intent,callingUid,callingPid,resolvedType,aInfo.applicationInfo);
  if (mService.mController != null) {
    try {
      Intent watchIntent=intent.cloneFilter();
      abort|=!mService.mController.activityStarting(watchIntent,aInfo.applicationInfo.packageName);
    }
 catch (    RemoteException e) {
      mService.mController=null;
    }
  }
  if (abort) {
    if (resultRecord != null) {
      resultStack.sendActivityResultLocked(-1,resultRecord,resultWho,requestCode,Activity.RESULT_CANCELED,null);
    }
    ActivityOptions.abort(options);
    return ActivityManager.START_SUCCESS;
  }
  ActivityRecord r=new ActivityRecord(mService,callerApp,callingUid,callingPackage,intent,resolvedType,aInfo,mService.mConfiguration,resultRecord,resultWho,requestCode,componentSpecified,this,container,options);
  if (outActivity != null) {
    outActivity[0]=r;
  }
  final ActivityStack stack=getFocusedStack();
  if (voiceSession == null && (stack.mResumedActivity == null || stack.mResumedActivity.info.applicationInfo.uid != callingUid)) {
    if (!mService.checkAppSwitchAllowedLocked(callingPid,callingUid,realCallingPid,realCallingUid,"String_Node_Str")) {
      PendingActivityLaunch pal=new PendingActivityLaunch(r,sourceRecord,startFlags,stack);
      mPendingActivityLaunches.add(pal);
      ActivityOptions.abort(options);
      return ActivityManager.START_SWITCHES_CANCELED;
    }
  }
  if (mService.mDidAppSwitch) {
    mService.mAppSwitchesAllowedTime=0;
  }
 else {
    mService.mDidAppSwitch=true;
  }
  doPendingActivityLaunchesLocked(false);
  err=startActivityUncheckedLocked(r,sourceRecord,voiceSession,voiceInteractor,startFlags,true,options,inTask);
  if (err < 0) {
    notifyActivityDrawnForKeyguard();
  }
  return err;
}