nus-yam/ex-repair huggingface dataset:
Program: 193293
Project: 193293
Buggy source:
void finishExit(){
  if (WindowManagerService.DEBUG_ANIM)   Slog.v(TAG,"String_Node_Str" + this + "String_Node_Str"+ mWin.mExiting+ "String_Node_Str"+ mWin.mRemoveOnExit+ "String_Node_Str"+ isWindowAnimating());
  final int N=mWin.mChildWindows.size();
  for (int i=0; i < N; i++) {
    mWin.mChildWindows.get(i).mWinAnimator.finishExit();
  }
  if (mEnteringAnimation) {
    mEnteringAnimation=false;
    mService.requestTraversal();
    if (mWin.mAppToken == null) {
      try {
        mWin.mClient.dispatchWindowShown();
      }
 catch (      RemoteException e) {
      }
    }
  }
  if (!isWindowAnimating()) {
    if (mService.mAccessibilityController != null && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
      mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
    }
  }
  if (!mWin.mExiting) {
    return;
  }
  if (isWindowAnimating()) {
    return;
  }
  if (WindowManagerService.localLOGV)   Slog.v(TAG,"String_Node_Str" + this + "String_Node_Str"+ mWin.mRemoveOnExit);
  if (mSurfaceController != null && mSurfaceController.hasSurface()) {
    mService.mDestroySurface.add(mWin);
    mWin.mDestroying=true;
    if (SHOW_TRANSACTIONS)     WindowManagerService.logSurface(mWin,"String_Node_Str",null);
    hide();
  }
  mWin.mExiting=false;
  if (mWin.mRemoveOnExit) {
    mService.mPendingRemove.add(mWin);
    mWin.mRemoveOnExit=false;
  }
  mWallpaperControllerLocked.hideWallpapers(mWin);
}

Fixed version (ground truth):
void finishExit(){
  if (WindowManagerService.DEBUG_ANIM)   Slog.v(TAG,"String_Node_Str" + this + "String_Node_Str"+ mWin.mExiting+ "String_Node_Str"+ mWin.mRemoveOnExit+ "String_Node_Str"+ isWindowAnimating());
  final int N=mWin.mChildWindows.size();
  for (int i=0; i < N; i++) {
    mWin.mChildWindows.get(i).mWinAnimator.finishExit();
  }
  if (mEnteringAnimation) {
    mEnteringAnimation=false;
    mService.requestTraversal();
    if (mWin.mAppToken == null) {
      try {
        mWin.mClient.dispatchWindowShown();
      }
 catch (      RemoteException e) {
      }
    }
  }
  if (!isWindowAnimating()) {
    if (mService.mAccessibilityController != null && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
      mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
    }
  }
  if (!mWin.mExiting) {
    return;
  }
  if (isWindowAnimating()) {
    return;
  }
  if (WindowManagerService.localLOGV)   Slog.v(TAG,"String_Node_Str" + this + "String_Node_Str"+ mWin.mRemoveOnExit);
  if (mSurfaceController != null && mSurfaceController.hasSurface()) {
    mService.mDestroySurface.add(mWin);
    mWin.mDestroying=true;
    hide("String_Node_Str");
  }
  mWin.mExiting=false;
  if (mWin.mRemoveOnExit) {
    mService.mPendingRemove.add(mWin);
    mWin.mRemoveOnExit=false;
  }
  mWallpaperControllerLocked.hideWallpapers(mWin);
}
Program: 193294
Project: 193294
Buggy source:
void preserveSurfaceLocked(){
  if (mDestroyPreservedSurfaceUponRedraw) {
    return;
  }
  mSurfaceController.setLayer(WINDOW_FREEZE_LAYER);
  mDestroyPreservedSurfaceUponRedraw=true;
  mSurfaceDestroyDeferred=true;
  destroySurfaceLocked();
}

Fixed version (ground truth):
void preserveSurfaceLocked(){
  if (mDestroyPreservedSurfaceUponRedraw) {
    return;
  }
  if (SHOW_TRANSACTIONS)   WindowManagerService.logSurface(mWin,"String_Node_Str",null);
  mSurfaceController.setLayer(mAnimLayer + 1);
  mDestroyPreservedSurfaceUponRedraw=true;
  mSurfaceDestroyDeferred=true;
  destroySurfaceLocked();
}
Program: 193296
Project: 193296
Buggy source:
void hide(){
  if (!mLastHidden) {
    mLastHidden=true;
    mSurfaceController.hideInTransaction();
  }
}

Fixed version (ground truth):
void hide(String reason){
  if (!mLastHidden) {
    mLastHidden=true;
    mSurfaceController.hideInTransaction(reason);
  }
}
Program: 193297
Project: 193297
Buggy source:
void setCropInTransaction(Rect clipRect,boolean recoveringMemory){
  if (SHOW_TRANSACTIONS)   logSurface("String_Node_Str" + clipRect.toShortString(),null);
  try {
    if (clipRect.width() > 0 && clipRect.height() > 0) {
      mSurfaceControl.setWindowCrop(clipRect);
      mHiddenForCrop=false;
    }
 else {
      hideInTransaction();
      mHiddenForCrop=true;
    }
  }
 catch (  RuntimeException e) {
    Slog.w(TAG,"String_Node_Str" + this + "String_Node_Str"+ clipRect.toShortString(),e);
    if (!recoveringMemory) {
      mAnimator.reclaimSomeSurfaceMemory("String_Node_Str",true);
    }
  }
}

Fixed version (ground truth):
void setCropInTransaction(Rect clipRect,boolean recoveringMemory){
  if (SHOW_TRANSACTIONS)   logSurface("String_Node_Str" + clipRect.toShortString(),null);
  try {
    if (clipRect.width() > 0 && clipRect.height() > 0) {
      mSurfaceControl.setWindowCrop(clipRect);
      mHiddenForCrop=false;
    }
 else {
      hideInTransaction("String_Node_Str");
      mHiddenForCrop=true;
    }
  }
 catch (  RuntimeException e) {
    Slog.w(TAG,"String_Node_Str" + this + "String_Node_Str"+ clipRect.toShortString(),e);
    if (!recoveringMemory) {
      mAnimator.reclaimSomeSurfaceMemory("String_Node_Str",true);
    }
  }
}
Program: 193298
Project: 193298
Buggy source:
void hideInTransaction(){
  if (SHOW_TRANSACTIONS)   logSurface("String_Node_Str",null);
  if (mSurfaceControl != null) {
    mSurfaceShown=false;
    try {
      mSurfaceControl.hide();
    }
 catch (    RuntimeException e) {
      Slog.w(TAG,"String_Node_Str" + this);
    }
  }
}

