diff options
author | Jeff Sharkey <jsharkey@android.com> | 2016-04-28 15:33:38 -0600 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2016-04-29 12:30:02 -0600 |
commit | b3597b9d2fdde31bb0a8af821e3da3ca786e277b (patch) | |
tree | 375cd055478b96d305856e72b222e795decc1309 /src/com/android/providers | |
parent | 67db99b0fc55846a4fa6d4a134a0533426428e7f (diff) | |
download | android_packages_providers_DownloadProvider-b3597b9d2fdde31bb0a8af821e3da3ca786e277b.tar.gz android_packages_providers_DownloadProvider-b3597b9d2fdde31bb0a8af821e3da3ca786e277b.tar.bz2 android_packages_providers_DownloadProvider-b3597b9d2fdde31bb0a8af821e3da3ca786e277b.zip |
Visible downloads should run while blocked/dozing.
Downloads with visible notifications should behave as if the
requesting app was running a foreground service. The easiest way
to implement this for now is to ignore any BLOCKED network status
and use the new setWillBeForeground() API so job scheduling ignores
any active blocked/dozing status.
Bug: 26571724
Change-Id: I8ea2b2a7cdb5f469adc11b4d897ff55bd8a9db9a
Diffstat (limited to 'src/com/android/providers')
5 files changed, 42 insertions, 20 deletions
diff --git a/src/com/android/providers/downloads/DownloadInfo.java b/src/com/android/providers/downloads/DownloadInfo.java index c94dd6c2..8996eded 100644 --- a/src/com/android/providers/downloads/DownloadInfo.java +++ b/src/com/android/providers/downloads/DownloadInfo.java @@ -16,6 +16,9 @@ package com.android.providers.downloads; +import static android.provider.Downloads.Impl.VISIBILITY_VISIBLE; +import static android.provider.Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED; + import static com.android.providers.downloads.Constants.TAG; import android.app.DownloadManager; @@ -247,6 +250,19 @@ public class DownloadInfo { } /** + * Return if this download is visible to the user while running. + */ + public boolean isVisible() { + switch (mVisibility) { + case VISIBILITY_VISIBLE: + case VISIBILITY_VISIBLE_NOTIFY_COMPLETED: + return true; + default: + return false; + } + } + + /** * Add random fuzz to the given delay so it's anywhere between 1-1.5x the * requested delay. */ diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index c559367f..3bcde17e 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -221,6 +221,7 @@ public class DownloadThread extends Thread { private long mLastUpdateBytes = 0; private long mLastUpdateTime = 0; + private boolean mIgnoreBlocked; private Network mNetwork; private int mNetworkType = ConnectivityManager.TYPE_NONE; @@ -269,10 +270,15 @@ public class DownloadThread extends Thread { mInfoDelta.mStatus = STATUS_RUNNING; mInfoDelta.writeToDatabase(); + // If we're showing a foreground notification for the requesting + // app, the download isn't affected by the blocked status of the + // requesting app + mIgnoreBlocked = mInfo.isVisible(); + // Use the caller's default network to make this connection, since // they might be subject to restrictions that we shouldn't let them - // circumvent. - mNetwork = mSystemFacade.getActiveNetwork(mInfo.mUid); + // circumvent + mNetwork = mSystemFacade.getActiveNetwork(mInfo.mUid, mIgnoreBlocked); if (mNetwork == null) { throw new StopRequestException(STATUS_WAITING_FOR_NETWORK, "No network associated with requesting UID"); @@ -280,7 +286,8 @@ public class DownloadThread extends Thread { // Remember which network this download started on; used to // determine if errors were due to network changes. - final NetworkInfo info = mSystemFacade.getNetworkInfo(mNetwork); + final NetworkInfo info = mSystemFacade.getNetworkInfo(mNetwork, mInfo.mUid, + mIgnoreBlocked); if (info != null) { mNetworkType = info.getType(); } @@ -323,7 +330,8 @@ public class DownloadThread extends Thread { } if (mInfoDelta.mNumFailed < Constants.MAX_RETRIES) { - final NetworkInfo info = mSystemFacade.getNetworkInfo(mNetwork); + final NetworkInfo info = mSystemFacade.getNetworkInfo(mNetwork, mInfo.mUid, + mIgnoreBlocked); if (info != null && info.getType() == mNetworkType && info.isConnected()) { // Underlying network is still intact, use normal backoff mInfoDelta.mStatus = STATUS_WAITING_TO_RETRY; @@ -707,7 +715,8 @@ public class DownloadThread extends Thread { .getRequiredNetworkType(mInfoDelta.mTotalBytes) != JobInfo.NETWORK_TYPE_UNMETERED; final boolean allowRoaming = mInfo.isRoamingAllowed(); - final NetworkInfo info = mSystemFacade.getNetworkInfo(mNetwork); + final NetworkInfo info = mSystemFacade.getNetworkInfo(mNetwork, mInfo.mUid, + mIgnoreBlocked); if (info == null || !info.isConnected()) { throw new StopRequestException(STATUS_WAITING_FOR_NETWORK, "Network is disconnected"); } @@ -870,7 +879,9 @@ public class DownloadThread extends Thread { @Override public void onRestrictBackgroundWhitelistChanged(int uid, boolean whitelisted) { // caller is NPMS, since we only register with them - mPolicyDirty = true; + if (uid == mInfo.mUid) { + mPolicyDirty = true; + } } }; diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java index b0737452..d43e1022 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -22,8 +22,6 @@ import static android.os.Environment.buildExternalStorageAppMediaDirs; import static android.os.Environment.buildExternalStorageAppObbDirs; import static android.provider.Downloads.Impl.FLAG_REQUIRES_CHARGING; import static android.provider.Downloads.Impl.FLAG_REQUIRES_DEVICE_IDLE; -import static android.provider.Downloads.Impl.VISIBILITY_VISIBLE; -import static android.provider.Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED; import static com.android.providers.downloads.Constants.TAG; @@ -138,12 +136,9 @@ public class Helpers { // When this download will show a notification, run with a higher // priority, since it's effectively a foreground service - switch (info.mVisibility) { - case VISIBILITY_VISIBLE: - case VISIBILITY_VISIBLE_NOTIFY_COMPLETED: - // TODO: force app out of doze, since they're showing a notification - builder.setPriority(JobInfo.PRIORITY_FOREGROUND_APP); - break; + if (info.isVisible()) { + builder.setPriority(JobInfo.PRIORITY_FOREGROUND_APP); + builder.setFlags(JobInfo.FLAG_WILL_BE_FOREGROUND); } // We might have a backoff constraint due to errors diff --git a/src/com/android/providers/downloads/RealSystemFacade.java b/src/com/android/providers/downloads/RealSystemFacade.java index da4e01ed..2203eefc 100644 --- a/src/com/android/providers/downloads/RealSystemFacade.java +++ b/src/com/android/providers/downloads/RealSystemFacade.java @@ -42,15 +42,15 @@ class RealSystemFacade implements SystemFacade { } @Override - public Network getActiveNetwork(int uid) { + public Network getActiveNetwork(int uid, boolean ignoreBlocked) { return mContext.getSystemService(ConnectivityManager.class) - .getActiveNetworkForUid(uid); + .getActiveNetworkForUid(uid, ignoreBlocked); } @Override - public NetworkInfo getNetworkInfo(Network network) { + public NetworkInfo getNetworkInfo(Network network, int uid, boolean ignoreBlocked) { return mContext.getSystemService(ConnectivityManager.class) - .getNetworkInfo(network); + .getNetworkInfoForUid(network, uid, ignoreBlocked); } @Override diff --git a/src/com/android/providers/downloads/SystemFacade.java b/src/com/android/providers/downloads/SystemFacade.java index e7852e95..5f020b1a 100644 --- a/src/com/android/providers/downloads/SystemFacade.java +++ b/src/com/android/providers/downloads/SystemFacade.java @@ -27,9 +27,9 @@ interface SystemFacade { */ public long currentTimeMillis(); - public Network getActiveNetwork(int uid); + public Network getActiveNetwork(int uid, boolean ignoreBlocked); - public NetworkInfo getNetworkInfo(Network network); + public NetworkInfo getNetworkInfo(Network network, int uid, boolean ignoreBlocked); /** * @return maximum size, in bytes, of downloads that may go over a mobile connection; or null if |