Java Code Examples for com.google.android.vending.expansion.downloader.Constants#LOGVV

The following examples show how to use com.google.android.vending.expansion.downloader.Constants#LOGVV . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadThread.java    From UnityOBBDownloader with Apache License 2.0 6 votes vote down vote up
/**
 * Report download progress through the database if necessary.
 */
private void reportProgress(State state, InnerState innerState) {
    long now = System.currentTimeMillis();
    if (innerState.mBytesSoFar - innerState.mBytesNotified
            > Constants.MIN_PROGRESS_STEP
            && now - innerState.mTimeLastNotification
            > Constants.MIN_PROGRESS_TIME) {
        // we store progress updates to the database here
        mInfo.mCurrentBytes = innerState.mBytesSoFar;
        mDB.updateDownloadCurrentBytes(mInfo);

        innerState.mBytesNotified = innerState.mBytesSoFar;
        innerState.mTimeLastNotification = now;

        long totalBytesSoFar = innerState.mBytesThisSession + mService.mBytesSoFar;

        if (Constants.LOGVV) {
            Log.v(Constants.TAG, "downloaded " + mInfo.mCurrentBytes + " out of "
                    + mInfo.mTotalBytes);
            Log.v(Constants.TAG, "     total " + totalBytesSoFar + " out of "
                    + mService.mTotalLength);
        }

        mService.notifyUpdateBytes(totalBytesSoFar);
    }
}
 
Example 2
Source File: DownloadThread.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * Report download progress through the database if necessary.
 */
private void reportProgress(State state, InnerState innerState) {
    long now = System.currentTimeMillis();
    if (innerState.mBytesSoFar - innerState.mBytesNotified
            > Constants.MIN_PROGRESS_STEP
            && now - innerState.mTimeLastNotification
            > Constants.MIN_PROGRESS_TIME) {
        // we store progress updates to the database here
        mInfo.mCurrentBytes = innerState.mBytesSoFar;
        mDB.updateDownloadCurrentBytes(mInfo);

        innerState.mBytesNotified = innerState.mBytesSoFar;
        innerState.mTimeLastNotification = now;

        long totalBytesSoFar = innerState.mBytesThisSession + mService.mBytesSoFar;

        if (Constants.LOGVV) {
            Log.v(Constants.TAG, "downloaded " + mInfo.mCurrentBytes + " out of "
                    + mInfo.mTotalBytes);
            Log.v(Constants.TAG, "     total " + totalBytesSoFar + " out of "
                    + mService.mTotalLength);
        }

        mService.notifyUpdateBytes(totalBytesSoFar);
    }
}
 
Example 3
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Report download progress through the database if necessary.
 */
private void reportProgress(State state, InnerState innerState) {
    long now = System.currentTimeMillis();
    if (innerState.mBytesSoFar - innerState.mBytesNotified
            > Constants.MIN_PROGRESS_STEP
            && now - innerState.mTimeLastNotification
            > Constants.MIN_PROGRESS_TIME) {
        // we store progress updates to the database here
        mInfo.mCurrentBytes = innerState.mBytesSoFar;
        mDB.updateDownloadCurrentBytes(mInfo);

        innerState.mBytesNotified = innerState.mBytesSoFar;
        innerState.mTimeLastNotification = now;

        long totalBytesSoFar = innerState.mBytesThisSession + mService.mBytesSoFar;

        if (Constants.LOGVV) {
            Log.v(Constants.TAG, "downloaded " + mInfo.mCurrentBytes + " out of "
                    + mInfo.mTotalBytes);
            Log.v(Constants.TAG, "     total " + totalBytesSoFar + " out of "
                    + mService.mTotalLength);
        }

        mService.notifyUpdateBytes(totalBytesSoFar);
    }
}
 
Example 4
Source File: DownloadThread.java    From travelguide with Apache License 2.0 6 votes vote down vote up
/**
 * Report download progress through the database if necessary.
 */
