summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/providers/downloads/DownloadInfo.java4
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java20
-rw-r--r--src/com/android/providers/downloads/Helpers.java15
3 files changed, 27 insertions, 12 deletions
diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java
index 8996ede..00a2dd7 100644
--- a/src/com/android/providers/downloads/DownloadInfo.java
+++ b/src/com/android/providers/downloads/DownloadInfo.java
@@ -368,6 +368,10 @@ public class DownloadInfo {
return false;
}
+ public boolean isMeteredAllowed(long totalBytes) {
+ return getRequiredNetworkType(totalBytes) != JobInfo.NETWORK_TYPE_UNMETERED;
+ }
+
public boolean isRoamingAllowed() {
if (mIsPublicApi) {
return mAllowRoaming;
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 34d6ad1..60a04ff 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -353,6 +353,13 @@ public class DownloadThread extends Thread {
}
}
+ // If we're waiting for a network that must be unmetered, our status
+ // is actually queued so we show relevant notifications
+ if (mInfoDelta.mStatus == STATUS_WAITING_FOR_NETWORK
+ && !mInfo.isMeteredAllowed(mInfoDelta.mTotalBytes)) {
+ mInfoDelta.mStatus = STATUS_QUEUED_FOR_WIFI;
+ }
+
} catch (Throwable t) {
mInfoDelta.mStatus = STATUS_UNKNOWN_ERROR;
mInfoDelta.mErrorMsg = t.toString();
@@ -380,7 +387,8 @@ public class DownloadThread extends Thread {
DownloadScanner.requestScanBlocking(mContext, mInfo);
}
} else if (mInfoDelta.mStatus == STATUS_WAITING_TO_RETRY
- || mInfoDelta.mStatus == STATUS_WAITING_FOR_NETWORK) {
+ || mInfoDelta.mStatus == STATUS_WAITING_FOR_NETWORK
+ || mInfoDelta.mStatus == STATUS_QUEUED_FOR_WIFI) {
Helpers.scheduleJob(mContext, DownloadInfo.queryDownloadInfo(mContext, mId));
}
@@ -727,20 +735,16 @@ public class DownloadThread extends Thread {
// checking connectivity will apply current policy
mPolicyDirty = false;
- final boolean allowMetered = mInfo
- .getRequiredNetworkType(mInfoDelta.mTotalBytes) != JobInfo.NETWORK_TYPE_UNMETERED;
- final boolean allowRoaming = mInfo.isRoamingAllowed();
-
final NetworkInfo info = mSystemFacade.getNetworkInfo(mNetwork, mInfo.mUid,
mIgnoreBlocked);
if (info == null || !info.isConnected()) {
throw new StopRequestException(STATUS_WAITING_FOR_NETWORK, "Network is disconnected");
}
- if (info.isRoaming() && !allowRoaming) {
+ if (info.isRoaming() && !mInfo.isRoamingAllowed()) {
throw new StopRequestException(STATUS_WAITING_FOR_NETWORK, "Network is roaming");
}
- if (info.isMetered() && !allowMetered) {
- throw new StopRequestException(STATUS_QUEUED_FOR_WIFI, "Network is metered");
+ if (info.isMetered() && !mInfo.isMeteredAllowed(mInfoDelta.mTotalBytes)) {
+ throw new StopRequestException(STATUS_WAITING_FOR_NETWORK, "Network is metered");
}
}
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index d43e102..e954905 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -112,15 +112,21 @@ public class Helpers {
}
public static void scheduleJob(Context context, long downloadId) {
- scheduleJob(context, DownloadInfo.queryDownloadInfo(context, downloadId));
+ final boolean scheduled = scheduleJob(context,
+ DownloadInfo.queryDownloadInfo(context, downloadId));
+ if (!scheduled) {
+ // If we didn't schedule a future job, kick off a notification
+ // update pass immediately
+ getDownloadNotifier(context).update();
+ }
}
/**
* Schedule (or reschedule) a job for the given {@link DownloadInfo} using
* its current state to define job constraints.
*/
- public static void scheduleJob(Context context, DownloadInfo info) {
- if (info == null) return;
+ public static boolean scheduleJob(Context context, DownloadInfo info) {
+ if (info == null) return false;
final JobScheduler scheduler = context.getSystemService(JobScheduler.class);
@@ -129,7 +135,7 @@ public class Helpers {
scheduler.cancel(jobId);
// Skip scheduling if download is paused or finished
- if (!info.isReadyToSchedule()) return;
+ if (!info.isReadyToSchedule()) return false;
final JobInfo.Builder builder = new JobInfo.Builder(jobId,
new ComponentName(context, DownloadJobService.class));
@@ -166,6 +172,7 @@ public class Helpers {
}
scheduler.scheduleAsPackage(builder.build(), packageName, UserHandle.myUserId(), TAG);
+ return true;
}
/*