Program: 191784
Project: 191784
Buggy source:
public void testLauncherCallback_crossProfile() throws Throwable {
  prepareCrossProfileDataSet();
  final Handler h=new Handler(Looper.getMainLooper());
  final LauncherApps.Callback c0_1=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c0_2=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c0_3=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c0_4=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback cP0_1=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c10_1=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c10_2=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c11_1=mock(LauncherApps.Callback.class);
  final List<LauncherApps.Callback> all=list(c0_1,c0_2,c0_3,c0_4,cP0_1,c10_1,c11_1);
  setDefaultLauncherChecker((pkg,userId) -> {
switch (userId) {
case USER_0:
      return LAUNCHER_2.equals(pkg);
case USER_P0:
    return LAUNCHER_1.equals(pkg);
case USER_10:
  return LAUNCHER_1.equals(pkg);
case USER_11:
return LAUNCHER_1.equals(pkg);
default :
return false;
}
}
);
runWithCaller(LAUNCHER_1,USER_0,() -> mLauncherApps.registerCallback(c0_1,h));
runWithCaller(LAUNCHER_2,USER_0,() -> mLauncherApps.registerCallback(c0_2,h));
runWithCaller(LAUNCHER_3,USER_0,() -> mLauncherApps.registerCallback(c0_3,h));
runWithCaller(LAUNCHER_4,USER_0,() -> mLauncherApps.registerCallback(c0_4,h));
runWithCaller(LAUNCHER_1,USER_P0,() -> mLauncherApps.registerCallback(cP0_1,h));
runWithCaller(LAUNCHER_1,USER_10,() -> mLauncherApps.registerCallback(c10_1,h));
runWithCaller(LAUNCHER_2,USER_10,() -> mLauncherApps.registerCallback(c10_2,h));
runWithCaller(LAUNCHER_1,USER_11,() -> mLauncherApps.registerCallback(c11_1,h));
resetAll(all);
runWithCaller(CALLING_PACKAGE_1,USER_0,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(c10_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
assertCallbackReceived(c0_2,HANDLE_USER_0,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str");
assertCallbackReceived(cP0_1,HANDLE_USER_0,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
resetAll(all);
runWithCaller(CALLING_PACKAGE_3,USER_0,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(c10_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
assertCallbackReceived(c0_2,HANDLE_USER_0,CALLING_PACKAGE_3,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
assertCallbackReceived(cP0_1,HANDLE_USER_0,CALLING_PACKAGE_3,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
resetAll(all);
runWithCaller(CALLING_PACKAGE_1,USER_P0,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_2);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(cP0_1);
assertCallbackNotReceived(c10_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
when(mMockUserManager.isUserRunning(anyInt())).thenReturn(false);
when(mMockUserManager.isUserRunning(eq(USER_P0))).thenReturn(true);
resetAll(all);
runWithCaller(CALLING_PACKAGE_1,USER_P0,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(c10_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
assertCallbackReceived(c0_2,HANDLE_USER_P0,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
assertCallbackReceived(cP0_1,HANDLE_USER_P0,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
when(mMockUserManager.isUserRunning(anyInt())).thenReturn(false);
when(mMockUserManager.isUserRunning(eq(USER_10))).thenReturn(true);
resetAll(all);
runWithCaller(CALLING_PACKAGE_1,USER_10,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_2);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(cP0_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
assertCallbackReceived(c10_1,HANDLE_USER_10,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
}

Fixed version (ground truth):
public void testLauncherCallback_crossProfile() throws Throwable {
  prepareCrossProfileDataSet();
  final Handler h=new Handler(Looper.getMainLooper());
  final LauncherApps.Callback c0_1=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c0_2=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c0_3=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c0_4=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback cP0_1=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c10_1=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c10_2=mock(LauncherApps.Callback.class);
  final LauncherApps.Callback c11_1=mock(LauncherApps.Callback.class);
  final List<LauncherApps.Callback> all=list(c0_1,c0_2,c0_3,c0_4,cP0_1,c10_1,c11_1);
  setDefaultLauncherChecker((pkg,userId) -> {
switch (userId) {
case USER_0:
      return LAUNCHER_2.equals(pkg);
case USER_P0:
    return LAUNCHER_1.equals(pkg);
case USER_10:
  return LAUNCHER_1.equals(pkg);
case USER_11:
return LAUNCHER_1.equals(pkg);
default :
return false;
}
}
);
runWithCaller(LAUNCHER_1,USER_0,() -> mLauncherApps.registerCallback(c0_1,h));
runWithCaller(LAUNCHER_2,USER_0,() -> mLauncherApps.registerCallback(c0_2,h));
runWithCaller(LAUNCHER_3,USER_0,() -> mLauncherApps.registerCallback(c0_3,h));
runWithCaller(LAUNCHER_4,USER_0,() -> mLauncherApps.registerCallback(c0_4,h));
runWithCaller(LAUNCHER_1,USER_P0,() -> mLauncherApps.registerCallback(cP0_1,h));
runWithCaller(LAUNCHER_1,USER_10,() -> mLauncherApps.registerCallback(c10_1,h));
runWithCaller(LAUNCHER_2,USER_10,() -> mLauncherApps.registerCallback(c10_2,h));
runWithCaller(LAUNCHER_1,USER_11,() -> mLauncherApps.registerCallback(c11_1,h));
resetAll(all);
runWithCaller(CALLING_PACKAGE_1,USER_0,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(c10_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
assertCallbackReceived(c0_2,HANDLE_USER_0,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str");
assertCallbackReceived(cP0_1,HANDLE_USER_0,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
resetAll(all);
runWithCaller(CALLING_PACKAGE_3,USER_0,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(c10_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
assertCallbackReceived(c0_2,HANDLE_USER_0,CALLING_PACKAGE_3,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
assertCallbackReceived(cP0_1,HANDLE_USER_0,CALLING_PACKAGE_3,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
resetAll(all);
runWithCaller(CALLING_PACKAGE_1,USER_P0,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_2);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(cP0_1);
assertCallbackNotReceived(c10_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
doAnswer(new AnswerIsUserRunning(false)).when(mMockUserManager).isUserRunning(anyInt());
doAnswer(new AnswerIsUserRunning(true)).when(mMockUserManager).isUserRunning(eq(USER_P0));
resetAll(all);
runWithCaller(CALLING_PACKAGE_1,USER_P0,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(c10_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
assertCallbackReceived(c0_2,HANDLE_USER_P0,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
assertCallbackReceived(cP0_1,HANDLE_USER_P0,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
doAnswer(new AnswerIsUserRunning(false)).when(mMockUserManager).isUserRunning(anyInt());
doAnswer(new AnswerIsUserRunning(true)).when(mMockUserManager).isUserRunning(eq(USER_10));
resetAll(all);
runWithCaller(CALLING_PACKAGE_1,USER_10,() -> {
mManager.removeDynamicShortcuts(list());
}
);
waitOnMainThread();
assertCallbackNotReceived(c0_1);
assertCallbackNotReceived(c0_2);
assertCallbackNotReceived(c0_3);
assertCallbackNotReceived(c0_4);
assertCallbackNotReceived(cP0_1);
assertCallbackNotReceived(c10_2);
assertCallbackNotReceived(c11_1);
assertCallbackReceived(c10_1,HANDLE_USER_10,CALLING_PACKAGE_1,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
}