Notification banning updates.

- Dismiss notifications from banned topics
- Don't ban all topics when banning an app.
- Block notifications from banned topics.

Bug: 26154396
Change-Id: I1d94e6176a413386d89f8dc1c4899aee8a8a73b8
This commit is contained in:
Julia Reynolds
2016-01-08 17:49:11 -05:00
parent d1d533610a
commit 85aa6cb177
7 changed files with 53 additions and 14 deletions

View File

@@ -33569,6 +33569,7 @@ package android.service.notification {
field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb
field public static final int REASON_PACKAGE_BANNED = 7; // 0x7
field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
field public static final int REASON_TOPIC_BANNED = 14; // 0xe
field public static final int REASON_USER_STOPPED = 6; // 0x6
field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
}

View File

@@ -35705,6 +35705,7 @@ package android.service.notification {
field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb
field public static final int REASON_PACKAGE_BANNED = 7; // 0x7
field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
field public static final int REASON_TOPIC_BANNED = 14; // 0xe
field public static final int REASON_USER_STOPPED = 6; // 0x6
field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
}

View File

@@ -33583,6 +33583,7 @@ package android.service.notification {
field public static final int REASON_LISTENER_CANCEL_ALL = 11; // 0xb
field public static final int REASON_PACKAGE_BANNED = 7; // 0x7
field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
field public static final int REASON_TOPIC_BANNED = 14; // 0xe
field public static final int REASON_USER_STOPPED = 6; // 0x6
field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
}

View File

