use of android.app.PendingIntent.CanceledException in project robolectric by robolectric.
the class ShadowUsageStatsManager method triggerRegisteredAppUsageObserver.
/**
* Triggers a currently registered {@link AppUsageObserver} with {@code observerId}.
*
* <p>The observer will be no longer registered afterwards.
*/
public void triggerRegisteredAppUsageObserver(int observerId, long timeUsedInMillis) {
AppUsageObserver observer = appUsageObserversById.remove(observerId);
long timeLimitInMillis = observer.getTimeUnit().toMillis(observer.getTimeLimit());
Intent intent = new Intent().putExtra(UsageStatsManager.EXTRA_OBSERVER_ID, observerId).putExtra(UsageStatsManager.EXTRA_TIME_LIMIT, timeLimitInMillis).putExtra(UsageStatsManager.EXTRA_TIME_USED, timeUsedInMillis);
try {
observer.getCallbackIntent().send(RuntimeEnvironment.getApplication(), 0, intent);
} catch (CanceledException e) {
throw new RuntimeException(e);
}
}
use of android.app.PendingIntent.CanceledException in project robolectric by robolectric.
the class ShadowUsageStatsManager method triggerRegisteredSessionStepObserver.
/**
* Triggers a currently registered {@link UsageSessionObserver} with {@code observerId}.
*
* <p>The observer SHOULD be registered afterwards.
*/
public void triggerRegisteredSessionStepObserver(int observerId, long timeUsedInMillis) {
UsageSessionObserver observer = usageSessionObserversById.get(observerId);
long sessionStepTimeInMillis = observer.getSessionStepDuration().toMillis();
Intent intent = new Intent().putExtra(UsageStatsManager.EXTRA_OBSERVER_ID, observerId).putExtra(UsageStatsManager.EXTRA_TIME_LIMIT, sessionStepTimeInMillis).putExtra(UsageStatsManager.EXTRA_TIME_USED, timeUsedInMillis);
try {
observer.getSessionStepTriggeredIntent().send(RuntimeEnvironment.getApplication(), 0, intent);
} catch (CanceledException e) {
throw new RuntimeException(e);
}
}
use of android.app.PendingIntent.CanceledException in project robolectric by robolectric.
the class ShadowUsageStatsManager method triggerRegisteredSessionEndedObserver.
/**
* Triggers a currently registered {@link UsageSessionObserver} with {@code observerId}.
*
* <p>The observer SHOULD be registered afterwards.
*/
public void triggerRegisteredSessionEndedObserver(int observerId) {
UsageSessionObserver observer = usageSessionObserversById.get(observerId);
Intent intent = new Intent().putExtra(UsageStatsManager.EXTRA_OBSERVER_ID, observerId);
try {
observer.getSessionEndedIntent().send(RuntimeEnvironment.getApplication(), 0, intent);
} catch (CanceledException e) {
throw new RuntimeException(e);
}
}
Aggregations