summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android')
-rwxr-xr-x[-rw-r--r--]src/com/android/providers/downloads/Constants.java3
-rw-r--r--src/com/android/providers/downloads/DownloadInfo.java3
-rwxr-xr-x[-rw-r--r--]src/com/android/providers/downloads/DownloadNotifier.java72
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java50
-rwxr-xr-x[-rw-r--r--]src/com/android/providers/downloads/DownloadReceiver.java3
-rw-r--r--src/com/android/providers/downloads/DownloadService.java6
-rwxr-xr-x[-rw-r--r--]src/com/android/providers/downloads/DownloadStorageProvider.java18
-rwxr-xr-x[-rw-r--r--]src/com/android/providers/downloads/DownloadThread.java18
-rw-r--r--src/com/android/providers/downloads/Helpers.java10
-rw-r--r--src/com/android/providers/downloads/LiveFolderConfigActivity.java40
-rw-r--r--src/com/android/providers/downloads/LiveFolderReceiver.java143
-rw-r--r--src/com/android/providers/downloads/OpenHelper.java9
12 files changed, 337 insertions, 38 deletions
diff --git a/src/com/android/providers/downloads/Constants.java b/src/com/android/providers/downloads/Constants.java
index 89210a25..1128afc6 100644..100755
--- a/src/com/android/providers/downloads/Constants.java
+++ b/src/com/android/providers/downloads/Constants.java
@@ -60,6 +60,9 @@ public class Constants {
/** the intent that gets sent when deleting the notification of a completed download */
public static final String ACTION_HIDE = "android.intent.action.DOWNLOAD_HIDE";
+ /** the intent that gets sent when choosing to resume the paused download */
+ public static final String ACTION_RESUME = "android.intent.action.DOWNLOAD_RESUME";
+
/** The default base name for downloaded files if we can't get one at the HTTP level */
public static final String DEFAULT_DL_FILENAME = "downloadfile";
diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java
index 7a912d5a..05ea2e23 100644
--- a/src/com/android/providers/downloads/DownloadInfo.java
+++ b/src/com/android/providers/downloads/DownloadInfo.java
@@ -353,7 +353,8 @@ public class DownloadInfo {
if (!Downloads.Impl.isStatusCompleted(mStatus)) {
return false;
}
- if (mVisibility == Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) {
+ if (mVisibility == Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED ||
+ mVisibility == DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION) {
return true;
}
return false;
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java
index ac52eba2..809347fd 100644..100755
--- 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;
@@ -150,9 +151,25 @@ public class DownloadNotifier {
}
builder.setWhen(firstShown);
+ // Check paused status about these downloads. If exists, will
+ // update icon and content title/content text in notification.
+ boolean hasPausedStatus = false;
+ int pausedStatus = -1;
+ for (DownloadInfo info : cluster) {
+ if (isPausedStatus(info.mStatus)) {
+ hasPausedStatus = true;
+ pausedStatus = info.mStatus;
+ break;
+ }
+ }
+
// Show relevant icon
if (type == TYPE_ACTIVE) {
- builder.setSmallIcon(android.R.drawable.stat_sys_download);
+ if (hasPausedStatus) {
+ builder.setSmallIcon(R.drawable.download_pause);
+ } else {
+ builder.setSmallIcon(android.R.drawable.stat_sys_download);
+ }
} else if (type == TYPE_WAITING) {
builder.setSmallIcon(android.R.drawable.stat_sys_warning);
} else if (type == TYPE_COMPLETE) {
@@ -202,6 +219,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;
@@ -222,8 +240,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);
}
builder.setProgress(100, percent, false);
@@ -236,14 +272,17 @@ public class DownloadNotifier {
final Notification notif;
if (cluster.size() == 1) {
final DownloadInfo info = cluster.iterator().next();
-
builder.setContentTitle(getDownloadTitle(res, info));
if (type == TYPE_ACTIVE) {
- if (!TextUtils.isEmpty(info.mDescription)) {
- builder.setContentText(info.mDescription);
- } else {
- builder.setContentText(remainingText);
+ if (hasPausedStatus) {
+ if (pausedStatus == Downloads.Impl.STATUS_PAUSED_BY_MANUAL)
+ builder.setContentText(res.getText(R.string.download_paused));
+ else
+ builder.setContentText(res.getText(R.string.download_queued));
+ } else if (speedAsSizeText != null) {
+ builder.setContentText(res.getString(R.string.download_speed_text,
+ remainingText, speedAsSizeText));
}
builder.setContentInfo(percentText);
@@ -270,10 +309,15 @@ public class DownloadNotifier {
}
if (type == TYPE_ACTIVE) {
- builder.setContentTitle(res.getQuantityString(
- R.plurals.notif_summary_active, cluster.size(), cluster.size()));
+ if (hasPausedStatus) {
+ builder.setContentTitle(res.getString(R.string.download_queued));
+ } else {
+ 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) {
@@ -356,7 +400,7 @@ public class DownloadNotifier {
}
private static boolean isActiveAndVisible(DownloadInfo download) {
- return download.mStatus == STATUS_RUNNING &&
+ return Downloads.Impl.isStatusInformational(download.mStatus) &&
(download.mVisibility == VISIBILITY_VISIBLE
|| download.mVisibility == VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
@@ -366,4 +410,10 @@ public class DownloadNotifier {
(download.mVisibility == VISIBILITY_VISIBLE_NOTIFY_COMPLETED
|| download.mVisibility == VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);
}
+
+ private static boolean isPausedStatus(int status) {
+ return status == Downloads.Impl.STATUS_WAITING_FOR_NETWORK ||
+ status == Downloads.Impl.STATUS_PAUSED_BY_MANUAL;
+ }
+
}
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index ad3cf7ac..0928fdfc 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -1051,12 +1051,16 @@ public final class DownloadProvider extends ContentProvider {
filteredValues = values;
String filename = values.getAsString(Downloads.Impl._DATA);
if (filename != null) {
- Cursor c = query(uri, new String[]
- { Downloads.Impl.COLUMN_TITLE }, null, null, null);
- if (!c.moveToFirst() || c.getString(0).isEmpty()) {
- values.put(Downloads.Impl.COLUMN_TITLE, new File(filename).getName());
+ Cursor c = null;
+ try {
+ c = query(uri, new String[]
+ { Downloads.Impl.COLUMN_TITLE }, null, null, null);
+ if (!c.moveToFirst() || c.getString(0).isEmpty()) {
+ values.put(Downloads.Impl.COLUMN_TITLE, new File(filename).getName());
+ }
+ } finally {
+ IoUtils.closeQuietly(c);
}
- c.close();
}
Integer status = values.getAsInteger(Downloads.Impl.COLUMN_STATUS);
@@ -1275,29 +1279,35 @@ public final class DownloadProvider extends ContentProvider {
if (cursor == null) {
Log.v(Constants.TAG, "null cursor in openFile");
} else {
- if (!cursor.moveToFirst()) {
- Log.v(Constants.TAG, "empty cursor in openFile");
- } else {
- do {
- Log.v(Constants.TAG, "row " + cursor.getInt(0) + " available");
- } while(cursor.moveToNext());
+ try {
+ if (!cursor.moveToFirst()) {
+ Log.v(Constants.TAG, "empty cursor in openFile");
+ } else {
+ do {
+ Log.v(Constants.TAG, "row " + cursor.getInt(0) + " available");
+ } while(cursor.moveToNext());
+ }
+ } finally {
+ cursor.close();
}
- cursor.close();
}
cursor = query(uri, new String[] { "_data" }, null, null, null);
if (cursor == null) {
Log.v(Constants.TAG, "null cursor in openFile");
} else {
- if (!cursor.moveToFirst()) {
- Log.v(Constants.TAG, "empty cursor in openFile");
- } else {
- String filename = cursor.getString(0);
- Log.v(Constants.TAG, "filename in openFile: " + filename);
- if (new java.io.File(filename).isFile()) {
- Log.v(Constants.TAG, "file exists in openFile");
+ try {
+ if (!cursor.moveToFirst()) {
+ Log.v(Constants.TAG, "empty cursor in openFile");
+ } else {
+ String filename = cursor.getString(0);
+ Log.v(Constants.TAG, "filename in openFile: " + filename);
+ if (new java.io.File(filename).isFile()) {
+ Log.v(Constants.TAG, "file exists in openFile");
+ }
}
+ } finally {
+ cursor.close();
}
- cursor.close();
}
}
diff --git a/src/com/android/providers/downloads/DownloadReceiver.java b/src/com/android/providers/downloads/DownloadReceiver.java
index f3d23766..a70a2936 100644..100755
--- a/src/com/android/providers/downloads/DownloadReceiver.java
+++ b/src/com/android/providers/downloads/DownloadReceiver.java
@@ -81,7 +81,8 @@ public class DownloadReceiver extends BroadcastReceiver {
if (info != null && info.isConnected()) {
startService(context);
}
- } else if (action.equals(Constants.ACTION_RETRY)) {
+ } else if (action.equals(Constants.ACTION_RETRY) ||
+ action.equals(Constants.ACTION_RESUME)) {
startService(context);
} else if (action.equals(Constants.ACTION_OPEN)
|| action.equals(Constants.ACTION_LIST)
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index 7d746cca..3f29841a 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -323,6 +323,7 @@ public class DownloadService extends Service {
deleteFileIfExists(info.mFileName);
resolver.delete(info.getAllDownloadsUri(), null, null);
+ staleIds.add(info.mId);
} else {
// Kick off download task if ready
@@ -368,6 +369,10 @@ public class DownloadService extends Service {
PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT));
}
+ if (!isActive) {
+ LiveFolderReceiver.updateFolders(this, 0);
+ }
+
return isActive;
}
@@ -413,6 +418,7 @@ public class DownloadService extends Service {
deleteFileIfExists(info.mFileName);
}
mDownloads.remove(info.mId);
+ LiveFolderReceiver.updateFolders(this, 0);
}
private void deleteFileIfExists(String path) {
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java
index ecef54e0..ce15981c 100644..100755
--- a/src/com/android/providers/downloads/DownloadStorageProvider.java
+++ b/src/com/android/providers/downloads/DownloadStorageProvider.java
@@ -305,21 +305,33 @@ public class DownloadStorageProvider extends DocumentsProvider {
if (size == -1) {
size = null;
}
+ final long progress = cursor.getLong(cursor.getColumnIndexOrThrow(
+ DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
final int status = cursor.getInt(
cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
+ final int reason = cursor.getInt(
+ cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON));
switch (status) {
case DownloadManager.STATUS_SUCCESSFUL:
break;
case DownloadManager.STATUS_PAUSED:
- summary = getContext().getString(R.string.download_queued);
+ //summary = getContext().getString(R.string.download_queued);
+ if (size != null) {
+ final long percent = progress * 100 / size;
+ summary = (reason == DownloadManager.PAUSED_BY_MANUAL) ?
+ getContext().getString(R.string.download_paused_percent, percent) :
+ getContext().getString(R.string.download_queued_percent, percent);
+ } else {
+ summary = (reason == DownloadManager.PAUSED_BY_MANUAL) ?
+ getContext().getString(R.string.download_paused) :
+ getContext().getString(R.string.download_queued);
+ }
break;
case DownloadManager.STATUS_PENDING:
summary = getContext().getString(R.string.download_queued);
break;
case DownloadManager.STATUS_RUNNING:
- final long progress = cursor.getLong(cursor.getColumnIndexOrThrow(
- DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
if (size != null) {
final long percent = progress * 100 / size;
summary = getContext().getString(R.string.download_running_percent, percent);
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 93f8d650..9d5274c4 100644..100755
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -92,6 +92,11 @@ public class DownloadThread implements Runnable {
private volatile boolean mPolicyDirty;
+ // Add for carrier feature - download breakpoint continuing.
+ // Support continuing download after the download is broken
+ // although HTTP Server doesn't contain etag in its response.
+ private final static String QRD_ETAG = "qrd_magic_etag";
+
public DownloadThread(Context context, SystemFacade systemFacade, DownloadInfo info,
StorageManager storageManager, DownloadNotifier notifier) {
mContext = context;
@@ -522,6 +527,11 @@ public class DownloadThread implements Runnable {
if (mInfo.mStatus == Downloads.Impl.STATUS_CANCELED || mInfo.mDeleted) {
throw new StopRequestException(Downloads.Impl.STATUS_CANCELED, "download canceled");
}
+
+ if (mInfo.mStatus == Downloads.Impl.STATUS_PAUSED_BY_MANUAL) {
+ // user pauses the download by manual, here send exception and stop data transfer.
+ throw new StopRequestException(Downloads.Impl.STATUS_PAUSED_BY_MANUAL, "download paused by manual");
+ }
}
// if policy has been changed, trigger connectivity check
@@ -711,6 +721,10 @@ public class DownloadThread implements Runnable {
state.mHeaderETag = conn.getHeaderField("ETag");
+ if (state.mHeaderETag == null) {
+ state.mHeaderETag = QRD_ETAG;
+ }
+
final String transferEncoding = conn.getHeaderField("Transfer-Encoding");
if (transferEncoding == null) {
state.mContentLength = getHeaderFieldLong(conn, "Content-Length", -1);
@@ -831,7 +845,9 @@ public class DownloadThread implements Runnable {
if (state.mContinuingDownload) {
if (state.mHeaderETag != null) {
- conn.addRequestProperty("If-Match", state.mHeaderETag);
+ if (!state.mHeaderETag.equals(QRD_ETAG)) {
+ conn.addRequestProperty("If-Match", state.mHeaderETag);
+ }
}
conn.addRequestProperty("Range", "bytes=" + state.mCurrentBytes + "-");
}
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 013faf27..3562dac7 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -141,7 +141,15 @@ public class Helpers {
// Claim this filename inside lock to prevent other threads from
// clobbering us. We're not paranoid enough to use O_EXCL.
try {
- new File(path).createNewFile();
+ File file = new File(path);
+ File parent = file.getParentFile();
+
+ // Make sure the parent directories exists before generates new file
+ if (parent != null && !parent.exists()) {
+ parent.mkdirs();
+ }
+
+ file.createNewFile();
} catch (IOException e) {
throw new StopRequestException(Downloads.Impl.STATUS_FILE_ERROR,
"Failed to create target file " + path, e);
diff --git a/src/com/android/providers/downloads/LiveFolderConfigActivity.java b/src/com/android/providers/downloads/LiveFolderConfigActivity.java
new file mode 100644
index 00000000..cf8183e2
--- /dev/null
+++ b/src/com/android/providers/downloads/LiveFolderConfigActivity.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 The CyanogenMod 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.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.Bundle;
+
+import org.cyanogenmod.support.ui.LiveFolder;
+
+public class LiveFolderConfigActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Intent i = new Intent();
+ // Set the receiver responsible for folder updates
+ ComponentName receiver = new ComponentName(this, LiveFolderReceiver.class);
+ i.putExtra(LiveFolder.Constants.FOLDER_RECEIVER_EXTRA, receiver);
+ i.putExtra(LiveFolder.Constants.FOLDER_TITLE_EXTRA, getString(R.string.live_folder_label));
+ setResult(RESULT_OK, i);
+ finish();
+ }
+
+}
diff --git a/src/com/android/providers/downloads/LiveFolderReceiver.java b/src/com/android/providers/downloads/LiveFolderReceiver.java
new file mode 100644
index 00000000..9f888c5b
--- /dev/null
+++ b/src/com/android/providers/downloads/LiveFolderReceiver.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2013 The CyanogenMod 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.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+import android.provider.BaseColumns;
+import android.text.TextUtils;
+
+import com.android.providers.downloads.OpenHelper;
+
+import org.cyanogenmod.support.ui.LiveFolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class LiveFolderReceiver extends BroadcastReceiver {
+
+ private static int sNumLiveFolders = 0;
+
+ private static Bitmap retrieveAndSetIcon(Context context, String mediaType) {
+ if (mediaType == null) {
+ return null;
+ }
+
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(Uri.fromParts("file", "", null), mediaType);
+
+ PackageManager pm = context.getPackageManager();
+ List<ResolveInfo> list = pm.queryIntentActivities(intent,
+ PackageManager.MATCH_DEFAULT_ONLY);
+
+ if (list.isEmpty()) {
+ return BitmapFactory.decodeResource(context.getResources(),
+ R.drawable.ic_download_misc_file_type);
+ } else {
+ Drawable d = list.get(0).activityInfo.loadIcon(pm);
+ return ((BitmapDrawable) d).getBitmap();
+ }
+ }
+
+ public static void updateFolders(Context context, long folderId) {
+ if (sNumLiveFolders == 0) {
+ return;
+ }
+
+ DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
+ dm.setAccessAllDownloads(true);
+
+ DownloadManager.Query baseQuery =
+ new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true);
+ Cursor cursor = dm.query(baseQuery);
+ if (cursor == null) {
+ return;
+ }
+ ArrayList<LiveFolder.Item> folderItems = new ArrayList<LiveFolder.Item>();
+
+ while (cursor.moveToNext() && folderItems.size() < LiveFolder.Constants.MAX_ITEMS) {
+ long id = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID));
+ String title = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE));
+ String mediaType =
+ cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE));
+
+ LiveFolder.Item folderItem = new LiveFolder.Item();
+ folderItem.setLabel(title);
+ folderItem.setIcon(retrieveAndSetIcon(context, mediaType));
+ folderItem.setId((int) id);
+ folderItems.add(folderItem);
+ }
+
+ if (folderItems.isEmpty()) {
+ return;
+ }
+
+ if (folderId == 0) {
+ LiveFolder.updateAllFolders(context, folderItems);
+ } else {
+ LiveFolder.updateSingleFolder(context, folderId, folderItems);
+ }
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String type = intent.getStringExtra(LiveFolder.Constants.FOLDER_UPDATE_TYPE_EXTRA);
+
+ if (TextUtils.isEmpty(type)) {
+ return;
+ }
+
+ long folderId = intent.getLongExtra(LiveFolder.Constants.FOLDER_ID_EXTRA, 0);
+ if (folderId <= 0 && !type.equals(LiveFolder.Constants.EXISTING_FOLDERS_CREATED)) {
+ return;
+ }
+
+ if (type.equals(LiveFolder.Constants.NEW_FOLDER_CREATED)) {
+ sNumLiveFolders++;
+ updateFolders(context, folderId);
+ } else if (type.equals(LiveFolder.Constants.EXISTING_FOLDERS_CREATED)) {
+ long[] existingFolders = intent.getLongArrayExtra(
+ LiveFolder.Constants.EXISTING_FOLDER_IDS_EXTRA);
+ sNumLiveFolders = existingFolders.length;
+ updateFolders(context, 0);
+ } else if (type.equals(LiveFolder.Constants.FOLDER_ITEM_SELECTED)) {
+ int itemId = intent.getIntExtra(LiveFolder.Constants.FOLDER_ITEM_ID_EXTRA, 0);
+ OpenHelper.startViewIntent(context, itemId, Intent.FLAG_ACTIVITY_NEW_TASK);
+ } else if (type.equals(LiveFolder.Constants.FOLDER_ITEM_REMOVED)) {
+ // Get selected item id
+ int itemId = intent.getIntExtra(LiveFolder.Constants.FOLDER_ITEM_ID_EXTRA, 0);
+ DownloadManager dm =
+ (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
+
+ dm.setAccessAllDownloads(true);
+ dm.markRowDeleted(itemId);
+ } else if (type.equals(LiveFolder.Constants.FOLDER_DELETED)) {
+ sNumLiveFolders--;
+ }
+ }
+
+}
diff --git a/src/com/android/providers/downloads/OpenHelper.java b/src/com/android/providers/downloads/OpenHelper.java
index 4eb319c4..58c8ed69 100644
--- a/src/com/android/providers/downloads/OpenHelper.java
+++ b/src/com/android/providers/downloads/OpenHelper.java
@@ -18,6 +18,7 @@ package com.android.providers.downloads;
import static android.app.DownloadManager.COLUMN_LOCAL_FILENAME;
import static android.app.DownloadManager.COLUMN_LOCAL_URI;
+import static android.app.DownloadManager.COLUMN_MEDIAPROVIDER_URI;
import static android.app.DownloadManager.COLUMN_MEDIA_TYPE;
import static android.app.DownloadManager.COLUMN_URI;
import static android.provider.Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI;
@@ -88,6 +89,10 @@ public class OpenHelper {
intent.putExtra(Intent.EXTRA_ORIGINATING_URI, remoteUri);
intent.putExtra(Intent.EXTRA_REFERRER, getRefererUri(context, id));
intent.putExtra(Intent.EXTRA_ORIGINATING_UID, getOriginatingUid(context, id));
+ } else if (mimeType.startsWith("image/") && !isNull(cursor, COLUMN_MEDIAPROVIDER_URI)) {
+ final Uri mediaUri = getCursorUri(cursor, COLUMN_MEDIAPROVIDER_URI);
+ intent.setDataAndType(mediaUri, mimeType);
+ intent.putExtra("SingleItemOnly", true);
} else if ("file".equals(localUri.getScheme())) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
@@ -139,6 +144,10 @@ public class OpenHelper {
return -1;
}
+ private static Boolean isNull(Cursor cursor, String column) {
+ return cursor.isNull(cursor.getColumnIndexOrThrow(column));
+ }
+
private static String getCursorString(Cursor cursor, String column) {
return cursor.getString(cursor.getColumnIndexOrThrow(column));
}