Fixed version (ground truth):
void hideInTransaction(String reason){
  if (SHOW_TRANSACTIONS)   logSurface("String_Node_Str" + reason + "String_Node_Str",null);
  if (mSurfaceControl != null) {
    mSurfaceShown=false;
    try {
      mSurfaceControl.hide();
    }
 catch (    RuntimeException e) {
      Slog.w(TAG,"String_Node_Str" + this);
    }
  }
}
Program: 193299
Project: 193299
Buggy source:
/** 
 * An entry was removed.
 * @param removed the removed entry
 * @param sbn the notification the entry has, which doesn't need to be the same as it's internalnotification
 */
private void onEntryRemovedInternal(NotificationData.Entry removed,final StatusBarNotification sbn){
  Notification notif=sbn.getNotification();
  String groupKey=sbn.getGroupKey();
  final NotificationGroup group=mGroupMap.get(groupKey);
  if (group == null) {
    return;
  }
  if (notif.isGroupSummary()) {
    group.summary=null;
  }
 else {
    group.children.remove(removed);
  }
  if (group.children.isEmpty()) {
    if (group.summary == null) {
      mGroupMap.remove(groupKey);
    }
 else     if (!group.expanded) {
      group.summary.row.updateNotificationHeader();
    }
  }
}

Fixed version (ground truth):
/** 
 * An entry was removed.
 * @param removed the removed entry
 * @param sbn the notification the entry has, which doesn't need to be the same as it's internalnotification
 */
private void onEntryRemovedInternal(NotificationData.Entry removed,final StatusBarNotification sbn){
  Notification notif=sbn.getNotification();
  String groupKey=sbn.getGroupKey();
  final NotificationGroup group=mGroupMap.get(groupKey);
  if (group == null) {
    return;
  }
  if (notif.isGroupChild()) {
    group.children.remove(removed);
  }
 else {
    group.summary=null;
  }
  if (group.children.isEmpty()) {
    if (group.summary == null) {
      mGroupMap.remove(groupKey);
    }
 else     if (!group.expanded) {
      group.summary.row.updateNotificationHeader();
    }
  }
}
Program: 193300
Project: 193300
Buggy source:
public void onEntryAdded(NotificationData.Entry added){
  StatusBarNotification sbn=added.notification;
  Notification notif=sbn.getNotification();
  String groupKey=sbn.getGroupKey();
  NotificationGroup group=mGroupMap.get(groupKey);
  if (group == null) {
    group=new NotificationGroup();
    mGroupMap.put(groupKey,group);
  }
  if (notif.isGroupSummary()) {
    group.summary=added;
    group.expanded=added.row.areChildrenExpanded();
    if (!group.children.isEmpty()) {
      mListener.onGroupCreatedFromChildren(group);
    }
  }
 else {
    group.children.add(added);
    if (group.summary != null && group.children.size() == 1 && !group.expanded) {
      group.summary.row.updateNotificationHeader();
    }
  }
}

Fixed version (ground truth):
public void onEntryAdded(NotificationData.Entry added){
  StatusBarNotification sbn=added.notification;
  Notification notif=sbn.getNotification();
  String groupKey=sbn.getGroupKey();
  NotificationGroup group=mGroupMap.get(groupKey);
  if (group == null) {
    group=new NotificationGroup();
    mGroupMap.put(groupKey,group);
  }
  if (notif.isGroupChild()) {
    group.children.add(added);
    if (group.summary != null && group.children.size() == 1 && !group.expanded) {
      group.summary.row.updateNotificationHeader();
    }
  }
 else {
    group.summary=added;
    group.expanded=added.row.areChildrenExpanded();
    if (!group.children.isEmpty()) {
      mListener.onGroupCreatedFromChildren(group);
    }
  }
}
Program: 193301
Project: 193301
Buggy source:
/** 
 * @return whether a given notification is a summary in a group which has children
 */
public boolean isSummaryOfGroup(StatusBarNotification sbn){
  if (sbn.getNotification().isGroupChild()) {
    return false;
  }
  NotificationGroup group=mGroupMap.get(sbn.getGroupKey());
  if (group == null) {
    return false;
  }
  return !group.children.isEmpty();
}

Fixed version (ground truth):
/** 
 * @return whether a given notification is a summary in a group which has children
 */
public boolean isSummaryOfGroup(StatusBarNotification sbn){
  if (!sbn.getNotification().isGroupSummary()) {
    return false;
  }
  NotificationGroup group=mGroupMap.get(sbn.getGroupKey());
  if (group == null) {
    return false;
  }
  return !group.children.isEmpty();
}
Program: 193305
Project: 193305
Buggy source:
public DocumentHolder(View view){
  super(view);
  this.view=view;
  this.view.setFocusable(true);
  this.view.setOnKeyListener(this);
}

Fixed version (ground truth):
public DocumentHolder(View view){
  super(view);
  view.setFocusable(true);
  view.setOnKeyListener(this);
}
Program: 193306
Project: 193306
Buggy source:
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  final View view=inflater.inflate(R.layout.fragment_directory,container,false);
  mMessageBar=MessageBar.create(getChildFragmentManager());
  mProgressBar=view.findViewById(R.id.progressbar);
  mEmptyView=view.findViewById(android.R.id.empty);
  mRecView=(RecyclerView)view.findViewById(R.id.list);
  mRecView.setRecyclerListener(new RecyclerListener(){
    @Override public void onViewRecycled(    ViewHolder holder){
      cancelThumbnailTask(holder.itemView);
    }
  }
);
  mRecView.addOnLayoutChangeListener(new View.OnLayoutChangeListener(){
    @Override public void onLayoutChange(    View v,    int left,    int top,    int right,    int bottom,    int oldLeft,    int oldTop,    int oldRight,    int oldBottom){
      mColumnCount=calculateColumnCount();
      if (mGridLayout != null) {
        mGridLayout.setSpanCount(mColumnCount);
      }
    }
  }
);
  ((SimpleItemAnimator)mRecView.getItemAnimator()).setSupportsChangeAnimations(false);
  if (DEBUG_ENABLE_DND) {
    setupDragAndDropOnDirectoryView(mRecView);
  }
  return view;
}

