Program: 191775
Project: 191775
Buggy source:
public void testHandlePackageUpdate() throws Throwable {
  final Icon res32x32=Icon.createWithResource(getTestContext(),R.drawable.black_32x32);
  final Icon bmp32x32=Icon.createWithBitmap(BitmapFactory.decodeResource(getTestContext().getResources(),R.drawable.black_32x32));
  runWithCaller(CALLING_PACKAGE_1,USER_0,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("String_Node_Str"),makeShortcutWithIcon("String_Node_Str",res32x32),makeShortcutWithIcon("String_Node_Str",res32x32),makeShortcutWithIcon("String_Node_Str",bmp32x32))));
  }
);
  runWithCaller(CALLING_PACKAGE_2,USER_0,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("String_Node_Str"),makeShortcutWithIcon("String_Node_Str",bmp32x32))));
  }
);
  runWithCaller(CALLING_PACKAGE_3,USER_0,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcutWithIcon("String_Node_Str",res32x32))));
  }
);
  runWithCaller(CALLING_PACKAGE_1,USER_10,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcutWithIcon("String_Node_Str",res32x32),makeShortcutWithIcon("String_Node_Str",res32x32))));
  }
);
  runWithCaller(CALLING_PACKAGE_2,USER_10,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcutWithIcon("String_Node_Str",bmp32x32),makeShortcutWithIcon("String_Node_Str",bmp32x32))));
  }
);
  LauncherApps.Callback c0=mock(LauncherApps.Callback.class);
  LauncherApps.Callback c10=mock(LauncherApps.Callback.class);
  runWithCaller(LAUNCHER_1,USER_0,() -> {
    mLauncherApps.registerCallback(c0,new Handler(Looper.getMainLooper()));
  }
);
  runWithCaller(LAUNCHER_1,USER_10,() -> {
    mLauncherApps.registerCallback(c10,new Handler(Looper.getMainLooper()));
  }
);
  mInjectedCurrentTimeLillis=START_TIME + 100;
  ArgumentCaptor<List> shortcuts;
  reset(c0);
  reset(c10);
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_1,USER_0));
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_1,USER_10));
  waitOnMainThread();
  verify(c0,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  verify(c10,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  reset(c0);
  reset(c10);
  updatePackageVersion(CALLING_PACKAGE_1,1);
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_1,USER_0));
  waitOnMainThread();
  shortcuts=ArgumentCaptor.forClass(List.class);
  verify(c0).onShortcutsChanged(eq(CALLING_PACKAGE_1),shortcuts.capture(),eq(HANDLE_USER_0));
  verify(c10,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  assertShortcutIds(shortcuts.getValue(),"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
  assertEquals(START_TIME,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  assertEquals(START_TIME + 100,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  assertEquals(START_TIME + 100,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  assertEquals(START_TIME,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  mInjectedCurrentTimeLillis=START_TIME + 200;
  when(mMockUserManager.isUserRunning(eq(USER_10))).thenReturn(true);
  reset(c0);
  reset(c10);
  mService.handleUnlockUser(USER_10);
  shortcuts=ArgumentCaptor.forClass(List.class);
  verify(c0,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  verify(c10).onShortcutsChanged(eq(CALLING_PACKAGE_1),shortcuts.capture(),eq(HANDLE_USER_10));
  assertShortcutIds(shortcuts.getValue(),"String_Node_Str","String_Node_Str");
  assertEquals(START_TIME + 200,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  assertEquals(START_TIME + 200,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  mInjectedCurrentTimeLillis=START_TIME + 300;
  reset(c0);
  reset(c10);
  updatePackageVersion(CALLING_PACKAGE_2,10);
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_2,USER_0));
  mService.handleUnlockUser(USER_10);
  waitOnMainThread();
  verify(c0,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  verify(c10,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  mInjectedCurrentTimeLillis=START_TIME + 400;
  reset(c0);
  reset(c10);
  updatePackageVersion(CALLING_PACKAGE_3,100);
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_3,USER_0));
  mService.handleUnlockUser(USER_10);
  waitOnMainThread();
  shortcuts=ArgumentCaptor.forClass(List.class);
  verify(c0).onShortcutsChanged(eq(CALLING_PACKAGE_3),shortcuts.capture(),eq(HANDLE_USER_0));
  verify(c10,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_3),any(List.class),any(UserHandle.class));
  assertShortcutIds(shortcuts.getValue(),"String_Node_Str");
  assertEquals(START_TIME + 400,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
}

Fixed version (ground truth):
public void testHandlePackageUpdate() throws Throwable {
  final Icon res32x32=Icon.createWithResource(getTestContext(),R.drawable.black_32x32);
  final Icon bmp32x32=Icon.createWithBitmap(BitmapFactory.decodeResource(getTestContext().getResources(),R.drawable.black_32x32));
  runWithCaller(CALLING_PACKAGE_1,USER_0,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("String_Node_Str"),makeShortcutWithIcon("String_Node_Str",res32x32),makeShortcutWithIcon("String_Node_Str",res32x32),makeShortcutWithIcon("String_Node_Str",bmp32x32))));
  }
);
  runWithCaller(CALLING_PACKAGE_2,USER_0,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("String_Node_Str"),makeShortcutWithIcon("String_Node_Str",bmp32x32))));
  }
);
  runWithCaller(CALLING_PACKAGE_3,USER_0,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcutWithIcon("String_Node_Str",res32x32))));
  }
);
  runWithCaller(CALLING_PACKAGE_1,USER_10,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcutWithIcon("String_Node_Str",res32x32),makeShortcutWithIcon("String_Node_Str",res32x32))));
  }
);
  runWithCaller(CALLING_PACKAGE_2,USER_10,() -> {
    assertTrue(mManager.setDynamicShortcuts(list(makeShortcutWithIcon("String_Node_Str",bmp32x32),makeShortcutWithIcon("String_Node_Str",bmp32x32))));
  }
);
  LauncherApps.Callback c0=mock(LauncherApps.Callback.class);
  LauncherApps.Callback c10=mock(LauncherApps.Callback.class);
  runWithCaller(LAUNCHER_1,USER_0,() -> {
    mLauncherApps.registerCallback(c0,new Handler(Looper.getMainLooper()));
  }
);
  runWithCaller(LAUNCHER_1,USER_10,() -> {
    mLauncherApps.registerCallback(c10,new Handler(Looper.getMainLooper()));
  }
);
  mInjectedCurrentTimeLillis=START_TIME + 100;
  ArgumentCaptor<List> shortcuts;
  reset(c0);
  reset(c10);
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_1,USER_0));
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_1,USER_10));
  waitOnMainThread();
  verify(c0,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  verify(c10,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  reset(c0);
  reset(c10);
  updatePackageVersion(CALLING_PACKAGE_1,1);
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_1,USER_0));
  waitOnMainThread();
  shortcuts=ArgumentCaptor.forClass(List.class);
  verify(c0).onShortcutsChanged(eq(CALLING_PACKAGE_1),shortcuts.capture(),eq(HANDLE_USER_0));
  verify(c10,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  assertShortcutIds(shortcuts.getValue(),"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
  assertEquals(START_TIME,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  assertEquals(START_TIME + 100,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  assertEquals(START_TIME + 100,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  assertEquals(START_TIME,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  mInjectedCurrentTimeLillis=START_TIME + 200;
  doAnswer(new AnswerIsUserRunning(true)).when(mMockUserManager).isUserRunning(eq(USER_10));
  reset(c0);
  reset(c10);
  mService.handleUnlockUser(USER_10);
  shortcuts=ArgumentCaptor.forClass(List.class);
  verify(c0,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  verify(c10).onShortcutsChanged(eq(CALLING_PACKAGE_1),shortcuts.capture(),eq(HANDLE_USER_10));
  assertShortcutIds(shortcuts.getValue(),"String_Node_Str","String_Node_Str");
  assertEquals(START_TIME + 200,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  assertEquals(START_TIME + 200,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
  mInjectedCurrentTimeLillis=START_TIME + 300;
  reset(c0);
  reset(c10);
  updatePackageVersion(CALLING_PACKAGE_2,10);
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_2,USER_0));
  mService.handleUnlockUser(USER_10);
  waitOnMainThread();
  verify(c0,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  verify(c10,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_1),any(List.class),any(UserHandle.class));
  mInjectedCurrentTimeLillis=START_TIME + 400;
  reset(c0);
  reset(c10);
  updatePackageVersion(CALLING_PACKAGE_3,100);
  mService.mPackageMonitor.onReceive(getTestContext(),genPackageUpdateIntent(CALLING_PACKAGE_3,USER_0));
  mService.handleUnlockUser(USER_10);
  waitOnMainThread();
  shortcuts=ArgumentCaptor.forClass(List.class);
  verify(c0).onShortcutsChanged(eq(CALLING_PACKAGE_3),shortcuts.capture(),eq(HANDLE_USER_0));
  verify(c10,times(0)).onShortcutsChanged(eq(CALLING_PACKAGE_3),any(List.class),any(UserHandle.class));
  assertShortcutIds(shortcuts.getValue(),"String_Node_Str");
  assertEquals(START_TIME + 400,findShortcut(shortcuts.getValue(),"String_Node_Str").getLastChangedTimestamp());
}