Program: 21903
Project: 21903
Buggy source:
private final void processNextBroadcast(boolean fromMsg){
synchronized (this) {
    BroadcastRecord r;
    if (DEBUG_BROADCAST)     Slog.v(TAG,"String_Node_Str" + mParallelBroadcasts.size() + "String_Node_Str"+ mOrderedBroadcasts.size()+ "String_Node_Str");
    updateCpuStats();
    if (fromMsg) {
      mBroadcastsScheduled=false;
    }
    while (mParallelBroadcasts.size() > 0) {
      r=mParallelBroadcasts.remove(0);
      r.dispatchTime=SystemClock.uptimeMillis();
      final int N=r.receivers.size();
      if (DEBUG_BROADCAST_LIGHT)       Slog.v(TAG,"String_Node_Str" + r);
      for (int i=0; i < N; i++) {
        Object target=r.receivers.get(i);
        if (DEBUG_BROADCAST)         Slog.v(TAG,"String_Node_Str" + target + "String_Node_Str"+ r);
        deliverToRegisteredReceiver(r,(BroadcastFilter)target,false);
      }
      addBroadcastToHistoryLocked(r);
      if (DEBUG_BROADCAST_LIGHT)       Slog.v(TAG,"String_Node_Str" + r);
    }
    if (mPendingBroadcast != null) {
      if (DEBUG_BROADCAST_LIGHT) {
        Slog.v(TAG,"String_Node_Str" + mPendingBroadcast.curApp);
      }
      boolean isDead;
synchronized (mPidsSelfLocked) {
        isDead=(mPidsSelfLocked.get(mPendingBroadcast.curApp.pid) == null);
      }
      if (!isDead) {
        return;
      }
 else {
        Slog.w(TAG,"String_Node_Str" + mPendingBroadcast.curApp + "String_Node_Str");
        mPendingBroadcast.state=BroadcastRecord.IDLE;
        mPendingBroadcast.nextReceiver=mPendingBroadcastRecvIndex;
        mPendingBroadcast=null;
      }
    }
    boolean looped=false;
    do {
      if (mOrderedBroadcasts.size() == 0) {
        scheduleAppGcsLocked();
        if (looped) {
          updateOomAdjLocked();
        }
        return;
      }
      r=mOrderedBroadcasts.get(0);
      boolean forceReceive=false;
      int numReceivers=(r.receivers != null) ? r.receivers.size() : 0;
      if (mProcessesReady && r.dispatchTime > 0) {
        long now=SystemClock.uptimeMillis();
        if ((numReceivers > 0) && (now > r.dispatchTime + (2 * BROADCAST_TIMEOUT * numReceivers))) {
          Slog.w(TAG,"String_Node_Str" + "String_Node_Str" + now + "String_Node_Str"+ r.dispatchTime+ "String_Node_Str"+ r.receiverTime+ "String_Node_Str"+ r.intent+ "String_Node_Str"+ numReceivers+ "String_Node_Str"+ r.nextReceiver+ "String_Node_Str"+ r.state);
          broadcastTimeout();
          forceReceive=true;
          r.state=BroadcastRecord.IDLE;
        }
      }
      if (r.state != BroadcastRecord.IDLE) {
        if (DEBUG_BROADCAST)         Slog.d(TAG,"String_Node_Str" + r.state + "String_Node_Str");
        return;
      }
      if (r.receivers == null || r.nextReceiver >= numReceivers || r.resultAbort || forceReceive) {
        if (r.resultTo != null) {
          try {
            if (DEBUG_BROADCAST) {
              int seq=r.intent.getIntExtra("String_Node_Str",-1);
              Slog.i(TAG,"String_Node_Str" + r.intent.getAction() + "String_Node_Str"+ seq+ "String_Node_Str"+ r.callerApp);
            }
            performReceive(r.callerApp,r.resultTo,new Intent(r.intent),r.resultCode,r.resultData,r.resultExtras,false,false);
          }
 catch (          RemoteException e) {
            Slog.w(TAG,"String_Node_Str" + r.intent,e);
          }
        }
        if (DEBUG_BROADCAST)         Slog.v(TAG,"String_Node_Str");
        mHandler.removeMessages(BROADCAST_TIMEOUT_MSG);
        if (DEBUG_BROADCAST_LIGHT)         Slog.v(TAG,"String_Node_Str" + r);
        addBroadcastToHistoryLocked(r);
        mOrderedBroadcasts.remove(0);
        r=null;
        looped=true;
        continue;
      }
    }
 while (r == null);
    int recIdx=r.nextReceiver++;
    r.receiverTime=SystemClock.uptimeMillis();
    if (recIdx == 0) {
      r.dispatchTime=r.receiverTime;
      if (DEBUG_BROADCAST_LIGHT)       Slog.v(TAG,"String_Node_Str" + r);
      if (DEBUG_BROADCAST)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ (r.receiverTime + BROADCAST_TIMEOUT));
      Message msg=mHandler.obtainMessage(BROADCAST_TIMEOUT_MSG);
      mHandler.sendMessageAtTime(msg,r.receiverTime + BROADCAST_TIMEOUT);
    }
    Object nextReceiver=r.receivers.get(recIdx);
    if (nextReceiver instanceof BroadcastFilter) {
      BroadcastFilter filter=(BroadcastFilter)nextReceiver;
      if (DEBUG_BROADCAST)       Slog.v(TAG,"String_Node_Str" + filter + "String_Node_Str"+ r);
      deliverToRegisteredReceiver(r,filter,r.ordered);
      if (r.receiver == null || !r.ordered) {
        if (DEBUG_BROADCAST)         Slog.v(TAG,"String_Node_Str" + r.ordered + "String_Node_Str"+ r.receiver);
        r.state=BroadcastRecord.IDLE;
        scheduleBroadcastsLocked();
      }
      return;
    }
    ResolveInfo info=(ResolveInfo)nextReceiver;
    boolean skip=false;
    int perm=checkComponentPermission(info.activityInfo.permission,r.callingPid,r.callingUid,info.activityInfo.exported ? -1 : info.activityInfo.applicationInfo.uid);
    if (perm != PackageManager.PERMISSION_GRANTED) {
      Slog.w(TAG,"String_Node_Str" + r.intent.toString() + "String_Node_Str"+ r.callerPackage+ "String_Node_Str"+ r.callingPid+ "String_Node_Str"+ r.callingUid+ "String_Node_Str"+ "String_Node_Str"+ info.activityInfo.permission+ "String_Node_Str"+ info.activityInfo.packageName+ "String_Node_Str"+ info.activityInfo.name);
      skip=true;
    }
    if (r.callingUid != Process.SYSTEM_UID && r.requiredPermission != null) {
      try {
        perm=AppGlobals.getPackageManager().checkPermission(r.requiredPermission,info.activityInfo.applicationInfo.packageName);
      }
 catch (      RemoteException e) {
        perm=PackageManager.PERMISSION_DENIED;
      }
      if (perm != PackageManager.PERMISSION_GRANTED) {
        Slog.w(TAG,"String_Node_Str" + r.intent + "String_Node_Str"+ info.activityInfo.applicationInfo.packageName+ "String_Node_Str"+ r.requiredPermission+ "String_Node_Str"+ r.callerPackage+ "String_Node_Str"+ r.callingUid+ "String_Node_Str");
        skip=true;
      }
    }
    if (r.curApp != null && r.curApp.crashing) {
      if (DEBUG_BROADCAST)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.curApp+ "String_Node_Str");
      skip=true;
    }
    if (skip) {
      if (DEBUG_BROADCAST)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str");
      r.receiver=null;
      r.curFilter=null;
      r.state=BroadcastRecord.IDLE;
      scheduleBroadcastsLocked();
      return;
    }
    r.state=BroadcastRecord.APP_RECEIVE;
    String targetProcess=info.activityInfo.processName;
    r.curComponent=new ComponentName(info.activityInfo.applicationInfo.packageName,info.activityInfo.name);
    r.curReceiver=info.activityInfo;
    ProcessRecord app=getProcessRecordLocked(targetProcess,info.activityInfo.applicationInfo.uid);
    if (app != null && app.thread != null) {
      try {
        processCurBroadcastLocked(r,app);
        return;
      }
 catch (      RemoteException e) {
        Slog.w(TAG,"String_Node_Str" + r.curComponent,e);
      }
    }
    if (DEBUG_BROADCAST)     Slog.v(TAG,"String_Node_Str" + targetProcess + "String_Node_Str"+ r);
    if ((r.curApp=startProcessLocked(targetProcess,info.activityInfo.applicationInfo,true,r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND,"String_Node_Str",r.curComponent,(r.intent.getFlags() & Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0)) == null) {
      Slog.w(TAG,"String_Node_Str" + info.activityInfo.applicationInfo.packageName + "String_Node_Str"+ info.activityInfo.applicationInfo.uid+ "String_Node_Str"+ r.intent+ "String_Node_Str");
      logBroadcastReceiverDiscard(r);
      finishReceiverLocked(r.receiver,r.resultCode,r.resultData,r.resultExtras,r.resultAbort,true);
      scheduleBroadcastsLocked();
      r.state=BroadcastRecord.IDLE;
      return;
    }
    mPendingBroadcast=r;
    mPendingBroadcastRecvIndex=recIdx;
  }
}

