nus-yam/ex-repair huggingface dataset:
Program: 192982
Project: 192982
Buggy source:
/** 
 * Perform the common clean-up of an activity record.  This is called both as part of destroyActivityLocked() (when destroying the client-side representation) and cleaning things up as a result of its hosting processing going away, in which case there is no remaining client-side state to destroy so only the cleanup here is needed. Note: Call before #removeActivityFromHistoryLocked.
 */
final void cleanUpActivityLocked(ActivityRecord r,boolean cleanServices,boolean setState){
  if (mResumedActivity == r) {
    mResumedActivity=null;
  }
  if (mPausingActivity == r) {
    mPausingActivity=null;
  }
  mService.resetFocusedActivityIfNeededLocked(r);
  r.configDestroy=false;
  r.frozenBeforeDestroy=false;
  if (setState) {
    if (DEBUG_STATES)     Slog.v(TAG_STATES,"String_Node_Str" + r + "String_Node_Str");
    r.state=ActivityState.DESTROYED;
    if (DEBUG_APP)     Slog.v(TAG_APP,"String_Node_Str" + r);
    r.app=null;
  }
  mStackSupervisor.mFinishingActivities.remove(r);
  mStackSupervisor.mWaitingVisibleActivities.remove(r);
  if (r.finishing && r.pendingResults != null) {
    for (    WeakReference<PendingIntentRecord> apr : r.pendingResults) {
      PendingIntentRecord rec=apr.get();
      if (rec != null) {
        mService.cancelIntentSenderLocked(rec,false);
      }
    }
    r.pendingResults=null;
  }
  if (cleanServices) {
    cleanUpActivityServicesLocked(r);
  }
  removeTimeoutsForActivityLocked(r);
  if (getVisibleBehindActivity() == r) {
    mStackSupervisor.requestVisibleBehindLocked(r,false);
  }
}

Fixed version (ground truth):
/** 
 * Perform the common clean-up of an activity record.  This is called both as part of destroyActivityLocked() (when destroying the client-side representation) and cleaning things up as a result of its hosting processing going away, in which case there is no remaining client-side state to destroy so only the cleanup here is needed. Note: Call before #removeActivityFromHistoryLocked.
 */
final void cleanUpActivityLocked(ActivityRecord r,boolean cleanServices,boolean setState){
  if (mResumedActivity == r) {
    mResumedActivity=null;
  }
  if (mPausingActivity == r) {
    mPausingActivity=null;
  }
  mService.resetFocusedActivityIfNeededLocked(r);
  r.deferRelaunchUntilPaused=false;
  r.frozenBeforeDestroy=false;
  if (setState) {
    if (DEBUG_STATES)     Slog.v(TAG_STATES,"String_Node_Str" + r + "String_Node_Str");
    r.state=ActivityState.DESTROYED;
    if (DEBUG_APP)     Slog.v(TAG_APP,"String_Node_Str" + r);
    r.app=null;
  }
  mStackSupervisor.mFinishingActivities.remove(r);
  mStackSupervisor.mWaitingVisibleActivities.remove(r);
  if (r.finishing && r.pendingResults != null) {
    for (    WeakReference<PendingIntentRecord> apr : r.pendingResults) {
      PendingIntentRecord rec=apr.get();
      if (rec != null) {
        mService.cancelIntentSenderLocked(rec,false);
      }
    }
    r.pendingResults=null;
  }
  if (cleanServices) {
    cleanUpActivityServicesLocked(r);
  }
  removeTimeoutsForActivityLocked(r);
  if (getVisibleBehindActivity() == r) {
    mStackSupervisor.requestVisibleBehindLocked(r,false);
  }
}
Program: 192985
Project: 192985
Buggy source:
final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove){
  ArrayList<ActivityRecord> stops=null;
  final boolean nowVisible=allResumedActivitiesVisible();
  for (int activityNdx=mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) {
    ActivityRecord s=mStoppingActivities.get(activityNdx);
    final boolean waitingVisible=mWaitingVisibleActivities.contains(s);
    if (DEBUG_ALL)     Slog.v(TAG,"String_Node_Str" + s + "String_Node_Str"+ nowVisible+ "String_Node_Str"+ waitingVisible+ "String_Node_Str"+ s.finishing);
    if (waitingVisible && nowVisible) {
      mWaitingVisibleActivities.remove(s);
      if (s.finishing) {
        if (DEBUG_ALL)         Slog.v(TAG,"String_Node_Str" + s);
        mWindowManager.setAppVisibility(s.appToken,false);
      }
    }
    if ((!waitingVisible || mService.isSleepingOrShuttingDown()) && remove) {
      if (DEBUG_ALL)       Slog.v(TAG,"String_Node_Str" + s);
      if (stops == null) {
        stops=new ArrayList<>();
      }
      stops.add(s);
      mStoppingActivities.remove(activityNdx);
    }
  }
  return stops;
}