Fixed version (ground truth):
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  final View view=inflater.inflate(R.layout.fragment_directory,container,false);
  mMessageBar=MessageBar.create(getChildFragmentManager());
  mProgressBar=view.findViewById(R.id.progressbar);
  mEmptyView=view.findViewById(android.R.id.empty);
  mRecView=(RecyclerView)view.findViewById(R.id.list);
  mRecView.setRecyclerListener(new RecyclerListener(){
    @Override public void onViewRecycled(    ViewHolder holder){
      cancelThumbnailTask(holder.itemView);
    }
  }
);
  mRecView.addOnLayoutChangeListener(new View.OnLayoutChangeListener(){
    @Override public void onLayoutChange(    View v,    int left,    int top,    int right,    int bottom,    int oldLeft,    int oldTop,    int oldRight,    int oldBottom){
      mColumnCount=calculateColumnCount();
      if (mGridLayout != null) {
        mGridLayout.setSpanCount(mColumnCount);
      }
    }
  }
);
  mRecView.setItemAnimator(new DirectoryItemAnimator(getActivity()));
  if (DEBUG_ENABLE_DND) {
    setupDragAndDropOnDirectoryView(mRecView);
  }
  return view;
}
Program: 193307
Project: 193307
Buggy source:
/** 
 * Notifies registered listeners when the selection status of a single item (identified by   {@code position}) changes.
 */
private void notifyItemStateChanged(int position,boolean selected){
  int lastListener=mCallbacks.size() - 1;
  for (int i=lastListener; i > -1; i--) {
    mCallbacks.get(i).onItemStateChanged(position,selected);
  }
  mAdapter.notifyItemChanged(position);
}

Fixed version (ground truth):
/** 
 * Notifies registered listeners when the selection status of a single item (identified by   {@code position}) changes.
 */
private void notifyItemStateChanged(int position,boolean selected){
  int lastListener=mCallbacks.size() - 1;
  for (int i=lastListener; i > -1; i--) {
    mCallbacks.get(i).onItemStateChanged(position,selected);
  }
  mAdapter.notifyItemChanged(position,SELECTION_CHANGED_MARKER);
}
Program: 193310
Project: 193310
Buggy source:
public DocumentHolder(View view){
  super(view);
  this.view=view;
  this.view.setFocusable(true);
  this.view.setOnKeyListener(this);
}

Fixed version (ground truth):
public DocumentHolder(View view){
  super(view);
  view.setFocusable(true);
  view.setOnKeyListener(this);
}
Program: 193311
Project: 193311
Buggy source:
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  final View view=inflater.inflate(R.layout.fragment_directory,container,false);
  mMessageBar=MessageBar.create(getChildFragmentManager());
  mProgressBar=view.findViewById(R.id.progressbar);
  mEmptyView=view.findViewById(android.R.id.empty);
  mRecView=(RecyclerView)view.findViewById(R.id.list);
  mRecView.setRecyclerListener(new RecyclerListener(){
    @Override public void onViewRecycled(    ViewHolder holder){
      cancelThumbnailTask(holder.itemView);
    }
  }
);
  mRecView.addOnLayoutChangeListener(new View.OnLayoutChangeListener(){
    @Override public void onLayoutChange(    View v,    int left,    int top,    int right,    int bottom,    int oldLeft,    int oldTop,    int oldRight,    int oldBottom){
      mColumnCount=calculateColumnCount();
      if (mGridLayout != null) {
        mGridLayout.setSpanCount(mColumnCount);
      }
    }
  }
);
  ((SimpleItemAnimator)mRecView.getItemAnimator()).setSupportsChangeAnimations(false);
  if (DEBUG_ENABLE_DND) {
    setupDragAndDropOnDirectoryView(mRecView);
  }
  return view;
}

Fixed version (ground truth):
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  final View view=inflater.inflate(R.layout.fragment_directory,container,false);
  mMessageBar=MessageBar.create(getChildFragmentManager());
  mProgressBar=view.findViewById(R.id.progressbar);
  mEmptyView=view.findViewById(android.R.id.empty);
  mRecView=(RecyclerView)view.findViewById(R.id.list);
  mRecView.setRecyclerListener(new RecyclerListener(){
    @Override public void onViewRecycled(    ViewHolder holder){
      cancelThumbnailTask(holder.itemView);
    }
  }
);
  mRecView.addOnLayoutChangeListener(new View.OnLayoutChangeListener(){
    @Override public void onLayoutChange(    View v,    int left,    int top,    int right,    int bottom,    int oldLeft,    int oldTop,    int oldRight,    int oldBottom){
      mColumnCount=calculateColumnCount();
      if (mGridLayout != null) {
        mGridLayout.setSpanCount(mColumnCount);
      }
    }
  }
);
  mRecView.setItemAnimator(new DirectoryItemAnimator(getActivity()));
  if (DEBUG_ENABLE_DND) {
    setupDragAndDropOnDirectoryView(mRecView);
  }
  return view;
}
Program: 193312
Project: 193312
Buggy source:
/** 
 * Notifies registered listeners when the selection status of a single item (identified by   {@code position}) changes.
 */
private void notifyItemStateChanged(int position,boolean selected){
  int lastListener=mCallbacks.size() - 1;
  for (int i=lastListener; i > -1; i--) {
    mCallbacks.get(i).onItemStateChanged(position,selected);
  }
  mAdapter.notifyItemChanged(position);
}

Fixed version (ground truth):
/** 
 * Notifies registered listeners when the selection status of a single item (identified by   {@code position}) changes.
 */
private void notifyItemStateChanged(int position,boolean selected){
  int lastListener=mCallbacks.size() - 1;
  for (int i=lastListener; i > -1; i--) {
    mCallbacks.get(i).onItemStateChanged(position,selected);
  }
  mAdapter.notifyItemChanged(position,SELECTION_CHANGED_MARKER);
}
Program: 193313
Project: 193313
Buggy source:
/** 
 * Returns true if the app has not been used for a certain amount of time. How much time? Could be hours, could be days, who knows?
 * @param packageName
 * @param userId
 * @return
 */
public abstract boolean isAppIdle(String packageName,int userId);

Fixed version (ground truth):
/** 
 * Returns true if the app has not been used for a certain amount of time. How much time? Could be hours, could be days, who knows?
 * @param packageName
 * @param uidForAppId The uid of the app, which will be used for its app id
 * @param userId
 * @return
 */
