diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-12-23 19:28:09 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-01-09 18:32:03 -0800 |
commit | 0de55602ec6d350548248feddc68c91b29326eff (patch) | |
tree | f64aa79577aa145c331a81bdbf23f12c6e8bd9be /src/com/android/providers/downloads/StopRequestException.java | |
parent | 8ac10e0e0667a4fe35191deebb5fa9786bf4226c (diff) | |
download | android_packages_providers_DownloadProvider-0de55602ec6d350548248feddc68c91b29326eff.tar.gz android_packages_providers_DownloadProvider-0de55602ec6d350548248feddc68c91b29326eff.tar.bz2 android_packages_providers_DownloadProvider-0de55602ec6d350548248feddc68c91b29326eff.zip |
Simplify download flow control, handle redirects.
Move redirection handling into a single loop, and handle each HTTP
response code inline to make flow control easier to reason about.
Fix race condition in tests by waiting for first status update.
Bug: 7887226
Change-Id: Id4bfd182941baad4cd0bb702376c4beeb7275bb2
Diffstat (limited to 'src/com/android/providers/downloads/StopRequestException.java')
-rw-r--r-- | src/com/android/providers/downloads/StopRequestException.java | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/com/android/providers/downloads/StopRequestException.java b/src/com/android/providers/downloads/StopRequestException.java index 0ccf53cb..6df61dce 100644 --- a/src/com/android/providers/downloads/StopRequestException.java +++ b/src/com/android/providers/downloads/StopRequestException.java @@ -15,6 +15,9 @@ */ package com.android.providers.downloads; +import static android.provider.Downloads.Impl.STATUS_UNHANDLED_HTTP_CODE; +import static android.provider.Downloads.Impl.STATUS_UNHANDLED_REDIRECT; + /** * Raised to indicate that the current request should be stopped immediately. * @@ -23,15 +26,35 @@ package com.android.providers.downloads; * URI, headers, or destination filename. */ class StopRequestException extends Exception { - public int mFinalStatus; + private final int mFinalStatus; public StopRequestException(int finalStatus, String message) { super(message); mFinalStatus = finalStatus; } - public StopRequestException(int finalStatus, String message, Throwable throwable) { - super(message, throwable); + public StopRequestException(int finalStatus, Throwable t) { + super(t); + mFinalStatus = finalStatus; + } + + public StopRequestException(int finalStatus, String message, Throwable t) { + super(message, t); mFinalStatus = finalStatus; } + + public int getFinalStatus() { + return mFinalStatus; + } + + public static StopRequestException throwUnhandledHttpError(int responseCode) + throws StopRequestException { + if (responseCode >= 400 && responseCode < 600) { + throw new StopRequestException(responseCode, "Unhandled HTTP response"); + } else if (responseCode >= 300 && responseCode < 400) { + throw new StopRequestException(STATUS_UNHANDLED_REDIRECT, "Unhandled HTTP response"); + } else { + throw new StopRequestException(STATUS_UNHANDLED_HTTP_CODE, "Unhandled HTTP response"); + } + } } |