private void reportProgress(State state, InnerState innerState) {
    long now = System.currentTimeMillis();
    if (innerState.mBytesSoFar - innerState.mBytesNotified
            > Constants.MIN_PROGRESS_STEP
            && now - innerState.mTimeLastNotification
            > Constants.MIN_PROGRESS_TIME) {
        // we store progress updates to the database here
        mInfo.mCurrentBytes = innerState.mBytesSoFar;
        mDB.updateDownloadCurrentBytes(mInfo);

        innerState.mBytesNotified = innerState.mBytesSoFar;
        innerState.mTimeLastNotification = now;

        long totalBytesSoFar = innerState.mBytesThisSession + mService.mBytesSoFar;

        if (Constants.LOGVV) {
            Log.v(Constants.TAG, "downloaded " + mInfo.mCurrentBytes + " out of "
                    + mInfo.mTotalBytes);
            Log.v(Constants.TAG, "     total " + totalBytesSoFar + " out of "
                    + mService.mTotalLength);
        }

        mService.notifyUpdateBytes(totalBytesSoFar);
    }
}
 
Example 5
Source File: DownloadThread.java    From QtAndroidTools with MIT License 6 votes vote down vote up
/**
 * Report download progress through the database if necessary.
 */
private void reportProgress(State state, InnerState innerState) {
    long now = System.currentTimeMillis();
    if (innerState.mBytesSoFar - innerState.mBytesNotified
            > Constants.MIN_PROGRESS_STEP
            && now - innerState.mTimeLastNotification
            > Constants.MIN_PROGRESS_TIME) {
        // we store progress updates to the database here
        mInfo.mCurrentBytes = innerState.mBytesSoFar;
        mDB.updateDownloadCurrentBytes(mInfo);

        innerState.mBytesNotified = innerState.mBytesSoFar;
        innerState.mTimeLastNotification = now;

        long totalBytesSoFar = innerState.mBytesThisSession + mService.mBytesSoFar;

        if (Constants.LOGVV) {
            Log.v(Constants.TAG, "downloaded " + mInfo.mCurrentBytes + " out of "
                    + mInfo.mTotalBytes);
            Log.v(Constants.TAG, "     total " + totalBytesSoFar + " out of "
                    + mService.mTotalLength);
        }

        mService.notifyUpdateBytes(totalBytesSoFar);
    }
}
 
Example 6
Source File: DownloadThread.java    From travelguide with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpResponse response) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    Header header = response.getFirstHeader("Retry-After");
    if (header != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + header.getValue());
            }
            state.mRetryAfter = Integer.parseInt(header.getValue());
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}
 
Example 7
Source File: DownloadThread.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpURLConnection connection) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    String retryAfterValue = connection.getHeaderField("Retry-After");
    if (retryAfterValue != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + retryAfterValue);
            }
            state.mRetryAfter = Integer.parseInt(retryAfterValue);
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}
 
Example 8
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpResponse response) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    Header header = response.getFirstHeader("Retry-After");
    if (header != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + header.getValue());
            }
            state.mRetryAfter = Integer.parseInt(header.getValue());
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}
 
Example 9
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle a 3xx redirect status.
 */
private void handleRedirect(State state, HttpResponse response, int statusCode)
        throws StopRequest, RetryDownload {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP redirect " + statusCode);
    }
    if (state.mRedirectCount >= Constants.MAX_REDIRECTS) {
        throw new StopRequest(DownloaderService.STATUS_TOO_MANY_REDIRECTS, "too many redirects");
    }
    Header header = response.getFirstHeader("Location");
    if (header == null) {
        return;
    }
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Location :" + header.getValue());
    }

    String newUri;
    try {
        newUri = new URI(mInfo.mUri).resolve(new URI(header.getValue())).toString();
    } catch (URISyntaxException ex) {
        if (Constants.LOGV) {
            Log.d(Constants.TAG, "Couldn't resolve redirect URI " + header.getValue()
                    + " for " + mInfo.mUri);
        }
        throw new StopRequest(DownloaderService.STATUS_HTTP_DATA_ERROR,
                "Couldn't resolve redirect URI");
    }
    ++state.mRedirectCount;
    state.mRequestUri = newUri;
    throw new RetryDownload();
}
 
