use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NotificationBackendTest method getUsageEvents.
private UsageEvents getUsageEvents(List<UsageEvents.Event> events) {
UsageEvents usageEvents = new UsageEvents(events, new String[] { "pkg" });
Parcel parcel = Parcel.obtain();
parcel.setDataPosition(0);
usageEvents.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
return UsageEvents.CREATOR.createFromParcel(parcel);
}
use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentNotifyingAppsPreferenceControllerTest method display_showRecents.
@Test
public void display_showRecents() throws Exception {
List<Event> events = new ArrayList<>();
Event app = new Event();
app.mEventType = Event.NOTIFICATION_INTERRUPTION;
app.mPackage = "a";
app.mTimeStamp = System.currentTimeMillis();
events.add(app);
Event app1 = new Event();
app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
app1.mPackage = "com.android.settings";
app1.mTimeStamp = System.currentTimeMillis();
events.add(app1);
Event app2 = new Event();
app2.mEventType = Event.NOTIFICATION_INTERRUPTION;
app2.mPackage = "pkg.class2";
app2.mTimeStamp = System.currentTimeMillis() - 1000;
events.add(app2);
// app1, app2 are valid apps. app3 is invalid.
when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId())).thenReturn(mAppEntry);
when(mAppState.getEntry(app1.getPackageName(), UserHandle.myUserId())).thenReturn(mAppEntry);
when(mAppState.getEntry(app2.getPackageName(), UserHandle.myUserId())).thenReturn(null);
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(new ResolveInfo());
UsageEvents usageEvents = getUsageEvents(new String[] { app.getPackageName(), app1.getPackageName(), app2.getPackageName() }, events);
when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
mAppEntry.info = mApplicationInfo;
mController.displayPreference(mScreen);
verify(mCategory).setTitle(R.string.recent_notifications);
// Only add app1 & app2. app3 skipped because it's invalid app.
verify(mCategory, times(2)).addPreference(any(Preference.class));
verify(mSeeAllPref).setSummary(null);
verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp);
verify(mDivider).setVisible(true);
}
use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppStateNotificationBridge method getAggregatedUsageEvents.
protected NotificationsSentState getAggregatedUsageEvents(int userId, String pkg) {
NotificationsSentState stats = null;
long now = System.currentTimeMillis();
long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);
UsageEvents events = null;
try {
events = mUsageStatsManager.queryEventsForPackageForUser(startTime, now, userId, pkg, mContext.getPackageName());
} catch (RemoteException e) {
e.printStackTrace();
}
if (events != null) {
UsageEvents.Event event = new UsageEvents.Event();
while (events.hasNextEvent()) {
events.getNextEvent(event);
if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
if (stats == null) {
stats = new NotificationsSentState();
}
if (event.getTimeStamp() > stats.lastSent) {
stats.lastSent = event.getTimeStamp();
}
stats.sentCount++;
}
}
}
return stats;
}
use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppStateNotificationBridge method getAggregatedUsageEvents.
protected Map<String, NotificationsSentState> getAggregatedUsageEvents() {
ArrayMap<String, NotificationsSentState> aggregatedStats = new ArrayMap<>();
long now = System.currentTimeMillis();
long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);
for (int userId : mUserIds) {
UsageEvents events = null;
try {
events = mUsageStatsManager.queryEventsForUser(startTime, now, userId, mContext.getPackageName());
} catch (RemoteException e) {
e.printStackTrace();
}
if (events != null) {
UsageEvents.Event event = new UsageEvents.Event();
while (events.hasNextEvent()) {
events.getNextEvent(event);
NotificationsSentState stats = aggregatedStats.get(getKey(userId, event.getPackageName()));
if (stats == null) {
stats = new NotificationsSentState();
aggregatedStats.put(getKey(userId, event.getPackageName()), stats);
}
if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
if (event.getTimeStamp() > stats.lastSent) {
stats.lastSent = event.getTimeStamp();
}
stats.sentCount++;
}
}
}
}
return aggregatedStats;
}
use of android.app.usage.UsageEvents in project Signal-Android by signalapp.
the class BucketInfo method getInfo.
@NonNull
public static BucketInfo getInfo(@NonNull UsageStatsManager usageStatsManager, long overLastDurationMs) {
StringBuilder stringBuilder = new StringBuilder();
int currentBucket = usageStatsManager.getAppStandbyBucket();
int worseBucket = currentBucket;
int bestBucket = currentBucket;
long now = System.currentTimeMillis();
UsageEvents.Event event = new UsageEvents.Event();
UsageEvents usageEvents = usageStatsManager.queryEventsForSelf(now - overLastDurationMs, now);
while (usageEvents.hasNextEvent()) {
usageEvents.getNextEvent(event);
if (event.getEventType() == UsageEvents.Event.STANDBY_BUCKET_CHANGED) {
int appStandbyBucket = event.getAppStandbyBucket();
stringBuilder.append(new Date(event.getTimeStamp())).append(": ").append("Bucket Change: ").append(bucketToString(appStandbyBucket)).append("\n");
if (appStandbyBucket > worseBucket) {
worseBucket = appStandbyBucket;
}
if (appStandbyBucket < bestBucket) {
bestBucket = appStandbyBucket;
}
}
}
return new BucketInfo(currentBucket, worseBucket, bestBucket, stringBuilder);
}
Aggregations