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 12, 2019
1 parent 77b2e4e commit 16e0a28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 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,6 +36,8 @@
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 @@ -89,7 +91,6 @@ public class OperationsService extends Service {
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 @@ -219,6 +220,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
msg.arg1 = 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 Expand Up @@ -822,4 +828,4 @@ public void run() {
}
Log_OC.d(TAG, "Called " + count + " listeners");
}
}
}

0 comments on commit 16e0a28

Please sign in to comment.