public abstract boolean isAppIdle(String packageName,int uidForAppId,int userId);
Program: 193314
Project: 193314
Buggy source:
private void maybeUpdateUsageStatsLocked(ProcessRecord app){
  if (DEBUG_USAGE_STATS) {
    Slog.d(TAG,"String_Node_Str" + Arrays.toString(app.getPackageList()) + "String_Node_Str"+ app.setProcState+ "String_Node_Str"+ app.curProcState);
  }
  if (mUsageStatsService == null) {
    return;
  }
  boolean isInteraction;
  if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
    isInteraction=true;
    app.fgInteractionTime=0;
  }
 else   if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
    final long now=SystemClock.elapsedRealtime();
    if (app.fgInteractionTime == 0) {
      app.fgInteractionTime=now;
      isInteraction=false;
    }
 else {
      isInteraction=now > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME;
    }
  }
 else {
    isInteraction=app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
    app.fgInteractionTime=0;
  }
  if (isInteraction && !app.reportedInteraction) {
    String[] packages=app.getPackageList();
    if (packages != null) {
      for (int i=0; i < packages.length; i++) {
        mUsageStatsService.reportEvent(packages[i],app.userId,UsageEvents.Event.SYSTEM_INTERACTION);
      }
    }
  }
  app.reportedInteraction=isInteraction;
}

Fixed version (ground truth):
private void maybeUpdateUsageStatsLocked(ProcessRecord app,long nowElapsed){
  if (DEBUG_USAGE_STATS) {
    Slog.d(TAG,"String_Node_Str" + Arrays.toString(app.getPackageList()) + "String_Node_Str"+ app.setProcState+ "String_Node_Str"+ app.curProcState);
  }
  if (mUsageStatsService == null) {
    return;
  }
  boolean isInteraction;
  if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
    isInteraction=true;
    app.fgInteractionTime=0;
  }
 else   if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
    if (app.fgInteractionTime == 0) {
      app.fgInteractionTime=nowElapsed;
      isInteraction=false;
    }
 else {
      isInteraction=nowElapsed > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME;
    }
  }
 else {
    isInteraction=app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
    app.fgInteractionTime=0;
  }
  if (isInteraction && (!app.reportedInteraction || (nowElapsed - app.interactionEventTime) > USAGE_STATS_INTERACTION_INTERVAL)) {
    app.interactionEventTime=nowElapsed;
    String[] packages=app.getPackageList();
    if (packages != null) {
      for (int i=0; i < packages.length; i++) {
        mUsageStatsService.reportEvent(packages[i],app.userId,UsageEvents.Event.SYSTEM_INTERACTION);
      }
    }
  }
  app.reportedInteraction=isInteraction;
  if (!isInteraction) {
    app.interactionEventTime=0;
  }
}
Program: 193318
Project: 193318
Buggy source:
boolean isAppIdle(String packageName,int userId){
  return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName,userId);
}

Fixed version (ground truth):
boolean isAppIdle(String packageName,int uidForAppId,int userId){
  return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName,uidForAppId,userId);
}
Program: 193320
Project: 193320
Buggy source:
void setAppIdleParoleOn(boolean isAppIdleParoleOn){
  boolean changed=false;
synchronized (mTrackedTasks) {
    if (mAppIdleParoleOn == isAppIdleParoleOn) {
      return;
    }
    mAppIdleParoleOn=isAppIdleParoleOn;
    for (    JobStatus task : mTrackedTasks) {
      String packageName=task.job.getService().getPackageName();
      final boolean appIdle=!mAppIdleParoleOn && mUsageStatsInternal.isAppIdle(packageName,task.getUserId());
      if (DEBUG) {
        Slog.d(LOG_TAG,"String_Node_Str" + packageName + "String_Node_Str"+ appIdle);
      }
      if (task.appNotIdleConstraintSatisfied.get() == appIdle) {
        task.appNotIdleConstraintSatisfied.set(!appIdle);
        changed=true;
      }
    }
  }
  if (changed) {
    mStateChangedListener.onControllerStateChanged();
  }
}

Fixed version (ground truth):
void setAppIdleParoleOn(boolean isAppIdleParoleOn){
  boolean changed=false;
synchronized (mTrackedTasks) {
    if (mAppIdleParoleOn == isAppIdleParoleOn) {
      return;
    }
    mAppIdleParoleOn=isAppIdleParoleOn;
    for (    JobStatus task : mTrackedTasks) {
      String packageName=task.job.getService().getPackageName();
      final boolean appIdle=!mAppIdleParoleOn && mUsageStatsInternal.isAppIdle(packageName,task.uId,task.getUserId());
      if (DEBUG) {
        Slog.d(LOG_TAG,"String_Node_Str" + packageName + "String_Node_Str"+ appIdle);
      }
      if (task.appNotIdleConstraintSatisfied.get() == appIdle) {
        task.appNotIdleConstraintSatisfied.set(!appIdle);
        changed=true;
      }
    }
  }
  if (changed) {
    mStateChangedListener.onControllerStateChanged();
  }
}
Program: 193321
Project: 193321
Buggy source:
@Override public void maybeStartTrackingJob(JobStatus jobStatus){
synchronized (mTrackedTasks) {
    mTrackedTasks.add(jobStatus);
    String packageName=jobStatus.job.getService().getPackageName();
    final boolean appIdle=!mAppIdleParoleOn && mUsageStatsInternal.isAppIdle(packageName,jobStatus.getUserId());
    if (DEBUG) {
      Slog.d(LOG_TAG,"String_Node_Str" + packageName + "String_Node_Str"+ appIdle);
    }
    jobStatus.appNotIdleConstraintSatisfied.set(!appIdle);
  }
}

Fixed version (ground truth):
@Override public void maybeStartTrackingJob(JobStatus jobStatus){
synchronized (mTrackedTasks) {
    mTrackedTasks.add(jobStatus);
    String packageName=jobStatus.job.getService().getPackageName();
    final boolean appIdle=!mAppIdleParoleOn && mUsageStatsInternal.isAppIdle(packageName,jobStatus.uId,jobStatus.getUserId());
    if (DEBUG) {
      Slog.d(LOG_TAG,"String_Node_Str" + packageName + "String_Node_Str"+ appIdle);
    }
    jobStatus.appNotIdleConstraintSatisfied.set(!appIdle);
  }
}
Program: 193322
Project: 193322
Buggy source:
private boolean isUidIdle(int uid){
  final String[] packages=mContext.getPackageManager().getPackagesForUid(uid);
  final int userId=UserHandle.getUserId(uid);
  for (  String packageName : packages) {
    if (!mUsageStats.isAppIdle(packageName,userId)) {
      return false;
    }
  }
  return true;
}