Example 10
Source File: DownloadThread.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpURLConnection connection) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    String retryAfterValue = connection.getHeaderField("Retry-After");
    if (retryAfterValue != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + retryAfterValue);
            }
            state.mRetryAfter = Integer.parseInt(retryAfterValue);
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}
 
Example 11
Source File: DownloadThread.java    From QtAndroidTools with MIT License 5 votes vote down vote up
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpURLConnection connection) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    String retryAfterValue = connection.getHeaderField("Retry-After");
    if (retryAfterValue != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + retryAfterValue);
            }
            state.mRetryAfter = Integer.parseInt(retryAfterValue);
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}
 
Example 12
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}
 
Example 13
Source File: DownloadThread.java    From travelguide with Apache License 2.0 4 votes vote down vote up
/**
 * Read headers from the HTTP response and store them into local state.
 */
private void readResponseHeaders(State state, InnerState innerState, HttpResponse response)
        throws StopRequest {
    Header header = response.getFirstHeader("Content-Disposition");
    if (header != null) {
        innerState.mHeaderContentDisposition = header.getValue();
    }
    header = response.getFirstHeader("Content-Location");
    if (header != null) {
        innerState.mHeaderContentLocation = header.getValue();
    }
    header = response.getFirstHeader("ETag");
    if (header != null) {
        innerState.mHeaderETag = header.getValue();
    }
    String headerTransferEncoding = null;
    header = response.getFirstHeader("Transfer-Encoding");
    if (header != null) {
        headerTransferEncoding = header.getValue();
    }
    String headerContentType = null;
    header = response.getFirstHeader("Content-Type");
    if (header != null) {
        headerContentType = header.getValue();
        if (!headerContentType.equals("application/vnd.android.obb")) {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect Mime type");
        }
    }

    if (headerTransferEncoding == null) {
        header = response.getFirstHeader("Content-Length");
        if (header != null) {
            innerState.mHeaderContentLength = header.getValue();
            // this is always set from Market
            long contentLength = Long.parseLong(innerState.mHeaderContentLength);
            if (contentLength != -1 && contentLength != mInfo.mTotalBytes) {
                // we're most likely on a bad wifi connection -- we should
                // probably
                // also look at the mime type --- but the size mismatch is
                // enough
                // to tell us that something is wrong here
                Log.e(Constants.TAG, "Incorrect file size delivered.");
            }
        }
    } else {
        // Ignore content-length with transfer-encoding - 2616 4.4 3
        if (Constants.LOGVV) {
            Log.v(Constants.TAG,
                    "ignoring content-length because of xfer-encoding");
        }
    }
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Content-Disposition: " +
                innerState.mHeaderContentDisposition);
        Log.v(Constants.TAG, "Content-Length: " + innerState.mHeaderContentLength);
        Log.v(Constants.TAG, "Content-Location: " + innerState.mHeaderContentLocation);
        Log.v(Constants.TAG, "ETag: " + innerState.mHeaderETag);
        Log.v(Constants.TAG, "Transfer-Encoding: " + headerTransferEncoding);
    }

    boolean noSizeInfo = innerState.mHeaderContentLength == null
            && (headerTransferEncoding == null
            || !headerTransferEncoding.equalsIgnoreCase("chunked"));
    if (noSizeInfo) {
        throw new StopRequest(DownloaderService.STATUS_HTTP_DATA_ERROR,
                "can't know size of download, giving up");
    }
}
 
Example 14
Source File: DownloaderService.java    From travelguide with Apache License 2.0 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}
 
Example 15
Source File: DownloaderService.java    From play-apk-expansion with Apache License 2.0 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}
 
Example 16
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Read headers from the HTTP response and store them into local state.
 */