Fixed version (ground truth):
final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove){
  ArrayList<ActivityRecord> stops=null;
  final boolean nowVisible=allResumedActivitiesVisible();
  for (int activityNdx=mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) {
    ActivityRecord s=mStoppingActivities.get(activityNdx);
    final boolean waitingVisible=mWaitingVisibleActivities.contains(s);
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + s + "String_Node_Str"+ nowVisible+ "String_Node_Str"+ waitingVisible+ "String_Node_Str"+ s.finishing);
    if (waitingVisible && nowVisible) {
      mWaitingVisibleActivities.remove(s);
      if (s.finishing) {
        if (DEBUG_STATES)         Slog.v(TAG,"String_Node_Str" + s);
        mWindowManager.setAppVisibility(s.appToken,false);
      }
    }
    if ((!waitingVisible || mService.isSleepingOrShuttingDown()) && remove) {
      if (DEBUG_STATES)       Slog.v(TAG,"String_Node_Str" + s);
      if (stops == null) {
        stops=new ArrayList<>();
      }
      stops.add(s);
      mStoppingActivities.remove(activityNdx);
    }
  }
  return stops;
}
Program: 192986
Project: 192986
Buggy source:
/** 
 * This should be the only way to get the time from the system.
 */
private long checkAndGetTimeLocked(){
  final long actualSystemTime=System.currentTimeMillis();
  final long actualRealtime=SystemClock.elapsedRealtime();
  final long expectedSystemTime=(actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
  boolean resetBeginIdleTime=false;
  if (Math.abs(actualSystemTime - expectedSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
    if (Math.abs(actualSystemTime - expectedSystemTime) > mAppIdleDurationMillis) {
      mScreenOnSystemTimeSnapshot=actualSystemTime;
      mScreenOnTime=0;
      resetBeginIdleTime=true;
    }
    final int userCount=mUserState.size();
    for (int i=0; i < userCount; i++) {
      final UserUsageStatsService service=mUserState.valueAt(i);
      service.onTimeChanged(expectedSystemTime,actualSystemTime,resetBeginIdleTime);
    }
    mRealTimeSnapshot=actualRealtime;
    mSystemTimeSnapshot=actualSystemTime;
  }
  return actualSystemTime;
}

Fixed version (ground truth):
/** 
 * This should be the only way to get the time from the system.
 */
private long checkAndGetTimeLocked(){
  final long actualSystemTime=System.currentTimeMillis();
  final long actualRealtime=SystemClock.elapsedRealtime();
  final long expectedSystemTime=(actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
  boolean resetBeginIdleTime=false;
  if (Math.abs(actualSystemTime - expectedSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
    if (Math.abs(actualSystemTime - expectedSystemTime) > mAppIdleDurationMillis) {
      mScreenOnSystemTimeSnapshot=actualSystemTime;
      mScreenOnTime=0;
      resetBeginIdleTime=true;
    }
    final int userCount=mUserState.size();
    for (int i=0; i < userCount; i++) {
      final UserUsageStatsService service=mUserState.valueAt(i);
      service.onTimeChanged(expectedSystemTime,actualSystemTime,mScreenOnTime,resetBeginIdleTime);
    }
    mRealTimeSnapshot=actualRealtime;
    mSystemTimeSnapshot=actualSystemTime;
  }
  return actualSystemTime;
}
Program: 192987
Project: 192987
Buggy source:
void onTimeChanged(long oldTime,long newTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime);
}

Fixed version (ground truth):
void onTimeChanged(long oldTime,long newTime,long deviceUsageTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime,deviceUsageTime);
}
Program: 192988
Project: 192988
Buggy source:
/** 
 * If any of the apps don't have a last-used entry, add one now.
 * @param currentTimeMillis the current time
 * @param firstUpdate if it is the first update, touch all installed apps, otherwise onlytouch the system apps
 */
private void initializeDefaultsForApps(long currentTimeMillis,long deviceUsageTime,boolean firstUpdate){
  PackageManager pm=mContext.getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0,mUserId);
  final int packageCount=packages.size();
  for (int i=0; i < packageCount; i++) {
    final PackageInfo pi=packages.get(i);
    String packageName=pi.packageName;
    if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) {
      for (      IntervalStats stats : mCurrentStats) {
        stats.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
        stats.updateBeginIdleTime(packageName,deviceUsageTime);
        mStatsChanged=true;
      }
    }
  }
  persistActiveStats();
}

Fixed version (ground truth):
/** 
 * If any of the apps don't have a last-used entry, add one now.
 * @param currentTimeMillis the current time
 * @param firstUpdate if it is the first update, touch all installed apps, otherwise onlytouch the system apps
 */
