com.google.android.vending.expansion.downloader.Constants Java Examples
The following examples show how to use
com.google.android.vending.expansion.downloader.Constants.
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: DownloaderService.java From travelguide with Apache License 2.0 | 6 votes |
/** * Creates a filename (where the file should be saved) from info about a * download. */ public String generateSaveFile(String filename, long filesize) throws GenerateSaveFileError { String path = generateTempSaveFileName(filename); File expPath = new File(path); if (!Helpers.isExternalMediaMounted()) { Log.d(Constants.TAG, "External media not mounted: " + path); throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR, "external media is not yet mounted"); } if (expPath.exists()) { Log.d(Constants.TAG, "File already exists: " + path); throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR, "requested destination file already exists"); } if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) { throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR, "insufficient space on external storage"); } return path; }
Example #2
Source File: DownloadThread.java From Alite with GNU General Public License v3.0 | 6 votes |
/** * Check the HTTP response status and handle anything unusual (e.g. not * 200/206). */ private void handleExceptionalStatus(State state, InnerState innerState, HttpResponse response) throws StopRequest, RetryDownload { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 503 && mInfo.mNumFailed < Constants.MAX_RETRIES) { handleServiceUnavailable(state, response); } if (statusCode == 301 || statusCode == 302 || statusCode == 303 || statusCode == 307) { handleRedirect(state, response, statusCode); } int expectedStatus = innerState.mContinuingDownload ? 206 : DownloaderService.STATUS_SUCCESS; if (statusCode != expectedStatus) { handleOtherStatus(state, innerState, statusCode); } else { // no longer redirected state.mRedirectCount = 0; } }
Example #3
Source File: DownloadThread.java From Alite with GNU General Public License v3.0 | 6 votes |
/** * 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: DownloaderService.java From play-apk-expansion with Apache License 2.0 | 6 votes |
private void scheduleAlarm(long wakeUp) { AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (alarms == null) { Log.e(Constants.TAG, "couldn't get alarm manager"); return; } if (Constants.LOGV) { Log.v(Constants.TAG, "scheduling retry in " + wakeUp + "ms"); } String className = getAlarmReceiverClassName(); Intent intent = new Intent(Constants.ACTION_RETRY); intent.putExtra(EXTRA_PENDING_INTENT, mPendingIntent); intent.setClassName(this.getPackageName(), className); mAlarmIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); alarms.set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + wakeUp, mAlarmIntent ); }
Example #5
Source File: DownloaderService.java From Alite with GNU General Public License v3.0 | 6 votes |
private void scheduleAlarm(long wakeUp) { AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (alarms == null) { Log.e(Constants.TAG, "couldn't get alarm manager"); return; } if (Constants.LOGV) { Log.v(Constants.TAG, "scheduling retry in " + wakeUp + "ms"); } String className = getAlarmReceiverClassName(); Intent intent = new Intent(Constants.ACTION_RETRY); intent.putExtra(EXTRA_PENDING_INTENT, mPendingIntent); intent.setClassName(this.getPackageName(), className); mAlarmIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); alarms.set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + wakeUp, mAlarmIntent ); }
Example #6
Source File: DownloaderService.java From UnityOBBDownloader with Apache License 2.0 | 6 votes |
/** * Creates a filename (where the file should be saved) from info about a * download. */ public String generateSaveFile(String filename, long filesize) throws GenerateSaveFileError { String path = generateTempSaveFileName(filename); File expPath = new File(path); if (!Helpers.isExternalMediaMounted()) { Log.d(Constants.TAG, "External media not mounted: " + path); throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR, "external media is not yet mounted"); } if (expPath.exists()) { Log.d(Constants.TAG, "File already exists: " + path); throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR, "requested destination file already exists"); } if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) { throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR, "insufficient space on external storage"); } return path; }
Example #7
Source File: DownloaderService.java From Alite with GNU General Public License v3.0 | 6 votes |
/** * Creates a filename (where the file should be saved) from info about a * download. */ public String generateSaveFile(String filename, long filesize) throws GenerateSaveFileError { String path = generateTempSaveFileName(filename); File expPath = new File(path); if (!Helpers.isExternalMediaMounted()) { Log.d(Constants.TAG, "External media not mounted: " + path); throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR, "external media is not yet mounted"); } if (expPath.exists()) { Log.d(Constants.TAG, "File already exists: " + path); throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR, "requested destination file already exists"); } if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) { throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR, "insufficient space on external storage"); } return path; }
Example #8
Source File: DownloaderService.java From play-apk-expansion with Apache License 2.0 | 6 votes |
/** * Creates a filename (where the file should be saved) from info about a * download. */ public String generateSaveFile(String filename, long filesize) throws GenerateSaveFileError { String path = generateTempSaveFileName(filename); File expPath = new File(path); if (!Helpers.isExternalMediaMounted()) { Log.d(Constants.TAG, "External media not mounted: " + path); throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR, "external media is not yet mounted"); } if (expPath.exists()) { Log.d(Constants.TAG, "File already exists: " + path); throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR, "requested destination file already exists"); } if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) { throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR, "insufficient space on external storage"); } return path; }
Example #9
Source File: DownloadThread.java From UnityOBBDownloader with Apache License 2.0 | 6 votes |
/** * 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 #10
Source File: DownloadThread.java From travelguide with Apache License 2.0 | 6 votes |
/** * 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 #11
Source File: DownloadThread.java From travelguide with Apache License 2.0 | 6 votes |
/** * Check the HTTP response status and handle anything unusual (e.g. not * 200/206). */ private void handleExceptionalStatus(State state, InnerState innerState, HttpResponse response) throws StopRequest, RetryDownload { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 503 && mInfo.mNumFailed < Constants.MAX_RETRIES) { handleServiceUnavailable(state, response); } if (statusCode == 301 || statusCode == 302 || statusCode == 303 || statusCode == 307) { handleRedirect(state, response, statusCode); } int expectedStatus = innerState.mContinuingDownload ? 206 : DownloaderService.STATUS_SUCCESS; if (statusCode != expectedStatus) { handleOtherStatus(state, innerState, statusCode); } else { // no longer redirected state.mRedirectCount = 0; } }
Example #12
Source File: DownloadThread.java From QtAndroidTools with MIT License | 6 votes |
/** * 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 #13
Source File: DownloaderService.java From UnityOBBDownloader with Apache License 2.0 | 6 votes |
private void scheduleAlarm(long wakeUp) { AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (alarms == null) { Log.e(Constants.TAG, "couldn't get alarm manager"); return; } if (Constants.LOGV) { Log.v(Constants.TAG, "scheduling retry in " + wakeUp + "ms"); } String className = getAlarmReceiverClassName(); Intent intent = new Intent(Constants.ACTION_RETRY); intent.putExtra(EXTRA_PENDING_INTENT, mPendingIntent); intent.setClassName(this.getPackageName(), className); mAlarmIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); alarms.set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + wakeUp, mAlarmIntent ); }
Example #14
Source File: DownloadThread.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
/** * 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 #15
Source File: DownloadInfo.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
public void logVerboseInfo() { Log.v(Constants.TAG, "Service adding new entry"); Log.v(Constants.TAG, "FILENAME: " + mFileName); Log.v(Constants.TAG, "URI : " + mUri); Log.v(Constants.TAG, "FILENAME: " + mFileName); Log.v(Constants.TAG, "CONTROL : " + mControl); Log.v(Constants.TAG, "STATUS : " + mStatus); Log.v(Constants.TAG, "FAILED_C: " + mNumFailed); Log.v(Constants.TAG, "RETRY_AF: " + mRetryAfter); Log.v(Constants.TAG, "REDIRECT: " + mRedirectCount); Log.v(Constants.TAG, "LAST_MOD: " + mLastMod); Log.v(Constants.TAG, "TOTAL : " + mTotalBytes); Log.v(Constants.TAG, "CURRENT : " + mCurrentBytes); Log.v(Constants.TAG, "ETAG : " + mETag); }
Example #16
Source File: DownloadInfo.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
/** * Returns the time when a download should be restarted. */ public long restartTime(long now) { if (mNumFailed == 0) { return now; } if (mRetryAfter > 0) { return mLastMod + mRetryAfter; } return mLastMod + Constants.RETRY_FIRST_DELAY * (1000 + mFuzz) * (1 << (mNumFailed - 1)); }
Example #17
Source File: DownloaderService.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
private void cancelAlarms() { if (null != mAlarmIntent) { AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (alarms == null) { Log.e(Constants.TAG, "couldn't get alarm manager"); return; } alarms.cancel(mAlarmIntent); mAlarmIntent = null; } }
Example #18
Source File: DownloadThread.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
/** * Check the HTTP response status and handle anything unusual (e.g. not * 200/206). */ private void handleExceptionalStatus(State state, InnerState innerState, HttpURLConnection connection, int responseCode) throws StopRequest, RetryDownload { if (responseCode == 503 && mInfo.mNumFailed < Constants.MAX_RETRIES) { handleServiceUnavailable(state, connection); } int expectedStatus = innerState.mContinuingDownload ? 206 : DownloaderService.STATUS_SUCCESS; if (responseCode != expectedStatus) { handleOtherStatus(state, innerState, responseCode); } else { // no longer redirected state.mRedirectCount = 0; } }
Example #19
Source File: DownloadThread.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
private void logNetworkState() { if (Constants.LOGX) { Log.i(Constants.TAG, "Net " + (mService.getNetworkAvailabilityState(mDB) == DownloaderService.NETWORK_OK ? "Up" : "Down")); } }
Example #20
Source File: DownloadThread.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
/** * Close the destination output stream. */ private void closeDestination(State state) { try { // close the file if (state.mStream != null) { state.mStream.close(); state.mStream = null; } } catch (IOException ex) { if (Constants.LOGV) { Log.v(Constants.TAG, "exception when closing the file after download : " + ex); } // nothing can really be done if the file can't be closed } }
Example #21
Source File: DownloadThread.java From travelguide with Apache License 2.0 | 5 votes |
private int getFinalStatusForHttpError(State state) { if (mService.getNetworkAvailabilityState(mDB) != DownloaderService.NETWORK_OK) { return DownloaderService.STATUS_WAITING_FOR_NETWORK; } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { state.mCountRetry = true; return DownloaderService.STATUS_WAITING_TO_RETRY; } else { Log.w(Constants.TAG, "reached max retries for " + mInfo.mNumFailed); return DownloaderService.STATUS_HTTP_DATA_ERROR; } }
Example #22
Source File: DownloadThread.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
private int getFinalStatusForHttpError(State state) { if (mService.getNetworkAvailabilityState(mDB) != DownloaderService.NETWORK_OK) { return DownloaderService.STATUS_WAITING_FOR_NETWORK; } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) { state.mCountRetry = true; return DownloaderService.STATUS_WAITING_TO_RETRY; } else { Log.w(Constants.TAG, "reached max retries for " + mInfo.mNumFailed); return DownloaderService.STATUS_HTTP_DATA_ERROR; } }
Example #23
Source File: DownloadThread.java From Alite with GNU General Public License v3.0 | 5 votes |
private void logNetworkState() { if (Constants.LOGX) { Log.i(Constants.TAG, "Net " + (mService.getNetworkAvailabilityState(mDB) == DownloaderService.NETWORK_OK ? "Up" : "Down")); } }
Example #24
Source File: DownloadThread.java From Alite with GNU General Public License v3.0 | 5 votes |
/** * Close the destination output stream. */ private void closeDestination(State state) { try { // close the file if (state.mStream != null) { state.mStream.close(); state.mStream = null; } } catch (IOException ex) { if (Constants.LOGV) { Log.v(Constants.TAG, "exception when closing the file after download : " + ex); } // nothing can really be done if the file can't be closed } }
Example #25
Source File: DownloadThread.java From Alite with GNU General Public License v3.0 | 5 votes |
/** * Fully execute a single download request - setup and send the request, * handle the response, and transfer the data to the destination file. */ private void executeDownload(State state, AndroidHttpClient client, HttpGet request) throws StopRequest, RetryDownload { InnerState innerState = new InnerState(); byte data[] = new byte[Constants.BUFFER_SIZE]; checkPausedOrCanceled(state); setupDestinationFile(state, innerState); addRequestHeaders(innerState, request); // check just before sending the request to avoid using an invalid // connection at all checkConnectivity(state); mNotification.onDownloadStateChanged(IDownloaderClient.STATE_CONNECTING); HttpResponse response = sendRequest(state, client, request); handleExceptionalStatus(state, innerState, response); if (Constants.LOGV) { Log.v(Constants.TAG, "received response for " + mInfo.mUri); } processResponseHeaders(state, innerState, response); InputStream entityStream = openResponseEntity(state, response); mNotification.onDownloadStateChanged(IDownloaderClient.STATE_DOWNLOADING); transferData(state, innerState, data, entityStream); }
Example #26
Source File: DownloaderService.java From travelguide with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { pollNetworkState(); if (mStateChanged && !isServiceRunning()) { Log.d(Constants.TAG, "InnerBroadcastReceiver Called"); Intent fileIntent = new Intent(context, mService.getClass()); fileIntent.putExtra(EXTRA_PENDING_INTENT, mPendingIntent); // send a new intent to the service context.startService(fileIntent); } }
Example #27
Source File: DownloaderService.java From travelguide with Apache License 2.0 | 5 votes |
private void cancelAlarms() { if (null != mAlarmIntent) { AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (alarms == null) { Log.e(Constants.TAG, "couldn't get alarm manager"); return; } alarms.cancel(mAlarmIntent); mAlarmIntent = null; } }
Example #28
Source File: DownloaderService.java From UnityOBBDownloader with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { pollNetworkState(); if (mStateChanged && !isServiceRunning()) { Log.d(Constants.TAG, "InnerBroadcastReceiver Called"); Intent fileIntent = new Intent(context, mService.getClass()); fileIntent.putExtra(EXTRA_PENDING_INTENT, mPendingIntent); // send a new intent to the service context.startService(fileIntent); } }
Example #29
Source File: DownloadInfo.java From travelguide with Apache License 2.0 | 5 votes |
public void logVerboseInfo() { Log.v(Constants.TAG, "Service adding new entry"); Log.v(Constants.TAG, "FILENAME: " + mFileName); Log.v(Constants.TAG, "URI : " + mUri); Log.v(Constants.TAG, "FILENAME: " + mFileName); Log.v(Constants.TAG, "CONTROL : " + mControl); Log.v(Constants.TAG, "STATUS : " + mStatus); Log.v(Constants.TAG, "FAILED_C: " + mNumFailed); Log.v(Constants.TAG, "RETRY_AF: " + mRetryAfter); Log.v(Constants.TAG, "REDIRECT: " + mRedirectCount); Log.v(Constants.TAG, "LAST_MOD: " + mLastMod); Log.v(Constants.TAG, "TOTAL : " + mTotalBytes); Log.v(Constants.TAG, "CURRENT : " + mCurrentBytes); Log.v(Constants.TAG, "ETAG : " + mETag); }
Example #30
Source File: DownloadInfo.java From travelguide with Apache License 2.0 | 5 votes |
/** * Returns the time when a download should be restarted. */ public long restartTime(long now) { if (mNumFailed == 0) { return now; } if (mRetryAfter > 0) { return mLastMod + mRetryAfter; } return mLastMod + Constants.RETRY_FIRST_DELAY * (1000 + mFuzz) * (1 << (mNumFailed - 1)); }