Fixed version (ground truth):
private boolean isUidIdle(int uid){
  final String[] packages=mContext.getPackageManager().getPackagesForUid(uid);
  final int userId=UserHandle.getUserId(uid);
  for (  String packageName : packages) {
    if (!mUsageStats.isAppIdle(packageName,uid,userId)) {
      return false;
    }
  }
  return true;
}
Program: 193323
Project: 193323
Buggy source:
@Override public boolean isAppIdle(String packageName,int userId){
  return UsageStatsService.this.isAppIdleFiltered(packageName,userId,-1);
}

Fixed version (ground truth):
@Override public boolean isAppIdle(String packageName,int uidForAppId,int userId){
  return UsageStatsService.this.isAppIdleFiltered(packageName,uidForAppId,userId,-1);
}
Program: 193324
Project: 193324
Buggy source:
/** 
 * Check all running users' or specified user's apps to see if they enter an idle state. 
 */
void checkIdleStates(int checkUserId){
  if (!mAppIdleEnabled) {
    return;
  }
  final int[] userIds;
  try {
    if (checkUserId == UserHandle.USER_ALL) {
      userIds=ActivityManagerNative.getDefault().getRunningUserIds();
    }
 else {
      userIds=new int[]{checkUserId};
    }
  }
 catch (  RemoteException re) {
    return;
  }
  for (int i=0; i < userIds.length; i++) {
    final int userId=userIds[i];
    List<PackageInfo> packages=getContext().getPackageManager().getInstalledPackages(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES,userId);
synchronized (mLock) {
      final long timeNow=checkAndGetTimeLocked();
      final long screenOnTime=getScreenOnTimeLocked(timeNow);
      UserUsageStatsService service=getUserDataAndInitializeIfNeededLocked(userId,timeNow);
      final int packageCount=packages.size();
      for (int p=0; p < packageCount; p++) {
        final String packageName=packages.get(p).packageName;
        final boolean isIdle=isAppIdleFiltered(packageName,userId,service,timeNow,screenOnTime);
        mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS,userId,isIdle ? 1 : 0,packageName));
        mAppIdleHistory.addEntry(packageName,userId,isIdle,timeNow);
      }
    }
  }
  mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CHECK_IDLE_STATES,checkUserId,0),mCheckIdleIntervalMillis);
}

Fixed version (ground truth):
/** 
 * Check all running users' or specified user's apps to see if they enter an idle state. 
 */
void checkIdleStates(int checkUserId){
  if (!mAppIdleEnabled) {
    return;
  }
  final int[] userIds;
  try {
    if (checkUserId == UserHandle.USER_ALL) {
      userIds=ActivityManagerNative.getDefault().getRunningUserIds();
    }
 else {
      userIds=new int[]{checkUserId};
    }
  }
 catch (  RemoteException re) {
    return;
  }
  for (int i=0; i < userIds.length; i++) {
    final int userId=userIds[i];
    List<PackageInfo> packages=getContext().getPackageManager().getInstalledPackages(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES,userId);
synchronized (mLock) {
      final long timeNow=checkAndGetTimeLocked();
      final long screenOnTime=getScreenOnTimeLocked(timeNow);
      UserUsageStatsService service=getUserDataAndInitializeIfNeededLocked(userId,timeNow);
      final int packageCount=packages.size();
      for (int p=0; p < packageCount; p++) {
        final PackageInfo pi=packages.get(p);
        final String packageName=pi.packageName;
        final boolean isIdle=isAppIdleFiltered(packageName,UserHandle.getAppId(pi.applicationInfo.uid),userId,service,timeNow,screenOnTime);
        mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS,userId,isIdle ? 1 : 0,packageName));
        mAppIdleHistory.addEntry(packageName,userId,isIdle,timeNow);
      }
    }
  }
  mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CHECK_IDLE_STATES,checkUserId,0),mCheckIdleIntervalMillis);
}
Program: 193325
Project: 193325
Buggy source:
boolean isAppIdleFilteredOrParoled(String packageName,int userId,long timeNow){
  if (mAppIdleParoled) {
    return false;
  }
  return isAppIdleFiltered(packageName,userId,timeNow);
}