private void initializeDefaultsForApps(long currentTimeMillis,long deviceUsageTime,boolean firstUpdate){
  PackageManager pm=mContext.getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0,mUserId);
  final int packageCount=packages.size();
  for (int i=0; i < packageCount; i++) {
    final PackageInfo pi=packages.get(i);
    String packageName=pi.packageName;
    if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) {
      for (      IntervalStats stats : mCurrentStats) {
        stats.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
        stats.updateBeginIdleTime(packageName,deviceUsageTime);
      }
      mAppIdleRollingWindow.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
      mAppIdleRollingWindow.updateBeginIdleTime(packageName,deviceUsageTime);
      mStatsChanged=true;
    }
  }
  persistActiveStats();
}
Program: 192989
Project: 192989
Buggy source:
private static void mergePackageStats(IntervalStats dst,IntervalStats src){
  dst.endTime=Math.max(dst.endTime,src.endTime);
  final int srcPackageCount=src.packageStats.size();
  for (int i=0; i < srcPackageCount; i++) {
    final String packageName=src.packageStats.keyAt(i);
    final UsageStats srcStats=src.packageStats.valueAt(i);
    final UsageStats dstStats=dst.packageStats.get(packageName);
    if (dstStats == null) {
      dst.packageStats.put(packageName,new UsageStats(srcStats));
    }
 else {
      dstStats.add(src.packageStats.valueAt(i));
    }
  }
}

Fixed version (ground truth):
private static void mergePackageStats(IntervalStats dst,IntervalStats src,final long deviceUsageTime){
  dst.endTime=Math.max(dst.endTime,src.endTime);
  final int srcPackageCount=src.packageStats.size();
  for (int i=0; i < srcPackageCount; i++) {
    final String packageName=src.packageStats.keyAt(i);
    final UsageStats srcStats=src.packageStats.valueAt(i);
    UsageStats dstStats=dst.packageStats.get(packageName);
    if (dstStats == null) {
      dstStats=new UsageStats(srcStats);
      dst.packageStats.put(packageName,dstStats);
    }
 else {
      dstStats.add(src.packageStats.valueAt(i));
    }
    if (dstStats.mBeginIdleTime > deviceUsageTime) {
      dstStats.mBeginIdleTime=deviceUsageTime;
    }
  }
}
Program: 192990
Project: 192990
Buggy source:
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats);
}

Fixed version (ground truth):
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats,deviceUsageTime);
}
Program: 192992
Project: 192992
Buggy source:
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}

Fixed version (ground truth):
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp,deviceUsageTime);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}
Program: 192993
Project: 192993
Buggy source:
/** 
 * App idle operates on a rolling window of time. When we roll over time, we end up with a period of time where in-memory stats are empty and we don't hit the disk for older stats for performance reasons. Suddenly all apps will become idle. Instead, at times we do a deep query to find all the apps that have run in the past few days and keep the cached data up to date.
 * @param currentTimeMillis
 */
void refreshAppIdleRollingWindow(long currentTimeMillis){
  List<IntervalStats> stats=mDatabase.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,currentTimeMillis - (1000 * 60 * 60* 24* 2),currentTimeMillis,sPackageStatsMerger);
  if (stats == null || stats.isEmpty()) {
    mAppIdleRollingWindow=new IntervalStats();
    mergePackageStats(mAppIdleRollingWindow,mCurrentStats[UsageStatsManager.INTERVAL_YEARLY]);
  }
 else {
    mAppIdleRollingWindow=stats.get(0);
  }
}

Fixed version (ground truth):
/** 
 * App idle operates on a rolling window of time. When we roll over time, we end up with a period of time where in-memory stats are empty and we don't hit the disk for older stats for performance reasons. Suddenly all apps will become idle. Instead, at times we do a deep query to find all the apps that have run in the past few days and keep the cached data up to date.
 * @param currentTimeMillis
 */
void refreshAppIdleRollingWindow(final long currentTimeMillis,final long deviceUsageTime){
  List<IntervalStats> stats=mDatabase.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,currentTimeMillis - (1000 * 60 * 60* 24* 2),currentTimeMillis,new StatCombiner<IntervalStats>(){
    @Override public void combine(    IntervalStats stats,    boolean mutable,    List<IntervalStats> accumulatedResult){
      IntervalStats accum;
      if (accumulatedResult.isEmpty()) {
        accum=new IntervalStats();
        accum.beginTime=stats.beginTime;
        accumulatedResult.add(accum);
      }
 else {
        accum=accumulatedResult.get(0);
      }
      mergePackageStats(accum,stats,deviceUsageTime);
    }
  }
);
  if (stats == null || stats.isEmpty()) {
    mAppIdleRollingWindow=new IntervalStats();
    mergePackageStats(mAppIdleRollingWindow,mCurrentStats[UsageStatsManager.INTERVAL_YEARLY],deviceUsageTime);
  }
 else {
    mAppIdleRollingWindow=stats.get(0);
  }
}
Program: 192995
Project: 192995
Buggy source:
/** 
 * This should be the only way to get the time from the system.
 */
