Program: 193643
Project: 193643
Buggy source:
/** 
 * Make sure that all activities that need to be visible (that is, they currently can be seen by the user) actually are.
 */
final void ensureActivitiesVisibleLocked(ActivityRecord starting,int configChanges){
  ActivityRecord top=topRunningActivityLocked(null);
  if (top == null) {
    return;
  }
  if (DEBUG_VISIBILITY)   Slog.v(TAG_VISIBILITY,"String_Node_Str" + top + "String_Node_Str"+ Integer.toHexString(configChanges));
  if (mTranslucentActivityWaiting != top) {
    mUndrawnActivitiesBelowTopTranslucent.clear();
    if (mTranslucentActivityWaiting != null) {
      notifyActivityDrawnLocked(null);
      mTranslucentActivityWaiting=null;
    }
    mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG);
  }
  boolean aboveTop=true;
  boolean behindFullscreen=!isStackVisibleLocked();
  boolean noStackActivityResumed=(isInStackLocked(starting) == null);
  for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
    final TaskRecord task=mTaskHistory.get(taskNdx);
    final ArrayList<ActivityRecord> activities=task.mActivities;
    boolean behindFullscreenActivity=behindFullscreen;
    for (int activityNdx=activities.size() - 1; activityNdx >= 0; --activityNdx) {
      final ActivityRecord r=activities.get(activityNdx);
      if (r.finishing) {
        continue;
      }
      if (aboveTop && r != top) {
        continue;
      }
      aboveTop=false;
      if (!behindFullscreenActivity || r.mLaunchTaskBehind) {
        if (DEBUG_VISIBILITY)         Slog.v(TAG_VISIBILITY,"String_Node_Str" + r + "String_Node_Str"+ r.finishing+ "String_Node_Str"+ r.state);
        if (r != starting) {
          ensureActivityConfigurationLocked(r,0);
        }
        if (r.app == null || r.app.thread == null) {
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
          if (r != starting) {
            r.startFreezingScreenLocked(r.app,configChanges);
          }
          if (!r.visible || r.mLaunchTaskBehind) {
            if (DEBUG_VISIBILITY)             Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
            setVisible(r,true);
          }
          if (r != starting) {
            mStackSupervisor.startSpecificActivityLocked(r,noStackActivityResumed,false);
            if (activityNdx >= activities.size()) {
              activityNdx=activities.size() - 1;
            }
 else {
              noStackActivityResumed=false;
            }
          }
        }
 else         if (r.visible) {
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
          r.stopFreezingScreenLocked(false);
          try {
            if (r.returningOptions != null) {
              r.app.thread.scheduleOnNewActivityOptions(r.appToken,r.returningOptions);
            }
          }
 catch (          RemoteException e) {
          }
          if (r.state == ActivityState.RESUMED) {
            noStackActivityResumed=false;
          }
        }
 else {
          r.visible=true;
          if (r.state != ActivityState.RESUMED && r != starting) {
            if (DEBUG_VISIBILITY)             Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
            try {
              if (mTranslucentActivityWaiting != null) {
                r.updateOptionsLocked(r.returningOptions);
                mUndrawnActivitiesBelowTopTranslucent.add(r);
              }
              setVisible(r,true);
              r.sleeping=false;
              r.app.pendingUiClean=true;
              r.app.thread.scheduleWindowVisibility(r.appToken,true);
              r.stopFreezingScreenLocked(false);
            }
 catch (            Exception e) {
              Slog.w(TAG,"String_Node_Str" + r.intent.getComponent(),e);
            }
          }
        }
        configChanges|=r.configChangeFlags;
        if (r.fullscreen) {
          behindFullscreenActivity=true;
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r + "String_Node_Str"+ behindFullscreen+ "String_Node_Str"+ behindFullscreenActivity);
        }
 else         if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) {
          behindFullscreenActivity=true;
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r + "String_Node_Str"+ behindFullscreen+ "String_Node_Str"+ behindFullscreenActivity);
        }
      }
 else {
        if (DEBUG_VISIBILITY)         Slog.v(TAG_VISIBILITY,"String_Node_Str" + r + "String_Node_Str"+ r.finishing+ "String_Node_Str"+ r.state+ "String_Node_Str"+ behindFullscreen+ "String_Node_Str"+ behindFullscreenActivity);
        if (r.visible) {
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
          try {
            setVisible(r,false);
switch (r.state) {
case STOPPING:
case STOPPED:
              if (r.app != null && r.app.thread != null) {
                if (DEBUG_VISIBILITY)                 Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
                r.app.thread.scheduleWindowVisibility(r.appToken,false);
              }
            break;
case INITIALIZING:
case RESUMED:
case PAUSING:
case PAUSED:
          if (getVisibleBehindActivity() == r) {
            releaseBackgroundResources(r);
          }
 else {
            if (!mStackSupervisor.mStoppingActivities.contains(r)) {
              mStackSupervisor.mStoppingActivities.add(r);
            }
            mStackSupervisor.scheduleIdleLocked();
          }
        break;
default :
      break;
  }
}
 catch (Exception e) {
  Slog.w(TAG,"String_Node_Str" + r.intent.getComponent(),e);
}
}
 else {
if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
}
}
}
behindFullscreen|=task.mFullscreen;
}
if (mTranslucentActivityWaiting != null && mUndrawnActivitiesBelowTopTranslucent.isEmpty()) {
notifyActivityDrawnLocked(null);
}
}

