summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/downloads/DownloadNotification.java15
-rw-r--r--src/com/android/providers/downloads/DownloadReceiver.java5
-rw-r--r--src/com/android/providers/downloads/DownloadService.java19
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java17
-rw-r--r--src/com/android/providers/downloads/RealSystemFacade.java43
-rw-r--r--src/com/android/providers/downloads/StorageManager.java11
-rw-r--r--src/com/android/providers/downloads/SystemFacade.java32
7 files changed, 73 insertions, 69 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotification.java b/src/com/android/providers/downloads/DownloadNotification.java
index bbd39f60..f5778e79 100644
--- a/src/com/android/providers/downloads/DownloadNotification.java
+++ b/src/com/android/providers/downloads/DownloadNotification.java
@@ -17,6 +17,7 @@
package com.android.providers.downloads;
import android.app.Notification;
+import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentUris;
import android.content.Context;
@@ -38,9 +39,9 @@ import java.util.HashMap;
*/
class DownloadNotification {
- Context mContext;
- HashMap <String, NotificationItem> mNotifications;
- private SystemFacade mSystemFacade;
+ private Context mContext;
+ private NotificationManager mNotifManager;
+ private HashMap<String, NotificationItem> mNotifications;
/** Time when each {@link DownloadInfo#mId} was first shown. */
private SparseLongArray mFirstShown = new SparseLongArray();
@@ -102,7 +103,8 @@ class DownloadNotification {
*/
DownloadNotification(Context ctx, SystemFacade systemFacade) {
mContext = ctx;
- mSystemFacade = systemFacade;
+ mNotifManager = (NotificationManager) mContext.getSystemService(
+ Context.NOTIFICATION_SERVICE);
mNotifications = new HashMap<String, NotificationItem>();
}
@@ -207,8 +209,7 @@ class DownloadNotification {
builder.setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0));
- mSystemFacade.postNotification(item.mId, builder.getNotification());
-
+ mNotifManager.notify(item.mId, builder.build());
}
}
@@ -262,7 +263,7 @@ class DownloadNotification {
intent.setData(contentUri);
builder.setDeleteIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0));
- mSystemFacade.postNotification(id, builder.getNotification());
+ mNotifManager.notify((int) id, builder.build());
}
private boolean isActiveAndVisible(DownloadInfo download) {
diff --git a/src/com/android/providers/downloads/DownloadReceiver.java b/src/com/android/providers/downloads/DownloadReceiver.java
index 26ad992e..81ff4040 100644
--- a/src/com/android/providers/downloads/DownloadReceiver.java
+++ b/src/com/android/providers/downloads/DownloadReceiver.java
@@ -17,6 +17,7 @@
package com.android.providers.downloads;
import android.app.DownloadManager;
+import android.app.NotificationManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ContentUris;
@@ -120,7 +121,9 @@ public class DownloadReceiver extends BroadcastReceiver {
* @param cursor Cursor for reading the download's fields
*/
private void hideNotification(Context context, Uri uri, Cursor cursor) {
- mSystemFacade.cancelNotification(ContentUris.parseId(uri));
+ final NotificationManager notifManager = (NotificationManager) context.getSystemService(
+ Context.NOTIFICATION_SERVICE);
+ notifManager.cancel((int) ContentUris.parseId(uri));
int statusColumn = cursor.getColumnIndexOrThrow(Downloads.Impl.COLUMN_STATUS);
int status = cursor.getInt(statusColumn);
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index 3b566f8e..7030deae 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -19,6 +19,7 @@ package com.android.providers.downloads;
import static com.android.providers.downloads.Constants.TAG;
import android.app.AlarmManager;
+import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ComponentName;
@@ -38,7 +39,6 @@ import android.os.RemoteException;
import android.provider.Downloads;
import android.text.TextUtils;
import android.util.Log;
-import android.util.Slog;
import com.android.internal.util.IndentingPrintWriter;
import com.google.android.collect.Maps;
@@ -66,6 +66,7 @@ public class DownloadService extends Service {
/** Class to handle Notification Manager updates */
private DownloadNotification mNotifier;
+ private NotificationManager mNotifManager;
/**
* The Service's view of the list of downloads, mapping download IDs to the corresponding info
@@ -222,7 +223,9 @@ public class DownloadService extends Service {
mMediaScannerConnection = new MediaScannerConnection();
mNotifier = new DownloadNotification(this, mSystemFacade);
- mSystemFacade.cancelAllNotifications();
+ mNotifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ mNotifManager.cancelAll();
+
mStorageManager = StorageManager.getInstance(getApplicationContext());
updateFromProvider();
}
@@ -465,7 +468,7 @@ public class DownloadService extends Service {
!Downloads.Impl.isStatusCompleted(oldStatus)
&& Downloads.Impl.isStatusCompleted(info.mStatus);
if (lostVisibility || justCompleted) {
- mSystemFacade.cancelNotification(info.mId);
+ mNotifManager.cancel((int) info.mId);
}
info.startIfReady(now, mStorageManager);
@@ -483,10 +486,12 @@ public class DownloadService extends Service {
info.mStatus = Downloads.Impl.STATUS_CANCELED;
}
if (info.mDestination != Downloads.Impl.DESTINATION_EXTERNAL && info.mFileName != null) {
- Slog.d(TAG, "deleteDownloadLocked() deleting " + info.mFileName);
+ if (Constants.LOGVV) {
+ Log.d(TAG, "deleteDownloadLocked() deleting " + info.mFileName);
+ }
new File(info.mFileName).delete();
}
- mSystemFacade.cancelNotification(info.mId);
+ mNotifManager.cancel((int) info.mId);
mDownloads.remove(info.mId);
}
@@ -559,7 +564,9 @@ public class DownloadService extends Service {
private void deleteFileIfExists(String path) {
try {
if (!TextUtils.isEmpty(path)) {
- Slog.d(TAG, "deleteFileIfExists() deleting " + path);
+ if (Constants.LOGVV) {
+ Log.d(TAG, "deleteFileIfExists() deleting " + path);
+ }
File file = new File(path);
file.delete();
}
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index bd91eaa1..37db32b1 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -33,7 +33,6 @@ import android.provider.Downloads;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
-import android.util.Slog;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
@@ -330,7 +329,9 @@ public class DownloadThread extends Thread {
closeDestination(state);
if (state.mFilename != null && Downloads.Impl.isStatusError(finalStatus)) {
- Slog.d(TAG, "cleanupDestination() deleting " + state.mFilename);
+ if (Constants.LOGVV) {
+ Log.d(TAG, "cleanupDestination() deleting " + state.mFilename);
+ }
new File(state.mFilename).delete();
state.mFilename = null;
}
@@ -847,8 +848,10 @@ public class DownloadThread extends Thread {
long fileLength = f.length();
if (fileLength == 0) {
// The download hadn't actually started, we can restart from scratch
- Slog.d(TAG, "setupDestinationFile() found fileLength=0, deleting "
- + state.mFilename);
+ if (Constants.LOGVV) {
+ Log.d(TAG, "setupDestinationFile() found fileLength=0, deleting "
+ + state.mFilename);
+ }
f.delete();
state.mFilename = null;
if (Constants.LOGV) {
@@ -857,8 +860,10 @@ public class DownloadThread extends Thread {
}
} else if (mInfo.mETag == null && !mInfo.mNoIntegrity) {
// This should've been caught upon failure
- Slog.d(TAG, "setupDestinationFile() unable to resume download, deleting "
- + state.mFilename);
+ if (Constants.LOGVV) {
+ Log.d(TAG, "setupDestinationFile() unable to resume download, deleting "
+ + state.mFilename);
+ }
f.delete();
throw new StopRequestException(Downloads.Impl.STATUS_CANNOT_RESUME,
"Trying to resume a download that can't be resumed");
diff --git a/src/com/android/providers/downloads/RealSystemFacade.java b/src/com/android/providers/downloads/RealSystemFacade.java
index 6580f909..228c7165 100644
--- a/src/com/android/providers/downloads/RealSystemFacade.java
+++ b/src/com/android/providers/downloads/RealSystemFacade.java
@@ -1,26 +1,35 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.android.providers.downloads;
import android.app.DownloadManager;
-import android.app.Notification;
-import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
import android.telephony.TelephonyManager;
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() {
@@ -85,26 +94,6 @@ class RealSystemFacade implements SystemFacade {
}
@Override
- public void postNotification(long id, Notification notification) {
- /**
- * TODO: The system notification manager takes ints, not longs, as IDs, but the download
- * manager uses IDs take straight from the database, which are longs. This will have to be
- * dealt with at some point.
- */
- mNotificationManager.notify((int) id, notification);
- }
-
- @Override
- public void cancelNotification(long id) {
- mNotificationManager.cancel((int) id);
- }
-
- @Override
- public void cancelAllNotifications() {
- mNotificationManager.cancelAll();
- }
-
- @Override
public void startThread(Thread thread) {
thread.start();
}
diff --git a/src/com/android/providers/downloads/StorageManager.java b/src/com/android/providers/downloads/StorageManager.java
index 4b51921f..915d141b 100644
--- a/src/com/android/providers/downloads/StorageManager.java
+++ b/src/com/android/providers/downloads/StorageManager.java
@@ -30,7 +30,6 @@ import android.os.StatFs;
import android.provider.Downloads;
import android.text.TextUtils;
import android.util.Log;
-import android.util.Slog;
import com.android.internal.R;
@@ -342,9 +341,9 @@ class StorageManager {
if (TextUtils.isEmpty(data)) continue;
File file = new File(data);
- if (true || Constants.LOGV) {
- Slog.d(Constants.TAG, "purging " + file.getAbsolutePath() + " for " +
- file.length() + " bytes");
+ if (Constants.LOGV) {
+ Log.d(Constants.TAG, "purging " + file.getAbsolutePath() + " for "
+ + file.length() + " bytes");
}
totalFreed += file.length();
file.delete();
@@ -416,7 +415,9 @@ class StorageManager {
try {
final StructStat stat = Libcore.os.stat(path);
if (stat.st_uid == myUid) {
- Slog.d(TAG, "deleting spurious file " + path);
+ if (Constants.LOGVV) {
+ Log.d(TAG, "deleting spurious file " + path);
+ }
file.delete();
}
} catch (ErrnoException e) {
diff --git a/src/com/android/providers/downloads/SystemFacade.java b/src/com/android/providers/downloads/SystemFacade.java
index d1439354..fda97e08 100644
--- a/src/com/android/providers/downloads/SystemFacade.java
+++ b/src/com/android/providers/downloads/SystemFacade.java
@@ -1,12 +1,25 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.android.providers.downloads;
-import android.app.Notification;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.NetworkInfo;
-
interface SystemFacade {
/**
* @see System#currentTimeMillis()
@@ -50,21 +63,6 @@ interface SystemFacade {
public boolean userOwnsPackage(int uid, String pckg) throws NameNotFoundException;
/**
- * Post a system notification to the NotificationManager.
- */
- public void postNotification(long id, Notification notification);
-
- /**
- * Cancel a system notification.
- */
- public void cancelNotification(long id);
-
- /**
- * Cancel all system notifications.
- */
- public void cancelAllNotifications();
-
- /**
* Start a thread.
*/
public void startThread(Thread thread);