use of android.app.usage.UsageEvents.Event in project android_packages_apps_Settings by omnirom.
the class AppStateNotificationBridgeTest method testLoadAllExtraInfo_multiplePkgs.
@Test
public void testLoadAllExtraInfo_multiplePkgs() throws RemoteException {
List<Event> events = new ArrayList<>();
for (int i = 0; i < 8; i++) {
Event good = new Event();
good.mEventType = Event.NOTIFICATION_INTERRUPTION;
good.mPackage = PKG1;
good.mTimeStamp = i;
events.add(good);
}
Event good1 = new Event();
good1.mEventType = Event.NOTIFICATION_INTERRUPTION;
good1.mPackage = PKG2;
good1.mTimeStamp = 1;
events.add(good1);
UsageEvents usageEvents = getUsageEvents(events);
when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
ArrayList<AppEntry> apps = new ArrayList<>();
apps.add(getMockAppEntry(PKG1));
apps.add(getMockAppEntry(PKG2));
when(mSession.getAllApps()).thenReturn(apps);
mBridge.loadAllExtraInfo();
assertThat(((NotificationsSentState) apps.get(0).extraInfo).sentCount).isEqualTo(8);
assertThat(((NotificationsSentState) apps.get(0).extraInfo).lastSent).isEqualTo(7);
assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentWeekly).isEqualTo(0);
assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentDaily).isEqualTo(1);
assertThat(((NotificationsSentState) apps.get(1).extraInfo).sentCount).isEqualTo(1);
assertThat(((NotificationsSentState) apps.get(1).extraInfo).lastSent).isEqualTo(1);
assertThat(((NotificationsSentState) apps.get(1).extraInfo).avgSentWeekly).isEqualTo(1);
assertThat(((NotificationsSentState) apps.get(1).extraInfo).avgSentDaily).isEqualTo(0);
}
use of android.app.usage.UsageEvents.Event in project platform_frameworks_base by android.
the class UserUsageStatsService method printIntervalStats.
void printIntervalStats(IndentingPrintWriter pw, IntervalStats stats, boolean prettyDates) {
if (prettyDates) {
pw.printPair("timeRange", "\"" + DateUtils.formatDateRange(mContext, stats.beginTime, stats.endTime, sDateFormatFlags) + "\"");
} else {
pw.printPair("beginTime", stats.beginTime);
pw.printPair("endTime", stats.endTime);
}
pw.println();
pw.increaseIndent();
pw.println("packages");
pw.increaseIndent();
final ArrayMap<String, UsageStats> pkgStats = stats.packageStats;
final int pkgCount = pkgStats.size();
for (int i = 0; i < pkgCount; i++) {
final UsageStats usageStats = pkgStats.valueAt(i);
pw.printPair("package", usageStats.mPackageName);
pw.printPair("totalTime", formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates));
pw.printPair("lastTime", formatDateTime(usageStats.mLastTimeUsed, prettyDates));
pw.println();
}
pw.decreaseIndent();
pw.println("configurations");
pw.increaseIndent();
final ArrayMap<Configuration, ConfigurationStats> configStats = stats.configurations;
final int configCount = configStats.size();
for (int i = 0; i < configCount; i++) {
final ConfigurationStats config = configStats.valueAt(i);
pw.printPair("config", Configuration.resourceQualifierString(config.mConfiguration));
pw.printPair("totalTime", formatElapsedTime(config.mTotalTimeActive, prettyDates));
pw.printPair("lastTime", formatDateTime(config.mLastTimeActive, prettyDates));
pw.printPair("count", config.mActivationCount);
pw.println();
}
pw.decreaseIndent();
pw.println("events");
pw.increaseIndent();
final TimeSparseArray<UsageEvents.Event> events = stats.events;
final int eventCount = events != null ? events.size() : 0;
for (int i = 0; i < eventCount; i++) {
final UsageEvents.Event event = events.valueAt(i);
pw.printPair("time", formatDateTime(event.mTimeStamp, prettyDates));
pw.printPair("type", eventToString(event.mEventType));
pw.printPair("package", event.mPackage);
if (event.mClass != null) {
pw.printPair("class", event.mClass);
}
if (event.mConfiguration != null) {
pw.printPair("config", Configuration.resourceQualifierString(event.mConfiguration));
}
if (event.mShortcutId != null) {
pw.printPair("shortcutId", event.mShortcutId);
}
pw.println();
}
pw.decreaseIndent();
pw.decreaseIndent();
}
use of android.app.usage.UsageEvents.Event in project android_frameworks_base by DirtyUnicorns.
the class UserUsageStatsService method printIntervalStats.
void printIntervalStats(IndentingPrintWriter pw, IntervalStats stats, boolean prettyDates) {
if (prettyDates) {
pw.printPair("timeRange", "\"" + DateUtils.formatDateRange(mContext, stats.beginTime, stats.endTime, sDateFormatFlags) + "\"");
} else {
pw.printPair("beginTime", stats.beginTime);
pw.printPair("endTime", stats.endTime);
}
pw.println();
pw.increaseIndent();
pw.println("packages");
pw.increaseIndent();
final ArrayMap<String, UsageStats> pkgStats = stats.packageStats;
final int pkgCount = pkgStats.size();
for (int i = 0; i < pkgCount; i++) {
final UsageStats usageStats = pkgStats.valueAt(i);
pw.printPair("package", usageStats.mPackageName);
pw.printPair("totalTime", formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates));
pw.printPair("lastTime", formatDateTime(usageStats.mLastTimeUsed, prettyDates));
pw.println();
}
pw.decreaseIndent();
pw.println("configurations");
pw.increaseIndent();
final ArrayMap<Configuration, ConfigurationStats> configStats = stats.configurations;
final int configCount = configStats.size();
for (int i = 0; i < configCount; i++) {
final ConfigurationStats config = configStats.valueAt(i);
pw.printPair("config", Configuration.resourceQualifierString(config.mConfiguration));
pw.printPair("totalTime", formatElapsedTime(config.mTotalTimeActive, prettyDates));
pw.printPair("lastTime", formatDateTime(config.mLastTimeActive, prettyDates));
pw.printPair("count", config.mActivationCount);
pw.println();
}
pw.decreaseIndent();
pw.println("events");
pw.increaseIndent();
final TimeSparseArray<UsageEvents.Event> events = stats.events;
final int eventCount = events != null ? events.size() : 0;
for (int i = 0; i < eventCount; i++) {
final UsageEvents.Event event = events.valueAt(i);
pw.printPair("time", formatDateTime(event.mTimeStamp, prettyDates));
pw.printPair("type", eventToString(event.mEventType));
pw.printPair("package", event.mPackage);
if (event.mClass != null) {
pw.printPair("class", event.mClass);
}
if (event.mConfiguration != null) {
pw.printPair("config", Configuration.resourceQualifierString(event.mConfiguration));
}
if (event.mShortcutId != null) {
pw.printPair("shortcutId", event.mShortcutId);
}
pw.println();
}
pw.decreaseIndent();
pw.decreaseIndent();
}
use of android.app.usage.UsageEvents.Event in project android_frameworks_base by ResurrectionRemix.
the class UserUsageStatsService method printIntervalStats.
void printIntervalStats(IndentingPrintWriter pw, IntervalStats stats, boolean prettyDates) {
if (prettyDates) {
pw.printPair("timeRange", "\"" + DateUtils.formatDateRange(mContext, stats.beginTime, stats.endTime, sDateFormatFlags) + "\"");
} else {
pw.printPair("beginTime", stats.beginTime);
pw.printPair("endTime", stats.endTime);
}
pw.println();
pw.increaseIndent();
pw.println("packages");
pw.increaseIndent();
final ArrayMap<String, UsageStats> pkgStats = stats.packageStats;
final int pkgCount = pkgStats.size();
for (int i = 0; i < pkgCount; i++) {
final UsageStats usageStats = pkgStats.valueAt(i);
pw.printPair("package", usageStats.mPackageName);
pw.printPair("totalTime", formatElapsedTime(usageStats.mTotalTimeInForeground, prettyDates));
pw.printPair("lastTime", formatDateTime(usageStats.mLastTimeUsed, prettyDates));
pw.println();
}
pw.decreaseIndent();
pw.println("configurations");
pw.increaseIndent();
final ArrayMap<Configuration, ConfigurationStats> configStats = stats.configurations;
final int configCount = configStats.size();
for (int i = 0; i < configCount; i++) {
final ConfigurationStats config = configStats.valueAt(i);
pw.printPair("config", Configuration.resourceQualifierString(config.mConfiguration));
pw.printPair("totalTime", formatElapsedTime(config.mTotalTimeActive, prettyDates));
pw.printPair("lastTime", formatDateTime(config.mLastTimeActive, prettyDates));
pw.printPair("count", config.mActivationCount);
pw.println();
}
pw.decreaseIndent();
pw.println("events");
pw.increaseIndent();
final TimeSparseArray<UsageEvents.Event> events = stats.events;
final int eventCount = events != null ? events.size() : 0;
for (int i = 0; i < eventCount; i++) {
final UsageEvents.Event event = events.valueAt(i);
pw.printPair("time", formatDateTime(event.mTimeStamp, prettyDates));
pw.printPair("type", eventToString(event.mEventType));
pw.printPair("package", event.mPackage);
if (event.mClass != null) {
pw.printPair("class", event.mClass);
}
if (event.mConfiguration != null) {
pw.printPair("config", Configuration.resourceQualifierString(event.mConfiguration));
}
if (event.mShortcutId != null) {
pw.printPair("shortcutId", event.mShortcutId);
}
pw.println();
}
pw.decreaseIndent();
pw.decreaseIndent();
}
use of android.app.usage.UsageEvents.Event in project robolectric by robolectric.
the class ShadowUsageStatsManagerTest method testQueryEventsForSelf_shouldReturnsEventsForCurrentPackageOnly.
@Test
@Config(minSdk = Build.VERSION_CODES.P)
public void testQueryEventsForSelf_shouldReturnsEventsForCurrentPackageOnly() {
String packageName = context.getOpPackageName();
shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(1500L).setPackage(TEST_PACKAGE_NAME2).setClass(TEST_ACTIVITY_NAME).setEventType(Event.ACTIVITY_PAUSED).build());
shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(2200L).setPackage(packageName).setEventType(Event.ACTIVITY_RESUMED).setClass(TEST_ACTIVITY_NAME).build());
shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(2500L).setPackage(TEST_PACKAGE_NAME1).setEventType(Event.ACTIVITY_RESUMED).setClass(TEST_ACTIVITY_NAME).build());
shadowOf(usageStatsManager).addEvent(ShadowUsageStatsManager.EventBuilder.buildEvent().setTimeStamp(2800L).setPackage(packageName).setEventType(Event.ACTIVITY_STOPPED).setClass(TEST_ACTIVITY_NAME).build());
UsageEvents events = usageStatsManager.queryEventsForSelf(0L, 3000L);
Event event = new Event();
assertThat(events.hasNextEvent()).isTrue();
assertThat(events.getNextEvent(event)).isTrue();
assertThat(event.getPackageName()).isEqualTo(packageName);
assertThat(event.getTimeStamp()).isEqualTo(2200L);
assertThat(event.getEventType()).isEqualTo(Event.ACTIVITY_RESUMED);
assertThat(events.hasNextEvent()).isTrue();
assertThat(events.getNextEvent(event)).isTrue();
assertThat(event.getPackageName()).isEqualTo(packageName);
assertThat(event.getTimeStamp()).isEqualTo(2800L);
assertThat(event.getEventType()).isEqualTo(Event.ACTIVITY_STOPPED);
assertThat(events.hasNextEvent()).isFalse();
}
Aggregations