Program: 182055
Project: 182055
Buggy source:
/** 
 * Make sure the given activity matches the current configuration.  Returns false if the activity had to be destroyed.  Returns true if the configuration is the same, or the activity will remain running as-is for whatever reason.  Ensures the HistoryRecord is updated with the correct configuration and all other bookkeeping is handled.
 */
private final boolean ensureActivityConfigurationLocked(HistoryRecord r,int globalChanges){
  if (!mConfigWillChange) {
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + r);
    return true;
  }
  if (DEBUG_SWITCH || DEBUG_CONFIGURATION)   Slog.v(TAG,"String_Node_Str" + r);
  Configuration newConfig=mConfiguration;
  if (r.configuration == newConfig) {
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + r);
    return true;
  }
  if (r.finishing) {
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + r);
    r.stopFreezingScreenLocked(false);
    return true;
  }
  Configuration oldConfig=r.configuration;
  r.configuration=newConfig;
  if (r.app == null || r.app.thread == null) {
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + r);
    r.stopFreezingScreenLocked(false);
    return true;
  }
  if (!r.persistent) {
    int changes=oldConfig.diff(newConfig);
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
      Slog.v(TAG,"String_Node_Str" + r.info.name + "String_Node_Str"+ Integer.toHexString(changes)+ "String_Node_Str"+ Integer.toHexString(r.info.configChanges)+ "String_Node_Str"+ newConfig);
    }
    if ((changes & (~r.info.configChanges)) != 0) {
      r.configChangeFlags|=changes;
      r.startFreezingScreenLocked(r.app,globalChanges);
      if (r.app == null || r.app.thread == null) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)         Slog.v(TAG,"String_Node_Str" + r);
        destroyActivityLocked(r,true);
      }
 else       if (r.state == ActivityState.PAUSING) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)         Slog.v(TAG,"String_Node_Str" + r);
        r.configDestroy=true;
        return true;
      }
 else       if (r.state == ActivityState.RESUMED) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)         Slog.v(TAG,"String_Node_Str" + r);
        relaunchActivityLocked(r,r.configChangeFlags,true);
        r.configChangeFlags=0;
      }
 else {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)         Slog.v(TAG,"String_Node_Str" + r);
        relaunchActivityLocked(r,r.configChangeFlags,false);
        r.configChangeFlags=0;
      }
      return false;
    }
  }
  if (r.app != null && r.app.thread != null) {
    try {
      if (DEBUG_CONFIGURATION)       Slog.v(TAG,"String_Node_Str" + r);
      r.app.thread.scheduleActivityConfigurationChanged(r);
    }
 catch (    RemoteException e) {
    }
  }
  r.stopFreezingScreenLocked(false);
  return true;
}

Fixed version (ground truth):
/** 
 * Make sure the given activity matches the current configuration.  Returns false if the activity had to be destroyed.  Returns true if the configuration is the same, or the activity will remain running as-is for whatever reason.  Ensures the HistoryRecord is updated with the correct configuration and all other bookkeeping is handled.
 */
private final boolean ensureActivityConfigurationLocked(HistoryRecord r,int globalChanges){
  if (mConfigWillChange) {
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + r);
    return true;
  }
  if (DEBUG_SWITCH || DEBUG_CONFIGURATION)   Slog.v(TAG,"String_Node_Str" + r);
  Configuration newConfig=mConfiguration;
  if (r.configuration == newConfig) {
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + r);
    return true;
  }
  if (r.finishing) {
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + r);
    r.stopFreezingScreenLocked(false);
    return true;
  }
  Configuration oldConfig=r.configuration;
  r.configuration=newConfig;
  if (r.app == null || r.app.thread == null) {
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)     Slog.v(TAG,"String_Node_Str" + r);
    r.stopFreezingScreenLocked(false);
    return true;
  }
  if (!r.persistent) {
    int changes=oldConfig.diff(newConfig);
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
      Slog.v(TAG,"String_Node_Str" + r.info.name + "String_Node_Str"+ Integer.toHexString(changes)+ "String_Node_Str"+ Integer.toHexString(r.info.configChanges)+ "String_Node_Str"+ newConfig);
    }
    if ((changes & (~r.info.configChanges)) != 0) {
      r.configChangeFlags|=changes;
      r.startFreezingScreenLocked(r.app,globalChanges);
      if (r.app == null || r.app.thread == null) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)         Slog.v(TAG,"String_Node_Str" + r);
        destroyActivityLocked(r,true);
      }
 else       if (r.state == ActivityState.PAUSING) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)         Slog.v(TAG,"String_Node_Str" + r);
        r.configDestroy=true;
        return true;
      }
 else       if (r.state == ActivityState.RESUMED) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)         Slog.v(TAG,"String_Node_Str" + r);
        relaunchActivityLocked(r,r.configChangeFlags,true);
        r.configChangeFlags=0;
      }
 else {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)         Slog.v(TAG,"String_Node_Str" + r);
        relaunchActivityLocked(r,r.configChangeFlags,false);
        r.configChangeFlags=0;
      }
      return false;
    }
  }
  if (r.app != null && r.app.thread != null) {
    try {
      if (DEBUG_CONFIGURATION)       Slog.v(TAG,"String_Node_Str" + r);
      r.app.thread.scheduleActivityConfigurationChanged(r);
    }
 catch (    RemoteException e) {
    }
  }
  r.stopFreezingScreenLocked(false);
  return true;
}