@Test
@Config(minSdk = Build.VERSION_CODES.P)
public void testUnregisterAppUsageObserver_nonExistentObserverId_shouldBeNoOp() {
PendingIntent pendingIntent1 = PendingIntent.getBroadcast(context, 0, new Intent("ACTION1"), 0);
usageStatsManager.registerAppUsageObserver(
12, new String[] {"com.package1", "com.package2"}, 123L, TimeUnit.MINUTES, pendingIntent1);
PendingIntent pendingIntent2 = PendingIntent.getBroadcast(context, 0, new Intent("ACTION2"), 0);
usageStatsManager.registerAppUsageObserver(
24, new String[] {"com.package3"}, 456L, TimeUnit.SECONDS, pendingIntent2);
usageStatsManager.unregisterAppUsageObserver(36);
assertThat(shadowOf(usageStatsManager).getRegisteredAppUsageObservers())
.containsExactly(
new AppUsageObserver(
12,
ImmutableList.of("com.package1", "com.package2"),
123L,
TimeUnit.MINUTES,
pendingIntent1),
new AppUsageObserver(
24, ImmutableList.of("com.package3"), 456L, TimeUnit.SECONDS, pendingIntent2));
}