use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentNotifyingAppsPreferenceControllerTest method reloadData.
@Test
public void reloadData() throws Exception {
when(mUserManager.getProfileIdsWithDisabled(0)).thenReturn(new int[] { 0, 10 });
mController = new RecentNotifyingAppsPreferenceController(mContext, mBackend, mIUsageStatsManager, mUserManager, mAppState, mHost);
List<Event> events = new ArrayList<>();
Event app = new Event();
app.mEventType = Event.NOTIFICATION_INTERRUPTION;
app.mPackage = "b";
app.mTimeStamp = 1;
events.add(app);
Event app1 = new Event();
app1.mEventType = Event.MAX_EVENT_TYPE;
app1.mPackage = "com.foo.bar";
app1.mTimeStamp = 10;
events.add(app1);
UsageEvents usageEvents = getUsageEvents(new String[] { "b", "com.foo.bar" }, events);
when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), eq(0), anyString())).thenReturn(usageEvents);
List<Event> events10 = new ArrayList<>();
Event app10 = new Event();
app10.mEventType = Event.NOTIFICATION_INTERRUPTION;
app10.mPackage = "a";
app10.mTimeStamp = 2;
events10.add(app10);
Event app10a = new Event();
app10a.mEventType = Event.NOTIFICATION_INTERRUPTION;
app10a.mPackage = "a";
app10a.mTimeStamp = 20;
events10.add(app10a);
UsageEvents usageEvents10 = getUsageEvents(new String[] { "a" }, events10);
when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), eq(10), anyString())).thenReturn(usageEvents10);
mController.reloadData();
assertThat(mController.mApps.size()).isEqualTo(2);
boolean foundPkg0 = false;
boolean foundPkg10 = false;
for (NotifyingApp notifyingApp : mController.mApps) {
if (notifyingApp.getLastNotified() == 20 && notifyingApp.getPackage().equals("a") && notifyingApp.getUserId() == 10) {
foundPkg10 = true;
}
if (notifyingApp.getLastNotified() == 1 && notifyingApp.getPackage().equals("b") && notifyingApp.getUserId() == 0) {
foundPkg0 = true;
}
}
assertThat(foundPkg0).isTrue();
assertThat(foundPkg10).isTrue();
}
use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentNotifyingAppsPreferenceControllerTest method display_showRecentsWithInstantApp.
@Test
public void display_showRecentsWithInstantApp() throws Exception {
List<Event> events = new ArrayList<>();
Event app = new Event();
app.mEventType = Event.NOTIFICATION_INTERRUPTION;
app.mPackage = "com.foo.bar";
app.mTimeStamp = System.currentTimeMillis();
events.add(app);
Event app1 = new Event();
app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
app1.mPackage = "com.foo.barinstant";
app1.mTimeStamp = System.currentTimeMillis() + 200;
events.add(app1);
UsageEvents usageEvents = getUsageEvents(new String[] { "com.foo.bar", "com.foo.barinstant" }, events);
when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
ApplicationsState.AppEntry app1Entry = mock(ApplicationsState.AppEntry.class);
ApplicationsState.AppEntry app2Entry = mock(ApplicationsState.AppEntry.class);
app1Entry.info = mApplicationInfo;
app2Entry.info = mApplicationInfo;
when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId())).thenReturn(app1Entry);
when(mAppState.getEntry(app1.getPackageName(), UserHandle.myUserId())).thenReturn(app2Entry);
// Only the regular app app1 should have its intent resolve.
when(mPackageManager.resolveActivity(argThat(intentMatcher(app.getPackageName())), anyInt())).thenReturn(new ResolveInfo());
// Make sure app2 is considered an instant app.
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider", (InstantAppDataProvider) (ApplicationInfo info) -> {
if (info == app2Entry.info) {
return true;
} else {
return false;
}
});
mController.displayPreference(mScreen);
ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mCategory, times(2)).addPreference(prefCaptor.capture());
List<Preference> prefs = prefCaptor.getAllValues();
assertThat(prefs.get(1).getKey()).isEqualTo(RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app.getPackageName()));
assertThat(prefs.get(0).getKey()).isEqualTo(RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app1.getPackageName()));
}
use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentNotifyingAppsPreferenceControllerTest method getUsageEvents.
private UsageEvents getUsageEvents(String[] pkgs, List<Event> events) {
UsageEvents usageEvents = new UsageEvents(events, pkgs);
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 RecentNotifyingAppsPreferenceController method reloadData.
@VisibleForTesting
void reloadData() {
mApps = new ArrayList<>();
mCal = Calendar.getInstance();
mCal.add(Calendar.DAY_OF_YEAR, -DAYS);
for (int userId : mUserIds) {
UsageEvents events = null;
try {
events = mUsageStatsManager.queryEventsForUser(mCal.getTimeInMillis(), System.currentTimeMillis(), userId, mContext.getPackageName());
} catch (RemoteException e) {
e.printStackTrace();
}
if (events != null) {
ArrayMap<String, NotifyingApp> aggregatedStats = new ArrayMap<>();
UsageEvents.Event event = new UsageEvents.Event();
while (events.hasNextEvent()) {
events.getNextEvent(event);
if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
NotifyingApp app = aggregatedStats.get(getKey(userId, event.getPackageName()));
if (app == null) {
app = new NotifyingApp();
aggregatedStats.put(getKey(userId, event.getPackageName()), app);
app.setPackage(event.getPackageName());
app.setUserId(userId);
}
if (event.getTimeStamp() > app.getLastNotified()) {
app.setLastNotified(event.getTimeStamp());
}
}
}
mApps.addAll(aggregatedStats.values());
}
}
}
use of android.app.usage.UsageEvents in project android_packages_apps_Settings by omnirom.
the class AppStateNotificationBridgeTest method getUsageEvents.
private UsageEvents getUsageEvents(List<Event> events) {
UsageEvents usageEvents = new UsageEvents(events, new String[] { PKG1, PKG2 });
Parcel parcel = Parcel.obtain();
parcel.setDataPosition(0);
usageEvents.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
return UsageEvents.CREATOR.createFromParcel(parcel);
}
Aggregations