Program: 372
Project: 372
Buggy source:
/** 
 * Examines the current state and adds the transport to the widget pager when the state changes. Showing the initial transport and keeping it around is a bit tricky because the signals coming from music players aren't always clear. Here's how the states are handled:  {@link TRANSPORT_GONE} means we have no reason to show the transport - remove it if present.{@link TRANSPORT_INVISIBLE} means we have potential to show the transport because a musicplayer is registered but not currently playing music (or we don't know the state yet). The code adds it conditionally on play state. {@link #TRANSPORT_VISIBLE} means a music player is active and transport should be showing.Once the transport is showing, we always show it until keyguard is dismissed. This state is maintained by onSave/RestoreInstanceState(). This state is cleared in {@link KeyguardViewManager#hide} when keyguard is dismissed, which causes the transport to begone when keyguard is restarted until we get an update with the current state.
 * @param state
 */
private void ensureTransportPresentOrRemoved(int state){
  final boolean showing=getWidgetPosition(R.id.keyguard_transport_control) != -1;
  final boolean visible=state == TRANSPORT_VISIBLE;
  final boolean shouldBeVisible=state == TRANSPORT_INVISIBLE && isMusicPlaying(state);
  if (!showing && (visible || shouldBeVisible)) {
    if (DEBUGXPORT)     Log.v(TAG,"String_Node_Str");
    int lastWidget=mAppWidgetContainer.getChildCount() - 1;
    int position=0;
    if (lastWidget >= 0) {
      position=mAppWidgetContainer.isCameraPage(lastWidget) ? lastWidget : lastWidget + 1;
    }
    mAppWidgetContainer.addWidget(getOrCreateTransportControl(),position);
  }
 else   if (showing && state == TRANSPORT_GONE) {
    if (DEBUGXPORT)     Log.v(TAG,"String_Node_Str");
    mAppWidgetContainer.removeWidget(getOrCreateTransportControl());
    mTransportControl=null;
    KeyguardUpdateMonitor.getInstance(getContext()).dispatchSetBackground(null);
  }
}

Fixed version (ground truth):
/** 
 * Examines the current state and adds the transport to the widget pager when the state changes. Showing the initial transport and keeping it around is a bit tricky because the signals coming from music players aren't always clear. Here's how the states are handled:  {@link TRANSPORT_GONE} means we have no reason to show the transport - remove it if present.{@link TRANSPORT_INVISIBLE} means we have potential to show the transport because a musicplayer is registered but not currently playing music (or we don't know the state yet). The code adds it conditionally on play state. {@link #TRANSPORT_VISIBLE} means a music player is active and transport should be showing.Once the transport is showing, we always show it until keyguard is dismissed. This state is maintained by onSave/RestoreInstanceState(). This state is cleared in {@link KeyguardViewManager#hide} when keyguard is dismissed, which causes the transport to begone when keyguard is restarted until we get an update with the current state.
 * @param state
 */
private boolean ensureTransportPresentOrRemoved(int state){
  final boolean showing=getWidgetPosition(R.id.keyguard_transport_control) != -1;
  final boolean visible=state == TRANSPORT_VISIBLE;
  final boolean shouldBeVisible=state == TRANSPORT_INVISIBLE && isMusicPlaying(state);
  if (!showing && (visible || shouldBeVisible)) {
    int lastWidget=mAppWidgetContainer.getChildCount() - 1;
    int position=0;
    if (lastWidget >= 0) {
      position=mAppWidgetContainer.isCameraPage(lastWidget) ? lastWidget : lastWidget + 1;
    }
    if (DEBUGXPORT)     Log.v(TAG,"String_Node_Str" + position);
    mAppWidgetContainer.addWidget(getOrCreateTransportControl(),position);
    return true;
  }
 else   if (showing && state == TRANSPORT_GONE) {
    if (DEBUGXPORT)     Log.v(TAG,"String_Node_Str");
    mAppWidgetContainer.removeWidget(getOrCreateTransportControl());
    mTransportControl=null;
    KeyguardUpdateMonitor.getInstance(getContext()).dispatchSetBackground(null);
  }
  return false;
}