use of android.app.usage.UsageEvents in project android_packages_apps_Settings by omnirom.
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 Taskbar by farmerbb.
the class TaskbarController method filterForegroundApp.
@TargetApi(Build.VERSION_CODES.M)
@VisibleForTesting
void filterForegroundApp(Context context, SharedPreferences pref, long searchInterval, List<String> applicationIdsToRemove) {
if (pref.getBoolean(PREF_HIDE_FOREGROUND, false)) {
UsageStatsManager mUsageStatsManager = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
UsageEvents events = mUsageStatsManager.queryEvents(searchInterval, System.currentTimeMillis());
UsageEvents.Event eventCache = new UsageEvents.Event();
String currentForegroundApp = null;
while (events.hasNextEvent()) {
events.getNextEvent(eventCache);
if (eventCache.getEventType() == UsageEvents.Event.MOVE_TO_FOREGROUND) {
if (!(eventCache.getPackageName().contains(BuildConfig.BASE_APPLICATION_ID) && !eventCache.getClassName().equals(MainActivity.class.getCanonicalName()) && !eventCache.getClassName().equals(HomeActivity.class.getCanonicalName()) && !eventCache.getClassName().equals(HomeActivityDelegate.class.getCanonicalName()) && !eventCache.getClassName().equals(SecondaryHomeActivity.class.getCanonicalName()) && !eventCache.getClassName().equals(InvisibleActivityFreeform.class.getCanonicalName()))) {
currentForegroundApp = eventCache.getPackageName();
}
}
}
if (!applicationIdsToRemove.contains(currentForegroundApp)) {
applicationIdsToRemove.add(currentForegroundApp);
}
}
}
use of android.app.usage.UsageEvents in project android_frameworks_base by ResurrectionRemix.
the class UsageLogActivity method run.
@Override
public void run() {
long now = System.currentTimeMillis();
UsageEvents events = mUsageStatsManager.queryEvents(mLastTime, now);
long lastEventTime = mAdapter.update(events);
if (lastEventTime >= 0) {
mLastTime = lastEventTime + 1;
}
mHandler.postDelayed(this, 1000 * 5);
}
use of android.app.usage.UsageEvents in project platform_frameworks_base by android.
the class UsageLogActivity method run.
@Override
public void run() {
long now = System.currentTimeMillis();
UsageEvents events = mUsageStatsManager.queryEvents(mLastTime, now);
long lastEventTime = mAdapter.update(events);
if (lastEventTime >= 0) {
mLastTime = lastEventTime + 1;
}
mHandler.postDelayed(this, 1000 * 5);
}
use of android.app.usage.UsageEvents in project Signal-Android by WhisperSystems.
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