Skip to content

Commit

Permalink
fix forground crash
Browse files Browse the repository at this point in the history
attempt to fix upload
  • Loading branch information
hannesa2 committed Feb 10, 2019
1 parent e07901b commit 72a4297
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,23 @@ public int onStartCommand(Intent intent, int flags, int startId) {
KEY_REQUESTED_FROM_WIFI_BACK_EVENT, false
);

if ((createdBy == CREATED_AS_CAMERA_UPLOAD_PICTURE || createdBy == CREATED_AS_CAMERA_UPLOAD_VIDEO ||
isAvailableOfflineFile || isRequestedFromWifiBackEvent) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
/**
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
/*
* After calling startForegroundService method from {@link TransferRequester} for camera uploads or
* available offline, we have to call this within five seconds after the service is created to avoid
* an error
*/
Log_OC.d(TAG, "Starting FileUploader service in foreground");
startForeground(1, mNotificationBuilder.build());
mNotificationBuilder
.setOngoing(true)
.setSmallIcon(R.drawable.notification_icon)
.setTicker(getString(R.string.uploader_upload_in_progress_ticker))
.setContentTitle(getString(R.string.uploader_upload_in_progress_ticker))
.setProgress(100, 0, false)
.setContentText(String.format(getString(R.string.uploader_upload_in_progress_content), 0, ""))
.setChannelId(UPLOAD_NOTIFICATION_CHANNEL_ID)
.setWhen(System.currentTimeMillis());
startForeground(141, mNotificationBuilder.build());
}

boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
Expand Down Expand Up @@ -1152,4 +1159,4 @@ private void cancelUploadsForAccount(Account account) {
mPendingUploads.remove(account.name);
mUploadsStorageManager.removeUploads(account.name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Process;

import androidx.core.app.NotificationCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.util.Pair;

Expand Down Expand Up @@ -78,7 +76,6 @@
import com.owncloud.android.operations.UpdateSharePermissionsOperation;
import com.owncloud.android.operations.UpdateShareViaLinkOperation;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.ui.notifications.NotificationUtils;

import java.io.IOException;
import java.util.Iterator;
Expand All @@ -89,12 +86,10 @@
public class OperationsService extends Service {

private static final String TAG = OperationsService.class.getSimpleName();
private NotificationCompat.Builder mNotificationBuilder;

public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_SERVER_URL = "SERVER_URL";
public static final String EXTRA_OAUTH2_AUTHORIZATION_CODE = "OAUTH2_AUTHORIZATION_CODE";
public static final String EXTRA_OAUTH2_QUERY_PARAMETERS = "OAUTH2_AUTHORIZATION_QUERY_PARAMETERS";
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_NEWNAME = "NEWNAME";
public static final String EXTRA_REMOVE_ONLY_LOCAL = "REMOVE_LOCAL_COPY";
Expand Down Expand Up @@ -183,8 +178,6 @@ public void onCreate() {

// create manager for local broadcasts
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

mNotificationBuilder = NotificationUtils.newNotificationBuilder(this);
}


Expand Down Expand Up @@ -227,11 +220,6 @@ public int onStartCommand(Intent intent, int flags, int startId) {
mOperationsHandler.sendMessage(msg);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log_OC.d(TAG, "Starting OperationsService service in foreground");
startForeground(1, mNotificationBuilder.build());
}

return START_NOT_STICKY;
}

Expand Down

0 comments on commit 72a4297

Please sign in to comment.