Fixed version (ground truth):
/** 
 * Make sure that all activities that need to be visible (that is, they currently can be seen by the user) actually are.
 */
final void ensureActivitiesVisibleLocked(ActivityRecord starting,int configChanges){
  ActivityRecord top=topRunningActivityLocked(null);
  if (top == null) {
    return;
  }
  if (DEBUG_VISIBILITY)   Slog.v(TAG_VISIBILITY,"String_Node_Str" + top + "String_Node_Str"+ Integer.toHexString(configChanges));
  if (mTranslucentActivityWaiting != top) {
    mUndrawnActivitiesBelowTopTranslucent.clear();
    if (mTranslucentActivityWaiting != null) {
      notifyActivityDrawnLocked(null);
      mTranslucentActivityWaiting=null;
    }
    mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG);
  }
  boolean aboveTop=true;
  final boolean stackInvisible=!isStackVisibleLocked();
  boolean behindFullscreenActivity=stackInvisible;
  boolean noStackActivityResumed=(isInStackLocked(starting) == null);
  for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
    final TaskRecord task=mTaskHistory.get(taskNdx);
    final ArrayList<ActivityRecord> activities=task.mActivities;
    for (int activityNdx=activities.size() - 1; activityNdx >= 0; --activityNdx) {
      final ActivityRecord r=activities.get(activityNdx);
      if (r.finishing) {
        continue;
      }
      if (aboveTop && r != top) {
        continue;
      }
      aboveTop=false;
      if (!behindFullscreenActivity || r.mLaunchTaskBehind) {
        if (DEBUG_VISIBILITY)         Slog.v(TAG_VISIBILITY,"String_Node_Str" + r + "String_Node_Str"+ r.finishing+ "String_Node_Str"+ r.state);
        if (r != starting) {
          ensureActivityConfigurationLocked(r,0);
        }
        if (r.app == null || r.app.thread == null) {
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
          if (r != starting) {
            r.startFreezingScreenLocked(r.app,configChanges);
          }
          if (!r.visible || r.mLaunchTaskBehind) {
            if (DEBUG_VISIBILITY)             Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
            setVisible(r,true);
          }
          if (r != starting) {
            mStackSupervisor.startSpecificActivityLocked(r,noStackActivityResumed,false);
            if (activityNdx >= activities.size()) {
              activityNdx=activities.size() - 1;
            }
 else {
              noStackActivityResumed=false;
            }
          }
        }
 else         if (r.visible) {
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
          r.stopFreezingScreenLocked(false);
          try {
            if (r.returningOptions != null) {
              r.app.thread.scheduleOnNewActivityOptions(r.appToken,r.returningOptions);
            }
          }
 catch (          RemoteException e) {
          }
          if (r.state == ActivityState.RESUMED) {
            noStackActivityResumed=false;
          }
        }
 else {
          r.visible=true;
          if (r.state != ActivityState.RESUMED && r != starting) {
            if (DEBUG_VISIBILITY)             Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
            try {
              if (mTranslucentActivityWaiting != null) {
                r.updateOptionsLocked(r.returningOptions);
                mUndrawnActivitiesBelowTopTranslucent.add(r);
              }
              setVisible(r,true);
              r.sleeping=false;
              r.app.pendingUiClean=true;
              r.app.thread.scheduleWindowVisibility(r.appToken,true);
              r.stopFreezingScreenLocked(false);
            }
 catch (            Exception e) {
              Slog.w(TAG,"String_Node_Str" + r.intent.getComponent(),e);
            }
          }
        }
        configChanges|=r.configChangeFlags;
        if (r.fullscreen) {
          behindFullscreenActivity=true;
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r + "String_Node_Str"+ stackInvisible+ "String_Node_Str"+ behindFullscreenActivity);
        }
 else         if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) {
          behindFullscreenActivity=true;
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r + "String_Node_Str"+ stackInvisible+ "String_Node_Str"+ behindFullscreenActivity);
        }
      }
 else {
        if (DEBUG_VISIBILITY)         Slog.v(TAG_VISIBILITY,"String_Node_Str" + r + "String_Node_Str"+ r.finishing+ "String_Node_Str"+ r.state+ "String_Node_Str"+ stackInvisible+ "String_Node_Str"+ behindFullscreenActivity);
        if (r.visible) {
          if (DEBUG_VISIBILITY)           Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
          try {
            setVisible(r,false);
switch (r.state) {
case STOPPING:
case STOPPED:
              if (r.app != null && r.app.thread != null) {
                if (DEBUG_VISIBILITY)                 Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
                r.app.thread.scheduleWindowVisibility(r.appToken,false);
              }
            break;
case INITIALIZING:
case RESUMED:
case PAUSING:
case PAUSED:
          if (getVisibleBehindActivity() == r) {
            releaseBackgroundResources(r);
          }
 else {
            if (!mStackSupervisor.mStoppingActivities.contains(r)) {
              mStackSupervisor.mStoppingActivities.add(r);
            }
            mStackSupervisor.scheduleIdleLocked();
          }
        break;
default :
      break;
  }
}
 catch (Exception e) {
  Slog.w(TAG,"String_Node_Str" + r.intent.getComponent(),e);
}
}
 else {
if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,"String_Node_Str" + r);
}
}
}
if (mStackId == FREEFORM_WORKSPACE_STACK_ID) {
behindFullscreenActivity=stackInvisible;
}
}
if (mTranslucentActivityWaiting != null && mUndrawnActivitiesBelowTopTranslucent.isEmpty()) {
notifyActivityDrawnLocked(null);
}
}