Fixed version (ground truth):
boolean isAppIdleFilteredOrParoled(String packageName,int userId,long timeNow){
  if (mAppIdleParoled) {
    return false;
  }
  try {
    ApplicationInfo ai=getContext().getPackageManager().getApplicationInfo(packageName,PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
    return isAppIdleFiltered(packageName,ai.uid,userId,timeNow);
  }
 catch (  PackageManager.NameNotFoundException e) {
  }
  return false;
}
Program: 193326
Project: 193326
Buggy source:
/** 
 * Checks if an app has been idle for a while and filters out apps that are excluded. It returns false if the current system state allows all apps to be considered active. This happens if the device is plugged in or temporarily allowed to make exceptions. Called by interface impls.
 */
private boolean isAppIdleFiltered(String packageName,int userId,UserUsageStatsService userService,long timeNow,long screenOnTime){
  if (packageName == null)   return false;
  if (!mAppIdleEnabled) {
    return false;
  }
  if (packageName.equals("String_Node_Str"))   return false;
  try {
    if (mDeviceIdleController.isPowerSaveWhitelistExceptIdleApp(packageName)) {
      return false;
    }
  }
 catch (  RemoteException re) {
  }
  if (isActiveDeviceAdmin(packageName,userId)) {
    return false;
  }
  if (isCarrierApp(packageName)) {
    return false;
  }
  if (isActiveNetworkScorer(packageName)) {
    return false;
  }
  if (mAppWidgetManager != null && mAppWidgetManager.isBoundWidgetPackage(packageName,userId)) {
    return false;
  }
  return isAppIdleUnfiltered(packageName,userService,timeNow,screenOnTime);
}

Fixed version (ground truth):
/** 
 * Checks if an app has been idle for a while and filters out apps that are excluded. It returns false if the current system state allows all apps to be considered active. This happens if the device is plugged in or temporarily allowed to make exceptions. Called by interface impls.
 */
private boolean isAppIdleFiltered(String packageName,int appId,int userId,UserUsageStatsService userService,long timeNow,long screenOnTime){
  if (packageName == null)   return false;
  if (!mAppIdleEnabled) {
    return false;
  }
  if (appId < Process.FIRST_APPLICATION_UID) {
    return false;
  }
  if (packageName.equals("String_Node_Str")) {
    return false;
  }
  try {
    if (mDeviceIdleController.isPowerSaveWhitelistExceptIdleApp(packageName)) {
      return false;
    }
  }
 catch (  RemoteException re) {
  }
  if (isActiveDeviceAdmin(packageName,userId)) {
    return false;
  }
  if (isCarrierApp(packageName)) {
    return false;
  }
  if (isActiveNetworkScorer(packageName)) {
    return false;
  }
  if (mAppWidgetManager != null && mAppWidgetManager.isBoundWidgetPackage(packageName,userId)) {
    return false;
  }
  return isAppIdleUnfiltered(packageName,userService,timeNow,screenOnTime);
}
Program: 193327
Project: 193327
Buggy source:
/** 
 * Returns true if the app has not been used for a certain amount of time. How much time? Could be hours, could be days, who knows?
 * @param packageName
 * @param userId
 * @return
 */
public abstract boolean isAppIdle(String packageName,int userId);

Fixed version (ground truth):
/** 
 * Returns true if the app has not been used for a certain amount of time. How much time? Could be hours, could be days, who knows?
 * @param packageName
 * @param uidForAppId The uid of the app, which will be used for its app id
 * @param userId
 * @return
 */
public abstract boolean isAppIdle(String packageName,int uidForAppId,int userId);
Program: 193328
Project: 193328
Buggy source:
private void maybeUpdateUsageStatsLocked(ProcessRecord app){
  if (DEBUG_USAGE_STATS) {
    Slog.d(TAG,"String_Node_Str" + Arrays.toString(app.getPackageList()) + "String_Node_Str"+ app.setProcState+ "String_Node_Str"+ app.curProcState);
  }
  if (mUsageStatsService == null) {
    return;
  }
  boolean isInteraction;
  if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
    isInteraction=true;
    app.fgInteractionTime=0;
  }
 else   if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
    final long now=SystemClock.elapsedRealtime();
    if (app.fgInteractionTime == 0) {
      app.fgInteractionTime=now;
      isInteraction=false;
    }
 else {
      isInteraction=now > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME;
    }
  }
 else {
    isInteraction=app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
    app.fgInteractionTime=0;
  }
  if (isInteraction && !app.reportedInteraction) {
    String[] packages=app.getPackageList();
    if (packages != null) {
      for (int i=0; i < packages.length; i++) {
        mUsageStatsService.reportEvent(packages[i],app.userId,UsageEvents.Event.SYSTEM_INTERACTION);
      }
    }
  }
  app.reportedInteraction=isInteraction;
}

Fixed version (ground truth):
private void maybeUpdateUsageStatsLocked(ProcessRecord app,long nowElapsed){
  if (DEBUG_USAGE_STATS) {
    Slog.d(TAG,"String_Node_Str" + Arrays.toString(app.getPackageList()) + "String_Node_Str"+ app.setProcState+ "String_Node_Str"+ app.curProcState);
  }
  if (mUsageStatsService == null) {
    return;
  }
  boolean isInteraction;
  if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
    isInteraction=true;
    app.fgInteractionTime=0;
  }
 else   if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
    if (app.fgInteractionTime == 0) {
      app.fgInteractionTime=nowElapsed;
      isInteraction=false;
    }
 else {
      isInteraction=nowElapsed > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME;
    }
  }
 else {
    isInteraction=app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
    app.fgInteractionTime=0;
  }
  if (isInteraction && (!app.reportedInteraction || (nowElapsed - app.interactionEventTime) > USAGE_STATS_INTERACTION_INTERVAL)) {
    app.interactionEventTime=nowElapsed;
    String[] packages=app.getPackageList();
    if (packages != null) {
      for (int i=0; i < packages.length; i++) {
        mUsageStatsService.reportEvent(packages[i],app.userId,UsageEvents.Event.SYSTEM_INTERACTION);
      }
    }
  }
  app.reportedInteraction=isInteraction;
  if (!isInteraction) {
    app.interactionEventTime=0;
  }
}
Program: 193332
Project: 193332
Buggy source:
boolean isAppIdle(String packageName,int userId){
  return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName,userId);
}

Fixed version (ground truth):
boolean isAppIdle(String packageName,int uidForAppId,int userId){
  return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName,uidForAppId,userId);
}
Program: 193334
Project: 193334
Buggy source:
void setAppIdleParoleOn(boolean isAppIdleParoleOn){
  boolean changed=false;
synchronized (mTrackedTasks) {
    if (mAppIdleParoleOn == isAppIdleParoleOn) {
      return;
    }
    mAppIdleParoleOn=isAppIdleParoleOn;
    for (    JobStatus task : mTrackedTasks) {
      String packageName=task.job.getService().getPackageName();
      final boolean appIdle=!mAppIdleParoleOn && mUsageStatsInternal.isAppIdle(packageName,task.getUserId());
      if (DEBUG) {
        Slog.d(LOG_TAG,"String_Node_Str" + packageName + "String_Node_Str"+ appIdle);
      }
      if (task.appNotIdleConstraintSatisfied.get() == appIdle) {
        task.appNotIdleConstraintSatisfied.set(!appIdle);
        changed=true;
      }
    }
  }
  if (changed) {
    mStateChangedListener.onControllerStateChanged();
  }
}

