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 13, 2019
1 parent 2cca667 commit 70fbd7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 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 @@ -36,7 +36,6 @@
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.util.Pair;

import com.owncloud.android.MainApp;
Expand All @@ -45,13 +44,13 @@
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.authentication.oauth.OAuth2GrantType;
import com.owncloud.android.lib.common.authentication.oauth.OAuth2RequestBuilder;
import com.owncloud.android.lib.common.authentication.oauth.OAuth2Provider;
import com.owncloud.android.lib.common.authentication.oauth.OAuth2ProvidersRegistry;
import com.owncloud.android.lib.common.authentication.oauth.OAuth2RequestBuilder;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand Down Expand Up @@ -82,14 +81,15 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

public class OperationsService extends Service {

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

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 @@ -151,11 +151,11 @@ public Target(Account account, Uri serverUrl, String cookie) {

private ServiceHandler mOperationsHandler;
private OperationsServiceBinder mOperationsBinder;

private SyncFolderHandler mSyncFolderHandler;

private LocalBroadcastManager mLocalBroadcastManager;

/**
* Service initialization
*/
Expand All @@ -170,7 +170,7 @@ public void onCreate() {
thread.start();
mOperationsHandler = new ServiceHandler(thread.getLooper(), this);
mOperationsBinder = new OperationsServiceBinder(mOperationsHandler);

/// Separated worker thread for download of folders (WIP)
thread = new HandlerThread("Syncfolder thread", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
Expand Down Expand Up @@ -219,7 +219,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
msg.arg1 = startId;
mOperationsHandler.sendMessage(msg);
}

return START_NOT_STICKY;
}

Expand Down Expand Up @@ -822,4 +822,4 @@ public void run() {
}
Log_OC.d(TAG, "Called " + count + " listeners");
}
}
}

0 comments on commit 70fbd7f

Please sign in to comment.