private long checkAndGetTimeLocked(){
  final long actualSystemTime=System.currentTimeMillis();
  final long actualRealtime=SystemClock.elapsedRealtime();
  final long expectedSystemTime=(actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
  boolean resetBeginIdleTime=false;
  if (Math.abs(actualSystemTime - expectedSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
    if (Math.abs(actualSystemTime - expectedSystemTime) > mAppIdleDurationMillis) {
      mScreenOnSystemTimeSnapshot=actualSystemTime;
      mScreenOnTime=0;
      resetBeginIdleTime=true;
    }
    final int userCount=mUserState.size();
    for (int i=0; i < userCount; i++) {
      final UserUsageStatsService service=mUserState.valueAt(i);
      service.onTimeChanged(expectedSystemTime,actualSystemTime,resetBeginIdleTime);
    }
    mRealTimeSnapshot=actualRealtime;
    mSystemTimeSnapshot=actualSystemTime;
  }
  return actualSystemTime;
}

Fixed version (ground truth):
/** 
 * This should be the only way to get the time from the system.
 */
private long checkAndGetTimeLocked(){
  final long actualSystemTime=System.currentTimeMillis();
  final long actualRealtime=SystemClock.elapsedRealtime();
  final long expectedSystemTime=(actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
  boolean resetBeginIdleTime=false;
  if (Math.abs(actualSystemTime - expectedSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
    if (Math.abs(actualSystemTime - expectedSystemTime) > mAppIdleDurationMillis) {
      mScreenOnSystemTimeSnapshot=actualSystemTime;
      mScreenOnTime=0;
      resetBeginIdleTime=true;
    }
    final int userCount=mUserState.size();
    for (int i=0; i < userCount; i++) {
      final UserUsageStatsService service=mUserState.valueAt(i);
      service.onTimeChanged(expectedSystemTime,actualSystemTime,mScreenOnTime,resetBeginIdleTime);
    }
    mRealTimeSnapshot=actualRealtime;
    mSystemTimeSnapshot=actualSystemTime;
  }
  return actualSystemTime;
}
Program: 192996
Project: 192996
Buggy source:
void onTimeChanged(long oldTime,long newTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime);
}

Fixed version (ground truth):
void onTimeChanged(long oldTime,long newTime,long deviceUsageTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime,deviceUsageTime);
}
Program: 192997
Project: 192997
Buggy source:
/** 
 * If any of the apps don't have a last-used entry, add one now.
 * @param currentTimeMillis the current time
 * @param firstUpdate if it is the first update, touch all installed apps, otherwise onlytouch the system apps
 */
private void initializeDefaultsForApps(long currentTimeMillis,long deviceUsageTime,boolean firstUpdate){
  PackageManager pm=mContext.getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0,mUserId);
  final int packageCount=packages.size();
  for (int i=0; i < packageCount; i++) {
    final PackageInfo pi=packages.get(i);
    String packageName=pi.packageName;
    if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) {
      for (      IntervalStats stats : mCurrentStats) {
        stats.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
        stats.updateBeginIdleTime(packageName,deviceUsageTime);
        mStatsChanged=true;
      }
    }
  }
  persistActiveStats();
}

Fixed version (ground truth):
/** 
 * If any of the apps don't have a last-used entry, add one now.
 * @param currentTimeMillis the current time
 * @param firstUpdate if it is the first update, touch all installed apps, otherwise onlytouch the system apps
 */
private void initializeDefaultsForApps(long currentTimeMillis,long deviceUsageTime,boolean firstUpdate){
  PackageManager pm=mContext.getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0,mUserId);
  final int packageCount=packages.size();
  for (int i=0; i < packageCount; i++) {
    final PackageInfo pi=packages.get(i);
    String packageName=pi.packageName;
    if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) {
      for (      IntervalStats stats : mCurrentStats) {
        stats.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
        stats.updateBeginIdleTime(packageName,deviceUsageTime);
      }
      mAppIdleRollingWindow.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
      mAppIdleRollingWindow.updateBeginIdleTime(packageName,deviceUsageTime);
      mStatsChanged=true;
    }
  }
  persistActiveStats();
}
Program: 192998
Project: 192998
Buggy source:
private static void mergePackageStats(IntervalStats dst,IntervalStats src){
  dst.endTime=Math.max(dst.endTime,src.endTime);
  final int srcPackageCount=src.packageStats.size();
  for (int i=0; i < srcPackageCount; i++) {
    final String packageName=src.packageStats.keyAt(i);
    final UsageStats srcStats=src.packageStats.valueAt(i);
    final UsageStats dstStats=dst.packageStats.get(packageName);
    if (dstStats == null) {
      dst.packageStats.put(packageName,new UsageStats(srcStats));
    }
 else {
      dstStats.add(src.packageStats.valueAt(i));
    }
  }
}

