Add 'notificaton blocked' filter to notifications
Test: robotests Change-Id: I5c0cd9a2f73b6a22d66df7669e944bbe1473539c Fixes: 112576746
This commit is contained in:
@@ -8301,7 +8301,7 @@
|
|||||||
<!-- Label for showing apps with blocked notifications in list [CHAR LIMIT=30] -->
|
<!-- Label for showing apps with blocked notifications in list [CHAR LIMIT=30] -->
|
||||||
<string name="filter_notif_all_apps">Apps: All</string>
|
<string name="filter_notif_all_apps">Apps: All</string>
|
||||||
<!-- Label for showing apps with blocked notifications in list [CHAR LIMIT=30] -->
|
<!-- Label for showing apps with blocked notifications in list [CHAR LIMIT=30] -->
|
||||||
<string name="filter_notif_blocked_apps">Apps: Turned off</string>
|
<string name="filter_notif_blocked_apps">Turned off</string>
|
||||||
<!-- Label for showing categories with urgent notifications in list [CHAR LIMIT=30] -->
|
<!-- Label for showing categories with urgent notifications in list [CHAR LIMIT=30] -->
|
||||||
<string name="filter_notif_urgent_channels">Categories: Urgent importance</string>
|
<string name="filter_notif_urgent_channels">Categories: Urgent importance</string>
|
||||||
<!-- Label for showing categories with low importance notifications in list [CHAR LIMIT=30] -->
|
<!-- Label for showing categories with low importance notifications in list [CHAR LIMIT=30] -->
|
||||||
|
@@ -100,18 +100,20 @@ public class AppStateNotificationBridge extends AppStateBaseBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static CharSequence getSummary(Context context, NotificationsSentState state,
|
public static CharSequence getSummary(Context context, NotificationsSentState state,
|
||||||
boolean sortByRecency) {
|
int sortOrder) {
|
||||||
if (sortByRecency) {
|
if (sortOrder == R.id.sort_order_recent_notification) {
|
||||||
if (state.lastSent == 0) {
|
if (state.lastSent == 0) {
|
||||||
return context.getString(R.string.notifications_sent_never);
|
return context.getString(R.string.notifications_sent_never);
|
||||||
}
|
}
|
||||||
return StringUtil.formatRelativeTime(
|
return StringUtil.formatRelativeTime(
|
||||||
context, System.currentTimeMillis() - state.lastSent, true);
|
context, System.currentTimeMillis() - state.lastSent, true);
|
||||||
} else {
|
} else if (sortOrder == R.id.sort_order_frequent_notification) {
|
||||||
if (state.avgSentWeekly > 0) {
|
if (state.avgSentWeekly > 0) {
|
||||||
return context.getString(R.string.notifications_sent_weekly, state.avgSentWeekly);
|
return context.getString(R.string.notifications_sent_weekly, state.avgSentWeekly);
|
||||||
}
|
}
|
||||||
return context.getString(R.string.notifications_sent_daily, state.avgSentDaily);
|
return context.getString(R.string.notifications_sent_daily, state.avgSentDaily);
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,6 +269,21 @@ public class AppStateNotificationBridge extends AppStateBaseBridge {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static final AppFilter FILTER_APP_NOTIFICATION_BLOCKED = new AppFilter() {
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean filterApp(AppEntry info) {
|
||||||
|
NotificationsSentState state = getNotificationsSentState(info);
|
||||||
|
if (state != null) {
|
||||||
|
return state.blocked;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static final Comparator<AppEntry> RECENT_NOTIFICATION_COMPARATOR
|
public static final Comparator<AppEntry> RECENT_NOTIFICATION_COMPARATOR
|
||||||
= new Comparator<AppEntry>() {
|
= new Comparator<AppEntry>() {
|
||||||
@Override
|
@Override
|
||||||
|
@@ -49,6 +49,7 @@ public class AppFilterRegistry {
|
|||||||
FILTER_APPS_WITH_OVERLAY,
|
FILTER_APPS_WITH_OVERLAY,
|
||||||
FILTER_APPS_WRITE_SETTINGS,
|
FILTER_APPS_WRITE_SETTINGS,
|
||||||
FILTER_APPS_INSTALL_SOURCES,
|
FILTER_APPS_INSTALL_SOURCES,
|
||||||
|
FILTER_APPS_BLOCKED,
|
||||||
})
|
})
|
||||||
@interface FilterType {
|
@interface FilterType {
|
||||||
}
|
}
|
||||||
@@ -71,14 +72,15 @@ public class AppFilterRegistry {
|
|||||||
public static final int FILTER_APPS_INSTALL_SOURCES = 13;
|
public static final int FILTER_APPS_INSTALL_SOURCES = 13;
|
||||||
public static final int FILTER_APP_HAS_DIRECTORY_ACCESS = 14;
|
public static final int FILTER_APP_HAS_DIRECTORY_ACCESS = 14;
|
||||||
public static final int FILTER_APP_CAN_CHANGE_WIFI_STATE = 15;
|
public static final int FILTER_APP_CAN_CHANGE_WIFI_STATE = 15;
|
||||||
// Next id: 16
|
public static final int FILTER_APPS_BLOCKED = 16;
|
||||||
|
// Next id: 17
|
||||||
|
|
||||||
private static AppFilterRegistry sRegistry;
|
private static AppFilterRegistry sRegistry;
|
||||||
|
|
||||||
private final AppFilterItem[] mFilters;
|
private final AppFilterItem[] mFilters;
|
||||||
|
|
||||||
private AppFilterRegistry() {
|
private AppFilterRegistry() {
|
||||||
mFilters = new AppFilterItem[16];
|
mFilters = new AppFilterItem[17];
|
||||||
|
|
||||||
// High power whitelist, on
|
// High power whitelist, on
|
||||||
mFilters[FILTER_APPS_POWER_WHITELIST] = new AppFilterItem(
|
mFilters[FILTER_APPS_POWER_WHITELIST] = new AppFilterItem(
|
||||||
@@ -178,6 +180,12 @@ public class AppFilterRegistry {
|
|||||||
AppStateChangeWifiStateBridge.FILTER_CHANGE_WIFI_STATE,
|
AppStateChangeWifiStateBridge.FILTER_CHANGE_WIFI_STATE,
|
||||||
FILTER_APP_CAN_CHANGE_WIFI_STATE,
|
FILTER_APP_CAN_CHANGE_WIFI_STATE,
|
||||||
R.string.filter_write_settings_apps);
|
R.string.filter_write_settings_apps);
|
||||||
|
|
||||||
|
// Blocked Notifications
|
||||||
|
mFilters[FILTER_APPS_BLOCKED] = new AppFilterItem(
|
||||||
|
AppStateNotificationBridge.FILTER_APP_NOTIFICATION_BLOCKED,
|
||||||
|
FILTER_APPS_BLOCKED,
|
||||||
|
R.string.filter_notif_blocked_apps);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AppFilterRegistry getInstance() {
|
public static AppFilterRegistry getInstance() {
|
||||||
|
@@ -20,6 +20,8 @@ import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;
|
|||||||
|
|
||||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||||
.FILTER_APPS_ALL;
|
.FILTER_APPS_ALL;
|
||||||
|
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||||
|
.FILTER_APPS_BLOCKED;
|
||||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||||
.FILTER_APPS_DISABLED;
|
.FILTER_APPS_DISABLED;
|
||||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||||
@@ -409,6 +411,7 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
if (mListType == LIST_TYPE_NOTIFICATION) {
|
if (mListType == LIST_TYPE_NOTIFICATION) {
|
||||||
mFilterAdapter.enableFilter(FILTER_APPS_RECENT);
|
mFilterAdapter.enableFilter(FILTER_APPS_RECENT);
|
||||||
mFilterAdapter.enableFilter(FILTER_APPS_FREQUENT);
|
mFilterAdapter.enableFilter(FILTER_APPS_FREQUENT);
|
||||||
|
mFilterAdapter.enableFilter(FILTER_APPS_BLOCKED);
|
||||||
mFilterAdapter.disableFilter(FILTER_APPS_ALL);
|
mFilterAdapter.disableFilter(FILTER_APPS_ALL);
|
||||||
}
|
}
|
||||||
if (mListType == LIST_TYPE_HIGH_POWER) {
|
if (mListType == LIST_TYPE_HIGH_POWER) {
|
||||||
@@ -955,6 +958,8 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
rebuild(R.id.sort_order_frequent_notification);
|
rebuild(R.id.sort_order_frequent_notification);
|
||||||
} else if (FILTER_APPS_RECENT == appFilter.getFilterType()) {
|
} else if (FILTER_APPS_RECENT == appFilter.getFilterType()) {
|
||||||
rebuild(R.id.sort_order_recent_notification);
|
rebuild(R.id.sort_order_recent_notification);
|
||||||
|
} else if (FILTER_APPS_BLOCKED == appFilter.getFilterType()) {
|
||||||
|
rebuild(R.id.sort_order_alpha);
|
||||||
} else {
|
} else {
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
@@ -1111,17 +1116,8 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static boolean shouldUseStableItemHeight(int listType) {
|
static boolean shouldUseStableItemHeight(int listType) {
|
||||||
switch (listType) {
|
|
||||||
case LIST_TYPE_NOTIFICATION:
|
|
||||||
// Most entries in notification type has no summary. Don't use stable height
|
|
||||||
// so height is short for most entries.
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
// Other types have non-empty summary, so keep the height as we expect summary
|
|
||||||
// to fill in.
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean packageNameEquals(PackageItemInfo info1, PackageItemInfo info2) {
|
private static boolean packageNameEquals(PackageItemInfo info1, PackageItemInfo info2) {
|
||||||
if (info1 == null || info2 == null) {
|
if (info1 == null || info2 == null) {
|
||||||
@@ -1338,8 +1334,7 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
if (entry.extraInfo != null
|
if (entry.extraInfo != null
|
||||||
&& entry.extraInfo instanceof NotificationsSentState) {
|
&& entry.extraInfo instanceof NotificationsSentState) {
|
||||||
holder.setSummary(AppStateNotificationBridge.getSummary(mContext,
|
holder.setSummary(AppStateNotificationBridge.getSummary(mContext,
|
||||||
(NotificationsSentState) entry.extraInfo,
|
(NotificationsSentState) entry.extraInfo, mLastSortMode));
|
||||||
(mLastSortMode == R.id.sort_order_recent_notification)));
|
|
||||||
} else {
|
} else {
|
||||||
holder.setSummary(null);
|
holder.setSummary(null);
|
||||||
}
|
}
|
||||||
@@ -1388,8 +1383,7 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
if (entry.extraInfo != null
|
if (entry.extraInfo != null
|
||||||
&& entry.extraInfo instanceof NotificationsSentState) {
|
&& entry.extraInfo instanceof NotificationsSentState) {
|
||||||
holder.setSummary(AppStateNotificationBridge.getSummary(mContext,
|
holder.setSummary(AppStateNotificationBridge.getSummary(mContext,
|
||||||
(NotificationsSentState) entry.extraInfo,
|
(NotificationsSentState) entry.extraInfo, mLastSortMode));
|
||||||
(mLastSortMode == R.id.sort_order_recent_notification)));
|
|
||||||
} else {
|
} else {
|
||||||
holder.setSummary(null);
|
holder.setSummary(null);
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,8 @@ package com.android.settings.applications;
|
|||||||
|
|
||||||
import static android.text.format.DateUtils.DAY_IN_MILLIS;
|
import static android.text.format.DateUtils.DAY_IN_MILLIS;
|
||||||
|
|
||||||
|
import static com.android.settings.applications.AppStateNotificationBridge
|
||||||
|
.FILTER_APP_NOTIFICATION_BLOCKED;
|
||||||
import static com.android.settings.applications.AppStateNotificationBridge
|
import static com.android.settings.applications.AppStateNotificationBridge
|
||||||
.FILTER_APP_NOTIFICATION_FREQUENCY;
|
.FILTER_APP_NOTIFICATION_FREQUENCY;
|
||||||
import static com.android.settings.applications.AppStateNotificationBridge
|
import static com.android.settings.applications.AppStateNotificationBridge
|
||||||
@@ -379,10 +381,11 @@ public class AppStateNotificationBridgeTest {
|
|||||||
NotificationsSentState sent = new NotificationsSentState();
|
NotificationsSentState sent = new NotificationsSentState();
|
||||||
sent.lastSent = System.currentTimeMillis() - (2 * DAY_IN_MILLIS);
|
sent.lastSent = System.currentTimeMillis() - (2 * DAY_IN_MILLIS);
|
||||||
|
|
||||||
assertThat(AppStateNotificationBridge.getSummary(mContext, neverSent, true)).isEqualTo(
|
assertThat(AppStateNotificationBridge.getSummary(
|
||||||
|
mContext, neverSent, R.id.sort_order_recent_notification)).isEqualTo(
|
||||||
mContext.getString(R.string.notifications_sent_never));
|
mContext.getString(R.string.notifications_sent_never));
|
||||||
assertThat(AppStateNotificationBridge.getSummary(mContext, sent, true).toString())
|
assertThat(AppStateNotificationBridge.getSummary(
|
||||||
.contains("2");
|
mContext, sent, R.id.sort_order_recent_notification).toString()).contains("2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -392,12 +395,23 @@ public class AppStateNotificationBridgeTest {
|
|||||||
NotificationsSentState sentOften = new NotificationsSentState();
|
NotificationsSentState sentOften = new NotificationsSentState();
|
||||||
sentOften.avgSentDaily = 8;
|
sentOften.avgSentDaily = 8;
|
||||||
|
|
||||||
assertThat(AppStateNotificationBridge.getSummary(mContext, sentRarely, false).toString())
|
assertThat(AppStateNotificationBridge.getSummary(
|
||||||
|
mContext, sentRarely, R.id.sort_order_frequent_notification).toString())
|
||||||
.contains("1");
|
.contains("1");
|
||||||
assertThat(AppStateNotificationBridge.getSummary(mContext, sentOften, false).toString())
|
assertThat(AppStateNotificationBridge.getSummary(
|
||||||
|
mContext, sentOften, R.id.sort_order_frequent_notification).toString())
|
||||||
.contains("8");
|
.contains("8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSummary_alpha() {
|
||||||
|
NotificationsSentState sentRarely = new NotificationsSentState();
|
||||||
|
sentRarely.avgSentWeekly = 1;
|
||||||
|
assertThat(AppStateNotificationBridge.getSummary(
|
||||||
|
mContext, sentRarely, R.id.sort_order_alpha).toString())
|
||||||
|
.isEqualTo("");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterRecency() {
|
public void testFilterRecency() {
|
||||||
NotificationsSentState allowState = new NotificationsSentState();
|
NotificationsSentState allowState = new NotificationsSentState();
|
||||||
@@ -432,6 +446,23 @@ public class AppStateNotificationBridgeTest {
|
|||||||
assertFalse(FILTER_APP_NOTIFICATION_FREQUENCY.filterApp(deny));
|
assertFalse(FILTER_APP_NOTIFICATION_FREQUENCY.filterApp(deny));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFilterBlocked() {
|
||||||
|
NotificationsSentState allowState = new NotificationsSentState();
|
||||||
|
allowState.blocked = true;
|
||||||
|
AppEntry allow = mock(AppEntry.class);
|
||||||
|
allow.extraInfo = allowState;
|
||||||
|
|
||||||
|
assertTrue(FILTER_APP_NOTIFICATION_BLOCKED.filterApp(allow));
|
||||||
|
|
||||||
|
NotificationsSentState denyState = new NotificationsSentState();
|
||||||
|
denyState.blocked = false;
|
||||||
|
AppEntry deny = mock(AppEntry.class);
|
||||||
|
deny.extraInfo = denyState;
|
||||||
|
|
||||||
|
assertFalse(FILTER_APP_NOTIFICATION_BLOCKED.filterApp(deny));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComparators_nullsNoCrash() {
|
public void testComparators_nullsNoCrash() {
|
||||||
List<AppEntry> entries = new ArrayList<>();
|
List<AppEntry> entries = new ArrayList<>();
|
||||||
|
@@ -200,13 +200,13 @@ public class ManageApplicationsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldUseStableItemHeight_mainType_yes() {
|
public void shouldUseStableItemHeight() {
|
||||||
assertThat(ManageApplications.ApplicationsAdapter.shouldUseStableItemHeight(
|
assertThat(ManageApplications.ApplicationsAdapter.shouldUseStableItemHeight(
|
||||||
LIST_TYPE_MAIN))
|
LIST_TYPE_MAIN))
|
||||||
.isTrue();
|
.isTrue();
|
||||||
assertThat(ManageApplications.ApplicationsAdapter.shouldUseStableItemHeight(
|
assertThat(ManageApplications.ApplicationsAdapter.shouldUseStableItemHeight(
|
||||||
LIST_TYPE_NOTIFICATION))
|
LIST_TYPE_NOTIFICATION))
|
||||||
.isFalse();
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user