|
@@ -37,7 +37,6 @@ import android.app.Service;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
-import android.content.pm.ServiceInfo;
|
|
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.BitmapFactory;
|
|
import android.os.Binder;
|
|
import android.os.Binder;
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
@@ -59,10 +58,12 @@ import com.nextcloud.client.network.Connectivity;
|
|
import com.nextcloud.client.network.ConnectivityService;
|
|
import com.nextcloud.client.network.ConnectivityService;
|
|
import com.nextcloud.client.utils.FileUploaderDelegate;
|
|
import com.nextcloud.client.utils.FileUploaderDelegate;
|
|
import com.nextcloud.java.util.Optional;
|
|
import com.nextcloud.java.util.Optional;
|
|
|
|
+import com.nextcloud.utils.ForegroundServiceHelper;
|
|
import com.owncloud.android.MainApp;
|
|
import com.owncloud.android.MainApp;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.R;
|
|
import com.owncloud.android.authentication.AuthenticatorActivity;
|
|
import com.owncloud.android.authentication.AuthenticatorActivity;
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
|
|
+import com.owncloud.android.datamodel.ForegroundServiceType;
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
|
import com.owncloud.android.datamodel.UploadsStorageManager;
|
|
import com.owncloud.android.datamodel.UploadsStorageManager;
|
|
@@ -315,11 +316,7 @@ public class FileUploader extends Service
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
Log_OC.d(TAG, "Starting command with id " + startId);
|
|
Log_OC.d(TAG, "Starting command with id " + startId);
|
|
|
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
|
|
- startForeground(FOREGROUND_SERVICE_ID, mNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
|
|
|
|
- } else {
|
|
|
|
- startForeground(FOREGROUND_SERVICE_ID, mNotification);
|
|
|
|
- }
|
|
|
|
|
|
+ ForegroundServiceHelper.INSTANCE.startService(this, FOREGROUND_SERVICE_ID, mNotification, ForegroundServiceType.DataSync);
|
|
|
|
|
|
if (intent == null) {
|
|
if (intent == null) {
|
|
Log_OC.e(TAG, "Intent is null");
|
|
Log_OC.e(TAG, "Intent is null");
|
|
@@ -389,7 +386,7 @@ public class FileUploader extends Service
|
|
List<String> requestedUploads,
|
|
List<String> requestedUploads,
|
|
boolean onWifiOnly,
|
|
boolean onWifiOnly,
|
|
boolean whileChargingOnly
|
|
boolean whileChargingOnly
|
|
- ) {
|
|
|
|
|
|
+ ) {
|
|
String[] localPaths = null;
|
|
String[] localPaths = null;
|
|
String[] remotePaths = null;
|
|
String[] remotePaths = null;
|
|
String[] mimeTypes = null;
|
|
String[] mimeTypes = null;
|
|
@@ -428,7 +425,7 @@ public class FileUploader extends Service
|
|
remotePaths[i],
|
|
remotePaths[i],
|
|
localPaths[i],
|
|
localPaths[i],
|
|
mimeTypes != null ? mimeTypes[i] : null
|
|
mimeTypes != null ? mimeTypes[i] : null
|
|
- );
|
|
|
|
|
|
+ );
|
|
if (files[i] == null) {
|
|
if (files[i] == null) {
|
|
Log_OC.e(TAG, "obtainNewOCFileToUpload() returned null for remotePaths[i]:" + remotePaths[i]
|
|
Log_OC.e(TAG, "obtainNewOCFileToUpload() returned null for remotePaths[i]:" + remotePaths[i]
|
|
+ " and localPaths[i]:" + localPaths[i]);
|
|
+ " and localPaths[i]:" + localPaths[i]);
|
|
@@ -528,7 +525,7 @@ public class FileUploader extends Service
|
|
user.getAccountName(),
|
|
user.getAccountName(),
|
|
file.getRemotePath(),
|
|
file.getRemotePath(),
|
|
newUpload
|
|
newUpload
|
|
- );
|
|
|
|
|
|
+ );
|
|
|
|
|
|
if (putResult != null) {
|
|
if (putResult != null) {
|
|
requestedUploads.add(putResult.first);
|
|
requestedUploads.add(putResult.first);
|
|
@@ -575,7 +572,7 @@ public class FileUploader extends Service
|
|
user.getAccountName(),
|
|
user.getAccountName(),
|
|
upload.getRemotePath(),
|
|
upload.getRemotePath(),
|
|
newUpload
|
|
newUpload
|
|
- );
|
|
|
|
|
|
+ );
|
|
if (putResult != null) {
|
|
if (putResult != null) {
|
|
String uploadKey = putResult.first;
|
|
String uploadKey = putResult.first;
|
|
requestedUploads.add(uploadKey);
|
|
requestedUploads.add(uploadKey);
|
|
@@ -717,12 +714,12 @@ 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
|
|
- Intent notificationActionIntent = new Intent(getApplicationContext(),UploadNotificationActionReceiver.class);
|
|
|
|
- notificationActionIntent.putExtra(EXTRA_ACCOUNT_NAME,upload.getUser().getAccountName());
|
|
|
|
- notificationActionIntent.putExtra(EXTRA_REMOTE_PATH,upload.getRemotePath());
|
|
|
|
|
|
+ Intent notificationActionIntent = new Intent(getApplicationContext(), UploadNotificationActionReceiver.class);
|
|
|
|
+ notificationActionIntent.putExtra(EXTRA_ACCOUNT_NAME, upload.getUser().getAccountName());
|
|
|
|
+ notificationActionIntent.putExtra(EXTRA_REMOTE_PATH, upload.getRemotePath());
|
|
notificationActionIntent.setAction(ACTION_CANCEL_BROADCAST);
|
|
notificationActionIntent.setAction(ACTION_CANCEL_BROADCAST);
|
|
|
|
|
|
- PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),secureRandomGenerator.nextInt(),notificationActionIntent, PendingIntent.FLAG_IMMUTABLE);
|
|
|
|
|
|
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), secureRandomGenerator.nextInt(), notificationActionIntent, PendingIntent.FLAG_IMMUTABLE);
|
|
mLastPercent = 0;
|
|
mLastPercent = 0;
|
|
mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils);
|
|
mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, viewThemeUtils);
|
|
mNotificationBuilder
|
|
mNotificationBuilder
|
|
@@ -735,7 +732,7 @@ public class FileUploader extends Service
|
|
String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName())
|
|
String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName())
|
|
)
|
|
)
|
|
.clearActions() // to make sure there is only one action
|
|
.clearActions() // to make sure there is only one action
|
|
- .addAction(R.drawable.ic_action_cancel_grey,getApplicationContext().getString(R.string.common_cancel),pendingIntent);
|
|
|
|
|
|
+ .addAction(R.drawable.ic_action_cancel_grey, getApplicationContext().getString(R.string.common_cancel), pendingIntent);
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
@@ -773,7 +770,7 @@ public class FileUploader extends Service
|
|
long totalTransferredSoFar,
|
|
long totalTransferredSoFar,
|
|
long totalToTransfer,
|
|
long totalToTransfer,
|
|
String filePath
|
|
String filePath
|
|
- ) {
|
|
|
|
|
|
+ ) {
|
|
int percent = (int) (100.0 * ((double) totalTransferredSoFar) / ((double) totalToTransfer));
|
|
int percent = (int) (100.0 * ((double) totalTransferredSoFar) / ((double) totalToTransfer));
|
|
if (percent != mLastPercent) {
|
|
if (percent != mLastPercent) {
|
|
mNotificationBuilder.setProgress(100, percent, false);
|
|
mNotificationBuilder.setProgress(100, percent, false);
|
|
@@ -839,11 +836,11 @@ public class FileUploader extends Service
|
|
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
|
|
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
|
|
updateAccountCredentials.putExtra(
|
|
updateAccountCredentials.putExtra(
|
|
AuthenticatorActivity.EXTRA_ACCOUNT, upload.getUser().toPlatformAccount()
|
|
AuthenticatorActivity.EXTRA_ACCOUNT, upload.getUser().toPlatformAccount()
|
|
- );
|
|
|
|
|
|
+ );
|
|
updateAccountCredentials.putExtra(
|
|
updateAccountCredentials.putExtra(
|
|
AuthenticatorActivity.EXTRA_ACTION,
|
|
AuthenticatorActivity.EXTRA_ACTION,
|
|
AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN
|
|
AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN
|
|
- );
|
|
|
|
|
|
+ );
|
|
|
|
|
|
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
|
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
|
@@ -853,7 +850,7 @@ public class FileUploader extends Service
|
|
(int) System.currentTimeMillis(),
|
|
(int) System.currentTimeMillis(),
|
|
updateAccountCredentials,
|
|
updateAccountCredentials,
|
|
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE
|
|
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE
|
|
- ));
|
|
|
|
|
|
+ ));
|
|
} else {
|
|
} else {
|
|
Intent intent;
|
|
Intent intent;
|
|
if (uploadResult.getCode() == ResultCode.SYNC_CONFLICT) {
|
|
if (uploadResult.getCode() == ResultCode.SYNC_CONFLICT) {
|
|
@@ -1179,11 +1176,11 @@ public class FileUploader extends Service
|
|
*/
|
|
*/
|
|
public void cancel(String accountName, String remotePath, @Nullable ResultCode resultCode) {
|
|
public void cancel(String accountName, String remotePath, @Nullable ResultCode resultCode) {
|
|
// Cancel for Android version >= Android 11
|
|
// Cancel for Android version >= Android 11
|
|
- if (useFilesUploadWorker(getApplicationContext())){
|
|
|
|
- try{
|
|
|
|
|
|
+ if (useFilesUploadWorker(getApplicationContext())) {
|
|
|
|
+ try {
|
|
new FilesUploadHelper().cancelFileUpload(remotePath, accountManager.getUser(accountName).get());
|
|
new FilesUploadHelper().cancelFileUpload(remotePath, accountManager.getUser(accountName).get());
|
|
- }catch(NoSuchElementException e){
|
|
|
|
- Log_OC.e(TAG,"Error cancelling current upload because user does not exist!");
|
|
|
|
|
|
+ } catch (NoSuchElementException e) {
|
|
|
|
+ Log_OC.e(TAG, "Error cancelling current upload because user does not exist!");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// Cancel for Android version <= Android 10
|
|
// Cancel for Android version <= Android 10
|
|
@@ -1222,7 +1219,7 @@ public class FileUploader extends Service
|
|
cancelPendingUploads(accountName);
|
|
cancelPendingUploads(accountName);
|
|
if (useFilesUploadWorker(getApplicationContext())) {
|
|
if (useFilesUploadWorker(getApplicationContext())) {
|
|
new FilesUploadHelper().restartUploadJob(accountManager.getUser(accountName).get());
|
|
new FilesUploadHelper().restartUploadJob(accountManager.getUser(accountName).get());
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
if (mCurrentUpload != null && mCurrentUpload.getUser().nameEquals(accountName)) {
|
|
if (mCurrentUpload != null && mCurrentUpload.getUser().nameEquals(accountName)) {
|
|
mCurrentUpload.cancel(ResultCode.CANCELLED);
|
|
mCurrentUpload.cancel(ResultCode.CANCELLED);
|
|
}
|
|
}
|
|
@@ -1273,7 +1270,7 @@ public class FileUploader extends Service
|
|
OnDatatransferProgressListener listener,
|
|
OnDatatransferProgressListener listener,
|
|
User user,
|
|
User user,
|
|
OCFile file
|
|
OCFile file
|
|
- ) {
|
|
|
|
|
|
+ ) {
|
|
if (user == null || file == null || listener == null) {
|
|
if (user == null || file == null || listener == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1291,7 +1288,7 @@ public class FileUploader extends Service
|
|
public void addDatatransferProgressListener(
|
|
public void addDatatransferProgressListener(
|
|
OnDatatransferProgressListener listener,
|
|
OnDatatransferProgressListener listener,
|
|
OCUpload ocUpload
|
|
OCUpload ocUpload
|
|
- ) {
|
|
|
|
|
|
+ ) {
|
|
if (ocUpload == null || listener == null) {
|
|
if (ocUpload == null || listener == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1311,7 +1308,7 @@ public class FileUploader extends Service
|
|
OnDatatransferProgressListener listener,
|
|
OnDatatransferProgressListener listener,
|
|
User user,
|
|
User user,
|
|
OCFile file
|
|
OCFile file
|
|
- ) {
|
|
|
|
|
|
+ ) {
|
|
if (user == null || file == null || listener == null) {
|
|
if (user == null || file == null || listener == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1331,7 +1328,7 @@ public class FileUploader extends Service
|
|
public void removeDatatransferProgressListener(
|
|
public void removeDatatransferProgressListener(
|
|
OnDatatransferProgressListener listener,
|
|
OnDatatransferProgressListener listener,
|
|
OCUpload ocUpload
|
|
OCUpload ocUpload
|
|
- ) {
|
|
|
|
|
|
+ ) {
|
|
if (ocUpload == null || listener == null) {
|
|
if (ocUpload == null || listener == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -1348,7 +1345,7 @@ public class FileUploader extends Service
|
|
long totalTransferredSoFar,
|
|
long totalTransferredSoFar,
|
|
long totalToTransfer,
|
|
long totalToTransfer,
|
|
String fileName
|
|
String fileName
|
|
- ) {
|
|
|
|
|
|
+ ) {
|
|
String key = buildRemoteName(mCurrentUpload.getUser().getAccountName(), mCurrentUpload.getFile().getRemotePath());
|
|
String key = buildRemoteName(mCurrentUpload.getUser().getAccountName(), mCurrentUpload.getFile().getRemotePath());
|
|
OnDatatransferProgressListener boundListener = mBoundListeners.get(key);
|
|
OnDatatransferProgressListener boundListener = mBoundListeners.get(key);
|
|
|
|
|
|
@@ -1373,7 +1370,7 @@ public class FileUploader extends Service
|
|
mCurrentUpload.getUser().getAccountName(),
|
|
mCurrentUpload.getUser().getAccountName(),
|
|
mCurrentUpload.getFile().getRemotePath(),
|
|
mCurrentUpload.getFile().getRemotePath(),
|
|
cancelReason
|
|
cancelReason
|
|
- );
|
|
|
|
|
|
+ );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1444,11 +1441,13 @@ public class FileUploader extends Service
|
|
if (ACTION_CANCEL_BROADCAST.equals(action)) {
|
|
if (ACTION_CANCEL_BROADCAST.equals(action)) {
|
|
Log_OC.d(TAG, "Cancel broadcast received for file " + remotePath + " at " + System.currentTimeMillis());
|
|
Log_OC.d(TAG, "Cancel broadcast received for file " + remotePath + " at " + System.currentTimeMillis());
|
|
|
|
|
|
- if (accountName == null || remotePath == null) return;
|
|
|
|
|
|
+ if (accountName == null || remotePath == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
FileUploaderBinder uploadBinder = (FileUploaderBinder) mBinder;
|
|
FileUploaderBinder uploadBinder = (FileUploaderBinder) mBinder;
|
|
uploadBinder.cancel(accountName, remotePath, null);
|
|
uploadBinder.cancel(accountName, remotePath, null);
|
|
- }else if(ACTION_PAUSE_BROADCAST.equals(action)){
|
|
|
|
|
|
+ } else if (ACTION_PAUSE_BROADCAST.equals(action)) {
|
|
|
|
|
|
} else {
|
|
} else {
|
|
Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver.");
|
|
Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver.");
|