Search in sources :

Example 31 with UsageEvents

use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationBackend method recordAggregatedUsageEvents.

protected void recordAggregatedUsageEvents(Context context, AppRow appRow) {
    long now = System.currentTimeMillis();
    long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);
    UsageEvents events = null;
    try {
        events = sUsageStatsManager.queryEventsForPackageForUser(startTime, now, appRow.userId, appRow.pkg, context.getPackageName());
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    recordAggregatedUsageEvents(events, appRow);
}
Also used : UsageEvents(android.app.usage.UsageEvents) RemoteException(android.os.RemoteException)

Example 32 with UsageEvents

use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppStateNotificationBridgeTest method testGetAggregatedUsageEvents_onlyNotificationEvents.

@Test
public void testGetAggregatedUsageEvents_onlyNotificationEvents() throws Exception {
    List<Event> events = new ArrayList<>();
    Event good = new Event();
    good.mEventType = Event.NOTIFICATION_INTERRUPTION;
    good.mPackage = PKG1;
    good.mTimeStamp = 1;
    events.add(good);
    Event bad = new Event();
    bad.mEventType = Event.CHOOSER_ACTION;
    bad.mPackage = PKG1;
    bad.mTimeStamp = 2;
    events.add(bad);
    UsageEvents usageEvents = getUsageEvents(events);
    when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
    Map<String, NotificationsSentState> map = mBridge.getAggregatedUsageEvents();
    assertThat(map.get(AppStateNotificationBridge.getKey(0, PKG1)).sentCount).isEqualTo(1);
}
Also used : NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 33 with UsageEvents

use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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);
}
Also used : AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 34 with UsageEvents

use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppStateNotificationBridgeTest method testUpdateExtraInfo_multipleEventsAgg.

@Test
public void testUpdateExtraInfo_multipleEventsAgg() throws RemoteException {
    List<Event> events = new ArrayList<>();
    for (int i = 0; i < 13; i++) {
        Event good = new Event();
        good.mEventType = Event.NOTIFICATION_INTERRUPTION;
        good.mPackage = PKG1;
        good.mTimeStamp = i;
        events.add(good);
    }
    UsageEvents usageEvents = getUsageEvents(events);
    when(mUsageStats.queryEventsForPackageForUser(anyLong(), anyLong(), anyInt(), anyString(), anyString())).thenReturn(usageEvents);
    AppEntry entry = getMockAppEntry(PKG1);
    mBridge.updateExtraInfo(entry, "", 0);
    assertThat(((NotificationsSentState) entry.extraInfo).sentCount).isEqualTo(13);
    assertThat(((NotificationsSentState) entry.extraInfo).lastSent).isEqualTo(12);
    assertThat(((NotificationsSentState) entry.extraInfo).avgSentDaily).isEqualTo(2);
    assertThat(((NotificationsSentState) entry.extraInfo).avgSentWeekly).isEqualTo(0);
    assertThat(((NotificationsSentState) entry.extraInfo).blocked).isTrue();
    assertThat(((NotificationsSentState) entry.extraInfo).systemApp).isTrue();
    assertThat(((NotificationsSentState) entry.extraInfo).blockable).isTrue();
}
Also used : AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) NotificationsSentState(com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState) ArrayList(java.util.ArrayList) Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 35 with UsageEvents

use of android.app.usage.UsageEvents in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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);
}
Also used : Parcel(android.os.Parcel) UsageEvents(android.app.usage.UsageEvents)

Aggregations

UsageEvents (android.app.usage.UsageEvents)45 Event (android.app.usage.UsageEvents.Event)24 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)19 NotificationsSentState (com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState)14 AppEntry (com.android.settingslib.applications.ApplicationsState.AppEntry)8 RemoteException (android.os.RemoteException)7 Parcel (android.os.Parcel)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 ResolveInfo (android.content.pm.ResolveInfo)4 UsageStatsManager (android.app.usage.UsageStatsManager)3 Intent (android.content.Intent)3 ArrayMap (android.util.ArrayMap)3 MotionEvent (android.view.MotionEvent)3 Date (java.util.Date)3 SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 NotifyingApp (android.service.notification.NotifyingApp)2 NonNull (androidx.annotation.NonNull)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2