use of android.service.notification.NotifyingApp 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.service.notification.NotifyingApp 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.service.notification.NotifyingApp in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentNotifyingAppsPreferenceController method getDisplayableRecentAppList.
private List<NotifyingApp> getDisplayableRecentAppList() {
Collections.sort(mApps);
List<NotifyingApp> displayableApps = new ArrayList<>(SHOW_RECENT_APP_COUNT);
int count = 0;
for (NotifyingApp app : mApps) {
final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(app.getPackage(), app.getUserId());
if (appEntry == null) {
continue;
}
if (!shouldIncludePkgInRecents(app.getPackage(), app.getUserId())) {
continue;
}
displayableApps.add(app);
count++;
if (count >= SHOW_RECENT_APP_COUNT) {
break;
}
}
return displayableApps;
}
use of android.service.notification.NotifyingApp in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentNotifyingAppsPreferenceController method displayRecentApps.
private void displayRecentApps(Context prefContext, List<NotifyingApp> recentApps) {
mCategory.setTitle(R.string.recent_notifications);
mDivider.setVisible(true);
mSeeAllPref.setSummary(null);
mSeeAllPref.setIcon(R.drawable.ic_chevron_right_24dp);
// Rebind prefs/avoid adding new prefs if possible. Adding/removing prefs causes jank.
// Build a cached preference pool
final Map<String, NotificationAppPreference> appPreferences = new ArrayMap<>();
int prefCount = mCategory.getPreferenceCount();
for (int i = 0; i < prefCount; i++) {
final Preference pref = mCategory.getPreference(i);
final String key = pref.getKey();
if (!TextUtils.equals(key, KEY_SEE_ALL)) {
appPreferences.put(key, (NotificationAppPreference) pref);
}
}
final int recentAppsCount = recentApps.size();
for (int i = 0; i < recentAppsCount; i++) {
final NotifyingApp app = recentApps.get(i);
// Bind recent apps to existing prefs if possible, or create a new pref.
final String pkgName = app.getPackage();
final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(app.getPackage(), app.getUserId());
if (appEntry == null) {
continue;
}
boolean rebindPref = true;
NotificationAppPreference pref = appPreferences.remove(getKey(app.getUserId(), pkgName));
if (pref == null) {
pref = new NotificationAppPreference(prefContext);
rebindPref = false;
}
pref.setKey(getKey(app.getUserId(), pkgName));
pref.setTitle(appEntry.label);
pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL);
pref.setSummary(StringUtil.formatRelativeTime(mContext, System.currentTimeMillis() - app.getLastNotified(), true));
pref.setOrder(i);
Bundle args = new Bundle();
args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName);
args.putInt(AppInfoBase.ARG_PACKAGE_UID, appEntry.info.uid);
pref.setOnPreferenceClickListener(preference -> {
new SubSettingLauncher(mHost.getActivity()).setDestination(AppNotificationSettings.class.getName()).setTitleRes(R.string.notifications_title).setArguments(args).setUserHandle(new UserHandle(UserHandle.getUserId(appEntry.info.uid))).setSourceMetricsCategory(SettingsEnums.MANAGE_APPLICATIONS_NOTIFICATIONS).launch();
return true;
});
pref.setSwitchEnabled(mNotificationBackend.isBlockable(mContext, appEntry.info));
pref.setOnPreferenceChangeListener((preference, newValue) -> {
boolean blocked = !(Boolean) newValue;
mNotificationBackend.setNotificationsEnabledForPackage(pkgName, appEntry.info.uid, !blocked);
return true;
});
pref.setChecked(!mNotificationBackend.getNotificationsBanned(pkgName, appEntry.info.uid));
if (!rebindPref) {
mCategory.addPreference(pref);
}
}
// Remove unused prefs from pref cache pool
for (Preference unusedPrefs : appPreferences.values()) {
mCategory.removePreference(unusedPrefs);
}
}
Aggregations