@@ -95,6 +95,9 @@ public abstract class NotificationAssistantService extends NotificationListenerS
/** Notification was canceled because it was an invisible member of a group. */
public static final int REASON_GROUP_OPTIMIZATION = 13;
/** Notification was canceled by the user banning the topic. */
public static final int REASON_TOPIC_BANNED = 14;
public class Adjustment {
int mImportance;
CharSequence mExplanation;

View File

@@ -28,6 +28,7 @@ import static android.service.notification.NotificationAssistantService.REASON_L
import static android.service.notification.NotificationAssistantService.REASON_LISTENER_CANCEL_ALL;
import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_BANNED;
import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_CHANGED;
import static android.service.notification.NotificationAssistantService.REASON_TOPIC_BANNED;
import static android.service.notification.NotificationAssistantService.REASON_USER_STOPPED;
import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_EFFECTS;
import static android.service.notification.NotificationListenerService.Ranking.IMPORTANCE_HIGH;
@@ -741,7 +742,7 @@ public class NotificationManagerService extends SystemService {
for (String pkgName : pkgList) {
if (cancelNotifications) {
cancelAllNotificationsInt(MY_UID, MY_PID, pkgName, 0, 0, !queryRestart,
changeUserId, REASON_PACKAGE_CHANGED, null);
changeUserId, REASON_PACKAGE_CHANGED, null, null);
}
}
}
@@ -774,7 +775,7 @@ public class NotificationManagerService extends SystemService {
int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
if (userHandle >= 0) {
cancelAllNotificationsInt(MY_UID, MY_PID, null, 0, 0, true, userHandle,
REASON_USER_STOPPED, null);
REASON_USER_STOPPED, null, null);
}
} else if (action.equals(Intent.ACTION_USER_PRESENT)) {
// turn off LED when user passes through lock screen
@@ -1051,7 +1052,7 @@ public class NotificationManagerService extends SystemService {
// Now, cancel any outstanding notifications that are part of a just-disabled app
if (ENABLE_BLOCKED_NOTIFICATIONS && !enabled) {
cancelAllNotificationsInt(MY_UID, MY_PID, pkg, 0, 0, true, UserHandle.getUserId(uid),
REASON_PACKAGE_BANNED, null);
REASON_PACKAGE_BANNED, null, null);
}
}
@@ -1209,7 +1210,7 @@ public class NotificationManagerService extends SystemService {
// running foreground services.
cancelAllNotificationsInt(Binder.getCallingUid(), Binder.getCallingPid(),
pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true, userId,
REASON_APP_CANCEL_ALL, null);
REASON_APP_CANCEL_ALL, null, null);
}
@Override
@@ -1266,6 +1267,11 @@ public class NotificationManagerService extends SystemService {
public void setTopicImportance(String pkg, int uid, Notification.Topic topic,
int importance) {
enforceSystemOrSystemUI("Caller not system or systemui");
if (NotificationListenerService.Ranking.IMPORTANCE_NONE == importance) {
cancelAllNotificationsInt(MY_UID, MY_PID, pkg, 0, 0, true,
UserHandle.getUserId(uid),
REASON_TOPIC_BANNED, topic, null);
}
mRankingHelper.setTopicImportance(pkg, uid, topic, importance);
savePolicyFile();
}
@@ -2284,8 +2290,9 @@ public class NotificationManagerService extends SystemService {
mRankingHelper.extractSignals(r);
savePolicyFile();
// blocked apps
if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg, callingUid)) {
// blocked apps/topics
if (r.getImportance() == NotificationListenerService.Ranking.IMPORTANCE_NONE
|| !noteNotificationOp(pkg, callingUid)) {
if (!isSystemNotification) {
Slog.e(TAG, "Suppressing notification from package " + pkg
+ " by user request.");
@@ -3067,11 +3074,11 @@ public class NotificationManagerService extends SystemService {
}
/**
* Cancels all notifications from a given package that have all of the
* Cancels all notifications from a given package or topic that have all of the
* {@code mustHaveFlags}.
*/
boolean cancelAllNotificationsInt(int callingUid, int callingPid, String pkg, int mustHaveFlags,
int mustNotHaveFlags, boolean doit, int userId, int reason,
int mustNotHaveFlags, boolean doit, int userId, int reason, Notification.Topic topic,
ManagedServiceInfo listener) {
String listenerName = listener == null ? null : listener.component.toShortString();
EventLogTags.writeNotificationCancelAll(callingUid, callingPid,
@@ -3099,6 +3106,10 @@ public class NotificationManagerService extends SystemService {
if (pkg != null && !r.sbn.getPackageName().equals(pkg)) {
continue;
}
if (topic != null
&& !topic.getId().equals(r.getNotification().getTopic().getId())) {
continue;
}
if (canceledNotifications == null) {
canceledNotifications = new ArrayList<>();
}

View File

@@ -423,14 +423,16 @@ public class RankingHelper implements RankingConfig {
/**
* Sets the default importance for all new topics that appear in the future, and resets
* the importance of all current topics.
* the importance of all current topics (unless the app is being blocked).
*/
@Override
public void setAppImportance(String pkgName, int uid, int importance) {
final Record r = getOrCreateRecord(pkgName, uid);
r.importance = importance;
for (Topic t : r.topics.values()) {
t.importance = importance;
if (Ranking.IMPORTANCE_NONE != importance) {
for (Topic t : r.topics.values()) {
t.importance = importance;
}
}
updateConfig();
}
@@ -483,7 +485,9 @@ public class RankingHelper implements RankingConfig {
pw.print(prefix);
pw.println("per-package config:");
}
pw.println("Records:");
dumpRecords(pw, prefix, filter, mRecords);
pw.println("Restored without uid:");
dumpRecords(pw, prefix, filter, mRestoredWithoutUids);
}

View File

@@ -175,7 +175,7 @@ public class NotificationTestList extends TestActivity
.setTopic(new Notification.Topic("hello", "Hello"))
.build();
mNM.notify(999, n);
mNM.notify(70, n);
}
},
@@ -194,7 +194,7 @@ public class NotificationTestList extends TestActivity
.setStyle(picture)
.build();
mNM.notify(9999, n);
mNM.notify(71, n);
}
},
new Test("with topic Bananas") {
@@ -211,10 +211,28 @@ public class NotificationTestList extends TestActivity
.setTopic(new Notification.Topic("bananas", "Bananas"))
.build();
mNM.notify(999, n);
mNM.notify(72, n);
}
},
new Test("with delete intent") {
public void run() {
Notification.BigTextStyle bigText = new Notification.BigTextStyle();
bigText.bigText("bananas are great\nso tasty\nyum\nyum\nyum\n");
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon1)
.setStyle(bigText)
.setWhen(mActivityCreateTime)
.setContentTitle("bananananana")
.setContentText("This is a banana!!!")
.setTopic(new Notification.Topic("bananas", "Bananas"))
.setDeleteIntent(makeIntent2())
.build();
mNM.notify(73, n);
}
},
new Test("Whens") {
public void run()
{