Fixed version (ground truth):
void setAppIdleParoleOn(boolean isAppIdleParoleOn){
  boolean changed=false;
synchronized (mTrackedTasks) {
    if (mAppIdleParoleOn == isAppIdleParoleOn) {
      return;
    }
    mAppIdleParoleOn=isAppIdleParoleOn;
    for (    JobStatus task : mTrackedTasks) {
      String packageName=task.job.getService().getPackageName();
      final boolean appIdle=!mAppIdleParoleOn && mUsageStatsInternal.isAppIdle(packageName,task.uId,task.getUserId());
      if (DEBUG) {
        Slog.d(LOG_TAG,"String_Node_Str" + packageName + "String_Node_Str"+ appIdle);
      }
      if (task.appNotIdleConstraintSatisfied.get() == appIdle) {
        task.appNotIdleConstraintSatisfied.set(!appIdle);
        changed=true;
      }
    }
  }
  if (changed) {
    mStateChangedListener.onControllerStateChanged();
  }
}
Program: 193335
Project: 193335
Buggy source:
@Override public void maybeStartTrackingJob(JobStatus jobStatus){
synchronized (mTrackedTasks) {
    mTrackedTasks.add(jobStatus);
    String packageName=jobStatus.job.getService().getPackageName();
    final boolean appIdle=!mAppIdleParoleOn && mUsageStatsInternal.isAppIdle(packageName,jobStatus.getUserId());
    if (DEBUG) {
      Slog.d(LOG_TAG,"String_Node_Str" + packageName + "String_Node_Str"+ appIdle);
    }
    jobStatus.appNotIdleConstraintSatisfied.set(!appIdle);
  }
}

Fixed version (ground truth):
@Override public void maybeStartTrackingJob(JobStatus jobStatus){
synchronized (mTrackedTasks) {
    mTrackedTasks.add(jobStatus);
    String packageName=jobStatus.job.getService().getPackageName();
    final boolean appIdle=!mAppIdleParoleOn && mUsageStatsInternal.isAppIdle(packageName,jobStatus.uId,jobStatus.getUserId());
    if (DEBUG) {
      Slog.d(LOG_TAG,"String_Node_Str" + packageName + "String_Node_Str"+ appIdle);
    }
    jobStatus.appNotIdleConstraintSatisfied.set(!appIdle);
  }
}
Program: 193336
Project: 193336
Buggy source:
private boolean isUidIdle(int uid){
  final String[] packages=mContext.getPackageManager().getPackagesForUid(uid);
  final int userId=UserHandle.getUserId(uid);
  for (  String packageName : packages) {
    if (!mUsageStats.isAppIdle(packageName,userId)) {
      return false;
    }
  }
  return true;
}

Fixed version (ground truth):
private boolean isUidIdle(int uid){
  final String[] packages=mContext.getPackageManager().getPackagesForUid(uid);
  final int userId=UserHandle.getUserId(uid);
  for (  String packageName : packages) {
    if (!mUsageStats.isAppIdle(packageName,uid,userId)) {
      return false;
    }
  }
  return true;
}
Program: 193337
Project: 193337
Buggy source:
@Override public boolean isAppIdle(String packageName,int userId){
  return UsageStatsService.this.isAppIdleFiltered(packageName,userId,-1);
}

Fixed version (ground truth):
@Override public boolean isAppIdle(String packageName,int uidForAppId,int userId){
  return UsageStatsService.this.isAppIdleFiltered(packageName,uidForAppId,userId,-1);
}
Program: 193338
Project: 193338
Buggy source:
/** 
 * Check all running users' or specified user's apps to see if they enter an idle state. 
 */
void checkIdleStates(int checkUserId){
  if (!mAppIdleEnabled) {
    return;
  }
  final int[] userIds;
  try {
    if (checkUserId == UserHandle.USER_ALL) {
      userIds=ActivityManagerNative.getDefault().getRunningUserIds();
    }
 else {
      userIds=new int[]{checkUserId};
    }
  }
 catch (  RemoteException re) {
    return;
  }
  for (int i=0; i < userIds.length; i++) {
    final int userId=userIds[i];
    List<PackageInfo> packages=getContext().getPackageManager().getInstalledPackages(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES,userId);
synchronized (mLock) {
      final long timeNow=checkAndGetTimeLocked();
      final long screenOnTime=getScreenOnTimeLocked(timeNow);
      UserUsageStatsService service=getUserDataAndInitializeIfNeededLocked(userId,timeNow);
      final int packageCount=packages.size();
      for (int p=0; p < packageCount; p++) {
        final String packageName=packages.get(p).packageName;
        final boolean isIdle=isAppIdleFiltered(packageName,userId,service,timeNow,screenOnTime);
        mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS,userId,isIdle ? 1 : 0,packageName));
        mAppIdleHistory.addEntry(packageName,userId,isIdle,timeNow);
      }
    }
  }
  mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CHECK_IDLE_STATES,checkUserId,0),mCheckIdleIntervalMillis);
}

Fixed version (ground truth):
/** 
 * Check all running users' or specified user's apps to see if they enter an idle state. 
 */
void checkIdleStates(int checkUserId){
  if (!mAppIdleEnabled) {
    return;
  }
  final int[] userIds;
  try {
    if (checkUserId == UserHandle.USER_ALL) {
      userIds=ActivityManagerNative.getDefault().getRunningUserIds();
    }
 else {
      userIds=new int[]{checkUserId};
    }
  }
 catch (  RemoteException re) {
    return;
  }
  for (int i=0; i < userIds.length; i++) {
    final int userId=userIds[i];
    List<PackageInfo> packages=getContext().getPackageManager().getInstalledPackages(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES,userId);
synchronized (mLock) {
      final long timeNow=checkAndGetTimeLocked();
      final long screenOnTime=getScreenOnTimeLocked(timeNow);
      UserUsageStatsService service=getUserDataAndInitializeIfNeededLocked(userId,timeNow);
      final int packageCount=packages.size();
      for (int p=0; p < packageCount; p++) {
        final PackageInfo pi=packages.get(p);
        final String packageName=pi.packageName;
        final boolean isIdle=isAppIdleFiltered(packageName,UserHandle.getAppId(pi.applicationInfo.uid),userId,service,timeNow,screenOnTime);
        mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS,userId,isIdle ? 1 : 0,packageName));
        mAppIdleHistory.addEntry(packageName,userId,isIdle,timeNow);
      }
    }
  }
  mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CHECK_IDLE_STATES,checkUserId,0),mCheckIdleIntervalMillis);
}
Program: 193339
Project: 193339
Buggy source:
boolean isAppIdleFilteredOrParoled(String packageName,int userId,long timeNow){
  if (mAppIdleParoled) {
    return false;
  }
  return isAppIdleFiltered(packageName,userId,timeNow);
}

