Remove Notification Topics.

Bug: 23220370
Change-Id: Ifbcdbab1cf6974c192483091512f75762784a98e
This commit is contained in:
Julia Reynolds
2016-02-12 09:11:27 -05:00
parent 0f900c02d9
commit ef37f28436
21 changed files with 139 additions and 746 deletions

View File

@@ -4879,7 +4879,6 @@ package android.app {
method public android.graphics.drawable.Icon getLargeIcon();
method public android.graphics.drawable.Icon getSmallIcon();
method public java.lang.String getSortKey();
method public android.app.Notification.Topic getTopic();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.media.AudioAttributes AUDIO_ATTRIBUTES_DEFAULT;
field public static final java.lang.String CATEGORY_ALARM = "alarm";
@@ -4943,7 +4942,6 @@ package android.app {
field public static final int PRIORITY_MAX = 2; // 0x2
field public static final int PRIORITY_MIN = -2; // 0xfffffffe
field public static final deprecated int STREAM_DEFAULT = -1; // 0xffffffff
field public static final java.lang.String TOPIC_DEFAULT = "system_default_topic";
field public static final int VISIBILITY_PRIVATE = 0; // 0x0
field public static final int VISIBILITY_PUBLIC = 1; // 0x1
field public static final int VISIBILITY_SECRET = -1; // 0xffffffff
@@ -5095,7 +5093,6 @@ package android.app {
method public android.app.Notification.Builder setSubText(java.lang.CharSequence);
method public android.app.Notification.Builder setTicker(java.lang.CharSequence);
method public deprecated android.app.Notification.Builder setTicker(java.lang.CharSequence, android.widget.RemoteViews);
method public android.app.Notification.Builder setTopic(android.app.Notification.Topic);
method public android.app.Notification.Builder setUsesChronometer(boolean);
method public android.app.Notification.Builder setVibrate(long[]);
method public android.app.Notification.Builder setVisibility(int);
@@ -5163,16 +5160,6 @@ package android.app {
field protected android.app.Notification.Builder mBuilder;
}
public static class Notification.Topic implements android.os.Parcelable {
ctor public Notification.Topic(java.lang.String, java.lang.CharSequence);
method public android.app.Notification.Topic clone();
method public int describeContents();
method public java.lang.String getId();
method public java.lang.CharSequence getLabel();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.Notification.Topic> CREATOR;
}
public static final class Notification.WearableExtender implements android.app.Notification.Extender {
ctor public Notification.WearableExtender();
ctor public Notification.WearableExtender(android.app.Notification);
@@ -5235,7 +5222,7 @@ package android.app {
method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
method public java.util.List<android.app.AutomaticZenRule> getAutomaticZenRules();
method public final int getCurrentInterruptionFilter();
method public int getImportance(java.lang.String);
method public int getImportance();
method public android.app.NotificationManager.Policy getNotificationPolicy();
method public boolean isNotificationPolicyAccessGranted();
method public void notify(int, android.app.Notification);

View File

@@ -5011,7 +5011,6 @@ package android.app {
method public android.graphics.drawable.Icon getLargeIcon();
method public android.graphics.drawable.Icon getSmallIcon();
method public java.lang.String getSortKey();
method public android.app.Notification.Topic getTopic();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.media.AudioAttributes AUDIO_ATTRIBUTES_DEFAULT;
field public static final java.lang.String CATEGORY_ALARM = "alarm";
@@ -5075,7 +5074,6 @@ package android.app {
field public static final int PRIORITY_MAX = 2; // 0x2
field public static final int PRIORITY_MIN = -2; // 0xfffffffe
field public static final deprecated int STREAM_DEFAULT = -1; // 0xffffffff
field public static final java.lang.String TOPIC_DEFAULT = "system_default_topic";
field public static final int VISIBILITY_PRIVATE = 0; // 0x0
field public static final int VISIBILITY_PUBLIC = 1; // 0x1
field public static final int VISIBILITY_SECRET = -1; // 0xffffffff
@@ -5227,7 +5225,6 @@ package android.app {
method public android.app.Notification.Builder setSubText(java.lang.CharSequence);
method public android.app.Notification.Builder setTicker(java.lang.CharSequence);
method public deprecated android.app.Notification.Builder setTicker(java.lang.CharSequence, android.widget.RemoteViews);
method public android.app.Notification.Builder setTopic(android.app.Notification.Topic);
method public android.app.Notification.Builder setUsesChronometer(boolean);
method public android.app.Notification.Builder setVibrate(long[]);
method public android.app.Notification.Builder setVisibility(int);
@@ -5295,16 +5292,6 @@ package android.app {
field protected android.app.Notification.Builder mBuilder;
}
public static class Notification.Topic implements android.os.Parcelable {
ctor public Notification.Topic(java.lang.String, java.lang.CharSequence);
method public android.app.Notification.Topic clone();
method public int describeContents();
method public java.lang.String getId();
method public java.lang.CharSequence getLabel();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.Notification.Topic> CREATOR;
}
public static final class Notification.WearableExtender implements android.app.Notification.Extender {
ctor public Notification.WearableExtender();
ctor public Notification.WearableExtender(android.app.Notification);
@@ -5367,7 +5354,7 @@ package android.app {
method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
method public java.util.List<android.app.AutomaticZenRule> getAutomaticZenRules();
method public final int getCurrentInterruptionFilter();
method public int getImportance(java.lang.String);
method public int getImportance();
method public android.app.NotificationManager.Policy getNotificationPolicy();
method public boolean isNotificationPolicyAccessGranted();
method public void notify(int, android.app.Notification);
@@ -36977,9 +36964,8 @@ 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_PACKAGE_SUSPENDED = 15; // 0xf
field public static final int REASON_PROFILE_TURNED_OFF = 16; // 0x10
field public static final int REASON_TOPIC_BANNED = 14; // 0xe
field public static final int REASON_PACKAGE_SUSPENDED = 14; // 0xe
field public static final int REASON_PROFILE_TURNED_OFF = 15; // 0xf
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

@@ -4879,7 +4879,6 @@ package android.app {
method public android.graphics.drawable.Icon getLargeIcon();
method public android.graphics.drawable.Icon getSmallIcon();
method public java.lang.String getSortKey();
method public android.app.Notification.Topic getTopic();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.media.AudioAttributes AUDIO_ATTRIBUTES_DEFAULT;
field public static final java.lang.String CATEGORY_ALARM = "alarm";
@@ -4943,7 +4942,6 @@ package android.app {
field public static final int PRIORITY_MAX = 2; // 0x2
field public static final int PRIORITY_MIN = -2; // 0xfffffffe
field public static final deprecated int STREAM_DEFAULT = -1; // 0xffffffff
field public static final java.lang.String TOPIC_DEFAULT = "system_default_topic";
field public static final int VISIBILITY_PRIVATE = 0; // 0x0
field public static final int VISIBILITY_PUBLIC = 1; // 0x1
field public static final int VISIBILITY_SECRET = -1; // 0xffffffff
@@ -5095,7 +5093,6 @@ package android.app {
method public android.app.Notification.Builder setSubText(java.lang.CharSequence);
method public android.app.Notification.Builder setTicker(java.lang.CharSequence);
method public deprecated android.app.Notification.Builder setTicker(java.lang.CharSequence, android.widget.RemoteViews);
method public android.app.Notification.Builder setTopic(android.app.Notification.Topic);
method public android.app.Notification.Builder setUsesChronometer(boolean);
method public android.app.Notification.Builder setVibrate(long[]);
method public android.app.Notification.Builder setVisibility(int);
@@ -5163,16 +5160,6 @@ package android.app {
field protected android.app.Notification.Builder mBuilder;
}
public static class Notification.Topic implements android.os.Parcelable {
ctor public Notification.Topic(java.lang.String, java.lang.CharSequence);
method public android.app.Notification.Topic clone();
method public int describeContents();
method public java.lang.String getId();
method public java.lang.CharSequence getLabel();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.Notification.Topic> CREATOR;
}
public static final class Notification.WearableExtender implements android.app.Notification.Extender {
ctor public Notification.WearableExtender();
ctor public Notification.WearableExtender(android.app.Notification);
@@ -5235,7 +5222,7 @@ package android.app {
method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
method public java.util.List<android.app.AutomaticZenRule> getAutomaticZenRules();
method public final int getCurrentInterruptionFilter();
method public int getImportance(java.lang.String);
method public int getImportance();
method public android.app.NotificationManager.Policy getNotificationPolicy();
method public boolean isNotificationPolicyAccessGranted();
method public void notify(int, android.app.Notification);

View File

@@ -48,16 +48,13 @@ interface INotificationManager
boolean areNotificationsEnabledForPackage(String pkg, int uid);
boolean areNotificationsEnabled(String pkg);
ParceledListSlice getTopics(String pkg, int uid);
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);
int getTopicImportance(String pkg, String topicId);
boolean doesUserUseTopics(String pkg, int uid);
boolean hasBannedTopics(String pkg, int uid);
void setVisibilityOverride(String pkg, int uid, int visibility);
int getVisibilityOverride(String pkg, int uid);
void setPriority(String pkg, int uid, int priority);
int getPriority(String pkg, int uid);
void setImportance(String pkg, int uid, int importance);
int getImportance(String pkg, int uid);
int getPackageImportance(String pkg);
// TODO: Remove this when callers have been migrated to the equivalent
// INotificationListener method.

View File

@@ -1365,98 +1365,6 @@ public class Notification implements Parcelable
*/
public Notification publicVersion;
/**
* Structure to encapsulate a topic that is shown in Notification settings.
* It must include an id and label.
*/
public static class Topic implements Parcelable {
private final String id;
private final CharSequence label;
public Topic(String id, CharSequence label) {
this.id = id;
this.label = safeCharSequence(label);
}
private Topic(Parcel in) {
if (in.readInt() != 0) {
id = in.readString();
} else {
id = null;
}
label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
}
public String getId() {
return id;
}
public CharSequence getLabel() {
return label;
}
@Override
public String toString() {
return new StringBuilder(Topic.class.getSimpleName()).append('[')
.append("id=").append(id)
.append(",label=").append(label)
.append(']').toString();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Topic)) return false;
if (o == this) return true;
final Topic other = (Topic) o;
return Objects.equals(other.id, id)
&& Objects.equals(other.label, label);
}
@Override
public int hashCode() {
return Objects.hash(id, label);
}
@Override
public Topic clone() {
return new Topic(id, label);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
if (id != null) {
out.writeInt(1);
out.writeString(id);
} else {
out.writeInt(0);
}
TextUtils.writeToParcel(label, out, flags);
}
public static final Parcelable.Creator<Topic> CREATOR =
new Parcelable.Creator<Topic>() {
public Topic createFromParcel(Parcel in) {
return new Topic(in);
}
public Topic[] newArray(int size) {
return new Topic[size];
}
};
}
@SystemApi
public static final String TOPIC_DEFAULT = "system_default_topic";
private Topic topic;
public Topic getTopic() {
return topic;
}
/**
* Constructs a Notification object with default values.
* You might want to consider using {@link Builder} instead.
@@ -1583,10 +1491,6 @@ public class Notification implements Parcelable
}
color = parcel.readInt();
if (parcel.readInt() != 0) {
topic = Topic.CREATOR.createFromParcel(parcel);
}
}
@Override
@@ -1687,10 +1591,6 @@ public class Notification implements Parcelable
that.color = this.color;
if (this.topic != null) {
that.topic = this.topic.clone();
}
if (!heavy) {
that.lightenPayload(); // will clean out extras
}
@@ -1871,13 +1771,6 @@ public class Notification implements Parcelable
}
parcel.writeInt(color);
if (topic != null) {
parcel.writeInt(1);
topic.writeToParcel(parcel, 0);
} else {
parcel.writeInt(0);
}
}
/**
@@ -2020,10 +1913,6 @@ public class Notification implements Parcelable
sb.append(" publicVersion=");
sb.append(publicVersion.toString());
}
if (topic != null) {
sb.append("topic=");
sb.append(topic.toString());
}
sb.append(")");
return sb.toString();
}
@@ -2980,19 +2869,6 @@ public class Notification implements Parcelable
return this;
}
/**
* Sets the topic of this notification. Topics are typically displayed in Notification
* settings.
* <p>
* Every topic must have an id and a textual label.
*
* @param topic The topic to add.
*/
public Builder setTopic(Topic topic) {
mN.topic = topic;
return this;
}
private Drawable getProfileBadgeDrawable() {
// Note: This assumes that the current user can read the profile badge of the
// originating user.

View File

@@ -506,11 +506,10 @@ public class NotificationManager
return false;
}
public int getImportance(String topicId) {
Preconditions.checkNotNull(topicId);
public int getImportance() {
INotificationManager service = getService();
try {
return service.getTopicImportance(mContext.getPackageName(), topicId);
return service.getPackageImportance(mContext.getPackageName());
} catch (RemoteException e) {
}
return NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED;

View File

@@ -97,14 +97,11 @@ 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;
/** Notification was canceled by the device administrator suspending the package. */
public static final int REASON_PACKAGE_SUSPENDED = 15;
public static final int REASON_PACKAGE_SUSPENDED = 14;
/** Notification was canceled by the owning managed profile being turned off. */
public static final int REASON_PROFILE_TURNED_OFF = 16;
public static final int REASON_PROFILE_TURNED_OFF = 15;
public class Adjustment {
int mImportance;

View File

@@ -1992,10 +1992,10 @@
See {@link com.android.server.notification.NotificationSignalExtractor} -->
<string-array name="config_notificationSignalExtractors">
<item>com.android.server.notification.ValidateNotificationPeople</item>
<item>com.android.server.notification.TopicPriorityExtractor</item>
<item>com.android.server.notification.TopicImportanceExtractor</item>
<item>com.android.server.notification.PriorityExtractor</item>
<item>com.android.server.notification.ImportanceExtractor</item>
<item>com.android.server.notification.NotificationIntrusivenessExtractor</item>
<item>com.android.server.notification.TopicVisibilityExtractor</item>
<item>com.android.server.notification.VisibilityExtractor</item>
</string-array>
<!-- Flag indicating that this device does not rotate and will always remain in its default

View File

@@ -4162,9 +4162,7 @@
<item quantity="other"><xliff:g id="count" example="3">%1$d</xliff:g> selected</item>
</plurals>
<string name="default_notification_topic_label">Miscellaneous</string>
<string name="importance_from_topic">You set the importance of these notifications.</string>
<string name="importance_from_user">You set the importance of these notifications.</string>
<string name="importance_from_person">This is important because of the people involved.</string>
<!-- Message to user that app trying to create user for an account that already exists. [CHAR LIMIT=none] -->

View File

@@ -2388,7 +2388,6 @@
<java-symbol type="string" name="config_iccHotswapPromptForRestartDialogComponent" />
<java-symbol type="string" name="config_packagedKeyboardName" />
<java-symbol type="string" name="default_notification_topic_label" />
<java-symbol type="bool" name="config_forceWindowDrawsStatusBarBackground" />
<java-symbol type="color" name="system_bar_background_semi_transparent" />
@@ -2427,7 +2426,7 @@
<java-symbol type="dimen" name="notification_content_margin_end" />
<java-symbol type="dimen" name="notification_content_picture_margin" />
<java-symbol type="dimen" name="notification_content_margin_top" />
<java-symbol type="string" name="importance_from_topic" />
<java-symbol type="string" name="importance_from_user" />
<java-symbol type="string" name="importance_from_person" />
<java-symbol type="layout" name="work_widget_mask_view" />

View File

@@ -126,27 +126,6 @@
android:tint="@color/notification_guts_icon_tint" />
</FrameLayout>
<RadioGroup
android:id="@+id/apply_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton android:id="@+id/apply_to_topic"
android:layout_width="wrap_content"
android:layout_height="48dp"
style="@style/TextAppearance.NotificationGuts.Primary"
android:visibility="gone"
android:buttonTint="#858383"
/>
<RadioButton android:id="@+id/apply_to_app"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="@string/apply_to_app"
style="@style/TextAppearance.NotificationGuts.Primary"
android:visibility="gone"
android:buttonTint="#858383"
/>
</RadioGroup>
</LinearLayout>
<!-- buttons -->
<LinearLayout

View File

@@ -49,9 +49,7 @@ public class NotificationGuts extends LinearLayout {
private int mClipTopAmount;
private int mActualHeight;
private boolean mExposed;
private RadioButton mApplyToTopic;
private SeekBar mSeekBar;
private Notification.Topic mTopic;
private INotificationManager mINotificationManager;
private int mStartingImportance;
@@ -109,24 +107,9 @@ public class NotificationGuts extends LinearLayout {
mStartingImportance = importance;
mINotificationManager = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
mTopic = sbn.getNotification().getTopic() == null
? new Notification.Topic(Notification.TOPIC_DEFAULT, mContext.getString(
com.android.internal.R.string.default_notification_topic_label))
: sbn.getNotification().getTopic();
boolean doesUserUseTopics = false;
try {
doesUserUseTopics =
mINotificationManager.doesUserUseTopics(sbn.getPackageName(), sbn.getUid());
} catch (RemoteException e) {}
final boolean userUsesTopics = doesUserUseTopics;
mApplyToTopic = (RadioButton) row.findViewById(R.id.apply_to_topic);
if (userUsesTopics) {
mApplyToTopic.setChecked(true);
}
final View applyToApp = row.findViewById(R.id.apply_to_app);
final TextView topicSummary = ((TextView) row.findViewById(R.id.summary));
final TextView topicTitle = ((TextView) row.findViewById(R.id.title));
final TextView importanceSummary = ((TextView) row.findViewById(R.id.summary));
final TextView importanceTitle = ((TextView) row.findViewById(R.id.title));
mSeekBar = (SeekBar) row.findViewById(R.id.seekbar);
boolean systemApp = false;
try {
@@ -156,12 +139,6 @@ public class NotificationGuts extends LinearLayout {
updateTitleAndSummary(progress);
if (fromUser) {
MetricsLogger.action(mContext, MetricsEvent.ACTION_MODIFY_IMPORTANCE_SLIDER);
if (userUsesTopics) {
mApplyToTopic.setVisibility(View.VISIBLE);
mApplyToTopic.setText(
mContext.getString(R.string.apply_to_topic, mTopic.getLabel()));
applyToApp.setVisibility(View.VISIBLE);
}
}
}
@@ -178,29 +155,29 @@ public class NotificationGuts extends LinearLayout {
private void updateTitleAndSummary(int progress) {
switch (progress) {
case NotificationListenerService.Ranking.IMPORTANCE_NONE:
topicSummary.setText(mContext.getString(
importanceSummary.setText(mContext.getString(
R.string.notification_importance_blocked));
topicTitle.setText(mContext.getString(R.string.blocked_importance));
importanceTitle.setText(mContext.getString(R.string.blocked_importance));
break;
case NotificationListenerService.Ranking.IMPORTANCE_LOW:
topicSummary.setText(mContext.getString(
importanceSummary.setText(mContext.getString(
R.string.notification_importance_low));
topicTitle.setText(mContext.getString(R.string.low_importance));
importanceTitle.setText(mContext.getString(R.string.low_importance));
break;
case NotificationListenerService.Ranking.IMPORTANCE_DEFAULT:
topicSummary.setText(mContext.getString(
importanceSummary.setText(mContext.getString(
R.string.notification_importance_default));
topicTitle.setText(mContext.getString(R.string.default_importance));
importanceTitle.setText(mContext.getString(R.string.default_importance));
break;
case NotificationListenerService.Ranking.IMPORTANCE_HIGH:
topicSummary.setText(mContext.getString(
importanceSummary.setText(mContext.getString(
R.string.notification_importance_high));
topicTitle.setText(mContext.getString(R.string.high_importance));
importanceTitle.setText(mContext.getString(R.string.high_importance));
break;
case NotificationListenerService.Ranking.IMPORTANCE_MAX:
topicSummary.setText(mContext.getString(
importanceSummary.setText(mContext.getString(
R.string.notification_importance_max));
topicTitle.setText(mContext.getString(R.string.max_importance));
importanceTitle.setText(mContext.getString(R.string.max_importance));
break;
}
}
@@ -213,8 +190,7 @@ public class NotificationGuts extends LinearLayout {
MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE,
progress - mStartingImportance);
try {
mINotificationManager.setImportance(sbn.getPackageName(), sbn.getUid(),
mApplyToTopic.isChecked() ? mTopic : null, progress);
mINotificationManager.setImportance(sbn.getPackageName(), sbn.getUid(), progress);
} catch (RemoteException e) {
// :(
}

View File

@@ -21,7 +21,7 @@ import android.util.Slog;
/**
* Determines the importance of the given notification.
*/
public class TopicImportanceExtractor implements NotificationSignalExtractor {
public class ImportanceExtractor implements NotificationSignalExtractor {
private static final String TAG = "ImportantTopicExtractor";
private static final boolean DBG = false;
@@ -42,9 +42,8 @@ public class TopicImportanceExtractor implements NotificationSignalExtractor {
return null;
}
final int topicImportance = mConfig.getImportance(record.sbn.getPackageName(),
record.sbn.getUid(), record.sbn.getNotification().getTopic());
record.setTopicImportance(topicImportance);
record.setUserImportance(
mConfig.getImportance(record.sbn.getPackageName(), record.sbn.getUid()));
return null;
}

View File

@@ -30,7 +30,6 @@ import static android.service.notification.NotificationAssistantService.REASON_P
import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_CHANGED;
import static android.service.notification.NotificationAssistantService.REASON_PACKAGE_SUSPENDED;
import static android.service.notification.NotificationAssistantService.REASON_PROFILE_TURNED_OFF;
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.SUPPRESSED_EFFECT_SCREEN_OFF;
@@ -754,7 +753,7 @@ public class NotificationManagerService extends SystemService {
for (String pkgName : pkgList) {
if (cancelNotifications) {
cancelAllNotificationsInt(MY_UID, MY_PID, pkgName, 0, 0, !queryRestart,
changeUserId, reason, null, null);
changeUserId, reason, null);
}
}
}
@@ -787,14 +786,14 @@ 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, null);
REASON_USER_STOPPED, null);
}
} else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
boolean inQuietMode = intent.getBooleanExtra(Intent.EXTRA_QUIET_MODE, false);
int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
if (inQuietMode && userHandle >= 0) {
cancelAllNotificationsInt(MY_UID, MY_PID, null, 0, 0, true, userHandle,
REASON_PROFILE_TURNED_OFF, null, null);
REASON_PROFILE_TURNED_OFF, null);
}
} else if (action.equals(Intent.ACTION_USER_PRESENT)) {
// turn off LED when user passes through lock screen
@@ -1086,7 +1085,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, null);
REASON_PACKAGE_BANNED, null);
}
}
@@ -1250,7 +1249,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, null);
REASON_APP_CANCEL_ALL, null);
}
@Override
@@ -1279,79 +1278,50 @@ public class NotificationManagerService extends SystemService {
}
@Override
public boolean hasBannedTopics(String pkg, int uid) {
public void setPriority(String pkg, int uid, int priority) {
checkCallerIsSystem();
return mRankingHelper.hasBannedTopics(pkg, uid);
}
@Override
public ParceledListSlice<Notification.Topic> getTopics(String pkg, int uid) {
checkCallerIsSystem();
return new ParceledListSlice<Notification.Topic>(mRankingHelper.getTopics(pkg, uid));
}
@Override
public void setPriority(String pkg, int uid, Notification.Topic topic, int priority) {
checkCallerIsSystem();
mRankingHelper.setPriority(pkg, uid, topic, priority);
mRankingHelper.setPriority(pkg, uid, priority);
savePolicyFile();
}
@Override
public int getPriority(String pkg, int uid, Notification.Topic topic) {
public int getPriority(String pkg, int uid) {
checkCallerIsSystem();
return mRankingHelper.getPriority(pkg, uid, topic);
return mRankingHelper.getPriority(pkg, uid);
}
@Override
public void setVisibilityOverride(String pkg, int uid, Notification.Topic topic,
int visibility) {
public void setVisibilityOverride(String pkg, int uid, int visibility) {
checkCallerIsSystem();
mRankingHelper.setVisibilityOverride(pkg, uid, topic, visibility);
mRankingHelper.setVisibilityOverride(pkg, uid, visibility);
savePolicyFile();
}
@Override
public int getVisibilityOverride(String pkg, int uid, Notification.Topic topic) {
public int getVisibilityOverride(String pkg, int uid) {
checkCallerIsSystem();
return mRankingHelper.getVisibilityOverride(pkg, uid, topic);
return mRankingHelper.getVisibilityOverride(pkg, uid);
}
@Override
public void setImportance(String pkg, int uid, Notification.Topic topic,
int importance) {
public void setImportance(String pkg, int uid, int importance) {
enforceSystemOrSystemUI("Caller not system or systemui");
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.setImportance(pkg, uid, topic, importance);
setNotificationsEnabledForPackageImpl(pkg, uid,
importance != NotificationListenerService.Ranking.IMPORTANCE_NONE);
mRankingHelper.setImportance(pkg, uid, importance);
savePolicyFile();
}
@Override
public int getTopicImportance(String pkg, String topicId) {
public int getPackageImportance(String pkg) {
checkCallerIsSystemOrSameApp(pkg);
return mRankingHelper.getImportance(pkg, Binder.getCallingUid(), topicId);
return mRankingHelper.getImportance(pkg, Binder.getCallingUid());
}
@Override
public int getImportance(String pkg, int uid, Notification.Topic topic) {
public int getImportance(String pkg, int uid) {
checkCallerIsSystem();
return mRankingHelper.getImportance(pkg, uid, topic);
}
@Override
public boolean doesUserUseTopics(String pkg, int uid) {
enforceSystemOrSystemUI("Caller not system or systemui");
return mRankingHelper.doesUserUseTopics(pkg, uid);
return mRankingHelper.getImportance(pkg, uid);
}
/**
@@ -2381,11 +2351,9 @@ public class NotificationManagerService extends SystemService {
mRankingHelper.extractSignals(r);
// why is this here?
savePolicyFile();
final boolean isPackageSuspended = isPackageSuspendedForUser(pkg, callingUid);
// blocked apps/topics
// blocked apps
if (r.getImportance() == NotificationListenerService.Ranking.IMPORTANCE_NONE
|| !noteNotificationOp(pkg, callingUid) || isPackageSuspended) {
if (!isSystemNotification) {
@@ -3182,11 +3150,11 @@ public class NotificationManagerService extends SystemService {
}
/**
* Cancels all notifications from a given package or topic that have all of the
* Cancels all notifications from a given package 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, Notification.Topic topic,
int mustNotHaveFlags, boolean doit, int userId, int reason,
ManagedServiceInfo listener) {
String listenerName = listener == null ? null : listener.component.toShortString();
EventLogTags.writeNotificationCancelAll(callingUid, callingPid,
@@ -3214,10 +3182,6 @@ 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

@@ -35,7 +35,6 @@ import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.server.EventLogTags;
import java.io.PrintWriter;
@@ -92,12 +91,12 @@ public final class NotificationRecord {
private int mAuthoritativeRank;
private String mGlobalSortKey;
private int mPackageVisibility;
private int mTopicImportance = IMPORTANCE_UNSPECIFIED;
private int mUserImportance = IMPORTANCE_UNSPECIFIED;
private int mImportance = IMPORTANCE_UNSPECIFIED;
private CharSequence mImportanceExplanation = null;
private int mSuppressedVisualEffects = 0;
private String mTopicExplanation;
private String mUserExplanation;
private String mPeopleExplanation;
@VisibleForTesting
@@ -182,7 +181,7 @@ public final class NotificationRecord {
mRankingTimeMs = calculateRankingTimeMs(previous.getRankingTimeMs());
mCreationTimeMs = previous.mCreationTimeMs;
mVisibleSinceMs = previous.mVisibleSinceMs;
mTopicImportance = previous.mTopicImportance;
mUserImportance = previous.mUserImportance;
mImportance = previous.mImportance;
mImportanceExplanation = previous.mImportanceExplanation;
// Don't copy mGlobalSortKey, recompute it.
@@ -274,8 +273,8 @@ public final class NotificationRecord {
pw.println(prefix + " mRecentlyIntrusive=" + mRecentlyIntrusive);
pw.println(prefix + " mPackagePriority=" + mPackagePriority);
pw.println(prefix + " mPackageVisibility=" + mPackageVisibility);
pw.println(prefix + " mTopicImportance="
+ NotificationListenerService.Ranking.importanceToString(mTopicImportance));
pw.println(prefix + " mUserImportance="
+ NotificationListenerService.Ranking.importanceToString(mUserImportance));
pw.println(prefix + " mImportance="
+ NotificationListenerService.Ranking.importanceToString(mImportance));
pw.println(prefix + " mImportanceExplanation=" + mImportanceExplanation);
@@ -356,17 +355,17 @@ public final class NotificationRecord {
return mPackageVisibility;
}
public void setTopicImportance(int importance) {
mTopicImportance = importance;
applyTopicImportance();
public void setUserImportance(int importance) {
mUserImportance = importance;
applyUserImportance();
}
private String getTopicExplanation() {
if (mTopicExplanation == null) {
mTopicExplanation =
mContext.getString(com.android.internal.R.string.importance_from_topic);
private String getUserExplanation() {
if (mUserExplanation == null) {
mUserExplanation =
mContext.getString(com.android.internal.R.string.importance_from_user);
}
return mTopicExplanation;
return mUserExplanation;
}
private String getPeopleExplanation() {
@@ -377,15 +376,15 @@ public final class NotificationRecord {
return mPeopleExplanation;
}
private void applyTopicImportance() {
if (mTopicImportance != NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED) {
mImportance = mTopicImportance;
mImportanceExplanation = getTopicExplanation();
private void applyUserImportance() {
if (mUserImportance != NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED) {
mImportance = mUserImportance;
mImportanceExplanation = getUserExplanation();
}
}
public int getTopicImportance() {
return mTopicImportance;
public int getUserImportance() {
return mUserImportance;
}
public void setImportance(int importance, CharSequence explanation) {
@@ -393,7 +392,7 @@ public final class NotificationRecord {
mImportance = importance;
mImportanceExplanation = explanation;
}
applyTopicImportance();
applyUserImportance();
}
public int getImportance() {
@@ -528,6 +527,6 @@ public final class NotificationRecord {
}
public boolean isImportanceFromUser() {
return mImportance == mTopicImportance;
return mImportance == mUserImportance;
}
}

View File

@@ -21,7 +21,7 @@ import android.util.Slog;
/**
* Determines if the given notification can bypass Do Not Disturb.
*/
public class TopicPriorityExtractor implements NotificationSignalExtractor {
public class PriorityExtractor implements NotificationSignalExtractor {
private static final String TAG = "ImportantTopicExtractor";
private static final boolean DBG = false;
@@ -42,9 +42,8 @@ public class TopicPriorityExtractor implements NotificationSignalExtractor {
return null;
}
final int packagePriority = mConfig.getPriority(record.sbn.getPackageName(),
record.sbn.getUid(), record.sbn.getNotification().getTopic());
record.setPackagePriority(packagePriority);
record.setPackagePriority(
mConfig.getPriority(record.sbn.getPackageName(), record.sbn.getUid()));
return null;
}

View File

@@ -15,30 +15,17 @@
*/
package com.android.server.notification;
import android.app.Notification;
import java.util.List;
public interface RankingConfig {
List<Notification.Topic> getTopics(String packageName, int uid);
int getPriority(String packageName, int uid);
int getPriority(String packageName, int uid, Notification.Topic topic);
void setPriority(String packageName, int uid, int priority);
void setPriority(String packageName, int uid, Notification.Topic topic, int priority);
int getVisibilityOverride(String packageName, int uid);
int getVisibilityOverride(String packageName, int uid, Notification.Topic topic);
void setVisibilityOverride(String packageName, int uid, int visibility);
void setVisibilityOverride(String packageName, int uid, Notification.Topic topic,
int visibility);
void setImportance(String packageName, int uid, int importance);
void setImportance(String packageName, int uid, Notification.Topic topic, int importance);
int getImportance(String packageName, int uid, Notification.Topic topic);
boolean doesUserUseTopics(String packageName, int uid);
boolean hasBannedTopics(String packageName, int uid);
int getImportance(String packageName, int uid, String topicId);
int getImportance(String packageName, int uid);
}

View File

@@ -20,14 +20,11 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.Ranking;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Slog;
import com.android.internal.R;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
@@ -36,8 +33,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class RankingHelper implements RankingConfig {
private static final String TAG = "RankingHelper";
@@ -47,7 +42,6 @@ public class RankingHelper implements RankingConfig {
private static final String TAG_RANKING = "ranking";
private static final String TAG_PACKAGE = "package";
private static final String ATT_VERSION = "version";
private static final String TAG_TOPIC = "topic";
private static final String ATT_NAME = "name";
private static final String ATT_UID = "uid";
@@ -141,8 +135,6 @@ public class RankingHelper implements RankingConfig {
if (type == XmlPullParser.START_TAG) {
if (TAG_PACKAGE.equals(tag)) {
int uid = safeInt(parser, ATT_UID, Record.UNKNOWN_UID);
int priority = safeInt(parser, ATT_PRIORITY, DEFAULT_PRIORITY);
int vis = safeInt(parser, ATT_VISIBILITY, DEFAULT_VISIBILITY);
String name = parser.getAttributeValue(null, ATT_NAME);
if (!TextUtils.isEmpty(name)) {
@@ -165,16 +157,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.
Topic defaultTopic = r.topics.get(Notification.TOPIC_DEFAULT);
defaultTopic.priority = priority;
defaultTopic.visibility = vis;
parseTopics(r, parser);
r.priority = safeInt(parser, ATT_PRIORITY, DEFAULT_PRIORITY);
r.visibility = safeInt(parser, ATT_VISIBILITY, DEFAULT_VISIBILITY);
}
}
}
@@ -182,42 +166,6 @@ public class RankingHelper implements RankingConfig {
throw new IllegalStateException("Failed to reach END_DOCUMENT");
}
public void parseTopics(Record r, XmlPullParser parser)
throws XmlPullParserException, IOException {
final int innerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
String tagName = parser.getName();
if (TAG_TOPIC.equals(tagName)) {
int priority = safeInt(parser, ATT_PRIORITY, DEFAULT_PRIORITY);
int vis = safeInt(parser, ATT_VISIBILITY, DEFAULT_VISIBILITY);
int importance = safeInt(parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
String id = parser.getAttributeValue(null, ATT_TOPIC_ID);
CharSequence label = parser.getAttributeValue(null, ATT_TOPIC_LABEL);
if (!TextUtils.isEmpty(id)) {
Topic topic = new Topic(new Notification.Topic(id, label));
if (priority != DEFAULT_PRIORITY) {
topic.priority = priority;
}
if (vis != DEFAULT_VISIBILITY) {
topic.visibility = vis;
}
if (importance != DEFAULT_IMPORTANCE) {
topic.importance = importance;
}
r.topics.put(id, topic);
}
}
}
}
private static String recordKey(String pkg, int uid) {
return pkg + "|" + uid;
}
@@ -229,7 +177,6 @@ public class RankingHelper implements RankingConfig {
r = new Record();
r.pkg = pkg;
r.uid = uid;
r.topics.put(Notification.TOPIC_DEFAULT, new Topic(createDefaultTopic()));
mRecords.put(key, r);
}
return r;
@@ -246,46 +193,31 @@ public class RankingHelper implements RankingConfig {
if (forBackup && UserHandle.getUserId(r.uid) != UserHandle.USER_SYSTEM) {
continue;
}
out.startTag(null, TAG_PACKAGE);
out.attribute(null, ATT_NAME, r.pkg);
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));
}
final boolean hasNonDefaultSettings = r.importance != DEFAULT_IMPORTANCE
|| r.priority != DEFAULT_PRIORITY || r.visibility != DEFAULT_VISIBILITY;
if (hasNonDefaultSettings) {
out.startTag(null, TAG_PACKAGE);
out.attribute(null, ATT_NAME, r.pkg);
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));
}
if (!forBackup) {
out.attribute(null, ATT_UID, Integer.toString(r.uid));
}
writeTopicsXml(out, r);
out.endTag(null, TAG_PACKAGE);
out.endTag(null, TAG_PACKAGE);
}
}
out.endTag(null, TAG_RANKING);
}
public void writeTopicsXml(XmlSerializer out, Record r) throws IOException {
for (Topic t : r.topics.values()) {
out.startTag(null, TAG_TOPIC);
out.attribute(null, ATT_TOPIC_ID, t.topic.getId());
out.attribute(null, ATT_TOPIC_LABEL, t.topic.getLabel().toString());
if (t.priority != DEFAULT_PRIORITY) {
out.attribute(null, ATT_PRIORITY, Integer.toString(t.priority));
}
if (t.visibility != DEFAULT_VISIBILITY) {
out.attribute(null, ATT_VISIBILITY, Integer.toString(t.visibility));
}
if (t.importance != DEFAULT_IMPORTANCE) {
out.attribute(null, ATT_IMPORTANCE, Integer.toString(t.importance));
}
out.endTag(null, TAG_TOPIC);
}
}
private void updateConfig() {
final int N = mSignalExtractors.length;
for (int i = 0; i < N; i++) {
@@ -370,189 +302,62 @@ public class RankingHelper implements RankingConfig {
}
}
private static boolean safeBool(XmlPullParser parser, String att, boolean defValue) {
final String val = parser.getAttributeValue(null, att);
return tryParseBool(val, defValue);
}
private static boolean tryParseBool(String value, boolean defValue) {
if (TextUtils.isEmpty(value)) return defValue;
return Boolean.valueOf(value);
}
/**
* Gets priority.
*/
@Override
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()) {
topics.add(t.topic);
}
return topics;
}
@Override
public boolean hasBannedTopics(String packageName, int uid) {
final Record r = getOrCreateRecord(packageName, uid);
for (Topic t : r.topics.values()) {
if (t.importance == Ranking.IMPORTANCE_NONE) {
return true;
}
}
return false;
public int getPriority(String packageName, int uid) {
return getOrCreateRecord(packageName, uid).priority;
}
/**
* Gets priority. If a topic is given, returns the priority of that topic. Otherwise, the
* priority of the app.
* Sets priority.
*/
@Override
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 setPriority(String packageName, int uid, Notification.Topic topic,
int priority) {
final Record r = getOrCreateRecord(packageName, uid);
if (topic == null) {
r.priority = priority;
for (Topic t : r.topics.values()) {
t.priority = priority;
}
} else {
getOrCreateTopic(r, topic).priority = priority;
}
public void setPriority(String packageName, int uid, int priority) {
getOrCreateRecord(packageName, uid).priority = priority;
updateConfig();
}
/**
* Gets visual override. If a topic is given, returns the override of that topic. Otherwise, the
* override of the app.
* Gets visual override.
*/
@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;
public int getVisibilityOverride(String packageName, int uid) {
return getOrCreateRecord(packageName, uid).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.
* Sets visibility override.
*/
@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;
}
public void setVisibilityOverride(String pkgName, int uid, int visibility) {
getOrCreateRecord(pkgName, uid).visibility = visibility;
updateConfig();
}
/**
* Gets the importance of a topic. Unlike {@link #getImportance(String, int, String)}, does not
* create package or topic records if they don't exist.
* Gets importance.
*/
@Override
public int getImportance(String packageName, int uid, String topicId) {
final String key = recordKey(packageName, uid);
Record r = mRecords.get(key);
if (r == null) {
return Ranking.IMPORTANCE_UNSPECIFIED;
}
Topic t = r.topics.get(topicId);
if (t == null) {
return Ranking.IMPORTANCE_UNSPECIFIED;
}
return t.importance;
public int getImportance(String packageName, int uid) {
return getOrCreateRecord(packageName, uid).importance;
}
/**
* Gets importance. If a topic is given, returns the importance of that topic. Otherwise, the
* importance of the app.
* Sets importance.
*/
@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 setImportance(String pkgName, int uid, Notification.Topic topic,
int importance) {
final Record r = getOrCreateRecord(pkgName, uid);
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;
}
public void setImportance(String pkgName, int uid, int importance) {
getOrCreateRecord(pkgName, uid).importance = importance;
updateConfig();
}
@Override
public boolean doesUserUseTopics(String pkgName, int uid) {
final Record r = getOrCreateRecord(pkgName, uid);
for (Topic topic : r.topics.values()) {
if (topic.importance != Ranking.IMPORTANCE_UNSPECIFIED
&& r.importance != topic.importance)
return true;
}
return false;
}
private Topic getOrCreateTopic(Record r, Notification.Topic topic) {
if (topic == null) {
topic = createDefaultTopic();
}
Topic t = r.topics.get(topic.getId());
if (t != null) {
return t;
} 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;
}
}
private Notification.Topic createDefaultTopic() {
return new Notification.Topic(Notification.TOPIC_DEFAULT,
mContext.getString(R.string.default_notification_topic_label));
}
public void dump(PrintWriter pw, String prefix, NotificationManagerService.DumpFilter filter) {
if (filter == null) {
final int N = mSignalExtractors.length;
@@ -600,25 +405,6 @@ public class RankingHelper implements RankingConfig {
pw.print(Ranking.importanceToString(r.visibility));
}
pw.println();
for (Topic t : r.topics.values()) {
pw.print(prefix);
pw.print(" ");
pw.print(" ");
pw.print(t.topic.getId());
if (t.priority != DEFAULT_PRIORITY) {
pw.print(" priority=");
pw.print(Notification.priorityToString(t.priority));
}
if (t.visibility != DEFAULT_VISIBILITY) {
pw.print(" visibility=");
pw.print(Notification.visibilityToString(t.visibility));
}
if (t.importance != DEFAULT_IMPORTANCE) {
pw.print(" importance=");
pw.print(Ranking.importanceToString(t.importance));
}
pw.println();
}
}
}
}
@@ -657,17 +443,5 @@ public class RankingHelper implements RankingConfig {
int importance = DEFAULT_IMPORTANCE;
int priority = DEFAULT_PRIORITY;
int visibility = DEFAULT_VISIBILITY;
Map<String, Topic> topics = new ArrayMap<>();
}
private static class Topic {
Notification.Topic topic;
int priority = DEFAULT_PRIORITY;
int visibility = DEFAULT_VISIBILITY;
int importance = DEFAULT_IMPORTANCE;
public Topic(Notification.Topic topic) {
this.topic = topic;
}
}
}

View File

@@ -21,8 +21,8 @@ import android.util.Slog;
/**
* Determines if the given notification can display sensitive content on the lockscreen.
*/
public class TopicVisibilityExtractor implements NotificationSignalExtractor {
private static final String TAG = "TopicVisibilityExtractor";
public class VisibilityExtractor implements NotificationSignalExtractor {
private static final String TAG = "VisibilityExtractor";
private static final boolean DBG = false;
private RankingConfig mConfig;
@@ -42,10 +42,8 @@ public class TopicVisibilityExtractor implements NotificationSignalExtractor {
return null;
}
final int packageVisibility = mConfig.getVisibilityOverride(
record.sbn.getPackageName(), record.sbn.getUid(),
record.sbn.getNotification().getTopic());
record.setPackageVisibilityOverride(packageVisibility);
record.setPackageVisibilityOverride(
mConfig.getVisibilityOverride(record.sbn.getPackageName(), record.sbn.getUid()));
return null;
}

View File

@@ -25,7 +25,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import android.app.Notification;
import android.os.Handler;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.test.AndroidTestCase;
@@ -55,14 +54,13 @@ public class RankingHelperTest extends AndroidTestCase {
UserHandle user = UserHandle.ALL;
mHelper = new RankingHelper(getContext(), handler, mUsageStats,
new String[] {TopicImportanceExtractor.class.getName()});
new String[] {ImportanceExtractor.class.getName()});
mNotiGroupGSortA = new Notification.Builder(getContext())
.setContentTitle("A")
.setGroup("G")
.setSortKey("A")
.setWhen(1205)
.setTopic(new Notification.Topic("A", "a"))
.build();
mRecordGroupGSortA = new NotificationRecord(getContext(), new StatusBarNotification(
"package", "package", 1, null, 0, 0, 0, mNotiGroupGSortA, user));
@@ -72,7 +70,6 @@ public class RankingHelperTest extends AndroidTestCase {
.setGroup("G")
.setSortKey("B")
.setWhen(1200)
.setTopic(new Notification.Topic("A", "a"))
.build();
mRecordGroupGSortB = new NotificationRecord(getContext(), new StatusBarNotification(
"package", "package", 1, null, 0, 0, 0, mNotiGroupGSortB, user));
@@ -80,7 +77,6 @@ public class RankingHelperTest extends AndroidTestCase {
mNotiNoGroup = new Notification.Builder(getContext())
.setContentTitle("C")
.setWhen(1201)
.setTopic(new Notification.Topic("C", "c"))
.build();
mRecordNoGroup = new NotificationRecord(getContext(), new StatusBarNotification(
"package", "package", 1, null, 0, 0, 0, mNotiNoGroup, user));
@@ -88,7 +84,6 @@ public class RankingHelperTest extends AndroidTestCase {
mNotiNoGroup2 = new Notification.Builder(getContext())
.setContentTitle("D")
.setWhen(1202)
.setTopic(new Notification.Topic("D", "d"))
.build();
mRecordNoGroup2 = new NotificationRecord(getContext(), new StatusBarNotification(
"package", "package", 1, null, 0, 0, 0, mNotiNoGroup2, user));
@@ -97,7 +92,6 @@ public class RankingHelperTest extends AndroidTestCase {
.setContentTitle("E")
.setWhen(1201)
.setSortKey("A")
.setTopic(new Notification.Topic("E", "e"))
.build();
mRecordNoGroupSortA = new NotificationRecord(getContext(), new StatusBarNotification(
"package", "package", 1, null, 0, 0, 0, mNotiNoGroupSortA, user));
@@ -152,26 +146,4 @@ public class RankingHelperTest extends AndroidTestCase {
ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>();
mHelper.sort(notificationList);
}
@SmallTest
public void testTopicImportanceExtractor() throws Exception {
mHelper.setImportance("package", 0, new Notification.Topic("A", "a"), IMPORTANCE_MAX);
// There is no B. There never was a b. Moving on...
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.setImportance("package2", 0, new Notification.Topic("E", "e"), IMPORTANCE_NONE);
TopicImportanceExtractor validator = mHelper.findExtractor(TopicImportanceExtractor.class);
validator.process(mRecordGroupGSortA);
validator.process(mRecordGroupGSortB);
validator.process(mRecordNoGroup);
validator.process(mRecordNoGroup2);
validator.process(mRecordNoGroupSortA);
assertTrue(mRecordGroupGSortA.getTopicImportance() == IMPORTANCE_MAX);
assertTrue(mRecordGroupGSortB.getTopicImportance() == IMPORTANCE_MAX);
assertTrue(mRecordNoGroup.getTopicImportance() == IMPORTANCE_HIGH);
assertTrue(mRecordNoGroup2.getTopicImportance() == IMPORTANCE_LOW);
assertTrue(mRecordNoGroupSortA.getTopicImportance() == IMPORTANCE_UNSPECIFIED);
}
}

View File

@@ -162,78 +162,6 @@ public class NotificationTestList extends TestActivity
}
},
new Test("with topic Hello") {
public void run() {
Notification.BigTextStyle bigText = new Notification.BigTextStyle();
bigText.bigText("FgBHreherhethethethe\ntwetwrterter\netetweterteryetry");
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon1)
.setStyle(bigText)
.setWhen(mActivityCreateTime)
.setContentTitle("hihi")
.setContentText("This is a notification!!!")
.setContentIntent(makeIntent2())
.setTopic(new Notification.Topic("hello", "Hello"))
.build();
mNM.notify(70, n);
}
},
new Test("with topic GoodBye") {
public void run() {
Notification.BigPictureStyle picture = new Notification.BigPictureStyle();
picture.bigPicture(BitmapFactory.decodeResource(getResources(),
R.id.large_icon_pineapple2));
Notification n = new Notification.Builder(NotificationTestList.this)
.setSmallIcon(R.drawable.icon1)
.setWhen(mActivityCreateTime)
.setContentTitle("byebye")
.setContentText("This is a notification!!!")
.setContentIntent(makeIntent2())
.setTopic(new Notification.Topic("bye", "Goodbye"))
.setStyle(picture)
.build();
mNM.notify(71, n);
}
},
new Test("with topic Bananas") {
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!!!")
.setContentIntent(makeIntent2())
.setTopic(new Notification.Topic("bananas", "Bananas"))
.build();
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("Is blocked?") {
public void run() {
Toast.makeText(NotificationTestList.this,
@@ -242,18 +170,10 @@ public class NotificationTestList extends TestActivity
}
},
new Test("Topic banana importance?") {
new Test("importance?") {
public void run() {
Toast.makeText(NotificationTestList.this,
"bananas importance? " + mNM.getImportance("bananas"),
Toast.LENGTH_LONG).show();
}
},
new Test("Topic garbage importance?") {
public void run() {
Toast.makeText(NotificationTestList.this,
"garbage importance? " + mNM.getImportance("garbage"),
"importance? " + mNM.getImportance(),
Toast.LENGTH_LONG).show();
}
},