summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2016-04-20 23:23:09 -0600
committerJeff Sharkey <jsharkey@android.com>2016-04-25 12:59:46 -0600
commit3a5f5eafb34eaa4963c801882148e8f61514a61b (patch)
treec38ae2f58cb39e4e17be37e8eec2fe040b4b6436 /ui
parentdbcd4cfe7f0fed77a77afb1c1d242a508fc5462a (diff)
downloadandroid_packages_providers_DownloadProvider-3a5f5eafb34eaa4963c801882148e8f61514a61b.tar.gz
android_packages_providers_DownloadProvider-3a5f5eafb34eaa4963c801882148e8f61514a61b.tar.bz2
android_packages_providers_DownloadProvider-3a5f5eafb34eaa4963c801882148e8f61514a61b.zip
Move DownloadManager to use JobScheduler.
JobScheduler is in a much better position to coordinate tasks across the platform to optimize battery and RAM usage. This change removes a bunch of manual scheduling logic by representing each download as a separate job with relevant scheduling constraints. Requested network types, retry backoff timing, and newly added charging and idle constraints are plumbed through as job parameters. When a job times out, we halt the download and schedule it to resume later. The majority of downloads should have ETag values to enable resuming like this. Remove local wakelocks, since the platform now acquires and blames our jobs on the requesting app. When an active download is pushing updates to the database, check for both paused and cancelled state to quickly halt an ongoing download. Shift DownloadNotifier to update directly based on a Cursor, since we no longer have the overhead of fully-parsed DownloadInfo objects. Unify a handful of worker threads into a single shared thread. Remove legacy "large download" activity that was thrown in the face of the user; the UX best-practice is to go through notification, and update that dialog to let the user override and continue if under the hard limit. Bug: 28098882, 26571724 Change-Id: I33ebe59b3c2ea9c89ec526f70b1950c734abc4a7
Diffstat (limited to 'ui')
-rw-r--r--ui/res/values/strings.xml4
-rw-r--r--ui/src/com/android/providers/downloads/ui/TrampolineActivity.java30
2 files changed, 28 insertions, 6 deletions
diff --git a/ui/res/values/strings.xml b/ui/res/values/strings.xml
index 9e625ac7..3555e236 100644
--- a/ui/res/values/strings.xml
+++ b/ui/res/values/strings.xml
@@ -106,6 +106,10 @@
<!-- Text for button appearing in a dialog to restart a download, either one that failed or one
for which the downloaded file is now missing [CHAR LIMIT=25] -->
<string name="retry_download">Retry</string>
+ <!-- Text for button to start a download over the mobile connection now, even though it's over
+ the carrier-specified recommended maximum size for downloads over the mobile connection
+ [CHAR LIMIT=25] -->
+ <string name="start_now_download">Start now</string>
<!-- Text for button appearing in the pop-up selection menu to deselect all currently selected
downloads in the download list [CHAR LIMIT=25] -->
<string name="deselect_all">Deselect all</string>
diff --git a/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java b/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
index 104f144c..5d4e7a45 100644
--- a/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
+++ b/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
@@ -47,6 +47,7 @@ public class TrampolineActivity extends Activity {
private static final String KEY_ID = "id";
private static final String KEY_REASON = "reason";
+ private static final String KEY_SIZE = "size";
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -59,12 +60,15 @@ public class TrampolineActivity extends Activity {
final int status;
final int reason;
+ final long size;
final Cursor cursor = dm.query(new Query().setFilterById(id));
try {
if (cursor.moveToFirst()) {
status = cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
reason = cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON));
+ size = cursor.getLong(
+ cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
} else {
Toast.makeText(this, R.string.dialog_file_missing_body, Toast.LENGTH_SHORT).show();
finish();
@@ -84,7 +88,7 @@ public class TrampolineActivity extends Activity {
case DownloadManager.STATUS_PAUSED:
if (reason == DownloadManager.PAUSED_QUEUED_FOR_WIFI) {
- PausedDialogFragment.show(getFragmentManager(), id);
+ PausedDialogFragment.show(getFragmentManager(), id, size);
} else {
sendRunningDownloadClickedBroadcast(id);
finish();
@@ -113,10 +117,11 @@ public class TrampolineActivity extends Activity {
}
public static class PausedDialogFragment extends DialogFragment {
- public static void show(FragmentManager fm, long id) {
+ public static void show(FragmentManager fm, long id, long size) {
final PausedDialogFragment dialog = new PausedDialogFragment();
final Bundle args = new Bundle();
args.putLong(KEY_ID, id);
+ args.putLong(KEY_SIZE, size);
dialog.setArguments(args);
dialog.show(fm, TAG_PAUSED);
}
@@ -130,13 +135,27 @@ public class TrampolineActivity extends Activity {
dm.setAccessAllDownloads(true);
final long id = getArguments().getLong(KEY_ID);
+ final long size = getArguments().getLong(KEY_SIZE);
final AlertDialog.Builder builder = new AlertDialog.Builder(
- context, AlertDialog.THEME_HOLO_LIGHT);
+ context, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
builder.setTitle(R.string.dialog_title_queued_body);
builder.setMessage(R.string.dialog_queued_body);
- builder.setPositiveButton(R.string.keep_queued_download, null);
+ final Long maxSize = DownloadManager.getMaxBytesOverMobile(context);
+ if (maxSize != null && size > maxSize) {
+ // When we have a max size, we have no choice
+ builder.setPositiveButton(R.string.keep_queued_download, null);
+ } else {
+ // Give user the choice of starting now
+ builder.setPositiveButton(R.string.start_now_download,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dm.forceDownload(id);
+ }
+ });
+ }
builder.setNegativeButton(
R.string.remove_download, new DialogInterface.OnClickListener() {
@@ -181,10 +200,9 @@ public class TrampolineActivity extends Activity {
final int reason = getArguments().getInt(KEY_REASON);
final AlertDialog.Builder builder = new AlertDialog.Builder(
- context, AlertDialog.THEME_HOLO_LIGHT);
+ context, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
builder.setTitle(R.string.dialog_title_not_available);
- final String message;
switch (reason) {
case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
builder.setMessage(R.string.dialog_file_already_exists);