Fixed version (ground truth):
private static void mergePackageStats(IntervalStats dst,IntervalStats src,final long deviceUsageTime){
  dst.endTime=Math.max(dst.endTime,src.endTime);
  final int srcPackageCount=src.packageStats.size();
  for (int i=0; i < srcPackageCount; i++) {
    final String packageName=src.packageStats.keyAt(i);
    final UsageStats srcStats=src.packageStats.valueAt(i);
    UsageStats dstStats=dst.packageStats.get(packageName);
    if (dstStats == null) {
      dstStats=new UsageStats(srcStats);
      dst.packageStats.put(packageName,dstStats);
    }
 else {
      dstStats.add(src.packageStats.valueAt(i));
    }
    if (dstStats.mBeginIdleTime > deviceUsageTime) {
      dstStats.mBeginIdleTime=deviceUsageTime;
    }
  }
}
Program: 192999
Project: 192999
Buggy source:
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats);
}

Fixed version (ground truth):
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats,deviceUsageTime);
}
Program: 193001
Project: 193001
Buggy source:
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}

Fixed version (ground truth):
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp,deviceUsageTime);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}
Program: 193002
Project: 193002
Buggy source:
/** 
 * App idle operates on a rolling window of time. When we roll over time, we end up with a period of time where in-memory stats are empty and we don't hit the disk for older stats for performance reasons. Suddenly all apps will become idle. Instead, at times we do a deep query to find all the apps that have run in the past few days and keep the cached data up to date.
 * @param currentTimeMillis
 */
void refreshAppIdleRollingWindow(long currentTimeMillis){
  List<IntervalStats> stats=mDatabase.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,currentTimeMillis - (1000 * 60 * 60* 24* 2),currentTimeMillis,sPackageStatsMerger);
  if (stats == null || stats.isEmpty()) {
    mAppIdleRollingWindow=new IntervalStats();
    mergePackageStats(mAppIdleRollingWindow,mCurrentStats[UsageStatsManager.INTERVAL_YEARLY]);
  }
 else {
    mAppIdleRollingWindow=stats.get(0);
  }
}

Fixed version (ground truth):
/** 
 * App idle operates on a rolling window of time. When we roll over time, we end up with a period of time where in-memory stats are empty and we don't hit the disk for older stats for performance reasons. Suddenly all apps will become idle. Instead, at times we do a deep query to find all the apps that have run in the past few days and keep the cached data up to date.
 * @param currentTimeMillis
 */
void refreshAppIdleRollingWindow(final long currentTimeMillis,final long deviceUsageTime){
  List<IntervalStats> stats=mDatabase.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,currentTimeMillis - (1000 * 60 * 60* 24* 2),currentTimeMillis,new StatCombiner<IntervalStats>(){
    @Override public void combine(    IntervalStats stats,    boolean mutable,    List<IntervalStats> accumulatedResult){
      IntervalStats accum;
      if (accumulatedResult.isEmpty()) {
        accum=new IntervalStats();
        accum.beginTime=stats.beginTime;
        accumulatedResult.add(accum);
      }
 else {
        accum=accumulatedResult.get(0);
      }
      mergePackageStats(accum,stats,deviceUsageTime);
    }
  }
);
  if (stats == null || stats.isEmpty()) {
    mAppIdleRollingWindow=new IntervalStats();
    mergePackageStats(mAppIdleRollingWindow,mCurrentStats[UsageStatsManager.INTERVAL_YEARLY],deviceUsageTime);
  }
 else {
    mAppIdleRollingWindow=stats.get(0);
  }
}
Program: 193004
Project: 193004
Buggy source:
/** 
 * This should be the only way to get the time from the system.
 */
