|
@@ -34,7 +34,6 @@ import android.app.Service;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
import android.os.Binder;
|
|
import android.os.Binder;
|
|
-import android.os.Build;
|
|
|
|
import android.os.Handler;
|
|
import android.os.Handler;
|
|
import android.os.HandlerThread;
|
|
import android.os.HandlerThread;
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
@@ -45,6 +44,9 @@ import android.os.Process;
|
|
import android.support.v4.app.NotificationCompat;
|
|
import android.support.v4.app.NotificationCompat;
|
|
import android.util.Pair;
|
|
import android.util.Pair;
|
|
|
|
|
|
|
|
+import com.evernote.android.job.JobRequest;
|
|
|
|
+import com.evernote.android.job.util.Device;
|
|
|
|
+import com.owncloud.android.MainApp;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.authentication.AccountUtils;
|
|
import com.owncloud.android.authentication.AccountUtils;
|
|
import com.owncloud.android.authentication.AuthenticatorActivity;
|
|
import com.owncloud.android.authentication.AuthenticatorActivity;
|
|
@@ -77,6 +79,8 @@ import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Vector;
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
+import javax.annotation.Nullable;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Service for uploading files. Invoke using context.startService(...).
|
|
* Service for uploading files. Invoke using context.startService(...).
|
|
*
|
|
*
|
|
@@ -144,6 +148,9 @@ public class FileUploader extends Service
|
|
* Key to signal what is the origin of the upload request
|
|
* Key to signal what is the origin of the upload request
|
|
*/
|
|
*/
|
|
public static final String KEY_CREATED_BY = "CREATED_BY";
|
|
public static final String KEY_CREATED_BY = "CREATED_BY";
|
|
|
|
+
|
|
|
|
+ public static final String KEY_WHILE_ON_WIFI_ONLY = "KEY_ON_WIFI_ONLY";
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Set to true if upload is to performed only when phone is being charged.
|
|
* Set to true if upload is to performed only when phone is being charged.
|
|
*/
|
|
*/
|
|
@@ -194,7 +201,6 @@ public class FileUploader extends Service
|
|
sendBroadcastUploadStarted(mCurrentUpload);
|
|
sendBroadcastUploadStarted(mCurrentUpload);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Helper class providing methods to ease requesting commands to {@link FileUploader} .
|
|
* Helper class providing methods to ease requesting commands to {@link FileUploader} .
|
|
*
|
|
*
|
|
@@ -214,7 +220,37 @@ public class FileUploader extends Service
|
|
String[] mimeTypes,
|
|
String[] mimeTypes,
|
|
Integer behaviour,
|
|
Integer behaviour,
|
|
Boolean createRemoteFolder,
|
|
Boolean createRemoteFolder,
|
|
- int createdBy
|
|
|
|
|
|
+ int createdBy,
|
|
|
|
+ boolean requiresWifi,
|
|
|
|
+ boolean requiresCharging
|
|
|
|
+ ) {
|
|
|
|
+ Intent intent = new Intent(context, FileUploader.class);
|
|
|
|
+
|
|
|
|
+ intent.putExtra(FileUploader.KEY_ACCOUNT, account);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_LOCAL_FILE, localPaths);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_MIME_TYPE, mimeTypes);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_CREATED_BY, createdBy);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_WHILE_ON_WIFI_ONLY, requiresWifi);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_WHILE_CHARGING_ONLY, requiresCharging);
|
|
|
|
+
|
|
|
|
+ context.startService(intent);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void uploadFileWithOverwrite(
|
|
|
|
+ Context context,
|
|
|
|
+ Account account,
|
|
|
|
+ String[] localPaths,
|
|
|
|
+ String[] remotePaths,
|
|
|
|
+ String[] mimeTypes,
|
|
|
|
+ Integer behaviour,
|
|
|
|
+ Boolean createRemoteFolder,
|
|
|
|
+ int createdBy,
|
|
|
|
+ boolean requiresWifi,
|
|
|
|
+ boolean requiresCharging,
|
|
|
|
+ boolean overwrite
|
|
) {
|
|
) {
|
|
Intent intent = new Intent(context, FileUploader.class);
|
|
Intent intent = new Intent(context, FileUploader.class);
|
|
|
|
|
|
@@ -225,15 +261,41 @@ public class FileUploader extends Service
|
|
intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
|
|
intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
|
|
intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder);
|
|
intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder);
|
|
intent.putExtra(FileUploader.KEY_CREATED_BY, createdBy);
|
|
intent.putExtra(FileUploader.KEY_CREATED_BY, createdBy);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_WHILE_ON_WIFI_ONLY, requiresWifi);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_WHILE_CHARGING_ONLY, requiresCharging);
|
|
|
|
+ intent.putExtra(FileUploader.KEY_FORCE_OVERWRITE, overwrite);
|
|
|
|
|
|
context.startService(intent);
|
|
context.startService(intent);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Call to upload a file
|
|
|
|
+ */
|
|
|
|
+ public void uploadFileWithOverwrite(Context context, Account account, String localPath, String remotePath, int
|
|
|
|
+ behaviour, String mimeType, boolean createRemoteFile, int createdBy, boolean requiresWifi,
|
|
|
|
+ boolean requiresCharging, boolean overwrite) {
|
|
|
|
+
|
|
|
|
+ uploadFileWithOverwrite(
|
|
|
|
+ context,
|
|
|
|
+ account,
|
|
|
|
+ new String[]{localPath},
|
|
|
|
+ new String[]{remotePath},
|
|
|
|
+ new String[]{mimeType},
|
|
|
|
+ behaviour,
|
|
|
|
+ createRemoteFile,
|
|
|
|
+ createdBy,
|
|
|
|
+ requiresWifi,
|
|
|
|
+ requiresCharging,
|
|
|
|
+ overwrite
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Call to upload a new single file
|
|
* Call to upload a new single file
|
|
*/
|
|
*/
|
|
public void uploadNewFile(Context context, Account account, String localPath, String remotePath, int
|
|
public void uploadNewFile(Context context, Account account, String localPath, String remotePath, int
|
|
- behaviour, String mimeType, boolean createRemoteFile, int createdBy) {
|
|
|
|
|
|
+ behaviour, String mimeType, boolean createRemoteFile, int createdBy, boolean requiresWifi,
|
|
|
|
+ boolean requiresCharging) {
|
|
|
|
|
|
uploadNewFile(
|
|
uploadNewFile(
|
|
context,
|
|
context,
|
|
@@ -243,7 +305,9 @@ public class FileUploader extends Service
|
|
new String[]{mimeType},
|
|
new String[]{mimeType},
|
|
behaviour,
|
|
behaviour,
|
|
createRemoteFile,
|
|
createRemoteFile,
|
|
- createdBy
|
|
|
|
|
|
+ createdBy,
|
|
|
|
+ requiresWifi,
|
|
|
|
+ requiresCharging
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -288,7 +352,6 @@ public class FileUploader extends Service
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Retry a subset of all the stored failed uploads.
|
|
* Retry a subset of all the stored failed uploads.
|
|
*
|
|
*
|
|
@@ -306,7 +369,7 @@ public class FileUploader extends Service
|
|
boolean accountMatch;
|
|
boolean accountMatch;
|
|
for ( OCUpload failedUpload: failedUploads) {
|
|
for ( OCUpload failedUpload: failedUploads) {
|
|
accountMatch = (account == null || account.name.equals(failedUpload.getAccountName()));
|
|
accountMatch = (account == null || account.name.equals(failedUpload.getAccountName()));
|
|
- resultMatch = (uploadResult == null || uploadResult.equals(failedUpload.getLastResult()));
|
|
|
|
|
|
+ resultMatch = ((uploadResult == null || uploadResult.equals(failedUpload.getLastResult())));
|
|
if (accountMatch && resultMatch) {
|
|
if (accountMatch && resultMatch) {
|
|
if (currentAccount == null ||
|
|
if (currentAccount == null ||
|
|
!currentAccount.name.equals(failedUpload.getAccountName())) {
|
|
!currentAccount.name.equals(failedUpload.getAccountName())) {
|
|
@@ -330,13 +393,12 @@ public class FileUploader extends Service
|
|
i.putExtra(FileUploader.KEY_RETRY, true);
|
|
i.putExtra(FileUploader.KEY_RETRY, true);
|
|
i.putExtra(FileUploader.KEY_ACCOUNT, account);
|
|
i.putExtra(FileUploader.KEY_ACCOUNT, account);
|
|
i.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload);
|
|
i.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload);
|
|
|
|
+
|
|
context.startService(i);
|
|
context.startService(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Service initialization
|
|
* Service initialization
|
|
*/
|
|
*/
|
|
@@ -370,7 +432,6 @@ public class FileUploader extends Service
|
|
am.addOnAccountsUpdatedListener(this, null, false);
|
|
am.addOnAccountsUpdatedListener(this, null, false);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Service clean-up when restarted after being killed
|
|
* Service clean-up when restarted after being killed
|
|
*/
|
|
*/
|
|
@@ -379,7 +440,6 @@ public class FileUploader extends Service
|
|
mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
|
|
mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Service clean up
|
|
* Service clean up
|
|
*/
|
|
*/
|
|
@@ -399,7 +459,6 @@ public class FileUploader extends Service
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Entry point to add one or several files to the queue of uploads.
|
|
* Entry point to add one or several files to the queue of uploads.
|
|
*
|
|
*
|
|
@@ -426,9 +485,14 @@ public class FileUploader extends Service
|
|
return Service.START_NOT_STICKY;
|
|
return Service.START_NOT_STICKY;
|
|
}
|
|
}
|
|
OwnCloudVersion ocv = AccountUtils.getServerVersion(account);
|
|
OwnCloudVersion ocv = AccountUtils.getServerVersion(account);
|
|
|
|
+
|
|
boolean chunked = ocv.isChunkedUploadSupported();
|
|
boolean chunked = ocv.isChunkedUploadSupported();
|
|
|
|
|
|
|
|
+ boolean onWifiOnly = intent.getBooleanExtra(KEY_WHILE_ON_WIFI_ONLY, false);
|
|
|
|
+ boolean whileChargingOnly = intent.getBooleanExtra(KEY_WHILE_CHARGING_ONLY, false);
|
|
|
|
+
|
|
if (!retry) {
|
|
if (!retry) {
|
|
|
|
+
|
|
if (!(intent.hasExtra(KEY_LOCAL_FILE) ||
|
|
if (!(intent.hasExtra(KEY_LOCAL_FILE) ||
|
|
intent.hasExtra(KEY_FILE))) {
|
|
intent.hasExtra(KEY_FILE))) {
|
|
Log_OC.e(TAG, "Not enough information provided in intent");
|
|
Log_OC.e(TAG, "Not enough information provided in intent");
|
|
@@ -451,7 +515,6 @@ public class FileUploader extends Service
|
|
mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
|
|
mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
|
|
boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
|
|
int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
|
|
int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
|
|
|
|
|
|
@@ -503,10 +566,12 @@ public class FileUploader extends Service
|
|
ocUpload.setCreateRemoteFolder(isCreateRemoteFolder);
|
|
ocUpload.setCreateRemoteFolder(isCreateRemoteFolder);
|
|
ocUpload.setCreatedBy(createdBy);
|
|
ocUpload.setCreatedBy(createdBy);
|
|
ocUpload.setLocalAction(localAction);
|
|
ocUpload.setLocalAction(localAction);
|
|
- /*ocUpload.setUseWifiOnly(isUseWifiOnly);
|
|
|
|
- ocUpload.setWhileChargingOnly(isWhileChargingOnly);*/
|
|
|
|
|
|
+ ocUpload.setUseWifiOnly(onWifiOnly);
|
|
|
|
+ ocUpload.setWhileChargingOnly(whileChargingOnly);
|
|
|
|
+
|
|
ocUpload.setUploadStatus(UploadStatus.UPLOAD_IN_PROGRESS);
|
|
ocUpload.setUploadStatus(UploadStatus.UPLOAD_IN_PROGRESS);
|
|
|
|
|
|
|
|
+
|
|
newUpload = new UploadFileOperation(
|
|
newUpload = new UploadFileOperation(
|
|
account,
|
|
account,
|
|
files[i],
|
|
files[i],
|
|
@@ -514,7 +579,9 @@ public class FileUploader extends Service
|
|
chunked,
|
|
chunked,
|
|
forceOverwrite,
|
|
forceOverwrite,
|
|
localAction,
|
|
localAction,
|
|
- this
|
|
|
|
|
|
+ this,
|
|
|
|
+ onWifiOnly,
|
|
|
|
+ whileChargingOnly
|
|
);
|
|
);
|
|
newUpload.setCreatedBy(createdBy);
|
|
newUpload.setCreatedBy(createdBy);
|
|
if (isCreateRemoteFolder) {
|
|
if (isCreateRemoteFolder) {
|
|
@@ -561,6 +628,9 @@ public class FileUploader extends Service
|
|
}
|
|
}
|
|
OCUpload upload = intent.getParcelableExtra(KEY_RETRY_UPLOAD);
|
|
OCUpload upload = intent.getParcelableExtra(KEY_RETRY_UPLOAD);
|
|
|
|
|
|
|
|
+ onWifiOnly = upload.isUseWifiOnly();
|
|
|
|
+ whileChargingOnly = upload.isWhileChargingOnly();
|
|
|
|
+
|
|
UploadFileOperation newUpload = new UploadFileOperation(
|
|
UploadFileOperation newUpload = new UploadFileOperation(
|
|
account,
|
|
account,
|
|
null,
|
|
null,
|
|
@@ -568,7 +638,9 @@ public class FileUploader extends Service
|
|
chunked,
|
|
chunked,
|
|
upload.isForceOverwrite(), // TODO should be read from DB?
|
|
upload.isForceOverwrite(), // TODO should be read from DB?
|
|
upload.getLocalAction(), // TODO should be read from DB?
|
|
upload.getLocalAction(), // TODO should be read from DB?
|
|
- this
|
|
|
|
|
|
+ this,
|
|
|
|
+ onWifiOnly,
|
|
|
|
+ whileChargingOnly
|
|
);
|
|
);
|
|
|
|
|
|
newUpload.addDatatransferProgressListener(this);
|
|
newUpload.addDatatransferProgressListener(this);
|
|
@@ -634,9 +706,8 @@ public class FileUploader extends Service
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Binder to let client components to perform operations on the queue of
|
|
|
|
- * uploads.
|
|
|
|
- * <p/>
|
|
|
|
|
|
+ * Binder to let client components to perform operations on the queue of uploads.
|
|
|
|
+ *
|
|
* It provides by itself the available operations.
|
|
* It provides by itself the available operations.
|
|
*/
|
|
*/
|
|
public class FileUploaderBinder extends Binder implements OnDatatransferProgressListener {
|
|
public class FileUploaderBinder extends Binder implements OnDatatransferProgressListener {
|
|
@@ -645,9 +716,7 @@ public class FileUploader extends Service
|
|
* Map of listeners that will be reported about progress of uploads from a
|
|
* Map of listeners that will be reported about progress of uploads from a
|
|
* {@link FileUploaderBinder} instance
|
|
* {@link FileUploaderBinder} instance
|
|
*/
|
|
*/
|
|
- private Map<String, OnDatatransferProgressListener> mBoundListeners =
|
|
|
|
- new HashMap<String, OnDatatransferProgressListener>();
|
|
|
|
-
|
|
|
|
|
|
+ private Map<String, OnDatatransferProgressListener> mBoundListeners = new HashMap<>();
|
|
|
|
|
|
/**
|
|
/**
|
|
* Cancels a pending or current upload of a remote file.
|
|
* Cancels a pending or current upload of a remote file.
|
|
@@ -656,7 +725,7 @@ public class FileUploader extends Service
|
|
* @param file A file in the queue of pending uploads
|
|
* @param file A file in the queue of pending uploads
|
|
*/
|
|
*/
|
|
public void cancel(Account account, OCFile file) {
|
|
public void cancel(Account account, OCFile file) {
|
|
- cancel(account.name, file.getRemotePath());
|
|
|
|
|
|
+ cancel(account.name, file.getRemotePath(), null);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -665,7 +734,7 @@ public class FileUploader extends Service
|
|
* @param storedUpload Upload operation persisted
|
|
* @param storedUpload Upload operation persisted
|
|
*/
|
|
*/
|
|
public void cancel(OCUpload storedUpload) {
|
|
public void cancel(OCUpload storedUpload) {
|
|
- cancel(storedUpload.getAccountName(), storedUpload.getRemotePath());
|
|
|
|
|
|
+ cancel(storedUpload.getAccountName(), storedUpload.getRemotePath(), null);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -674,8 +743,10 @@ public class FileUploader extends Service
|
|
*
|
|
*
|
|
* @param accountName Local name of an ownCloud account where the remote file will be stored.
|
|
* @param accountName Local name of an ownCloud account where the remote file will be stored.
|
|
* @param remotePath Remote target of the upload
|
|
* @param remotePath Remote target of the upload
|
|
|
|
+ *
|
|
|
|
+ * Setting result code will pause rather than cancel the job
|
|
*/
|
|
*/
|
|
- private void cancel(String accountName, String remotePath) {
|
|
|
|
|
|
+ private void cancel(String accountName, String remotePath, @Nullable ResultCode resultCode ) {
|
|
Pair<UploadFileOperation, String> removeResult =
|
|
Pair<UploadFileOperation, String> removeResult =
|
|
mPendingUploads.remove(accountName, remotePath);
|
|
mPendingUploads.remove(accountName, remotePath);
|
|
UploadFileOperation upload = removeResult.first;
|
|
UploadFileOperation upload = removeResult.first;
|
|
@@ -686,14 +757,17 @@ public class FileUploader extends Service
|
|
|
|
|
|
upload = mCurrentUpload;
|
|
upload = mCurrentUpload;
|
|
}
|
|
}
|
|
|
|
+
|
|
if (upload != null) {
|
|
if (upload != null) {
|
|
upload.cancel();
|
|
upload.cancel();
|
|
// need to update now table in mUploadsStorageManager,
|
|
// need to update now table in mUploadsStorageManager,
|
|
// since the operation will not get to be run by FileUploader#uploadFile
|
|
// since the operation will not get to be run by FileUploader#uploadFile
|
|
- mUploadsStorageManager.removeUpload(accountName, remotePath);
|
|
|
|
- } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
- // try to cancel job in jobScheduler
|
|
|
|
- mUploadsStorageManager.cancelPendingJob(accountName, remotePath);
|
|
|
|
|
|
+ if (resultCode != null) {
|
|
|
|
+ mUploadsStorageManager.updateDatabaseUploadResult(new RemoteOperationResult(resultCode), upload);
|
|
|
|
+ notifyUploadResult(upload, new RemoteOperationResult(resultCode));
|
|
|
|
+ } else {
|
|
|
|
+ mUploadsStorageManager.removeUpload(accountName, remotePath);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -740,7 +814,6 @@ public class FileUploader extends Service
|
|
return (mPendingUploads.contains(account.name, file.getRemotePath()));
|
|
return (mPendingUploads.contains(account.name, file.getRemotePath()));
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
public boolean isUploadingNow(OCUpload upload) {
|
|
public boolean isUploadingNow(OCUpload upload) {
|
|
return (
|
|
return (
|
|
upload != null &&
|
|
upload != null &&
|
|
@@ -751,7 +824,6 @@ public class FileUploader extends Service
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Adds a listener interested in the progress of the upload for a concrete file.
|
|
* Adds a listener interested in the progress of the upload for a concrete file.
|
|
*
|
|
*
|
|
@@ -771,7 +843,6 @@ public class FileUploader extends Service
|
|
mBoundListeners.put(targetKey, listener);
|
|
mBoundListeners.put(targetKey, listener);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Adds a listener interested in the progress of the upload for a concrete file.
|
|
* Adds a listener interested in the progress of the upload for a concrete file.
|
|
*
|
|
*
|
|
@@ -789,7 +860,6 @@ public class FileUploader extends Service
|
|
mBoundListeners.put(targetKey, listener);
|
|
mBoundListeners.put(targetKey, listener);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Removes a listener interested in the progress of the upload for a concrete file.
|
|
* Removes a listener interested in the progress of the upload for a concrete file.
|
|
*
|
|
*
|
|
@@ -811,7 +881,6 @@ public class FileUploader extends Service
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Removes a listener interested in the progress of the upload for a concrete file.
|
|
* Removes a listener interested in the progress of the upload for a concrete file.
|
|
*
|
|
*
|
|
@@ -831,7 +900,6 @@ public class FileUploader extends Service
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void onTransferProgress(long progressRate, long totalTransferredSoFar,
|
|
public void onTransferProgress(long progressRate, long totalTransferredSoFar,
|
|
long totalToTransfer, String fileName) {
|
|
long totalToTransfer, String fileName) {
|
|
@@ -840,12 +908,24 @@ public class FileUploader extends Service
|
|
if (boundListener != null) {
|
|
if (boundListener != null) {
|
|
boundListener.onTransferProgress(progressRate, totalTransferredSoFar,
|
|
boundListener.onTransferProgress(progressRate, totalTransferredSoFar,
|
|
totalToTransfer, fileName);
|
|
totalToTransfer, fileName);
|
|
|
|
+
|
|
|
|
+ if (MainApp.getAppContext() != null) {
|
|
|
|
+ if (mCurrentUpload.getIsWifiRequired() && !Device.getNetworkType(MainApp.getAppContext()).
|
|
|
|
+ equals(JobRequest.NetworkType.UNMETERED)) {
|
|
|
|
+ cancel(mCurrentUpload.getAccount().name, mCurrentUpload.getFile().getRemotePath()
|
|
|
|
+ , ResultCode.DELAYED_FOR_WIFI);
|
|
|
|
+ } else if (mCurrentUpload.getIsChargingRequired() &&
|
|
|
|
+ !Device.isCharging(MainApp.getAppContext())) {
|
|
|
|
+ cancel(mCurrentUpload.getAccount().name, mCurrentUpload.getFile().getRemotePath()
|
|
|
|
+ , ResultCode.DELAYED_FOR_CHARGING);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Builds a key for the map of listeners.
|
|
* Builds a key for the map of listeners.
|
|
- * <p/>
|
|
|
|
|
|
+ *
|
|
* TODO use method in IndexedForest, or refactor both to a common place
|
|
* TODO use method in IndexedForest, or refactor both to a common place
|
|
* add to local database) to better policy (add to local database, then upload)
|
|
* add to local database) to better policy (add to local database, then upload)
|
|
*
|
|
*
|
|
@@ -863,7 +943,7 @@ public class FileUploader extends Service
|
|
/**
|
|
/**
|
|
* Upload worker. Performs the pending uploads in the order they were
|
|
* Upload worker. Performs the pending uploads in the order they were
|
|
* requested.
|
|
* requested.
|
|
- * <p/>
|
|
|
|
|
|
+ *
|
|
* Created with the Looper of a new thread, started in
|
|
* Created with the Looper of a new thread, started in
|
|
* {@link FileUploader#onCreate()}.
|
|
* {@link FileUploader#onCreate()}.
|
|
*/
|
|
*/
|
|
@@ -958,7 +1038,7 @@ public class FileUploader extends Service
|
|
mCurrentAccount.name,
|
|
mCurrentAccount.name,
|
|
mCurrentUpload.getOldFile().getRemotePath()
|
|
mCurrentUpload.getOldFile().getRemotePath()
|
|
);
|
|
);
|
|
- /** TODO: grant that name is also updated for mCurrentUpload.getOCUploadId */
|
|
|
|
|
|
+ // TODO: grant that name is also updated for mCurrentUpload.getOCUploadId
|
|
|
|
|
|
} else {
|
|
} else {
|
|
removeResult = mPendingUploads.removePayload(
|
|
removeResult = mPendingUploads.removePayload(
|
|
@@ -973,7 +1053,6 @@ public class FileUploader extends Service
|
|
notifyUploadResult(mCurrentUpload, uploadResult);
|
|
notifyUploadResult(mCurrentUpload, uploadResult);
|
|
|
|
|
|
sendBroadcastUploadFinished(mCurrentUpload, uploadResult, removeResult.second);
|
|
sendBroadcastUploadFinished(mCurrentUpload, uploadResult, removeResult.second);
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// generate new Thumbnail
|
|
// generate new Thumbnail
|
|
@@ -997,8 +1076,7 @@ public class FileUploader extends Service
|
|
private void notifyUploadStart(UploadFileOperation upload) {
|
|
private void notifyUploadStart(UploadFileOperation upload) {
|
|
// / create status notification with a progress bar
|
|
// / create status notification with a progress bar
|
|
mLastPercent = 0;
|
|
mLastPercent = 0;
|
|
- mNotificationBuilder =
|
|
|
|
- NotificationUtils.newNotificationBuilder(this);
|
|
|
|
|
|
+ mNotificationBuilder = NotificationUtils.newNotificationBuilder(this);
|
|
mNotificationBuilder
|
|
mNotificationBuilder
|
|
.setOngoing(true)
|
|
.setOngoing(true)
|
|
.setSmallIcon(R.drawable.notification_icon)
|
|
.setSmallIcon(R.drawable.notification_icon)
|
|
@@ -1022,7 +1100,6 @@ public class FileUploader extends Service
|
|
} // else wait until the upload really start (onTransferProgress is called), so that if it's discarded
|
|
} // else wait until the upload really start (onTransferProgress is called), so that if it's discarded
|
|
// due to lack of Wifi, no notification is shown
|
|
// due to lack of Wifi, no notification is shown
|
|
// TODO generalize for automated uploads
|
|
// TODO generalize for automated uploads
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1058,7 +1135,8 @@ public class FileUploader extends Service
|
|
if (!uploadResult.isCancelled() &&
|
|
if (!uploadResult.isCancelled() &&
|
|
!ResultCode.LOCAL_FILE_NOT_FOUND.equals(uploadResult.getCode()) &&
|
|
!ResultCode.LOCAL_FILE_NOT_FOUND.equals(uploadResult.getCode()) &&
|
|
!uploadResult.getCode().equals(ResultCode.DELAYED_FOR_WIFI) &&
|
|
!uploadResult.getCode().equals(ResultCode.DELAYED_FOR_WIFI) &&
|
|
- !uploadResult.getCode().equals(ResultCode.DELAYED_FOR_CHARGING)) {
|
|
|
|
|
|
+ !uploadResult.getCode().equals(ResultCode.DELAYED_FOR_CHARGING) &&
|
|
|
|
+ !uploadResult.getCode().equals(ResultCode.LOCK_FAILED) ) {
|
|
|
|
|
|
int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker :
|
|
int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker :
|
|
R.string.uploader_upload_failed_ticker;
|
|
R.string.uploader_upload_failed_ticker;
|
|
@@ -1077,9 +1155,7 @@ public class FileUploader extends Service
|
|
.setOngoing(false)
|
|
.setOngoing(false)
|
|
.setProgress(0, 0, false);
|
|
.setProgress(0, 0, false);
|
|
|
|
|
|
- content = ErrorMessageAdapter.getErrorCauseMessage(
|
|
|
|
- uploadResult, upload, getResources()
|
|
|
|
- );
|
|
|
|
|
|
+ content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, upload, getResources());
|
|
|
|
|
|
if (needsToUpdateCredentials) {
|
|
if (needsToUpdateCredentials) {
|
|
// let the user update credentials with one click
|
|
// let the user update credentials with one click
|
|
@@ -1130,7 +1206,6 @@ public class FileUploader extends Service
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Sends a broadcast in order to the interested activities can update their
|
|
* Sends a broadcast in order to the interested activities can update their
|
|
* view
|
|
* view
|
|
@@ -1144,7 +1219,6 @@ public class FileUploader extends Service
|
|
sendStickyBroadcast(start);
|
|
sendStickyBroadcast(start);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Sends a broadcast in order to the interested activities can update their
|
|
* Sends a broadcast in order to the interested activities can update their
|
|
* view
|
|
* view
|
|
@@ -1208,5 +1282,4 @@ public class FileUploader extends Service
|
|
mPendingUploads.remove(account.name);
|
|
mPendingUploads.remove(account.name);
|
|
mUploadsStorageManager.removeUploads(account.name);
|
|
mUploadsStorageManager.removeUploads(account.name);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|