private void readResponseHeaders(State state, InnerState innerState, HttpResponse response)
        throws StopRequest {
    Header header = response.getFirstHeader("Content-Disposition");
    if (header != null) {
        innerState.mHeaderContentDisposition = header.getValue();
    }
    header = response.getFirstHeader("Content-Location");
    if (header != null) {
        innerState.mHeaderContentLocation = header.getValue();
    }
    header = response.getFirstHeader("ETag");
    if (header != null) {
        innerState.mHeaderETag = header.getValue();
    }
    String headerTransferEncoding = null;
    header = response.getFirstHeader("Transfer-Encoding");
    if (header != null) {
        headerTransferEncoding = header.getValue();
    }
    String headerContentType = null;
    header = response.getFirstHeader("Content-Type");
    if (header != null) {
        headerContentType = header.getValue();
        if (!headerContentType.equals("application/vnd.android.obb")) {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect Mime type");
        }
    }

    if (headerTransferEncoding == null) {
        header = response.getFirstHeader("Content-Length");
        if (header != null) {
            innerState.mHeaderContentLength = header.getValue();
            // this is always set from Market
            long contentLength = Long.parseLong(innerState.mHeaderContentLength);
            if (contentLength != -1 && contentLength != mInfo.mTotalBytes) {
                // we're most likely on a bad wifi connection -- we should
                // probably
                // also look at the mime type --- but the size mismatch is
                // enough
                // to tell us that something is wrong here
                Log.e(Constants.TAG, "Incorrect file size delivered.");
            }
        }
    } else {
        // Ignore content-length with transfer-encoding - 2616 4.4 3
        if (Constants.LOGVV) {
            Log.v(Constants.TAG,
                    "ignoring content-length because of xfer-encoding");
        }
    }
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Content-Disposition: " +
                innerState.mHeaderContentDisposition);
        Log.v(Constants.TAG, "Content-Length: " + innerState.mHeaderContentLength);
        Log.v(Constants.TAG, "Content-Location: " + innerState.mHeaderContentLocation);
        Log.v(Constants.TAG, "ETag: " + innerState.mHeaderETag);
        Log.v(Constants.TAG, "Transfer-Encoding: " + headerTransferEncoding);
    }

    boolean noSizeInfo = innerState.mHeaderContentLength == null
            && (headerTransferEncoding == null
            || !headerTransferEncoding.equalsIgnoreCase("chunked"));
    if (noSizeInfo) {
        throw new StopRequest(DownloaderService.STATUS_HTTP_DATA_ERROR,
                "can't know size of download, giving up");
    }
}
 
Example 17
Source File: DownloadThread.java    From play-apk-expansion with Apache License 2.0 4 votes vote down vote up
/**
 * Read headers from the HTTP response and store them into local state.
 */
private void readResponseHeaders(State state, InnerState innerState, HttpURLConnection response)
        throws StopRequest {
    String value = response.getHeaderField("Content-Disposition");
    if (value != null) {
        innerState.mHeaderContentDisposition = value;
    }
    value = response.getHeaderField("Content-Location");
    if (value != null) {
        innerState.mHeaderContentLocation = value;
    }
    value = response.getHeaderField("ETag");
    if (value != null) {
        innerState.mHeaderETag = value;
    }
    String headerTransferEncoding = null;
    value = response.getHeaderField("Transfer-Encoding");
    if (value != null) {
        headerTransferEncoding = value;
    }
    String headerContentType = null;
    value = response.getHeaderField("Content-Type");
    if (value != null) {
        headerContentType = value;
        if (!headerContentType.equals("application/vnd.android.obb")) {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect Mime type");
        }
    }

    if (headerTransferEncoding == null) {
        long contentLength = response.getContentLength();
        if (value != null) {
            // this is always set from Market
            if (contentLength != -1 && contentLength != mInfo.mTotalBytes) {
                // we're most likely on a bad wifi connection -- we should
                // probably
                // also look at the mime type --- but the size mismatch is
                // enough
                // to tell us that something is wrong here
                Log.e(Constants.TAG, "Incorrect file size delivered.");
            } else {
                innerState.mHeaderContentLength = Long.toString(contentLength);
            }
        }
    } else {
        // Ignore content-length with transfer-encoding - 2616 4.4 3
        if (Constants.LOGVV) {
            Log.v(Constants.TAG,
                    "ignoring content-length because of xfer-encoding");
        }
    }
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Content-Disposition: " +
                innerState.mHeaderContentDisposition);
        Log.v(Constants.TAG, "Content-Length: " + innerState.mHeaderContentLength);
        Log.v(Constants.TAG, "Content-Location: " + innerState.mHeaderContentLocation);
        Log.v(Constants.TAG, "ETag: " + innerState.mHeaderETag);
        Log.v(Constants.TAG, "Transfer-Encoding: " + headerTransferEncoding);
    }

    boolean noSizeInfo = innerState.mHeaderContentLength == null
            && (headerTransferEncoding == null
            || !headerTransferEncoding.equalsIgnoreCase("chunked"));
    if (noSizeInfo) {
        throw new StopRequest(DownloaderService.STATUS_HTTP_DATA_ERROR,
                "can't know size of download, giving up");
    }
}
 