private long checkAndGetTimeLocked(){
  final long actualSystemTime=System.currentTimeMillis();
  final long actualRealtime=SystemClock.elapsedRealtime();
  final long expectedSystemTime=(actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
  boolean resetBeginIdleTime=false;
  if (Math.abs(actualSystemTime - expectedSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
    if (Math.abs(actualSystemTime - expectedSystemTime) > mAppIdleDurationMillis) {
      mScreenOnSystemTimeSnapshot=actualSystemTime;
      mScreenOnTime=0;
      resetBeginIdleTime=true;
    }
    final int userCount=mUserState.size();
    for (int i=0; i < userCount; i++) {
      final UserUsageStatsService service=mUserState.valueAt(i);
      service.onTimeChanged(expectedSystemTime,actualSystemTime,resetBeginIdleTime);
    }
    mRealTimeSnapshot=actualRealtime;
    mSystemTimeSnapshot=actualSystemTime;
  }
  return actualSystemTime;
}

Fixed version (ground truth):
/** 
 * This should be the only way to get the time from the system.
 */
private long checkAndGetTimeLocked(){
  final long actualSystemTime=System.currentTimeMillis();
  final long actualRealtime=SystemClock.elapsedRealtime();
  final long expectedSystemTime=(actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
  boolean resetBeginIdleTime=false;
  if (Math.abs(actualSystemTime - expectedSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
    if (Math.abs(actualSystemTime - expectedSystemTime) > mAppIdleDurationMillis) {
      mScreenOnSystemTimeSnapshot=actualSystemTime;
      mScreenOnTime=0;
      resetBeginIdleTime=true;
    }
    final int userCount=mUserState.size();
    for (int i=0; i < userCount; i++) {
      final UserUsageStatsService service=mUserState.valueAt(i);
      service.onTimeChanged(expectedSystemTime,actualSystemTime,mScreenOnTime,resetBeginIdleTime);
    }
    mRealTimeSnapshot=actualRealtime;
    mSystemTimeSnapshot=actualSystemTime;
  }
  return actualSystemTime;
}
Program: 193005
Project: 193005
Buggy source:
void onTimeChanged(long oldTime,long newTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime);
}

Fixed version (ground truth):
void onTimeChanged(long oldTime,long newTime,long deviceUsageTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime,deviceUsageTime);
}
Program: 193006
Project: 193006
Buggy source:
/** 
 * If any of the apps don't have a last-used entry, add one now.
 * @param currentTimeMillis the current time
 * @param firstUpdate if it is the first update, touch all installed apps, otherwise onlytouch the system apps
 */
private void initializeDefaultsForApps(long currentTimeMillis,long deviceUsageTime,boolean firstUpdate){
  PackageManager pm=mContext.getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0,mUserId);
  final int packageCount=packages.size();
  for (int i=0; i < packageCount; i++) {
    final PackageInfo pi=packages.get(i);
    String packageName=pi.packageName;
    if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) {
      for (      IntervalStats stats : mCurrentStats) {
        stats.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
        stats.updateBeginIdleTime(packageName,deviceUsageTime);
        mStatsChanged=true;
      }
    }
  }
  persistActiveStats();
}

Fixed version (ground truth):
/** 
 * If any of the apps don't have a last-used entry, add one now.
 * @param currentTimeMillis the current time
 * @param firstUpdate if it is the first update, touch all installed apps, otherwise onlytouch the system apps
 */
private void initializeDefaultsForApps(long currentTimeMillis,long deviceUsageTime,boolean firstUpdate){
  PackageManager pm=mContext.getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0,mUserId);
  final int packageCount=packages.size();
  for (int i=0; i < packageCount; i++) {
    final PackageInfo pi=packages.get(i);
    String packageName=pi.packageName;
    if (pi.applicationInfo != null && (firstUpdate || pi.applicationInfo.isSystemApp()) && getBeginIdleTime(packageName) == -1) {
      for (      IntervalStats stats : mCurrentStats) {
        stats.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
        stats.updateBeginIdleTime(packageName,deviceUsageTime);
      }
      mAppIdleRollingWindow.update(packageName,currentTimeMillis,Event.SYSTEM_INTERACTION);
      mAppIdleRollingWindow.updateBeginIdleTime(packageName,deviceUsageTime);
      mStatsChanged=true;
    }
  }
  persistActiveStats();
}
Program: 193007
Project: 193007
Buggy source:
private static void mergePackageStats(IntervalStats dst,IntervalStats src){
  dst.endTime=Math.max(dst.endTime,src.endTime);
  final int srcPackageCount=src.packageStats.size();
  for (int i=0; i < srcPackageCount; i++) {
    final String packageName=src.packageStats.keyAt(i);
    final UsageStats srcStats=src.packageStats.valueAt(i);
    final UsageStats dstStats=dst.packageStats.get(packageName);
    if (dstStats == null) {
      dst.packageStats.put(packageName,new UsageStats(srcStats));
    }
 else {
      dstStats.add(src.packageStats.valueAt(i));
    }
  }
}

Fixed version (ground truth):
private static void mergePackageStats(IntervalStats dst,IntervalStats src,final long deviceUsageTime){
  dst.endTime=Math.max(dst.endTime,src.endTime);
  final int srcPackageCount=src.packageStats.size();
  for (int i=0; i < srcPackageCount; i++) {
    final String packageName=src.packageStats.keyAt(i);
    final UsageStats srcStats=src.packageStats.valueAt(i);
    UsageStats dstStats=dst.packageStats.get(packageName);
    if (dstStats == null) {
      dstStats=new UsageStats(srcStats);
      dst.packageStats.put(packageName,dstStats);
    }
 else {
      dstStats.add(src.packageStats.valueAt(i));
    }
    if (dstStats.mBeginIdleTime > deviceUsageTime) {
      dstStats.mBeginIdleTime=deviceUsageTime;
    }
  }
}
Program: 193008
Project: 193008
Buggy source:
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats);
}

Fixed version (ground truth):
@Override public void combine(IntervalStats stats,boolean mutable,List<IntervalStats> accumulatedResult){
  IntervalStats accum;
  if (accumulatedResult.isEmpty()) {
    accum=new IntervalStats();
    accum.beginTime=stats.beginTime;
    accumulatedResult.add(accum);
  }
 else {
    accum=accumulatedResult.get(0);
  }
  mergePackageStats(accum,stats,deviceUsageTime);
}
Program: 193010
Project: 193010
Buggy source:
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}

