summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-07-26 12:25:39 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-07-26 12:25:39 -0700
commitf5373e6ba917cc60db4ee796aed8bc0e37a3f5e9 (patch)
tree45cdfa905e297ec6497e859d84dd61925b2a3a60 /src
parentf572f8d54340da87fcf19b4a526e6215ac1a8686 (diff)
parent93155e1da7e89d4925e244f5afa94afb8ada7381 (diff)
downloadandroid_packages_providers_DownloadProvider-f5373e6ba917cc60db4ee796aed8bc0e37a3f5e9.tar.gz
android_packages_providers_DownloadProvider-f5373e6ba917cc60db4ee796aed8bc0e37a3f5e9.tar.bz2
android_packages_providers_DownloadProvider-f5373e6ba917cc60db4ee796aed8bc0e37a3f5e9.zip
am 93155e1d: Stub out and test system notifications.
Merge commit '93155e1da7e89d4925e244f5afa94afb8ada7381' into gingerbread-plus-aosp * commit '93155e1da7e89d4925e244f5afa94afb8ada7381': Stub out and test system notifications.
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/downloads/DownloadNotification.java12
-rw-r--r--src/com/android/providers/downloads/DownloadReceiver.java11
-rw-r--r--src/com/android/providers/downloads/DownloadService.java10
-rw-r--r--src/com/android/providers/downloads/RealSystemFacade.java20
-rw-r--r--src/com/android/providers/downloads/SystemFacade.java16
5 files changed, 49 insertions, 20 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotification.java b/src/com/android/providers/downloads/DownloadNotification.java
index 3c0b7d9b..76bffbc6 100644
--- a/src/com/android/providers/downloads/DownloadNotification.java
+++ b/src/com/android/providers/downloads/DownloadNotification.java
@@ -17,7 +17,6 @@
package com.android.providers.downloads;
import android.app.Notification;
-import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -38,8 +37,8 @@ import java.util.HashMap;
class DownloadNotification {
Context mContext;
- public NotificationManager mNotificationMgr;
HashMap <String, NotificationItem> mNotifications;
+ private SystemFacade mSystemFacade;
static final String LOGTAG = "DownloadNotification";
static final String WHERE_RUNNING =
@@ -93,10 +92,9 @@ class DownloadNotification {
* @param ctx The context to use to obtain access to the
* Notification Service
*/
- DownloadNotification(Context ctx) {
+ DownloadNotification(Context ctx, SystemFacade systemFacade) {
mContext = ctx;
- mNotificationMgr = (NotificationManager) mContext
- .getSystemService(Context.NOTIFICATION_SERVICE);
+ mSystemFacade = systemFacade;
mNotifications = new HashMap<String, NotificationItem>();
}
@@ -208,7 +206,7 @@ class DownloadNotification {
n.contentIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
- mNotificationMgr.notify(item.mId, n);
+ mSystemFacade.postNotification(item.mId, n);
}
}
@@ -287,7 +285,7 @@ class DownloadNotification {
intent.setData(contentUri);
n.deleteIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
- mNotificationMgr.notify(c.getInt(idColumn), n);
+ mSystemFacade.postNotification(c.getInt(idColumn), n);
}
c.close();
}
diff --git a/src/com/android/providers/downloads/DownloadReceiver.java b/src/com/android/providers/downloads/DownloadReceiver.java
index 98c37103..852c3712 100644
--- a/src/com/android/providers/downloads/DownloadReceiver.java
+++ b/src/com/android/providers/downloads/DownloadReceiver.java
@@ -16,9 +16,6 @@
package com.android.providers.downloads;
-import com.google.common.annotations.VisibleForTesting;
-
-import android.app.NotificationManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ContentUris;
@@ -34,6 +31,8 @@ import android.provider.Downloads;
import android.util.Config;
import android.util.Log;
+import com.google.common.annotations.VisibleForTesting;
+
import java.io.File;
/**
@@ -164,11 +163,7 @@ public class DownloadReceiver extends BroadcastReceiver {
}
cursor.close();
}
- NotificationManager notMgr = (NotificationManager) context
- .getSystemService(Context.NOTIFICATION_SERVICE);
- if (notMgr != null) {
- notMgr.cancel((int) ContentUris.parseId(intent.getData()));
- }
+ mSystemFacade.cancelNotification((int) ContentUris.parseId(intent.getData()));
} else if (intent.getAction().equals(Constants.ACTION_HIDE)) {
if (Constants.LOGVV) {
Log.v(Constants.TAG, "Receiver hide for " + intent.getData());
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index 472b4c5f..a6175953 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -218,8 +218,8 @@ public class DownloadService extends Service {
mMediaScannerConnecting = false;
mMediaScannerConnection = new MediaScannerConnection();
- mNotifier = new DownloadNotification(this);
- mNotifier.mNotificationMgr.cancelAll();
+ mNotifier = new DownloadNotification(this, mSystemFacade);
+ mSystemFacade.cancelAllNotifications();
mNotifier.updateNotification();
trimDatabase();
@@ -641,7 +641,7 @@ public class DownloadService extends Service {
if (info.mVisibility == Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
&& newVisibility != Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
&& Downloads.Impl.isStatusCompleted(info.mStatus)) {
- mNotifier.mNotificationMgr.cancel(info.mId);
+ mSystemFacade.cancelNotification(info.mId);
}
info.mVisibility = newVisibility;
synchronized (info) {
@@ -651,7 +651,7 @@ public class DownloadService extends Service {
int newStatus = cursor.getInt(statusColumn);
if (!Downloads.Impl.isStatusCompleted(info.mStatus) &&
Downloads.Impl.isStatusCompleted(newStatus)) {
- mNotifier.mNotificationMgr.cancel(info.mId);
+ mSystemFacade.cancelNotification(info.mId);
}
info.mStatus = newStatus;
info.mNumFailed = cursor.getInt(failedColumn);
@@ -724,7 +724,7 @@ public class DownloadService extends Service {
&& info.mFileName != null) {
new File(info.mFileName).delete();
}
- mNotifier.mNotificationMgr.cancel(info.mId);
+ mSystemFacade.cancelNotification(info.mId);
mDownloads.remove(arrayPos);
}
diff --git a/src/com/android/providers/downloads/RealSystemFacade.java b/src/com/android/providers/downloads/RealSystemFacade.java
index f89f1659..1d9e64a9 100644
--- a/src/com/android/providers/downloads/RealSystemFacade.java
+++ b/src/com/android/providers/downloads/RealSystemFacade.java
@@ -1,5 +1,7 @@
package com.android.providers.downloads;
+import android.app.Notification;
+import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -10,9 +12,12 @@ import android.util.Log;
class RealSystemFacade implements SystemFacade {
private Context mContext;
+ private NotificationManager mNotificationManager;
public RealSystemFacade(Context context) {
mContext = context;
+ mNotificationManager = (NotificationManager)
+ mContext.getSystemService(Context.NOTIFICATION_SERVICE);
}
public long currentTimeMillis() {
@@ -67,4 +72,19 @@ class RealSystemFacade implements SystemFacade {
public boolean userOwnsPackage(int uid, String packageName) throws NameNotFoundException {
return mContext.getPackageManager().getApplicationInfo(packageName, 0).uid == uid;
}
+
+ @Override
+ public void postNotification(int id, Notification notification) {
+ mNotificationManager.notify(id, notification);
+ }
+
+ @Override
+ public void cancelNotification(int id) {
+ mNotificationManager.cancel(id);
+ }
+
+ @Override
+ public void cancelAllNotifications() {
+ mNotificationManager.cancelAll();
+ }
}
diff --git a/src/com/android/providers/downloads/SystemFacade.java b/src/com/android/providers/downloads/SystemFacade.java
index d48e6b80..e41644ab 100644
--- a/src/com/android/providers/downloads/SystemFacade.java
+++ b/src/com/android/providers/downloads/SystemFacade.java
@@ -1,6 +1,7 @@
package com.android.providers.downloads;
+import android.app.Notification;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -37,4 +38,19 @@ interface SystemFacade {
* Returns true if the specified UID owns the specified package name.
*/
public boolean userOwnsPackage(int uid, String pckg) throws NameNotFoundException;
+
+ /**
+ * Post a system notification to the NotificationManager.
+ */
+ public void postNotification(int id, Notification notification);
+
+ /**
+ * Cancel a system notification.
+ */
+ public void cancelNotification(int id);
+
+ /**
+ * Cancel all system notifications.
+ */
+ public void cancelAllNotifications();
}