Example 18
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
private void updateNetworkState(NetworkInfo info) {
    boolean isConnected = mIsConnected;
    boolean isFailover = mIsFailover;
    boolean isCellularConnection = mIsCellularConnection;
    boolean isRoaming = mIsRoaming;
    boolean isAtLeast3G = mIsAtLeast3G;
    if (null != info) {
        mIsRoaming = info.isRoaming();
        mIsFailover = info.isFailover();
        mIsConnected = info.isConnected();
        updateNetworkType(info.getType(), info.getSubtype());
    } else {
        mIsRoaming = false;
        mIsFailover = false;
        mIsConnected = false;
        updateNetworkType(-1, -1);
    }
    mStateChanged = (mStateChanged || isConnected != mIsConnected
            || isFailover != mIsFailover
            || isCellularConnection != mIsCellularConnection
            || isRoaming != mIsRoaming || isAtLeast3G != mIsAtLeast3G);
    if (Constants.LOGVV) {
        if (mStateChanged) {
            Log.v(LOG_TAG, "Network state changed: ");
            Log.v(LOG_TAG, "Starting State: " +
                    (isConnected ? "Connected " : "Not Connected ") +
                    (isCellularConnection ? "Cellular " : "WiFi ") +
                    (isRoaming ? "Roaming " : "Local ") +
                    (isAtLeast3G ? "3G+ " : "<3G "));
            Log.v(LOG_TAG, "Ending State: " +
                    (mIsConnected ? "Connected " : "Not Connected ") +
                    (mIsCellularConnection ? "Cellular " : "WiFi ") +
                    (mIsRoaming ? "Roaming " : "Local ") +
                    (mIsAtLeast3G ? "3G+ " : "<3G "));

            if (isServiceRunning()) {
                if (mIsRoaming) {
                    mStatus = STATUS_WAITING_FOR_NETWORK;
                    mControl = CONTROL_PAUSED;
                } else if (mIsCellularConnection) {
                    DownloadsDB db = DownloadsDB.getDB(this);
                    int flags = db.getFlags();
                    if (0 == (flags & FLAGS_DOWNLOAD_OVER_CELLULAR)) {
                        mStatus = STATUS_QUEUED_FOR_WIFI;
                        mControl = CONTROL_PAUSED;
                    }
                }
            }

        }
    }
}
 
Example 19
Source File: DownloadThread.java    From UnityOBBDownloader with Apache License 2.0 4 votes vote down vote up
/**
 * Read headers from the HTTP response and store them into local state.
 */
