summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2015-10-31 14:31:38 -0700
committerSteve Kondik <steve@cyngn.com>2015-10-31 14:31:38 -0700
commita65fb3f4e110f0e36d05d60930e2173eabb12b08 (patch)
tree1212c719d2c83a5a33e677b19e8acae1f740c6a1 /src/com/android
parenta83afb620af5aa6dfc4bcde74a120d90ee92175e (diff)
parentd64cb33d35423d6bf10d3244326acc7ca37d824b (diff)
downloadandroid_packages_providers_DownloadProvider-a65fb3f4e110f0e36d05d60930e2173eabb12b08.tar.gz
android_packages_providers_DownloadProvider-a65fb3f4e110f0e36d05d60930e2173eabb12b08.tar.bz2
android_packages_providers_DownloadProvider-a65fb3f4e110f0e36d05d60930e2173eabb12b08.zip
Merge branch 'cm-12.1' of git://github.com/CyanogenMod/android_packages_providers_DownloadProvider into cm-13.0
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/providers/downloads/DownloadNotifier.java32
-rw-r--r--src/com/android/providers/downloads/DownloadService.java2
-rw-r--r--src/com/android/providers/downloads/OpenHelper.java9
3 files changed, 36 insertions, 7 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java
index 60c249f9..3af97463 100644
--- a/src/com/android/providers/downloads/DownloadNotifier.java
+++ b/src/com/android/providers/downloads/DownloadNotifier.java
@@ -35,6 +35,7 @@ import android.os.SystemClock;
import android.provider.Downloads;
import android.text.TextUtils;
import android.text.format.DateUtils;
+import android.text.format.Formatter;
import android.util.Log;
import android.util.LongSparseLongArray;
@@ -205,6 +206,7 @@ public class DownloadNotifier {
// Calculate and show progress
String remainingText = null;
String percentText = null;
+ String speedAsSizeText = null;
if (type == TYPE_ACTIVE) {
long current = 0;
long total = 0;
@@ -225,8 +227,26 @@ public class DownloadNotifier {
if (speed > 0) {
final long remainingMillis = ((total - current) * 1000) / speed;
+ final int duration, durationResId;
+
+ // This duplicates DateUtils.formatDuration(), but uses our
+ // abbreviated plurals.
+ if (remainingMillis >= DateUtils.HOUR_IN_MILLIS) {
+ duration = (int) ((remainingMillis + 1800000)
+ / DateUtils.HOUR_IN_MILLIS);
+ durationResId = R.plurals.duration_hours;
+ } else if (remainingMillis >= DateUtils.MINUTE_IN_MILLIS) {
+ duration = (int) ((remainingMillis + 30000)
+ / DateUtils.MINUTE_IN_MILLIS);
+ durationResId = R.plurals.duration_minutes;
+ } else {
+ duration = (int) ((remainingMillis + 500)
+ / DateUtils.SECOND_IN_MILLIS);
+ durationResId = R.plurals.duration_seconds;
+ }
remainingText = res.getString(R.string.download_remaining,
- DateUtils.formatDuration(remainingMillis));
+ res.getQuantityString(durationResId, duration, duration));
+ speedAsSizeText = Formatter.formatFileSize(mContext, speed);
}
final int percent = (int) ((current * 100) / total);
@@ -244,10 +264,9 @@ public class DownloadNotifier {
builder.setContentTitle(getDownloadTitle(res, info));
if (type == TYPE_ACTIVE) {
- if (!TextUtils.isEmpty(info.mDescription)) {
- builder.setContentText(info.mDescription);
- } else {
- builder.setContentText(remainingText);
+ if (speedAsSizeText != null) {
+ builder.setContentText(res.getString(R.string.download_speed_text,
+ remainingText, speedAsSizeText));
}
builder.setContentInfo(percentText);
@@ -277,7 +296,8 @@ public class DownloadNotifier {
builder.setContentTitle(res.getQuantityString(
R.plurals.notif_summary_active, cluster.size(), cluster.size()));
builder.setContentText(remainingText);
- builder.setContentInfo(percentText);
+ builder.setContentInfo(res.getString(R.string.download_speed_text,
+ percentText, speedAsSizeText));
inboxStyle.setSummaryText(remainingText);
} else if (type == TYPE_WAITING) {
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index b0b73297..dbc2298d 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -366,7 +366,6 @@ public class DownloadService extends Service {
final int idColumn = cursor.getColumnIndexOrThrow(Downloads.Impl._ID);
while (cursor.moveToNext()) {
final long id = cursor.getLong(idColumn);
- staleIds.remove(id);
DownloadInfo info = mDownloads.get(id);
if (info != null) {
@@ -398,6 +397,7 @@ public class DownloadService extends Service {
isActive |= activeDownload;
isActive |= activeScan;
+ staleIds.remove(id);
}
// Keep track of nearest next action
diff --git a/src/com/android/providers/downloads/OpenHelper.java b/src/com/android/providers/downloads/OpenHelper.java
index 4eb319c4..0a12daac 100644
--- a/src/com/android/providers/downloads/OpenHelper.java
+++ b/src/com/android/providers/downloads/OpenHelper.java
@@ -32,6 +32,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.Downloads.Impl.RequestHeaders;
import android.util.Log;
+import android.webkit.MimeTypeMap;
import java.io.File;
@@ -75,6 +76,14 @@ public class OpenHelper {
final Uri localUri = getCursorUri(cursor, COLUMN_LOCAL_URI);
final File file = getCursorFile(cursor, COLUMN_LOCAL_FILENAME);
String mimeType = getCursorString(cursor, COLUMN_MEDIA_TYPE);
+ if ("application/octet-stream".equals(mimeType)) {
+ MimeTypeMap m = MimeTypeMap.getSingleton();
+ String guess = m.getMimeTypeFromExtension(
+ m.getFileExtensionFromUrl(localUri.toString()));
+ if (guess != null) {
+ mimeType = guess;
+ }
+ }
mimeType = DownloadDrmHelper.getOriginalMimeType(context, file, mimeType);
final Intent intent = new Intent(Intent.ACTION_VIEW);