Fixed version (ground truth):
boolean isAppIdleFilteredOrParoled(String packageName,int userId,long timeNow){
  if (mAppIdleParoled) {
    return false;
  }
  try {
    ApplicationInfo ai=getContext().getPackageManager().getApplicationInfo(packageName,PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
    return isAppIdleFiltered(packageName,ai.uid,userId,timeNow);
  }
 catch (  PackageManager.NameNotFoundException e) {
  }
  return false;
}
Program: 193340
Project: 193340
Buggy source:
/** 
 * Checks if an app has been idle for a while and filters out apps that are excluded. It returns false if the current system state allows all apps to be considered active. This happens if the device is plugged in or temporarily allowed to make exceptions. Called by interface impls.
 */
private boolean isAppIdleFiltered(String packageName,int userId,UserUsageStatsService userService,long timeNow,long screenOnTime){
  if (packageName == null)   return false;
  if (!mAppIdleEnabled) {
    return false;
  }
  if (packageName.equals("String_Node_Str"))   return false;
  try {
    if (mDeviceIdleController.isPowerSaveWhitelistExceptIdleApp(packageName)) {
      return false;
    }
  }
 catch (  RemoteException re) {
  }
  if (isActiveDeviceAdmin(packageName,userId)) {
    return false;
  }
  if (isCarrierApp(packageName)) {
    return false;
  }
  if (isActiveNetworkScorer(packageName)) {
    return false;
  }
  if (mAppWidgetManager != null && mAppWidgetManager.isBoundWidgetPackage(packageName,userId)) {
    return false;
  }
  return isAppIdleUnfiltered(packageName,userService,timeNow,screenOnTime);
}

Fixed version (ground truth):
/** 
 * Checks if an app has been idle for a while and filters out apps that are excluded. It returns false if the current system state allows all apps to be considered active. This happens if the device is plugged in or temporarily allowed to make exceptions. Called by interface impls.
 */
private boolean isAppIdleFiltered(String packageName,int appId,int userId,UserUsageStatsService userService,long timeNow,long screenOnTime){
  if (packageName == null)   return false;
  if (!mAppIdleEnabled) {
    return false;
  }
  if (appId < Process.FIRST_APPLICATION_UID) {
    return false;
  }
  if (packageName.equals("String_Node_Str")) {
    return false;
  }
  try {
    if (mDeviceIdleController.isPowerSaveWhitelistExceptIdleApp(packageName)) {
      return false;
    }
  }
 catch (  RemoteException re) {
  }
  if (isActiveDeviceAdmin(packageName,userId)) {
    return false;
  }
  if (isCarrierApp(packageName)) {
    return false;
  }
  if (isActiveNetworkScorer(packageName)) {
    return false;
  }
  if (mAppWidgetManager != null && mAppWidgetManager.isBoundWidgetPackage(packageName,userId)) {
    return false;
  }
  return isAppIdleUnfiltered(packageName,userService,timeNow,screenOnTime);
}
Program: 193341
Project: 193341
Buggy source:
/** 
 * Returns true if the app has not been used for a certain amount of time. How much time? Could be hours, could be days, who knows?
 * @param packageName
 * @param userId
 * @return
 */
public abstract boolean isAppIdle(String packageName,int userId);

Fixed version (ground truth):
/** 
 * Returns true if the app has not been used for a certain amount of time. How much time? Could be hours, could be days, who knows?
 * @param packageName
 * @param uidForAppId The uid of the app, which will be used for its app id
 * @param userId
 * @return
 */
public abstract boolean isAppIdle(String packageName,int uidForAppId,int userId);
Program: 193342
Project: 193342
Buggy source:
private void maybeUpdateUsageStatsLocked(ProcessRecord app){
  if (DEBUG_USAGE_STATS) {
    Slog.d(TAG,"String_Node_Str" + Arrays.toString(app.getPackageList()) + "String_Node_Str"+ app.setProcState+ "String_Node_Str"+ app.curProcState);
  }
  if (mUsageStatsService == null) {
    return;
  }
  boolean isInteraction;
  if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
    isInteraction=true;
    app.fgInteractionTime=0;
  }
 else   if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
    final long now=SystemClock.elapsedRealtime();
    if (app.fgInteractionTime == 0) {
      app.fgInteractionTime=now;
      isInteraction=false;
    }
 else {
      isInteraction=now > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME;
    }
  }
 else {
    isInteraction=app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
    app.fgInteractionTime=0;
  }
  if (isInteraction && !app.reportedInteraction) {
    String[] packages=app.getPackageList();
    if (packages != null) {
      for (int i=0; i < packages.length; i++) {
        mUsageStatsService.reportEvent(packages[i],app.userId,UsageEvents.Event.SYSTEM_INTERACTION);
      }
    }
  }
  app.reportedInteraction=isInteraction;
}

Fixed version (ground truth):
private void maybeUpdateUsageStatsLocked(ProcessRecord app,long nowElapsed){
  if (DEBUG_USAGE_STATS) {
    Slog.d(TAG,"String_Node_Str" + Arrays.toString(app.getPackageList()) + "String_Node_Str"+ app.setProcState+ "String_Node_Str"+ app.curProcState);
  }
  if (mUsageStatsService == null) {
    return;
  }
  boolean isInteraction;
  if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
    isInteraction=true;
    app.fgInteractionTime=0;
  }
 else   if (app.curProcState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) {
    if (app.fgInteractionTime == 0) {
      app.fgInteractionTime=nowElapsed;
      isInteraction=false;
    }
 else {
      isInteraction=nowElapsed > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME;
    }
  }
 else {
    isInteraction=app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
    app.fgInteractionTime=0;
  }
  if (isInteraction && (!app.reportedInteraction || (nowElapsed - app.interactionEventTime) > USAGE_STATS_INTERACTION_INTERVAL)) {
    app.interactionEventTime=nowElapsed;
    String[] packages=app.getPackageList();
    if (packages != null) {
      for (int i=0; i < packages.length; i++) {
        mUsageStatsService.reportEvent(packages[i],app.userId,UsageEvents.Event.SYSTEM_INTERACTION);
      }
    }
  }
  app.reportedInteraction=isInteraction;
  if (!isInteraction) {
    app.interactionEventTime=0;
  }
}
Program: 193346
Project: 193346
Buggy source:
boolean isAppIdle(String packageName,int userId){
  return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName,userId);
}

Fixed version (ground truth):
boolean isAppIdle(String packageName,int uidForAppId,int userId){
  return !mAppIdleParoleOn && mUsageStats.isAppIdle(packageName,uidForAppId,userId);
}