private void readResponseHeaders(State state, InnerState innerState, HttpURLConnection response)
        throws StopRequest {
    String value = response.getHeaderField("Content-Disposition");
    if (value != null) {
        innerState.mHeaderContentDisposition = value;
    }
    value = response.getHeaderField("Content-Location");
    if (value != null) {
        innerState.mHeaderContentLocation = value;
    }
    value = response.getHeaderField("ETag");
    if (value != null) {
        innerState.mHeaderETag = value;
    }
    String headerTransferEncoding = null;
    value = response.getHeaderField("Transfer-Encoding");
    if (value != null) {
        headerTransferEncoding = value;
    }
    String headerContentType = null;
    value = response.getHeaderField("Content-Type");
    if (value != null) {
        headerContentType = value;
        if (!headerContentType.equals("application/vnd.android.obb")) {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect Mime type");
        }
    }

    if (headerTransferEncoding == null) {
        long contentLength = response.getContentLength();
        if (value != null) {
            // this is always set from Market
            if (contentLength != -1 && contentLength != mInfo.mTotalBytes) {
                // we're most likely on a bad wifi connection -- we should
                // probably
                // also look at the mime type --- but the size mismatch is
                // enough
                // to tell us that something is wrong here
                Log.e(Constants.TAG, "Incorrect file size delivered.");
            } else {
                innerState.mHeaderContentLength = Long.toString(contentLength);
            }
        }
    } else {
        // Ignore content-length with transfer-encoding - 2616 4.4 3
        if (Constants.LOGVV) {
            Log.v(Constants.TAG,
                    "ignoring content-length because of xfer-encoding");
        }
    }
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Content-Disposition: " +
                innerState.mHeaderContentDisposition);
        Log.v(Constants.TAG, "Content-Length: " + innerState.mHeaderContentLength);
        Log.v(Constants.TAG, "Content-Location: " + innerState.mHeaderContentLocation);
        Log.v(Constants.TAG, "ETag: " + innerState.mHeaderETag);
        Log.v(Constants.TAG, "Transfer-Encoding: " + headerTransferEncoding);
    }

    boolean noSizeInfo = innerState.mHeaderContentLength == null
            && (headerTransferEncoding == null
            || !headerTransferEncoding.equalsIgnoreCase("chunked"));
    if (noSizeInfo) {
        throw new StopRequest(DownloaderService.STATUS_HTTP_DATA_ERROR,
                "can't know size of download, giving up");
    }
}
 
Example 20
Source File: DownloadThread.java    From QtAndroidTools with MIT License 4 votes vote down vote up
/**
 * Read headers from the HTTP response and store them into local state.
 */
private void readResponseHeaders(State state, InnerState innerState, HttpURLConnection response)
        throws StopRequest {
    String value = response.getHeaderField("Content-Disposition");
    if (value != null) {
        innerState.mHeaderContentDisposition = value;
    }
    value = response.getHeaderField("Content-Location");
    if (value != null) {
        innerState.mHeaderContentLocation = value;
    }
    value = response.getHeaderField("ETag");
    if (value != null) {
        innerState.mHeaderETag = value;
    }
    String headerTransferEncoding = null;
    value = response.getHeaderField("Transfer-Encoding");
    if (value != null) {
        headerTransferEncoding = value;
    }
    String headerContentType = null;
    value = response.getHeaderField("Content-Type");
    if (value != null) {
        headerContentType = value;
        if (!headerContentType.equals("application/vnd.android.obb")) {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect Mime type");
        }
    }

    if (headerTransferEncoding == null) {
        long contentLength = response.getContentLength();
        if (value != null) {
            // this is always set from Market
            if (contentLength != -1 && contentLength != mInfo.mTotalBytes) {
                // we're most likely on a bad wifi connection -- we should
                // probably
                // also look at the mime type --- but the size mismatch is
                // enough
                // to tell us that something is wrong here
                Log.e(Constants.TAG, "Incorrect file size delivered.");
            } else {
                innerState.mHeaderContentLength = Long.toString(contentLength);
            }
        }
    } else {
        // Ignore content-length with transfer-encoding - 2616 4.4 3
        if (Constants.LOGVV) {
            Log.v(Constants.TAG,
                    "ignoring content-length because of xfer-encoding");
        }
    }
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Content-Disposition: " +
                innerState.mHeaderContentDisposition);
        Log.v(Constants.TAG, "Content-Length: " + innerState.mHeaderContentLength);
        Log.v(Constants.TAG, "Content-Location: " + innerState.mHeaderContentLocation);
        Log.v(Constants.TAG, "ETag: " + innerState.mHeaderETag);
        Log.v(Constants.TAG, "Transfer-Encoding: " + headerTransferEncoding);
    }

    boolean noSizeInfo = innerState.mHeaderContentLength == null
            && (headerTransferEncoding == null
            || !headerTransferEncoding.equalsIgnoreCase("chunked"));
    if (noSizeInfo) {
        throw new StopRequest(DownloaderService.STATUS_HTTP_DATA_ERROR,
                "can't know size of download, giving up");
    }
}