From d2b1f00e1e34cdce0047af7374aa57b1e4b5b040 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Fri, 4 Jun 2010 10:42:41 -0700 Subject: [PATCH 1/4] Add some disabled logging and another test case for reapplying the notification views. Change-Id: I839d7771ab42a5d508ce7d15385f6ac6a4e3be83 --- .../systemui/statusbar/PhoneStatusBarService.java | 10 ++++++++++ .../android/statusbartest/NotificationTestList.java | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java index e9ae69a981786..8c57ad6c685f6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java @@ -349,6 +349,16 @@ public class PhoneStatusBarService extends StatusBarService { final RemoteViews contentView = notification.notification.contentView; + if (false) { + Slog.d(TAG, "old notification: when=" + oldNotification.notification.when + + " ongoing=" + oldNotification.isOngoing() + + " expanded=" + oldEntry.expanded + + " contentView=" + oldContentView); + Slog.d(TAG, "new notification: when=" + notification.notification.when + + " ongoing=" + oldNotification.isOngoing() + + " contentView=" + contentView); + } + // Can we just reapply the RemoteViews in place? If when didn't change, the order // didn't change. if (notification.notification.when == oldNotification.notification.when diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java index 3602fecfd84e2..f96a0790807f7 100644 --- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java +++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java @@ -44,6 +44,7 @@ public class NotificationTestList extends TestActivity Vibrator mVibrator = new Vibrator(); Handler mHandler = new Handler(); + long mActivityCreateTime = System.currentTimeMillis(); long mChronometerBase = 0; @Override @@ -421,7 +422,7 @@ public class NotificationTestList extends TestActivity new Test("Persistent #1") { public void run() { Notification n = new Notification(R.drawable.icon1, "tick tick tick", - System.currentTimeMillis()); + mActivityCreateTime); n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", "This is a notification!!!", makeIntent()); mNM.notify(1, n); @@ -481,6 +482,16 @@ public class NotificationTestList extends TestActivity } }, + new Test("Persistent #1 - different icon") { + public void run() { + Notification n = new Notification(R.drawable.icon2, null, + mActivityCreateTime); + n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", + "This is the same notification!!!", makeIntent()); + mNM.notify(1, n); + } + }, + new Test("Chronometer Start") { public void run() { Notification n = new Notification(R.drawable.icon2, "me me me me", From fe4f3ae33c8da86585399b4167fd7987c8a16066 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Fri, 4 Jun 2010 11:25:26 -0700 Subject: [PATCH 2/4] Move the usb mass storage notification & activity into SystemUI.apk. Also fix the notification to show properly when the runtime is restarted. Change-Id: Id0c7ef9f9dc9c9df18428cbaa7db1703f085137e --- core/res/AndroidManifest.xml | 3 --- packages/SystemUI/AndroidManifest.xml | 5 +++++ .../com/android/systemui/statusbar/StatusBarPolicy.java | 2 +- .../com/android/systemui/usb}/StorageNotification.java | 9 +++++---- .../com/android/systemui/usb}/UsbStorageActivity.java | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) rename {services/java/com/android/server/status => packages/SystemUI/src/com/android/systemui/usb}/StorageNotification.java (97%) rename {services/java/com/android/server/status => packages/SystemUI/src/com/android/systemui/usb}/UsbStorageActivity.java (99%) diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 1fcf186f5c93c..2ddb6b95ad9e4 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -1269,9 +1269,6 @@ - - diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 3f5b69d84ae37..aba5e05745a0e 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -18,5 +18,10 @@ android:name=".statusbar.PhoneStatusBarService" android:exported="false" /> + + + + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java index 9ef9d0da306fe..4f39ee402a3de 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java @@ -365,7 +365,7 @@ public class StatusBarPolicy { // storage mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); mStorageManager.registerListener( - new com.android.server.status.StorageNotification(context)); + new com.android.systemui.usb.StorageNotification(context)); // battery mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0); diff --git a/services/java/com/android/server/status/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java similarity index 97% rename from services/java/com/android/server/status/StorageNotification.java rename to packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java index 8da8cd357cace..f8abc5a66048a 100644 --- a/services/java/com/android/server/status/StorageNotification.java +++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.server.status; +package com.android.systemui.usb; import android.app.Activity; import android.app.Notification; @@ -80,9 +80,10 @@ public class StorageNotification extends StorageEventListener { mContext = context; mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); - mUmsAvailable = mStorageManager.isUsbMassStorageConnected(); + final boolean connected = mStorageManager.isUsbMassStorageConnected(); Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)", mUmsAvailable, Environment.getExternalStorageState())); + onUsbMassStorageConnectionChanged(connected); } /* @@ -122,7 +123,7 @@ public class StorageNotification extends StorageEventListener { * for stopping UMS. */ Intent intent = new Intent(); - intent.setClass(mContext, com.android.server.status.UsbStorageActivity.class); + intent.setClass(mContext, com.android.systemui.usb.UsbStorageActivity.class); PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0); setUsbStorageNotification( com.android.internal.R.string.usb_storage_stop_notification_title, @@ -240,7 +241,7 @@ public class StorageNotification extends StorageEventListener { if (available) { Intent intent = new Intent(); - intent.setClass(mContext, com.android.server.status.UsbStorageActivity.class); + intent.setClass(mContext, com.android.systemui.usb.UsbStorageActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final boolean adbOn = 1 == Settings.Secure.getInt( diff --git a/services/java/com/android/server/status/UsbStorageActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java similarity index 99% rename from services/java/com/android/server/status/UsbStorageActivity.java rename to packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java index e8631c53cc678..55d31ec00e804 100644 --- a/services/java/com/android/server/status/UsbStorageActivity.java +++ b/packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.server.status; +package com.android.systemui.usb; import com.android.internal.R; import android.app.Activity; From bd73d01a9cafc1ee8cc91f9691b5234e2a59bb98 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Fri, 4 Jun 2010 11:44:54 -0700 Subject: [PATCH 3/4] Cap the number of notifications that a given package can post. Right now the number is 50, just to prevent apps that have gone completely bonkers. I think the limit should be lower. Change-Id: Ib2c4abf669c8b0250e5421b6d5aeb81aeb2f82ce --- .../server/NotificationManagerService.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java index ac3b23bb86c00..b5c2b1bea32b2 100755 --- a/services/java/com/android/server/NotificationManagerService.java +++ b/services/java/com/android/server/NotificationManagerService.java @@ -70,6 +70,8 @@ class NotificationManagerService extends INotificationManager.Stub private static final String TAG = "NotificationService"; private static final boolean DBG = false; + private static final int MAX_PACKAGE_NOTIFICATIONS = 50; + // message codes private static final int MESSAGE_TIMEOUT = 2; @@ -657,6 +659,26 @@ class NotificationManagerService extends INotificationManager.Stub { checkIncomingCall(pkg); + // Limit the number of notifications that any given package except the android + // package can enqueue. Prevents DOS attacks and deals with leaks. + if (!"android".equals(pkg)) { + synchronized (mNotificationList) { + int count = 0; + final int N = mNotificationList.size(); + for (int i=0; i= MAX_PACKAGE_NOTIFICATIONS) { + Slog.e(TAG, "Package has already posted " + count + + " notifications. Not showing more. package=" + pkg); + return; + } + } + } + } + } + // This conditional is a dirty hack to limit the logging done on // behalf of the download manager without affecting other apps. if (!pkg.equals("com.android.providers.downloads") From d956ae8b813da893ab6a9357acfe287c529d6ac2 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Fri, 4 Jun 2010 11:48:18 -0700 Subject: [PATCH 4/4] dead code removal Change-Id: I4a11f027e764c92602d0429947e9ef39edd882e2 --- .../android/systemui/statusbar/PhoneStatusBarService.java | 7 ------- .../com/android/systemui/statusbar/StatusBarService.java | 6 ------ 2 files changed, 13 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java index 8c57ad6c685f6..ad59a0c6b9177 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java @@ -85,13 +85,6 @@ public class PhoneStatusBarService extends StatusBarService { private static final int MSG_ANIMATE = 1000; private static final int MSG_ANIMATE_REVEAL = 1001; - public interface NotificationCallbacks { - void onSetDisabled(int status); - void onClearAll(); - void onNotificationClick(String pkg, String tag, int id); - void onPanelRevealed(); - } - private class ExpandedDialog extends Dialog { ExpandedDialog(Context context) { super(context, com.android.internal.R.style.Theme_Light_NoTitleBar); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java index 4d9e695100853..d200886a45396 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java @@ -48,12 +48,6 @@ public abstract class StatusBarService extends Service implements CommandQueue.C CommandQueue mCommandQueue; IStatusBarService mBarService; - /* TODO - H mHandler = new H(); - Object mQueueLock = new Object(); - NotificationCallbacks mNotificationCallbacks; - */ - @Override public void onCreate() { // Connect in to the status bar manager service