Fixed version (ground truth):
void reportEvent(UsageEvents.Event event,long deviceUsageTime){
  if (DEBUG) {
    Slog.d(TAG,mLogPrefix + "String_Node_Str" + event.mPackage+ "String_Node_Str"+ event.mTimeStamp+ "String_Node_Str"+ eventToString(event.mEventType));
  }
  if (event.mTimeStamp >= mDailyExpiryDate.getTimeInMillis()) {
    rolloverStats(event.mTimeStamp,deviceUsageTime);
  }
  final IntervalStats currentDailyStats=mCurrentStats[UsageStatsManager.INTERVAL_DAILY];
  final Configuration newFullConfig=event.mConfiguration;
  if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE && currentDailyStats.activeConfiguration != null) {
    event.mConfiguration=Configuration.generateDelta(currentDailyStats.activeConfiguration,newFullConfig);
  }
  if (currentDailyStats.events == null) {
    currentDailyStats.events=new TimeSparseArray<>();
  }
  if (event.mEventType != UsageEvents.Event.SYSTEM_INTERACTION) {
    currentDailyStats.events.put(event.mTimeStamp,event);
  }
  for (  IntervalStats stats : mCurrentStats) {
    if (event.mEventType == UsageEvents.Event.CONFIGURATION_CHANGE) {
      stats.updateConfigurationStats(newFullConfig,event.mTimeStamp);
    }
 else {
      stats.update(event.mPackage,event.mTimeStamp,event.mEventType);
      stats.updateBeginIdleTime(event.mPackage,deviceUsageTime);
    }
  }
  if (event.mEventType != Event.CONFIGURATION_CHANGE) {
    mAppIdleRollingWindow.update(event.mPackage,event.mTimeStamp,event.mEventType);
    mAppIdleRollingWindow.updateBeginIdleTime(event.mPackage,deviceUsageTime);
  }
  notifyStatsChanged();
}
Program: 193011
Project: 193011
Buggy source:
/** 
 * App idle operates on a rolling window of time. When we roll over time, we end up with a period of time where in-memory stats are empty and we don't hit the disk for older stats for performance reasons. Suddenly all apps will become idle. Instead, at times we do a deep query to find all the apps that have run in the past few days and keep the cached data up to date.
 * @param currentTimeMillis
 */
void refreshAppIdleRollingWindow(long currentTimeMillis){
  List<IntervalStats> stats=mDatabase.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,currentTimeMillis - (1000 * 60 * 60* 24* 2),currentTimeMillis,sPackageStatsMerger);
  if (stats == null || stats.isEmpty()) {
    mAppIdleRollingWindow=new IntervalStats();
    mergePackageStats(mAppIdleRollingWindow,mCurrentStats[UsageStatsManager.INTERVAL_YEARLY]);
  }
 else {
    mAppIdleRollingWindow=stats.get(0);
  }
}

Fixed version (ground truth):
/** 
 * App idle operates on a rolling window of time. When we roll over time, we end up with a period of time where in-memory stats are empty and we don't hit the disk for older stats for performance reasons. Suddenly all apps will become idle. Instead, at times we do a deep query to find all the apps that have run in the past few days and keep the cached data up to date.
 * @param currentTimeMillis
 */
void refreshAppIdleRollingWindow(final long currentTimeMillis,final long deviceUsageTime){
  List<IntervalStats> stats=mDatabase.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,currentTimeMillis - (1000 * 60 * 60* 24* 2),currentTimeMillis,new StatCombiner<IntervalStats>(){
    @Override public void combine(    IntervalStats stats,    boolean mutable,    List<IntervalStats> accumulatedResult){
      IntervalStats accum;
      if (accumulatedResult.isEmpty()) {
        accum=new IntervalStats();
        accum.beginTime=stats.beginTime;
        accumulatedResult.add(accum);
      }
 else {
        accum=accumulatedResult.get(0);
      }
      mergePackageStats(accum,stats,deviceUsageTime);
    }
  }
);
  if (stats == null || stats.isEmpty()) {
    mAppIdleRollingWindow=new IntervalStats();
    mergePackageStats(mAppIdleRollingWindow,mCurrentStats[UsageStatsManager.INTERVAL_YEARLY],deviceUsageTime);
  }
 else {
    mAppIdleRollingWindow=stats.get(0);
  }
}
Program: 193013
Project: 193013
Buggy source:
/** 
 * Retrieves whether the current DPM allows use of the Profile Challenge.
 */
public boolean isSeparateProfileChallengeAllowed(int userHandle){
  UserInfo info=getUserManager().getUserInfo(userHandle);
  if (!info.isManagedProfile()) {
    return false;
  }
  return getDevicePolicyManager().isSeparateProfileChallengeAllowed(userHandle);
}

Fixed version (ground truth):
/** 
 * Retrieves whether the current DPM allows use of the Profile Challenge.
 */
