diff --git a/presentation/src/main/AndroidManifest.xml b/presentation/src/main/AndroidManifest.xml
index 8923143e2..9a7735bf0 100644
--- a/presentation/src/main/AndroidManifest.xml
+++ b/presentation/src/main/AndroidManifest.xml
@@ -14,7 +14,7 @@
-
+
+
(exceptionHandlers) {
+
+ fun refreshCloudToken(authenticationException: AuthenticationException) {
+ authenticationExceptionHandler.handleAuthenticationException( //
+ this@AutoUploadRefreshTokenPresenter, //
+ authenticationException, //
+ ActivityResultCallbacks.onAutoUploadCloudAuthenticated(authenticationException.cloud)
+ )
+ }
+
+ @Callback(dispatchResultOkOnly = false)
+ fun onAutoUploadCloudAuthenticated(result: ActivityResult, cloud: Cloud) {
+ if (result.isResultOk) {
+ val cryptomatorApp = activity().application as CryptomatorApp
+ cryptomatorApp.startAutoUpload(cloud)
+ }
+ finish()
+ }
+}
diff --git a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadNotification.kt b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadNotification.kt
index 7630e0fd3..3b4a53ddc 100644
--- a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadNotification.kt
+++ b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadNotification.kt
@@ -11,8 +11,11 @@ import android.content.Intent.ACTION_MAIN
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import androidx.core.app.NotificationCompat
+import org.cryptomator.domain.exception.authentication.AuthenticationException
import org.cryptomator.presentation.R
import org.cryptomator.presentation.service.AutoUploadService.cancelAutoUploadIntent
+import org.cryptomator.presentation.ui.activity.AutoUploadRefreshTokenActivity
+import org.cryptomator.presentation.ui.activity.AutoUploadRefreshTokenActivity.Companion.AUTHENTICATION_EXCEPTION_ARG
import org.cryptomator.presentation.ui.activity.VaultListActivity
import org.cryptomator.presentation.util.ResourceHelper.Companion.getColor
import org.cryptomator.presentation.util.ResourceHelper.Companion.getString
@@ -107,6 +110,23 @@ class AutoUploadNotification(private val context: Context, private val amountOfP
showErrorWithMessage(context.getString(R.string.notification_auto_upload_permission_not_granted))
}
+ fun showWrongCredentialNotification(authenticationException: AuthenticationException) {
+ val startTheActivity = Intent(context, AutoUploadRefreshTokenActivity::class.java)
+ startTheActivity.action = ACTION_MAIN
+ startTheActivity.flags = FLAG_ACTIVITY_CLEAR_TASK or FLAG_ACTIVITY_NEW_TASK
+ startTheActivity.putExtra(AUTHENTICATION_EXCEPTION_ARG, authenticationException)
+ val intent = PendingIntent.getActivity(context, 0, startTheActivity, FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE)
+ builder
+ .setContentIntent(intent)
+ .setContentTitle(context.getString(R.string.notification_auto_upload_failed_title))
+ .setContentText(context.getString(R.string.notification_auto_upload_failed_due_to_authentication_problem))
+ .setProgress(0, 0, false)
+ .setAutoCancel(true)
+ .setOngoing(false)
+ .clearActions()
+ show()
+ }
+
private fun showErrorWithMessage(message: String) {
builder
.setContentIntent(startTheActivity())
diff --git a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java
index b760436d2..522a97e52 100644
--- a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java
+++ b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java
@@ -25,6 +25,8 @@
import org.cryptomator.domain.exception.FileRemovedDuringUploadException;
import org.cryptomator.domain.exception.MissingCryptorException;
import org.cryptomator.domain.exception.NoSuchCloudFileException;
+import org.cryptomator.domain.exception.authentication.AuthenticationException;
+import org.cryptomator.domain.exception.authentication.WrongCredentialsException;
import org.cryptomator.domain.repository.CloudContentRepository;
import org.cryptomator.domain.usecases.ProgressAware;
import org.cryptomator.domain.usecases.cloud.CancelAwareDataSource;
@@ -107,7 +109,7 @@ private void startBackgroundImageUpload(Cloud cloud) {
}
upload(progress -> updateNotification(progress.asPercentage()));
- } catch (FatalBackendException | BackendException | MissingCryptorException e) {
+ } catch (FatalBackendException | BackendException | MissingCryptorException | AuthenticationException e) {
if (e instanceof NoSuchCloudFileException) {
notification.showFolderMissing();
} else if (e instanceof MissingCryptorException) {
@@ -116,6 +118,8 @@ private void startBackgroundImageUpload(Cloud cloud) {
Timber.tag("AutoUploadService").i("Upload canceled by user");
} else if (wrappedStoragePermissionException(e)) {
notification.showPermissionNotGrantedNotification();
+ } else if (e instanceof AuthenticationException) {
+ notification.showWrongCredentialNotification((WrongCredentialsException) e);
} else {
notification.showGeneralErrorDuringUpload();
}
diff --git a/presentation/src/main/java/org/cryptomator/presentation/ui/activity/AutoUploadRefreshTokenActivity.kt b/presentation/src/main/java/org/cryptomator/presentation/ui/activity/AutoUploadRefreshTokenActivity.kt
new file mode 100644
index 000000000..21b37247c
--- /dev/null
+++ b/presentation/src/main/java/org/cryptomator/presentation/ui/activity/AutoUploadRefreshTokenActivity.kt
@@ -0,0 +1,33 @@
+package org.cryptomator.presentation.ui.activity
+
+import android.os.Bundle
+import org.cryptomator.domain.exception.authentication.AuthenticationException
+import org.cryptomator.generator.Activity
+import org.cryptomator.presentation.R
+import org.cryptomator.presentation.presenter.AutoUploadRefreshTokenPresenter
+import org.cryptomator.presentation.ui.activity.view.AutoUploadRefreshTokenView
+import javax.inject.Inject
+import timber.log.Timber
+
+@Activity(layout = R.layout.activity_empty)
+class AutoUploadRefreshTokenActivity : BaseActivity(), AutoUploadRefreshTokenView {
+
+ @Inject
+ lateinit var presenter: AutoUploadRefreshTokenPresenter
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ val cloud = intent.getSerializableExtra(AUTHENTICATION_EXCEPTION_ARG) as? AuthenticationException
+ cloud?.let {
+ presenter.refreshCloudToken(it)
+ } ?: run {
+ Timber.tag("AutoUploadRefreshTokenActivity").e("WrongCredentialsException not provided")
+ finish()
+ }
+ }
+
+ companion object {
+ const val AUTHENTICATION_EXCEPTION_ARG = "authenticationException"
+ }
+
+}
diff --git a/presentation/src/main/java/org/cryptomator/presentation/ui/activity/view/AutoUploadRefreshTokenView.kt b/presentation/src/main/java/org/cryptomator/presentation/ui/activity/view/AutoUploadRefreshTokenView.kt
new file mode 100644
index 000000000..aa4c1f515
--- /dev/null
+++ b/presentation/src/main/java/org/cryptomator/presentation/ui/activity/view/AutoUploadRefreshTokenView.kt
@@ -0,0 +1,5 @@
+package org.cryptomator.presentation.ui.activity.view
+
+interface AutoUploadRefreshTokenView : View {
+
+}
diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml
index ff1dff58e..4f7777ccb 100644
--- a/presentation/src/main/res/values/strings.xml
+++ b/presentation/src/main/res/values/strings.xml
@@ -573,6 +573,7 @@
Vault locked during upload, please reopen vault to continue
Vault specified for auto upload doesn\'t exist anymore.
@string/permission_snackbar_auth_auto_upload
+ Tap to refresh authentication.
@string/dialog_button_cancel
Open writable file