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";
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
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);
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);
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);
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";
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
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);
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);
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);
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";
}
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";
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
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);
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);
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);
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.
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.
*/
}
color = parcel.readInt();
-
- if (parcel.readInt() != 0) {
- topic = Topic.CREATOR.createFromParcel(parcel);
- }
}
@Override
that.color = this.color;
- if (this.topic != null) {
- that.topic = this.topic.clone();
- }
-
if (!heavy) {
that.lightenPayload(); // will clean out extras
}
}
parcel.writeInt(color);
-
- if (topic != null) {
- parcel.writeInt(1);
- topic.writeToParcel(parcel, 0);
- } else {
- parcel.writeInt(0);
- }
}
/**
sb.append(" publicVersion=");
sb.append(publicVersion.toString());
}
- if (topic != null) {
- sb.append("topic=");
- sb.append(topic.toString());
- }
sb.append(")");
return sb.toString();
}
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.
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;
/** 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;
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
<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] -->
<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" />
<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" />
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
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;
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 {
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);
- }
}
}
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;
}
}
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) {
// :(
}
/**
* 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;
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;
}
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;
for (String pkgName : pkgList) {
if (cancelNotifications) {
cancelAllNotificationsInt(MY_UID, MY_PID, pkgName, 0, 0, !queryRestart,
- changeUserId, reason, null, null);
+ changeUserId, reason, null);
}
}
}
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
// 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);
}
}
// 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
}
@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);
}
/**
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) {
}
/**
- * 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,
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<>();
}
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;
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
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.
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);
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() {
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) {
mImportance = importance;
mImportanceExplanation = explanation;
}
- applyTopicImportance();
+ applyUserImportance();
}
public int getImportance() {
}
public boolean isImportanceFromUser() {
- return mImportance == mTopicImportance;
+ return mImportance == mUserImportance;
}
}
/**
* 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;
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;
}
*/
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, Notification.Topic topic);
-
- void setPriority(String packageName, int uid, Notification.Topic topic, int priority);
-
- int getVisibilityOverride(String packageName, int uid, Notification.Topic topic);
-
- void setVisibilityOverride(String packageName, int uid, Notification.Topic topic,
- int visibility);
+ int getPriority(String packageName, int uid);
- void setImportance(String packageName, int uid, Notification.Topic topic, int importance);
+ void setPriority(String packageName, int uid, int priority);
- int getImportance(String packageName, int uid, Notification.Topic topic);
+ int getVisibilityOverride(String packageName, int uid);
- boolean doesUserUseTopics(String packageName, int uid);
+ void setVisibilityOverride(String packageName, int uid, int visibility);
- boolean hasBannedTopics(String packageName, int uid);
+ void setImportance(String packageName, int uid, int importance);
- int getImportance(String packageName, int uid, String topicId);
+ int getImportance(String packageName, int uid);
}
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;
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";
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";
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)) {
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);
}
}
}
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;
}
r = new Record();
r.pkg = pkg;
r.uid = uid;
- r.topics.put(Notification.TOPIC_DEFAULT, new Topic(createDefaultTopic()));
mRecords.put(key, r);
}
return r;
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));
- }
-
- if (!forBackup) {
- out.attribute(null, ATT_UID, Integer.toString(r.uid));
- }
+ 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));
+ }
- writeTopicsXml(out, r);
- out.endTag(null, TAG_PACKAGE);
- }
- out.endTag(null, TAG_RANKING);
- }
+ if (!forBackup) {
+ out.attribute(null, ATT_UID, Integer.toString(r.uid));
+ }
- 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));
+ out.endTag(null, TAG_PACKAGE);
}
- if (t.importance != DEFAULT_IMPORTANCE) {
- out.attribute(null, ATT_IMPORTANCE, Integer.toString(t.importance));
- }
- out.endTag(null, TAG_TOPIC);
}
+ out.endTag(null, TAG_RANKING);
}
private void updateConfig() {
}
}
- 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);
}
- @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;
- }
-
/**
- * Gets priority. If a topic is given, returns the priority of that topic. Otherwise, the
- * priority of the app.
+ * Gets 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;
+ public int getPriority(String packageName, int uid) {
+ return getOrCreateRecord(packageName, uid).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.
+ * Sets priority.
*/
@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.
- */
- @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;
- }
-
- /**
- * Gets importance. If a topic is given, returns the importance of that topic. Otherwise, the
- * importance of the app.
+ * Gets 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;
+ public int getImportance(String packageName, int uid) {
+ return getOrCreateRecord(packageName, uid).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).
+ * Sets importance.
*/
@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;
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();
- }
}
}
}
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;
- }
- }
}
/**
* 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;
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;
}
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;
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));
.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));
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));
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));
.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));
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);
- }
}
}
},
- 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,
}
},
- new Test("Topic banana importance?") {
- public void run() {
- Toast.makeText(NotificationTestList.this,
- "bananas importance? " + mNM.getImportance("bananas"),
- Toast.LENGTH_LONG).show();
- }
- },
-
- new Test("Topic garbage importance?") {
+ new Test("importance?") {
public void run() {
Toast.makeText(NotificationTestList.this,
- "garbage importance? " + mNM.getImportance("garbage"),
+ "importance? " + mNM.getImportance(),
Toast.LENGTH_LONG).show();
}
},