Make bad notifications crash their application.

Implement notification manager handling of bad notifications, to
call a new activity manager to have the owner's process crashed
(if there is one).

Change-Id: Ib15e8d0c598756f3b39c99cc2045c18e054daf6b
This commit is contained in:
Dianne Hackborn
2010-06-24 15:57:42 -07:00
parent 01e4cfc47d
commit 9d39d0cb36
11 changed files with 161 additions and 12 deletions

View File

@@ -164,16 +164,21 @@ class NotificationManagerService extends INotificationManager.Stub
final String pkg;
final String tag;
final int id;
final int uid;
final int initialPid;
ITransientNotification callback;
int duration;
final Notification notification;
IBinder statusBarKey;
NotificationRecord(String pkg, String tag, int id, Notification notification)
NotificationRecord(String pkg, String tag, int id, int uid, int initialPid,
Notification notification)
{
this.pkg = pkg;
this.tag = tag;
this.id = id;
this.uid = uid;
this.initialPid = initialPid;
this.notification = notification;
}
@@ -304,10 +309,18 @@ class NotificationManagerService extends INotificationManager.Stub
}
}
public void onNotificationError(String pkg, String tag, int id, String message) {
public void onNotificationError(String pkg, String tag, int id,
int uid, int initialPid, String message) {
Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id);
cancelNotification(pkg, tag, id, 0, 0);
// TODO: Tell the activity manager.
long ident = Binder.clearCallingIdentity();
try {
ActivityManagerNative.getDefault().crashApplication(uid, initialPid, pkg,
"Bad notification posted from package " + pkg
+ ": " + message);
} catch (RemoteException e) {
}
Binder.restoreCallingIdentity(ident);
}
};
@@ -663,6 +676,9 @@ class NotificationManagerService extends INotificationManager.Stub
public void enqueueNotificationWithTag(String pkg, String tag, int id,
Notification notification, int[] idOut)
{
final int callingUid = Binder.getCallingUid();
final int callingPid = Binder.getCallingPid();
checkIncomingCall(pkg);
// Limit the number of notifications that any given package except the android
@@ -708,7 +724,8 @@ class NotificationManagerService extends INotificationManager.Stub
}
synchronized (mNotificationList) {
NotificationRecord r = new NotificationRecord(pkg, tag, id, notification);
NotificationRecord r = new NotificationRecord(pkg, tag, id,
callingUid, callingPid, notification);
NotificationRecord old = null;
int index = indexOfNotificationLocked(pkg, tag, id);
@@ -732,7 +749,8 @@ class NotificationManagerService extends INotificationManager.Stub
}
if (notification.icon != 0) {
StatusBarNotification n = new StatusBarNotification(pkg, id, tag, notification);
StatusBarNotification n = new StatusBarNotification(pkg, id, tag,
r.uid, r.initialPid, notification);
if (old != null && old.statusBarKey != null) {
r.statusBarKey = old.statusBarKey;
long identity = Binder.clearCallingIdentity();