Move notification channel from record to sbn.
So notificationlisteners know about it. Test: runtest systemui-notification Change-Id: I28fc86730d3f7ad246a0164f44157594f57430c0
This commit is contained in:
@@ -34985,7 +34985,7 @@ package android.service.notification {
|
||||
}
|
||||
|
||||
public class StatusBarNotification implements android.os.Parcelable {
|
||||
ctor public StatusBarNotification(java.lang.String, java.lang.String, int, java.lang.String, int, int, int, android.app.Notification, android.os.UserHandle, long);
|
||||
ctor public deprecated StatusBarNotification(java.lang.String, java.lang.String, int, java.lang.String, int, int, int, android.app.Notification, android.os.UserHandle, long);
|
||||
ctor public StatusBarNotification(android.os.Parcel);
|
||||
method public android.service.notification.StatusBarNotification clone();
|
||||
method public int describeContents();
|
||||
@@ -34993,6 +34993,7 @@ package android.service.notification {
|
||||
method public int getId();
|
||||
method public java.lang.String getKey();
|
||||
method public android.app.Notification getNotification();
|
||||
method public android.app.NotificationChannel getNotificationChannel();
|
||||
method public java.lang.String getOverrideGroupKey();
|
||||
method public java.lang.String getPackageName();
|
||||
method public long getPostTime();
|
||||
|
||||
@@ -37784,7 +37784,7 @@ package android.service.notification {
|
||||
}
|
||||
|
||||
public class StatusBarNotification implements android.os.Parcelable {
|
||||
ctor public StatusBarNotification(java.lang.String, java.lang.String, int, java.lang.String, int, int, int, android.app.Notification, android.os.UserHandle, long);
|
||||
ctor public deprecated StatusBarNotification(java.lang.String, java.lang.String, int, java.lang.String, int, int, int, android.app.Notification, android.os.UserHandle, long);
|
||||
ctor public StatusBarNotification(android.os.Parcel);
|
||||
method public android.service.notification.StatusBarNotification clone();
|
||||
method public int describeContents();
|
||||
@@ -37792,6 +37792,7 @@ package android.service.notification {
|
||||
method public int getId();
|
||||
method public java.lang.String getKey();
|
||||
method public android.app.Notification getNotification();
|
||||
method public android.app.NotificationChannel getNotificationChannel();
|
||||
method public java.lang.String getOverrideGroupKey();
|
||||
method public java.lang.String getPackageName();
|
||||
method public long getPostTime();
|
||||
|
||||
@@ -35074,7 +35074,7 @@ package android.service.notification {
|
||||
}
|
||||
|
||||
public class StatusBarNotification implements android.os.Parcelable {
|
||||
ctor public StatusBarNotification(java.lang.String, java.lang.String, int, java.lang.String, int, int, int, android.app.Notification, android.os.UserHandle, long);
|
||||
ctor public deprecated StatusBarNotification(java.lang.String, java.lang.String, int, java.lang.String, int, int, int, android.app.Notification, android.os.UserHandle, long);
|
||||
ctor public StatusBarNotification(android.os.Parcel);
|
||||
method public android.service.notification.StatusBarNotification clone();
|
||||
method public int describeContents();
|
||||
@@ -35082,6 +35082,7 @@ package android.service.notification {
|
||||
method public int getId();
|
||||
method public java.lang.String getKey();
|
||||
method public android.app.Notification getNotification();
|
||||
method public android.app.NotificationChannel getNotificationChannel();
|
||||
method public java.lang.String getOverrideGroupKey();
|
||||
method public java.lang.String getPackageName();
|
||||
method public long getPostTime();
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.service.notification;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -42,25 +43,21 @@ public class StatusBarNotification implements Parcelable {
|
||||
private final Notification notification;
|
||||
private final UserHandle user;
|
||||
private final long postTime;
|
||||
private final NotificationChannel channel;
|
||||
|
||||
private Context mContext; // used for inflation & icon expansion
|
||||
|
||||
/** @hide */
|
||||
public StatusBarNotification(String pkg, String opPkg, int id, String tag, int uid,
|
||||
int initialPid, int score, Notification notification, UserHandle user) {
|
||||
this(pkg, opPkg, id, tag, uid, initialPid, score, notification, user,
|
||||
System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public StatusBarNotification(String pkg, String opPkg, int id, String tag, int uid,
|
||||
int initialPid, Notification notification, UserHandle user, String overrideGroupKey,
|
||||
long postTime) {
|
||||
public StatusBarNotification(String pkg, String opPkg, NotificationChannel channel, int id,
|
||||
String tag, int uid, int initialPid, Notification notification, UserHandle user,
|
||||
String overrideGroupKey, long postTime) {
|
||||
if (pkg == null) throw new NullPointerException();
|
||||
if (notification == null) throw new NullPointerException();
|
||||
if (channel == null) throw new IllegalArgumentException();
|
||||
|
||||
this.pkg = pkg;
|
||||
this.opPkg = opPkg;
|
||||
this.channel = channel;
|
||||
this.id = id;
|
||||
this.tag = tag;
|
||||
this.uid = uid;
|
||||
@@ -73,6 +70,7 @@ public class StatusBarNotification implements Parcelable {
|
||||
this.groupKey = groupKey();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public StatusBarNotification(String pkg, String opPkg, int id, String tag, int uid,
|
||||
int initialPid, int score, Notification notification, UserHandle user,
|
||||
long postTime) {
|
||||
@@ -90,6 +88,7 @@ public class StatusBarNotification implements Parcelable {
|
||||
this.postTime = postTime;
|
||||
this.key = key();
|
||||
this.groupKey = groupKey();
|
||||
this.channel = null;
|
||||
}
|
||||
|
||||
public StatusBarNotification(Parcel in) {
|
||||
@@ -113,6 +112,7 @@ public class StatusBarNotification implements Parcelable {
|
||||
}
|
||||
this.key = key();
|
||||
this.groupKey = groupKey();
|
||||
this.channel = NotificationChannel.CREATOR.createFromParcel(in);
|
||||
}
|
||||
|
||||
private String key() {
|
||||
@@ -182,6 +182,7 @@ public class StatusBarNotification implements Parcelable {
|
||||
} else {
|
||||
out.writeInt(0);
|
||||
}
|
||||
this.channel.writeToParcel(out, flags);
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
@@ -208,14 +209,14 @@ public class StatusBarNotification implements Parcelable {
|
||||
public StatusBarNotification cloneLight() {
|
||||
final Notification no = new Notification();
|
||||
this.notification.cloneInto(no, false); // light copy
|
||||
return new StatusBarNotification(this.pkg, this.opPkg,
|
||||
return new StatusBarNotification(this.pkg, this.opPkg, this.channel,
|
||||
this.id, this.tag, this.uid, this.initialPid,
|
||||
no, this.user, this.overrideGroupKey, this.postTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatusBarNotification clone() {
|
||||
return new StatusBarNotification(this.pkg, this.opPkg,
|
||||
return new StatusBarNotification(this.pkg, this.opPkg, this.channel,
|
||||
this.id, this.tag, this.uid, this.initialPid,
|
||||
this.notification.clone(), this.user, this.overrideGroupKey, this.postTime);
|
||||
}
|
||||
@@ -334,6 +335,13 @@ public class StatusBarNotification implements Parcelable {
|
||||
return overrideGroupKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the channel this notification was posted to.
|
||||
*/
|
||||
public NotificationChannel getNotificationChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
|
||||
@@ -1649,9 +1649,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
newNotification.headsUpContentView = sbn.getNotification().headsUpContentView;
|
||||
|
||||
StatusBarNotification newSbn = new StatusBarNotification(sbn.getPackageName(),
|
||||
sbn.getOpPkg(),
|
||||
sbn.getOpPkg(), sbn.getNotificationChannel(),
|
||||
sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
|
||||
0, newNotification, sbn.getUser(), sbn.getPostTime());
|
||||
newNotification, sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime());
|
||||
|
||||
updateNotification(newSbn, null);
|
||||
mKeysKeptForRemoteInput.add(entry.key);
|
||||
|
||||
@@ -1671,10 +1671,10 @@ public class NotificationManagerService extends SystemService {
|
||||
final StatusBarNotification sbnOut = new StatusBarNotification(
|
||||
sbn.getPackageName(),
|
||||
sbn.getOpPkg(),
|
||||
sbn.getNotificationChannel(),
|
||||
sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
|
||||
0, // hide score from apps
|
||||
sbn.getNotification().clone(),
|
||||
sbn.getUser(), sbn.getPostTime());
|
||||
sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime());
|
||||
list.add(sbnOut);
|
||||
}
|
||||
}
|
||||
@@ -2467,15 +2467,14 @@ public class NotificationManagerService extends SystemService {
|
||||
}
|
||||
final StatusBarNotification summarySbn =
|
||||
new StatusBarNotification(adjustedSbn.getPackageName(),
|
||||
adjustedSbn.getOpPkg(), Integer.MAX_VALUE,
|
||||
adjustedSbn.getOpPkg(),
|
||||
adjustedSbn.getNotificationChannel(),
|
||||
Integer.MAX_VALUE,
|
||||
GroupHelper.AUTOGROUP_KEY, adjustedSbn.getUid(),
|
||||
adjustedSbn.getInitialPid(), summaryNotification,
|
||||
adjustedSbn.getUser(), GroupHelper.AUTOGROUP_KEY,
|
||||
System.currentTimeMillis());
|
||||
summaryRecord = new NotificationRecord(getContext(), summarySbn,
|
||||
mRankingHelper.getNotificationChannel(adjustedSbn.getPackageName(),
|
||||
adjustedSbn.getUid(),
|
||||
adjustedSbn.getNotification().getNotificationChannel()));
|
||||
summaryRecord = new NotificationRecord(getContext(), summarySbn);
|
||||
summaries.put(pkg, summarySbn.getKey());
|
||||
}
|
||||
}
|
||||
@@ -2722,9 +2721,11 @@ public class NotificationManagerService extends SystemService {
|
||||
throw new IllegalArgumentException("null not allowed: pkg=" + pkg
|
||||
+ " id=" + id + " notification=" + notification);
|
||||
}
|
||||
final NotificationChannel channel = mRankingHelper.getNotificationChannelWithFallback(pkg,
|
||||
callingUid, notification.getNotificationChannel());
|
||||
final StatusBarNotification n = new StatusBarNotification(
|
||||
pkg, opPkg, id, tag, callingUid, callingPid, 0, notification,
|
||||
user);
|
||||
pkg, opPkg, channel, id, tag, callingUid, callingPid, notification,
|
||||
user, null, System.currentTimeMillis());
|
||||
|
||||
// Limit the number of notifications that any given package except the android
|
||||
// package or a registered listener can enqueue. Prevents DOS attacks and deals with leaks.
|
||||
@@ -2787,9 +2788,7 @@ public class NotificationManagerService extends SystemService {
|
||||
Notification.PRIORITY_MAX);
|
||||
|
||||
// setup local book-keeping
|
||||
final NotificationRecord r = new NotificationRecord(getContext(), n,
|
||||
mRankingHelper.getNotificationChannelWithFallback(pkg, callingUid,
|
||||
n.getNotification().getNotificationChannel()));
|
||||
final NotificationRecord r = new NotificationRecord(getContext(), n);
|
||||
mHandler.post(new EnqueueNotificationRunnable(userId, r));
|
||||
|
||||
idOut[0] = id;
|
||||
|
||||
@@ -101,11 +101,8 @@ public final class NotificationRecord {
|
||||
private String mUserExplanation;
|
||||
private String mPeopleExplanation;
|
||||
|
||||
private NotificationChannel mNotificationChannel;
|
||||
|
||||
@VisibleForTesting
|
||||
public NotificationRecord(Context context, StatusBarNotification sbn,
|
||||
NotificationChannel channel)
|
||||
public NotificationRecord(Context context, StatusBarNotification sbn)
|
||||
{
|
||||
this.sbn = sbn;
|
||||
mOriginalFlags = sbn.getNotification().flags;
|
||||
@@ -114,7 +111,6 @@ public final class NotificationRecord {
|
||||
mUpdateTimeMs = mCreationTimeMs;
|
||||
mContext = context;
|
||||
stats = new NotificationUsageStats.SingleNotificationStats();
|
||||
mNotificationChannel = channel;
|
||||
mImportance = defaultImportance();
|
||||
}
|
||||
|
||||
@@ -148,8 +144,8 @@ public final class NotificationRecord {
|
||||
|| (n.defaults & Notification.DEFAULT_VIBRATE) != 0
|
||||
|| n.sound != null
|
||||
|| n.vibrate != null
|
||||
|| mNotificationChannel.shouldVibrate()
|
||||
|| mNotificationChannel.getRingtone() != null;
|
||||
|| sbn.getNotificationChannel().shouldVibrate()
|
||||
|| sbn.getNotificationChannel().getRingtone() != null;
|
||||
stats.isNoisy = isNoisy;
|
||||
|
||||
if (!isNoisy && importance > IMPORTANCE_LOW) {
|
||||
@@ -287,7 +283,7 @@ public final class NotificationRecord {
|
||||
pw.println(prefix + " mVisibleSinceMs=" + mVisibleSinceMs);
|
||||
pw.println(prefix + " mUpdateTimeMs=" + mUpdateTimeMs);
|
||||
pw.println(prefix + " mSuppressedVisualEffects= " + mSuppressedVisualEffects);
|
||||
pw.println(prefix + " mNotificationChannel= " + mNotificationChannel);
|
||||
pw.println(prefix + " notificationChannel= " + notification.getNotificationChannel());
|
||||
}
|
||||
|
||||
|
||||
@@ -535,6 +531,6 @@ public final class NotificationRecord {
|
||||
}
|
||||
|
||||
public NotificationChannel getChannel() {
|
||||
return mNotificationChannel;
|
||||
return sbn.getNotificationChannel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,11 +226,11 @@ public class BuzzBeepBlinkTest {
|
||||
if (insistent) {
|
||||
n.flags |= Notification.FLAG_INSISTENT;
|
||||
}
|
||||
StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, mTag, mUid, mPid,
|
||||
mScore, n, mUser, System.currentTimeMillis());
|
||||
NotificationRecord r = new NotificationRecord(getContext(), sbn,
|
||||
new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "misc",
|
||||
NotificationManager.IMPORTANCE_DEFAULT));
|
||||
NotificationChannel channel =
|
||||
new NotificationChannel("test", "test", NotificationManager.IMPORTANCE_HIGH);
|
||||
StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, channel, id, mTag, mUid,
|
||||
mPid, n, mUser, null, System.currentTimeMillis());
|
||||
NotificationRecord r = new NotificationRecord(getContext(), sbn);
|
||||
mService.addNotification(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
@@ -68,7 +69,10 @@ public class GroupHelperTest {
|
||||
if (groupKey != null) {
|
||||
nb.setGroup(groupKey);
|
||||
}
|
||||
return new StatusBarNotification(pkg, pkg, id, tag, 0, 0, 0, nb.build(), user);
|
||||
NotificationChannel channel =
|
||||
new NotificationChannel("test", "test", NotificationManager.IMPORTANCE_LOW);
|
||||
return new StatusBarNotification(pkg, pkg, channel, id, tag, 0, 0, nb.build(), user, null,
|
||||
System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private StatusBarNotification getSbn(String pkg, int id, String tag,
|
||||
|
||||
@@ -69,9 +69,9 @@ public class ImportanceExtractorTest {
|
||||
.setDefaults(Notification.DEFAULT_SOUND);
|
||||
|
||||
Notification n = builder.build();
|
||||
StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, mId, mTag, mUid,
|
||||
mPid, mScore, n, mUser, System.currentTimeMillis());
|
||||
NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
|
||||
StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, channel, mId, mTag, mUid,
|
||||
mPid, n, mUser, null, System.currentTimeMillis());
|
||||
NotificationRecord r = new NotificationRecord(getContext(), sbn);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -98,8 +98,8 @@ public class RankingHelperTest {
|
||||
.setWhen(1205)
|
||||
.build();
|
||||
mRecordGroupGSortA = new NotificationRecord(getContext(), new StatusBarNotification(
|
||||
"package", "package", 1, null, 0, 0, 0, mNotiGroupGSortA, user),
|
||||
getDefaultChannel());
|
||||
"package", "package", getDefaultChannel(), 1, null, 0, 0, mNotiGroupGSortA, user,
|
||||
null, System.currentTimeMillis()));
|
||||
|
||||
mNotiGroupGSortB = new Notification.Builder(getContext())
|
||||
.setContentTitle("B")
|
||||
@@ -108,24 +108,24 @@ public class RankingHelperTest {
|
||||
.setWhen(1200)
|
||||
.build();
|
||||
mRecordGroupGSortB = new NotificationRecord(getContext(), new StatusBarNotification(
|
||||
"package", "package", 1, null, 0, 0, 0, mNotiGroupGSortB, user),
|
||||
getDefaultChannel());
|
||||
"package", "package", getDefaultChannel(), 1, null, 0, 0, mNotiGroupGSortB, user,
|
||||
null, System.currentTimeMillis()));
|
||||
|
||||
mNotiNoGroup = new Notification.Builder(getContext())
|
||||
.setContentTitle("C")
|
||||
.setWhen(1201)
|
||||
.build();
|
||||
mRecordNoGroup = new NotificationRecord(getContext(), new StatusBarNotification(
|
||||
"package", "package", 1, null, 0, 0, 0, mNotiNoGroup, user),
|
||||
getDefaultChannel());
|
||||
"package", "package", getDefaultChannel(), 1, null, 0, 0, mNotiNoGroup, user,
|
||||
null, System.currentTimeMillis()));
|
||||
|
||||
mNotiNoGroup2 = new Notification.Builder(getContext())
|
||||
.setContentTitle("D")
|
||||
.setWhen(1202)
|
||||
.build();
|
||||
mRecordNoGroup2 = new NotificationRecord(getContext(), new StatusBarNotification(
|
||||
"package", "package", 1, null, 0, 0, 0, mNotiNoGroup2, user),
|
||||
getDefaultChannel());
|
||||
"package", "package", getDefaultChannel(), 1, null, 0, 0, mNotiNoGroup2, user,
|
||||
null, System.currentTimeMillis()));
|
||||
|
||||
mNotiNoGroupSortA = new Notification.Builder(getContext())
|
||||
.setContentTitle("E")
|
||||
@@ -133,8 +133,8 @@ public class RankingHelperTest {
|
||||
.setSortKey("A")
|
||||
.build();
|
||||
mRecordNoGroupSortA = new NotificationRecord(getContext(), new StatusBarNotification(
|
||||
"package", "package", 1, null, 0, 0, 0, mNotiNoGroupSortA, user),
|
||||
getDefaultChannel());
|
||||
"package", "package", getDefaultChannel(), 1, null, 0, 0, mNotiNoGroupSortA, user,
|
||||
null, System.currentTimeMillis()));
|
||||
|
||||
final ApplicationInfo legacy = new ApplicationInfo();
|
||||
legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1;
|
||||
|
||||
@@ -178,9 +178,13 @@ public class SnoozeHelperTest {
|
||||
.setWhen(1205)
|
||||
.build();
|
||||
return new NotificationRecord(getContext(), new StatusBarNotification(
|
||||
pkg, pkg, id, tag, 0, 0, 0, n, user),
|
||||
new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name",
|
||||
NotificationManager.IMPORTANCE_HIGH));
|
||||
pkg, pkg, getDefaultChannel(), id, tag, 0, 0, n, user, null,
|
||||
System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
private NotificationChannel getDefaultChannel() {
|
||||
return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name",
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user