Merge "Show app level settings when an app doesn't use topics."
This commit is contained in:
committed by
Android (Google) Code Review
commit
e66515f542
@@ -48,13 +48,12 @@ interface INotificationManager
|
||||
boolean areNotificationsEnabledForPackage(String pkg, int uid);
|
||||
|
||||
ParceledListSlice getTopics(String pkg, int uid);
|
||||
void setTopicVisibilityOverride(String pkg, int uid, in Notification.Topic topic, int visibility);
|
||||
int getTopicVisibilityOverride(String pkg, int uid, in Notification.Topic topic);
|
||||
void setTopicPriority(String pkg, int uid, in Notification.Topic topic, int priority);
|
||||
int getTopicPriority(String pkg, int uid, in Notification.Topic topic);
|
||||
void setTopicImportance(String pkg, int uid, in Notification.Topic topic, int importance);
|
||||
int getTopicImportance(String pkg, int uid, in Notification.Topic topic);
|
||||
void setAppImportance(String pkg, int uid, int importance);
|
||||
void setVisibilityOverride(String pkg, int uid, in Notification.Topic topic, int visibility);
|
||||
int getVisibilityOverride(String pkg, int uid, in Notification.Topic topic);
|
||||
void setPriority(String pkg, int uid, in Notification.Topic topic, int priority);
|
||||
int getPriority(String pkg, int uid, in Notification.Topic topic);
|
||||
void setImportance(String pkg, int uid, in Notification.Topic topic, int importance);
|
||||
int getImportance(String pkg, int uid, in Notification.Topic topic);
|
||||
boolean doesAppUseTopics(String pkg, int uid);
|
||||
|
||||
// TODO: Remove this when callers have been migrated to the equivalent
|
||||
|
||||
@@ -206,13 +206,8 @@ public class NotificationGuts extends LinearLayout {
|
||||
void saveImportance(final StatusBarNotification sbn) {
|
||||
int progress = mSeekBar.getProgress();
|
||||
try {
|
||||
if (mApplyToTopic.isChecked()) {
|
||||
mINotificationManager.setTopicImportance(sbn.getPackageName(), sbn.getUid(), mTopic,
|
||||
progress);
|
||||
} else {
|
||||
mINotificationManager.setAppImportance(
|
||||
sbn.getPackageName(), sbn.getUid(), progress);
|
||||
}
|
||||
mINotificationManager.setImportance(sbn.getPackageName(), sbn.getUid(),
|
||||
mApplyToTopic.isChecked() ? mTopic : null, progress);
|
||||
} catch (RemoteException e) {
|
||||
// :(
|
||||
}
|
||||
|
||||
@@ -1242,58 +1242,55 @@ public class NotificationManagerService extends SystemService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopicPriority(String pkg, int uid, Notification.Topic topic, int priority) {
|
||||
public void setPriority(String pkg, int uid, Notification.Topic topic, int priority) {
|
||||
checkCallerIsSystem();
|
||||
mRankingHelper.setTopicPriority(pkg, uid, topic, priority);
|
||||
mRankingHelper.setPriority(pkg, uid, topic, priority);
|
||||
savePolicyFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTopicPriority(String pkg, int uid, Notification.Topic topic) {
|
||||
public int getPriority(String pkg, int uid, Notification.Topic topic) {
|
||||
checkCallerIsSystem();
|
||||
return mRankingHelper.getTopicPriority(pkg, uid, topic);
|
||||
return mRankingHelper.getPriority(pkg, uid, topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopicVisibilityOverride(String pkg, int uid, Notification.Topic topic,
|
||||
public void setVisibilityOverride(String pkg, int uid, Notification.Topic topic,
|
||||
int visibility) {
|
||||
checkCallerIsSystem();
|
||||
mRankingHelper.setTopicVisibilityOverride(pkg, uid, topic, visibility);
|
||||
mRankingHelper.setVisibilityOverride(pkg, uid, topic, visibility);
|
||||
savePolicyFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTopicVisibilityOverride(String pkg, int uid, Notification.Topic topic) {
|
||||
public int getVisibilityOverride(String pkg, int uid, Notification.Topic topic) {
|
||||
checkCallerIsSystem();
|
||||
return mRankingHelper.getTopicVisibilityOverride(pkg, uid, topic);
|
||||
return mRankingHelper.getVisibilityOverride(pkg, uid, topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopicImportance(String pkg, int uid, Notification.Topic topic,
|
||||
public void setImportance(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);
|
||||
if (topic == null) {
|
||||
// App wide, potentially store block in app ops.
|
||||
setNotificationsEnabledForPackageImpl(pkg, uid,
|
||||
importance != NotificationListenerService.Ranking.IMPORTANCE_NONE);
|
||||
} else {
|
||||
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);
|
||||
mRankingHelper.setImportance(pkg, uid, topic, importance);
|
||||
savePolicyFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTopicImportance(String pkg, int uid, Notification.Topic topic) {
|
||||
public int getImportance(String pkg, int uid, Notification.Topic topic) {
|
||||
checkCallerIsSystem();
|
||||
return mRankingHelper.getTopicImportance(pkg, uid, topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppImportance(String pkg, int uid, int importance) {
|
||||
enforceSystemOrSystemUI("Caller not system or systemui");
|
||||
setNotificationsEnabledForPackageImpl(pkg, uid,
|
||||
importance != NotificationListenerService.Ranking.IMPORTANCE_NONE);
|
||||
mRankingHelper.setAppImportance(pkg, uid, importance);
|
||||
savePolicyFile();
|
||||
return mRankingHelper.getImportance(pkg, uid, topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,20 +23,18 @@ public interface RankingConfig {
|
||||
|
||||
List<Notification.Topic> getTopics(String packageName, int uid);
|
||||
|
||||
int getTopicPriority(String packageName, int uid, Notification.Topic topic);
|
||||
int getPriority(String packageName, int uid, Notification.Topic topic);
|
||||
|
||||
void setTopicPriority(String packageName, int uid, Notification.Topic topic, int priority);
|
||||
void setPriority(String packageName, int uid, Notification.Topic topic, int priority);
|
||||
|
||||
int getTopicVisibilityOverride(String packageName, int uid, Notification.Topic topic);
|
||||
int getVisibilityOverride(String packageName, int uid, Notification.Topic topic);
|
||||
|
||||
void setTopicVisibilityOverride(String packageName, int uid, Notification.Topic topic,
|
||||
void setVisibilityOverride(String packageName, int uid, Notification.Topic topic,
|
||||
int visibility);
|
||||
|
||||
void setTopicImportance(String packageName, int uid, Notification.Topic topic, int importance);
|
||||
void setImportance(String packageName, int uid, Notification.Topic topic, int importance);
|
||||
|
||||
int getTopicImportance(String packageName, int uid, Notification.Topic topic);
|
||||
|
||||
void setAppImportance(String packageName, int uid, int importance);
|
||||
int getImportance(String packageName, int uid, Notification.Topic topic);
|
||||
|
||||
boolean doesAppUseTopics(String packageName, int uid);
|
||||
}
|
||||
|
||||
@@ -164,6 +164,8 @@ public class RankingHelper implements RankingConfig {
|
||||
r = getOrCreateRecord(name, uid);
|
||||
}
|
||||
r.importance = safeInt(parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
|
||||
r.priority = priority;
|
||||
r.visibility = vis;
|
||||
|
||||
// Migrate package level settings to the default topic.
|
||||
// Might be overwritten by parseTopics.
|
||||
@@ -245,7 +247,15 @@ public class RankingHelper implements RankingConfig {
|
||||
}
|
||||
out.startTag(null, TAG_PACKAGE);
|
||||
out.attribute(null, ATT_NAME, r.pkg);
|
||||
out.attribute(null, ATT_IMPORTANCE, Integer.toString(r.importance));
|
||||
if (r.importance != DEFAULT_IMPORTANCE) {
|
||||
out.attribute(null, ATT_IMPORTANCE, Integer.toString(r.importance));
|
||||
}
|
||||
if (r.priority != DEFAULT_PRIORITY) {
|
||||
out.attribute(null, ATT_PRIORITY, Integer.toString(r.priority));
|
||||
}
|
||||
if (r.visibility != DEFAULT_VISIBILITY) {
|
||||
out.attribute(null, ATT_VISIBILITY, Integer.toString(r.visibility));
|
||||
}
|
||||
|
||||
if (!forBackup) {
|
||||
out.attribute(null, ATT_UID, Integer.toString(r.uid));
|
||||
@@ -373,66 +383,109 @@ public class RankingHelper implements RankingConfig {
|
||||
public List<Notification.Topic> getTopics(String packageName, int uid) {
|
||||
final Record r = getOrCreateRecord(packageName, uid);
|
||||
List<Notification.Topic> topics = new ArrayList<>();
|
||||
for (Topic t : r.topics.values()) {
|
||||
for (Topic t : r.topics.values()) {
|
||||
topics.add(t.topic);
|
||||
}
|
||||
return topics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets priority. If a topic is given, returns the priority of that topic. Otherwise, the
|
||||
* priority of the app.
|
||||
*/
|
||||
@Override
|
||||
public int getTopicPriority(String packageName, int uid, Notification.Topic topic) {
|
||||
public int getPriority(String packageName, int uid, Notification.Topic topic) {
|
||||
final Record r = getOrCreateRecord(packageName, uid);
|
||||
if (topic == null) {
|
||||
return r.priority;
|
||||
}
|
||||
return getOrCreateTopic(r, topic).priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets priority. If a topic is given, sets the priority of that topic. If not,
|
||||
* sets the default priority for all new topics that appear in the future, and resets
|
||||
* the priority of all current topics.
|
||||
*/
|
||||
@Override
|
||||
public void setTopicPriority(String packageName, int uid, Notification.Topic topic,
|
||||
public void setPriority(String packageName, int uid, Notification.Topic topic,
|
||||
int priority) {
|
||||
final Record r = getOrCreateRecord(packageName, uid);
|
||||
getOrCreateTopic(r, topic).priority = priority;
|
||||
updateConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTopicVisibilityOverride(String packageName, int uid, Notification.Topic topic) {
|
||||
final Record r = getOrCreateRecord(packageName, uid);
|
||||
return getOrCreateTopic(r, topic).visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopicVisibilityOverride(String pkgName, int uid, Notification.Topic topic,
|
||||
int visibility) {
|
||||
final Record r = getOrCreateRecord(pkgName, uid);
|
||||
getOrCreateTopic(r, topic).visibility = visibility;
|
||||
updateConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTopicImportance(String packageName, int uid, Notification.Topic topic) {
|
||||
final Record r = getOrCreateRecord(packageName, uid);
|
||||
return getOrCreateTopic(r, topic).importance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopicImportance(String pkgName, int uid, Notification.Topic topic,
|
||||
int importance) {
|
||||
final Record r = getOrCreateRecord(pkgName, uid);
|
||||
getOrCreateTopic(r, topic).importance = importance;
|
||||
if (topic == null) {
|
||||
r.priority = priority;
|
||||
for (Topic t : r.topics.values()) {
|
||||
t.priority = priority;
|
||||
}
|
||||
} else {
|
||||
getOrCreateTopic(r, topic).priority = priority;
|
||||
}
|
||||
updateConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default importance for all new topics that appear in the future, and resets
|
||||
* Gets visual override. If a topic is given, returns the override of that topic. Otherwise, the
|
||||
* override of the app.
|
||||
*/
|
||||
@Override
|
||||
public int getVisibilityOverride(String packageName, int uid, Notification.Topic topic) {
|
||||
final Record r = getOrCreateRecord(packageName, uid);
|
||||
if (topic == null) {
|
||||
return r.visibility;
|
||||
}
|
||||
return getOrCreateTopic(r, topic).visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets visibility override. If a topic is given, sets the override of that topic. If not,
|
||||
* sets the default override for all new topics that appear in the future, and resets
|
||||
* the override of all current topics.
|
||||
*/
|
||||
@Override
|
||||
public void setVisibilityOverride(String pkgName, int uid, Notification.Topic topic,
|
||||
int visibility) {
|
||||
final Record r = getOrCreateRecord(pkgName, uid);
|
||||
if (topic == null) {
|
||||
r.visibility = visibility;
|
||||
for (Topic t : r.topics.values()) {
|
||||
t.visibility = visibility;
|
||||
}
|
||||
} else {
|
||||
getOrCreateTopic(r, topic).visibility = visibility;
|
||||
}
|
||||
updateConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets importance. If a topic is given, returns the importance of that topic. Otherwise, the
|
||||
* importance of the app.
|
||||
*/
|
||||
@Override
|
||||
public int getImportance(String packageName, int uid, Notification.Topic topic) {
|
||||
final Record r = getOrCreateRecord(packageName, uid);
|
||||
if (topic == null) {
|
||||
return r.importance;
|
||||
}
|
||||
return getOrCreateTopic(r, topic).importance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets importance. If a topic is given, sets the importance of that topic. If not, sets the
|
||||
* default importance for all new topics that appear in the future, and resets
|
||||
* the importance of all current topics (unless the app is being blocked).
|
||||
*/
|
||||
@Override
|
||||
public void setAppImportance(String pkgName, int uid, int importance) {
|
||||
public void setImportance(String pkgName, int uid, Notification.Topic topic,
|
||||
int importance) {
|
||||
final Record r = getOrCreateRecord(pkgName, uid);
|
||||
r.importance = importance;
|
||||
if (Ranking.IMPORTANCE_NONE != importance) {
|
||||
for (Topic t : r.topics.values()) {
|
||||
t.importance = importance;
|
||||
if (topic == null) {
|
||||
r.importance = importance;
|
||||
if (Ranking.IMPORTANCE_NONE != importance) {
|
||||
for (Topic t : r.topics.values()) {
|
||||
t.importance = importance;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getOrCreateTopic(r, topic).importance = importance;
|
||||
}
|
||||
updateConfig();
|
||||
}
|
||||
@@ -459,6 +512,8 @@ public class RankingHelper implements RankingConfig {
|
||||
} else {
|
||||
t = new Topic(topic);
|
||||
t.importance = r.importance;
|
||||
t.priority = r.priority;
|
||||
t.visibility = r.visibility;
|
||||
r.topics.put(topic.getId(), t);
|
||||
return t;
|
||||
}
|
||||
@@ -503,8 +558,18 @@ public class RankingHelper implements RankingConfig {
|
||||
pw.print(" (");
|
||||
pw.print(r.uid == Record.UNKNOWN_UID ? "UNKNOWN_UID" : Integer.toString(r.uid));
|
||||
pw.print(')');
|
||||
pw.print(" importance=");
|
||||
pw.print(Ranking.importanceToString(r.importance));
|
||||
if (r.importance != DEFAULT_IMPORTANCE) {
|
||||
pw.print(" importance=");
|
||||
pw.print(Ranking.importanceToString(r.importance));
|
||||
}
|
||||
if (r.priority != DEFAULT_PRIORITY) {
|
||||
pw.print(" priority=");
|
||||
pw.print(Ranking.importanceToString(r.priority));
|
||||
}
|
||||
if (r.visibility != DEFAULT_VISIBILITY) {
|
||||
pw.print(" visibility=");
|
||||
pw.print(Ranking.importanceToString(r.visibility));
|
||||
}
|
||||
pw.println();
|
||||
for (Topic t : r.topics.values()) {
|
||||
pw.print(prefix);
|
||||
@@ -561,6 +626,8 @@ public class RankingHelper implements RankingConfig {
|
||||
String pkg;
|
||||
int uid = UNKNOWN_UID;
|
||||
int importance = DEFAULT_IMPORTANCE;
|
||||
int priority = DEFAULT_PRIORITY;
|
||||
int visibility = DEFAULT_VISIBILITY;
|
||||
Map<String, Topic> topics = new ArrayMap<>();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TopicImportanceExtractor implements NotificationSignalExtractor {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int topicImportance = mConfig.getTopicImportance(record.sbn.getPackageName(),
|
||||
final int topicImportance = mConfig.getImportance(record.sbn.getPackageName(),
|
||||
record.sbn.getUid(), record.sbn.getNotification().getTopic());
|
||||
record.setTopicImportance(topicImportance);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TopicPriorityExtractor implements NotificationSignalExtractor {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int packagePriority = mConfig.getTopicPriority(record.sbn.getPackageName(),
|
||||
final int packagePriority = mConfig.getPriority(record.sbn.getPackageName(),
|
||||
record.sbn.getUid(), record.sbn.getNotification().getTopic());
|
||||
record.setPackagePriority(packagePriority);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TopicVisibilityExtractor implements NotificationSignalExtractor {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int packageVisibility = mConfig.getTopicVisibilityOverride(
|
||||
final int packageVisibility = mConfig.getVisibilityOverride(
|
||||
record.sbn.getPackageName(), record.sbn.getUid(),
|
||||
record.sbn.getNotification().getTopic());
|
||||
record.setPackageVisibilityOverride(packageVisibility);
|
||||
|
||||
@@ -155,16 +155,12 @@ public class RankingHelperTest extends AndroidTestCase {
|
||||
|
||||
@SmallTest
|
||||
public void testTopicImportanceExtractor() throws Exception {
|
||||
mHelper.setTopicImportance("package", 0, new Notification.Topic("A", "a"),
|
||||
IMPORTANCE_MAX);
|
||||
mHelper.setImportance("package", 0, new Notification.Topic("A", "a"), IMPORTANCE_MAX);
|
||||
// There is no B. There never was a b. Moving on...
|
||||
mHelper.setTopicImportance("package", 0, new Notification.Topic("C", "c"),
|
||||
IMPORTANCE_HIGH);
|
||||
mHelper.setTopicImportance("package", 0, new Notification.Topic("D", "d"),
|
||||
IMPORTANCE_LOW);
|
||||
mHelper.setImportance("package", 0, new Notification.Topic("C", "c"), IMPORTANCE_HIGH);
|
||||
mHelper.setImportance("package", 0, new Notification.Topic("D", "d"), IMPORTANCE_LOW);
|
||||
// watch out: different package.
|
||||
mHelper.setTopicImportance("package2", 0, new Notification.Topic("E", "e"),
|
||||
IMPORTANCE_NONE);
|
||||
mHelper.setImportance("package2", 0, new Notification.Topic("E", "e"), IMPORTANCE_NONE);
|
||||
|
||||
TopicImportanceExtractor validator = mHelper.findExtractor(TopicImportanceExtractor.class);
|
||||
validator.process(mRecordGroupGSortA);
|
||||
|
||||
Reference in New Issue
Block a user