@Test public void shouldContinueAfterFilter_TestFilterNone_MustReturnTrue() { String body = "A text without a meaning"; NotificationFilter filter = new NotificationFilter(); filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_NONE); assertTrue(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter)); }
boolean shouldContinueAfterFilter(String body, @NonNull List<String> wordsList, @NonNull NotificationFilter notificationFilter) { LOG.debug("Mode: '{}' Submode: '{}' WordsList: '{}'", notificationFilter.getNotificationFilterMode(), notificationFilter.getNotificationFilterSubMode(), wordsList); boolean allMode = notificationFilter.getNotificationFilterSubMode() == NOTIFICATION_FILTER_SUBMODE_ALL; switch (notificationFilter.getNotificationFilterMode()) { case NOTIFICATION_FILTER_MODE_BLACKLIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, blacklist has no effect, processing continues."); return true; } } LOG.info("Every word was found, blacklist has effect, processing stops."); return false; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (!containsAny) { LOG.info("No matching word was found, blacklist has no effect, processing continues."); } else { LOG.info("At least one matching word was found, blacklist has effect, processing stops."); } return !containsAny; } case NOTIFICATION_FILTER_MODE_WHITELIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, whitelist has no effect, processing stops."); return false; } } LOG.info("Every word was found, whitelist has effect, processing continues."); return true; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (containsAny) { LOG.info("At least one matching word was found, whitelist has effect, processing continues."); } else { LOG.info("No matching word was found, whitelist has no effect, processing stops."); } return containsAny; } default: return true; } }
NotificationListener extends NotificationListenerService { boolean shouldContinueAfterFilter(String body, @NonNull List<String> wordsList, @NonNull NotificationFilter notificationFilter) { LOG.debug("Mode: '{}' Submode: '{}' WordsList: '{}'", notificationFilter.getNotificationFilterMode(), notificationFilter.getNotificationFilterSubMode(), wordsList); boolean allMode = notificationFilter.getNotificationFilterSubMode() == NOTIFICATION_FILTER_SUBMODE_ALL; switch (notificationFilter.getNotificationFilterMode()) { case NOTIFICATION_FILTER_MODE_BLACKLIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, blacklist has no effect, processing continues."); return true; } } LOG.info("Every word was found, blacklist has effect, processing stops."); return false; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (!containsAny) { LOG.info("No matching word was found, blacklist has no effect, processing continues."); } else { LOG.info("At least one matching word was found, blacklist has effect, processing stops."); } return !containsAny; } case NOTIFICATION_FILTER_MODE_WHITELIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, whitelist has no effect, processing stops."); return false; } } LOG.info("Every word was found, whitelist has effect, processing continues."); return true; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (containsAny) { LOG.info("At least one matching word was found, whitelist has effect, processing continues."); } else { LOG.info("No matching word was found, whitelist has no effect, processing stops."); } return containsAny; } default: return true; } } }
NotificationListener extends NotificationListenerService { boolean shouldContinueAfterFilter(String body, @NonNull List<String> wordsList, @NonNull NotificationFilter notificationFilter) { LOG.debug("Mode: '{}' Submode: '{}' WordsList: '{}'", notificationFilter.getNotificationFilterMode(), notificationFilter.getNotificationFilterSubMode(), wordsList); boolean allMode = notificationFilter.getNotificationFilterSubMode() == NOTIFICATION_FILTER_SUBMODE_ALL; switch (notificationFilter.getNotificationFilterMode()) { case NOTIFICATION_FILTER_MODE_BLACKLIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, blacklist has no effect, processing continues."); return true; } } LOG.info("Every word was found, blacklist has effect, processing stops."); return false; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (!containsAny) { LOG.info("No matching word was found, blacklist has no effect, processing continues."); } else { LOG.info("At least one matching word was found, blacklist has effect, processing stops."); } return !containsAny; } case NOTIFICATION_FILTER_MODE_WHITELIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, whitelist has no effect, processing stops."); return false; } } LOG.info("Every word was found, whitelist has effect, processing continues."); return true; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (containsAny) { LOG.info("At least one matching word was found, whitelist has effect, processing continues."); } else { LOG.info("No matching word was found, whitelist has no effect, processing stops."); } return containsAny; } default: return true; } }  }
NotificationListener extends NotificationListenerService { boolean shouldContinueAfterFilter(String body, @NonNull List<String> wordsList, @NonNull NotificationFilter notificationFilter) { LOG.debug("Mode: '{}' Submode: '{}' WordsList: '{}'", notificationFilter.getNotificationFilterMode(), notificationFilter.getNotificationFilterSubMode(), wordsList); boolean allMode = notificationFilter.getNotificationFilterSubMode() == NOTIFICATION_FILTER_SUBMODE_ALL; switch (notificationFilter.getNotificationFilterMode()) { case NOTIFICATION_FILTER_MODE_BLACKLIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, blacklist has no effect, processing continues."); return true; } } LOG.info("Every word was found, blacklist has effect, processing stops."); return false; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (!containsAny) { LOG.info("No matching word was found, blacklist has no effect, processing continues."); } else { LOG.info("At least one matching word was found, blacklist has effect, processing stops."); } return !containsAny; } case NOTIFICATION_FILTER_MODE_WHITELIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, whitelist has no effect, processing stops."); return false; } } LOG.info("Every word was found, whitelist has effect, processing continues."); return true; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (containsAny) { LOG.info("At least one matching word was found, whitelist has effect, processing continues."); } else { LOG.info("No matching word was found, whitelist has no effect, processing stops."); } return containsAny; } default: return true; } }  @Override void onCreate(); @Override void onDestroy(); String getAppName(String pkg); @Override void onNotificationPosted(StatusBarNotification sbn); boolean handleMediaSessionNotification(MediaSessionCompat.Token mediaSession); @Override void onNotificationRemoved(StatusBarNotification sbn); }
NotificationListener extends NotificationListenerService { boolean shouldContinueAfterFilter(String body, @NonNull List<String> wordsList, @NonNull NotificationFilter notificationFilter) { LOG.debug("Mode: '{}' Submode: '{}' WordsList: '{}'", notificationFilter.getNotificationFilterMode(), notificationFilter.getNotificationFilterSubMode(), wordsList); boolean allMode = notificationFilter.getNotificationFilterSubMode() == NOTIFICATION_FILTER_SUBMODE_ALL; switch (notificationFilter.getNotificationFilterMode()) { case NOTIFICATION_FILTER_MODE_BLACKLIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, blacklist has no effect, processing continues."); return true; } } LOG.info("Every word was found, blacklist has effect, processing stops."); return false; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (!containsAny) { LOG.info("No matching word was found, blacklist has no effect, processing continues."); } else { LOG.info("At least one matching word was found, blacklist has effect, processing stops."); } return !containsAny; } case NOTIFICATION_FILTER_MODE_WHITELIST: if (allMode) { for (String word : wordsList) { if (!body.contains(word)) { LOG.info("Not every word was found, whitelist has no effect, processing stops."); return false; } } LOG.info("Every word was found, whitelist has effect, processing continues."); return true; } else { boolean containsAny = StringUtils.containsAny(body, wordsList.toArray(new CharSequence[0])); if (containsAny) { LOG.info("At least one matching word was found, whitelist has effect, processing continues."); } else { LOG.info("No matching word was found, whitelist has no effect, processing stops."); } return containsAny; } default: return true; } }  @Override void onCreate(); @Override void onDestroy(); String getAppName(String pkg); @Override void onNotificationPosted(StatusBarNotification sbn); boolean handleMediaSessionNotification(MediaSessionCompat.Token mediaSession); @Override void onNotificationRemoved(StatusBarNotification sbn); static final String ACTION_DISMISS; static final String ACTION_DISMISS_ALL; static final String ACTION_OPEN; static final String ACTION_MUTE; static final String ACTION_REPLY; static ArrayList<String> notificationStack; }