Fixed version (ground truth):
private final void processNextBroadcast(boolean fromMsg){
synchronized (this) {
    BroadcastRecord r;
    if (DEBUG_BROADCAST)     Slog.v(TAG,"String_Node_Str" + mParallelBroadcasts.size() + "String_Node_Str"+ mOrderedBroadcasts.size()+ "String_Node_Str");
    updateCpuStats();
    if (fromMsg) {
      mBroadcastsScheduled=false;
    }
    while (mParallelBroadcasts.size() > 0) {
      r=mParallelBroadcasts.remove(0);
      r.dispatchTime=SystemClock.uptimeMillis();
      final int N=r.receivers.size();
      if (DEBUG_BROADCAST_LIGHT)       Slog.v(TAG,"String_Node_Str" + r);
      for (int i=0; i < N; i++) {
        Object target=r.receivers.get(i);
        if (DEBUG_BROADCAST)         Slog.v(TAG,"String_Node_Str" + target + "String_Node_Str"+ r);
        deliverToRegisteredReceiverLocked(r,(BroadcastFilter)target,false);
      }
      addBroadcastToHistoryLocked(r);
      if (DEBUG_BROADCAST_LIGHT)       Slog.v(TAG,"String_Node_Str" + r);
    }
    if (mPendingBroadcast != null) {
      if (DEBUG_BROADCAST_LIGHT) {
        Slog.v(TAG,"String_Node_Str" + mPendingBroadcast.curApp);
      }
      boolean isDead;
synchronized (mPidsSelfLocked) {
        isDead=(mPidsSelfLocked.get(mPendingBroadcast.curApp.pid) == null);
      }
      if (!isDead) {
        return;
      }
 else {
        Slog.w(TAG,"String_Node_Str" + mPendingBroadcast.curApp + "String_Node_Str");
        mPendingBroadcast.state=BroadcastRecord.IDLE;
        mPendingBroadcast.nextReceiver=mPendingBroadcastRecvIndex;
        mPendingBroadcast=null;
      }
    }
    boolean looped=false;
    do {
      if (mOrderedBroadcasts.size() == 0) {
        scheduleAppGcsLocked();
        if (looped) {
          updateOomAdjLocked();
        }
        return;
      }
      r=mOrderedBroadcasts.get(0);
      boolean forceReceive=false;
      int numReceivers=(r.receivers != null) ? r.receivers.size() : 0;
      if (mProcessesReady && r.dispatchTime > 0) {
        long now=SystemClock.uptimeMillis();
        if ((numReceivers > 0) && (now > r.dispatchTime + (2 * BROADCAST_TIMEOUT * numReceivers))) {
          Slog.w(TAG,"String_Node_Str" + "String_Node_Str" + now + "String_Node_Str"+ r.dispatchTime+ "String_Node_Str"+ r.receiverTime+ "String_Node_Str"+ r.intent+ "String_Node_Str"+ numReceivers+ "String_Node_Str"+ r.nextReceiver+ "String_Node_Str"+ r.state);
          broadcastTimeoutLocked(false);
          forceReceive=true;
          r.state=BroadcastRecord.IDLE;
        }
      }
      if (r.state != BroadcastRecord.IDLE) {
        if (DEBUG_BROADCAST)         Slog.d(TAG,"String_Node_Str" + r.state + "String_Node_Str");
        return;
      }
      if (r.receivers == null || r.nextReceiver >= numReceivers || r.resultAbort || forceReceive) {
        if (r.resultTo != null) {
          try {
            if (DEBUG_BROADCAST) {
              int seq=r.intent.getIntExtra("String_Node_Str",-1);
              Slog.i(TAG,"String_Node_Str" + r.intent.getAction() + "String_Node_Str"+ seq+ "String_Node_Str"+ r.callerApp);
            }
            performReceiveLocked(r.callerApp,r.resultTo,new Intent(r.intent),r.resultCode,r.resultData,r.resultExtras,false,false);
          }
 catch (          RemoteException e) {
            Slog.w(TAG,"String_Node_Str" + r.intent,e);
          }
        }
        if (DEBUG_BROADCAST)         Slog.v(TAG,"String_Node_Str");
        cancelBroadcastTimeoutLocked();
        if (DEBUG_BROADCAST_LIGHT)         Slog.v(TAG,"String_Node_Str" + r);
        addBroadcastToHistoryLocked(r);
        mOrderedBroadcasts.remove(0);
        r=null;
        looped=true;
        continue;
      }
    }
 while (r == null);
    int recIdx=r.nextReceiver++;
    r.receiverTime=SystemClock.uptimeMillis();
    if (recIdx == 0) {
      r.dispatchTime=r.receiverTime;
      if (DEBUG_BROADCAST_LIGHT)       Slog.v(TAG,"String_Node_Str" + r);
    }
    if (!mPendingBroadcastTimeoutMessage) {
      long timeoutTime=r.receiverTime + BROADCAST_TIMEOUT;
      if (DEBUG_BROADCAST)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ timeoutTime);
      setBroadcastTimeoutLocked(timeoutTime);
    }
    Object nextReceiver=r.receivers.get(recIdx);
    if (nextReceiver instanceof BroadcastFilter) {
      BroadcastFilter filter=(BroadcastFilter)nextReceiver;
      if (DEBUG_BROADCAST)       Slog.v(TAG,"String_Node_Str" + filter + "String_Node_Str"+ r);
      deliverToRegisteredReceiverLocked(r,filter,r.ordered);
      if (r.receiver == null || !r.ordered) {
        if (DEBUG_BROADCAST)         Slog.v(TAG,"String_Node_Str" + r.ordered + "String_Node_Str"+ r.receiver);
        r.state=BroadcastRecord.IDLE;
        scheduleBroadcastsLocked();
      }
      return;
    }
    ResolveInfo info=(ResolveInfo)nextReceiver;
    boolean skip=false;
    int perm=checkComponentPermission(info.activityInfo.permission,r.callingPid,r.callingUid,info.activityInfo.exported ? -1 : info.activityInfo.applicationInfo.uid);
    if (perm != PackageManager.PERMISSION_GRANTED) {
      Slog.w(TAG,"String_Node_Str" + r.intent.toString() + "String_Node_Str"+ r.callerPackage+ "String_Node_Str"+ r.callingPid+ "String_Node_Str"+ r.callingUid+ "String_Node_Str"+ "String_Node_Str"+ info.activityInfo.permission+ "String_Node_Str"+ info.activityInfo.packageName+ "String_Node_Str"+ info.activityInfo.name);
      skip=true;
    }
    if (r.callingUid != Process.SYSTEM_UID && r.requiredPermission != null) {
      try {
        perm=AppGlobals.getPackageManager().checkPermission(r.requiredPermission,info.activityInfo.applicationInfo.packageName);
      }
 catch (      RemoteException e) {
        perm=PackageManager.PERMISSION_DENIED;
      }
      if (perm != PackageManager.PERMISSION_GRANTED) {
        Slog.w(TAG,"String_Node_Str" + r.intent + "String_Node_Str"+ info.activityInfo.applicationInfo.packageName+ "String_Node_Str"+ r.requiredPermission+ "String_Node_Str"+ r.callerPackage+ "String_Node_Str"+ r.callingUid+ "String_Node_Str");
        skip=true;
      }
    }
    if (r.curApp != null && r.curApp.crashing) {
      if (DEBUG_BROADCAST)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.curApp+ "String_Node_Str");
      skip=true;
    }
    if (skip) {
      if (DEBUG_BROADCAST)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str");
      r.receiver=null;
      r.curFilter=null;
      r.state=BroadcastRecord.IDLE;
      scheduleBroadcastsLocked();
      return;
    }
    r.state=BroadcastRecord.APP_RECEIVE;
    String targetProcess=info.activityInfo.processName;
    r.curComponent=new ComponentName(info.activityInfo.applicationInfo.packageName,info.activityInfo.name);
    r.curReceiver=info.activityInfo;
    ProcessRecord app=getProcessRecordLocked(targetProcess,info.activityInfo.applicationInfo.uid);
    if (app != null && app.thread != null) {
      try {
        processCurBroadcastLocked(r,app);
        return;
      }
 catch (      RemoteException e) {
        Slog.w(TAG,"String_Node_Str" + r.curComponent,e);
      }
    }
    if (DEBUG_BROADCAST)     Slog.v(TAG,"String_Node_Str" + targetProcess + "String_Node_Str"+ r);
    if ((r.curApp=startProcessLocked(targetProcess,info.activityInfo.applicationInfo,true,r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND,"String_Node_Str",r.curComponent,(r.intent.getFlags() & Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0)) == null) {
      Slog.w(TAG,"String_Node_Str" + info.activityInfo.applicationInfo.packageName + "String_Node_Str"+ info.activityInfo.applicationInfo.uid+ "String_Node_Str"+ r.intent+ "String_Node_Str");
      logBroadcastReceiverDiscardLocked(r);
      finishReceiverLocked(r.receiver,r.resultCode,r.resultData,r.resultExtras,r.resultAbort,true);
      scheduleBroadcastsLocked();
      r.state=BroadcastRecord.IDLE;
      return;
    }
    mPendingBroadcast=r;
    mPendingBroadcastRecvIndex=recIdx;
  }
}