public boolean isSeparateProfileChallengeAllowed(int userHandle){
  UserInfo info=getUserManager().getUserInfo(userHandle);
  if (info == null || !info.isManagedProfile()) {
    return false;
  }
  return getDevicePolicyManager().isSeparateProfileChallengeAllowed(userHandle);
}
Program: 193014
Project: 193014
Buggy source:
/** 
 * Retrieves whether the Separate Profile Challenge is enabled for this   {@param userHandle}.
 */
public boolean isSeparateProfileChallengeEnabled(int userHandle){
  UserInfo info=getUserManager().getUserInfo(userHandle);
  if (!info.isManagedProfile()) {
    return false;
  }
  return getBoolean(SEPARATE_PROFILE_CHALLENGE_KEY,false,userHandle);
}

Fixed version (ground truth):
/** 
 * Retrieves whether the Separate Profile Challenge is enabled for this   {@param userHandle}.
 */
public boolean isSeparateProfileChallengeEnabled(int userHandle){
  UserInfo info=getUserManager().getUserInfo(userHandle);
  if (info == null || !info.isManagedProfile()) {
    return false;
  }
  return getBoolean(SEPARATE_PROFILE_CHALLENGE_KEY,false,userHandle);
}
Program: 193015
Project: 193015
Buggy source:
@Override public boolean isDeviceSecure(int userId) throws RemoteException {
  userId=ActivityManager.handleIncomingUser(getCallingPid(),getCallingUid(),userId,false,true,"String_Node_Str",null);
  if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
    userId=resolveProfileParent(userId);
  }
  long token=Binder.clearCallingIdentity();
  try {
    return mLockPatternUtils.isSecure(userId);
  }
  finally {
    Binder.restoreCallingIdentity(token);
  }
}

Fixed version (ground truth):
@Override public boolean isDeviceSecure(int userId) throws RemoteException {
  userId=ActivityManager.handleIncomingUser(getCallingPid(),getCallingUid(),userId,false,true,"String_Node_Str",null);
  long token=Binder.clearCallingIdentity();
  try {
    if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
      userId=resolveProfileParent(userId);
    }
    return mLockPatternUtils.isSecure(userId);
  }
  finally {
    Binder.restoreCallingIdentity(token);
  }
}
Program: 193016
Project: 193016
Buggy source:
/** 
 * This should be the only way to get the time from the system.
 */
private long checkAndGetTimeLocked(){
  final long actualSystemTime=System.currentTimeMillis();
  final long actualRealtime=SystemClock.elapsedRealtime();
  final long expectedSystemTime=(actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
  boolean resetBeginIdleTime=false;
  if (Math.abs(actualSystemTime - expectedSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
    if (Math.abs(actualSystemTime - expectedSystemTime) > mAppIdleDurationMillis) {
      mScreenOnSystemTimeSnapshot=actualSystemTime;
      mScreenOnTime=0;
      resetBeginIdleTime=true;
    }
    final int userCount=mUserState.size();
    for (int i=0; i < userCount; i++) {
      final UserUsageStatsService service=mUserState.valueAt(i);
      service.onTimeChanged(expectedSystemTime,actualSystemTime,resetBeginIdleTime);
    }
    mRealTimeSnapshot=actualRealtime;
    mSystemTimeSnapshot=actualSystemTime;
  }
  return actualSystemTime;
}

Fixed version (ground truth):
/** 
 * This should be the only way to get the time from the system.
 */
private long checkAndGetTimeLocked(){
  final long actualSystemTime=System.currentTimeMillis();
  final long actualRealtime=SystemClock.elapsedRealtime();
  final long expectedSystemTime=(actualRealtime - mRealTimeSnapshot) + mSystemTimeSnapshot;
  boolean resetBeginIdleTime=false;
  if (Math.abs(actualSystemTime - expectedSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) {
    if (Math.abs(actualSystemTime - expectedSystemTime) > mAppIdleDurationMillis) {
      mScreenOnSystemTimeSnapshot=actualSystemTime;
      mScreenOnTime=0;
      resetBeginIdleTime=true;
    }
    final int userCount=mUserState.size();
    for (int i=0; i < userCount; i++) {
      final UserUsageStatsService service=mUserState.valueAt(i);
      service.onTimeChanged(expectedSystemTime,actualSystemTime,mScreenOnTime,resetBeginIdleTime);
    }
    mRealTimeSnapshot=actualRealtime;
    mSystemTimeSnapshot=actualSystemTime;
  }
  return actualSystemTime;
}
Program: 193017
Project: 193017
Buggy source:
void onTimeChanged(long oldTime,long newTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime);
}

Fixed version (ground truth):
void onTimeChanged(long oldTime,long newTime,long deviceUsageTime,boolean resetBeginIdleTime){
  persistActiveStats();
  mDatabase.onTimeChanged(newTime - oldTime);
  loadActiveStats(newTime,true,resetBeginIdleTime);
  refreshAppIdleRollingWindow(newTime,deviceUsageTime);
}