From 65cb1993ae3ee173369b0a7fed2e00eb76a3e01b Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 5 Jun 2024 19:14:43 +0600 Subject: [PATCH 01/31] fix: oidc authService.dispose() can throw exception, which can crash app --- .../kotlin/at/bitfire/davdroid/network/HttpClient.kt | 8 ++++++-- .../syncadapter/DefaultAccountAuthenticatorService.kt | 6 +++++- .../at/bitfire/davdroid/syncadapter/SyncManager.kt | 6 +++++- .../at/bitfire/davdroid/ui/setup/GoogleLoginFragment.kt | 6 +++++- .../davdroid/ui/setup/OpenIdAuthenticationViewModel.kt | 7 ++++++- .../davdroid/ui/signout/OpenIdEndSessionActivity.kt | 9 ++++++++- 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClient.kt b/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClient.kt index b5fff9d5f..e540e17f9 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClient.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClient.kt @@ -89,8 +89,12 @@ class HttpClient private constructor( } override fun close() { - authService?.dispose() - okHttpClient.cache?.close() + try { + okHttpClient.cache?.close() + authService?.dispose() + } catch (e: Exception) { + Logger.log.log(Level.SEVERE, "failed to clear resource on close httpClient", e) + } } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/DefaultAccountAuthenticatorService.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/DefaultAccountAuthenticatorService.kt index da635b072..16adca035 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/DefaultAccountAuthenticatorService.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/DefaultAccountAuthenticatorService.kt @@ -232,7 +232,11 @@ abstract class DefaultAccountAuthenticatorService : Service(), OnAccountsUpdateL result.putString(AccountManager.KEY_AUTHTOKEN, authState.accessToken) response?.onResult(result) - authorizationService.dispose() + try { + authorizationService.dispose() + } catch (e: Exception) { + Logger.log.log(Level.INFO, "failed to dispose oidc authorizationService", e) + } } val result = Bundle() diff --git a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt index 2a6688353..dd6b8418a 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt @@ -221,7 +221,11 @@ abstract class SyncManager, out CollectionType: L performSync(DEFAULT_RETRY_AFTER, DEFAULT_SECOND_RETRY_AFTER, DEFAULT_MAX_RETRY_TIME) } - authorizationService.dispose() + try { + authorizationService.dispose() + } catch (e: Exception) { + Logger.log.log(Level.INFO, "failed to dispose oidc authorizationService", e) + } } } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/GoogleLoginFragment.kt b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/GoogleLoginFragment.kt index 6ef6e0971..21c91f488 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/GoogleLoginFragment.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/GoogleLoginFragment.kt @@ -209,7 +209,11 @@ class GoogleLoginFragment(private val defaultEmail: String? = null): Fragment() } override fun onCleared() { - authService.dispose() + try { + authService.dispose() + } catch (e: Exception) { + Logger.log.log(Level.INFO, "failed to dispose oidc authorizationService", e) + } } } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/OpenIdAuthenticationViewModel.kt b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/OpenIdAuthenticationViewModel.kt index 175872dc5..f777a8d80 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/OpenIdAuthenticationViewModel.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/OpenIdAuthenticationViewModel.kt @@ -62,8 +62,13 @@ class OpenIdAuthenticationViewModel(application: Application) : AndroidViewModel } override fun onCleared() { - authorizationService.dispose() super.onCleared() + try { + authorizationService.dispose() + } catch (e: Exception) { + Logger.log.log(Level.INFO, "failed to dispose oidc authorizationService", e) + } + } fun getAuthState(): AuthState { diff --git a/app/src/main/kotlin/at/bitfire/davdroid/ui/signout/OpenIdEndSessionActivity.kt b/app/src/main/kotlin/at/bitfire/davdroid/ui/signout/OpenIdEndSessionActivity.kt index 631e4b8f7..5001315b4 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/ui/signout/OpenIdEndSessionActivity.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/ui/signout/OpenIdEndSessionActivity.kt @@ -20,11 +20,13 @@ import android.accounts.AccountManager import android.app.Activity import android.os.Bundle import at.bitfire.davdroid.authorization.IdentityProvider +import at.bitfire.davdroid.log.Logger import at.bitfire.davdroid.settings.AccountSettings import net.openid.appauth.AuthState import net.openid.appauth.AuthorizationService import net.openid.appauth.AuthorizationServiceConfiguration import net.openid.appauth.EndSessionRequest +import java.util.logging.Level class OpenIdEndSessionActivity : Activity() { @@ -79,7 +81,12 @@ class OpenIdEndSessionActivity : Activity() { } override fun onDestroy() { - authorizationService?.dispose() super.onDestroy() + + try { + authorizationService?.dispose() + } catch (e: Exception) { + Logger.log.log(Level.INFO, "failed to dispose oidc authorizationService", e) + } } } -- GitLab From 8cf3c1cfc057a9e637b54578afaf61bb0beafae7 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 5 Jun 2024 19:16:13 +0600 Subject: [PATCH 02/31] chore: remove clientSecret for murena OIDC auth flow As recomended by the industry, we will use only PKCE key for secrecy & remove clientSecret for murena OIDC flow --- .gitlab-ci.yml | 1 - app/build.gradle | 1 - .../at/bitfire/davdroid/authorization/IdentityProvider.kt | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8af528d99..012978291 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,6 @@ stages: before_script: - echo email.key=$PEPPER >> local.properties - echo MURENA_CLIENT_ID=$MURENA_CLIENT_ID >> local.properties - - echo MURENA_CLIENT_SECRET=$MURENA_CLIENT_SECRET >> local.properties - echo MURENA_REDIRECT_URI=$MURENA_REDIRECT_URI >> local.properties - echo MURENA_LOGOUT_REDIRECT_URI=$MURENA_LOGOUT_REDIRECT_URI >> local.properties - echo MURENA_BASE_URL=$MURENA_BASE_URL >> local.properties diff --git a/app/build.gradle b/app/build.gradle index b51c845a0..ad6359db0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,7 +109,6 @@ android { defaultConfig { buildConfigField "String", "MURENA_CLIENT_ID", "\"${retrieveKey("MURENA_CLIENT_ID")}\"" - buildConfigField "String", "MURENA_CLIENT_SECRET", "\"${retrieveKey("MURENA_CLIENT_SECRET")}\"" buildConfigField "String", "MURENA_REDIRECT_URI", "\"${retrieveKey("MURENA_REDIRECT_URI")}\"" buildConfigField "String", "MURENA_LOGOUT_REDIRECT_URI", "\"${retrieveKey("MURENA_LOGOUT_REDIRECT_URI")}\"" buildConfigField "String", "MURENA_BASE_URL", "\"${retrieveKey("MURENA_BASE_URL")}\"" diff --git a/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt b/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt index f7fce1c16..c7d8741aa 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt @@ -42,7 +42,7 @@ enum class IdentityProvider( authEndpoint = null, tokenEndpoint = null, clientId = BuildConfig.MURENA_CLIENT_ID, - clientSecret = BuildConfig.MURENA_CLIENT_SECRET, + clientSecret = null, redirectUri = BuildConfig.MURENA_REDIRECT_URI + ":/redirect", logoutRedirectUri = BuildConfig.MURENA_LOGOUT_REDIRECT_URI + ":/redirect", scope = "openid address profile email phone roles offline_access web-origins microprofile-jwt", -- GitLab From 5d366c55cdc455f80773ffdc4dd5954f164e6433 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 5 Jun 2024 19:16:27 +0600 Subject: [PATCH 03/31] chore: enable murena OIDC support --- .../at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt index c65296df1..53691500e 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt @@ -27,7 +27,7 @@ class EeloAuthenticatorModel(application: Application) : AndroidViewModel(applic companion object { // as https://gitlab.e.foundation/e/backlog/-/issues/6287 is blocked, the openId implementation is not ready yet. // But we want to push the changes so later we won't face any conflict. So we are disabling the openId feature for now. - const val enableOpenIdSupport = false + const val enableOpenIdSupport = true } private var initialized = false -- GitLab From e6594260f8f9f18f68b789129b1e336e09312b34 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 30 Sep 2024 17:52:29 +0600 Subject: [PATCH 04/31] fix: remove extra scopes for murena oidc for OIDC login, the accessToken length is dependent on the requested scopes. Which cause /e/OS mail is not working as expected for long accessToken (mailServer has a barier on perline length of request). Removing not required scopes resolve this issue. issue: https://gitlab.e.foundation/e/os/backlog/-/issues/2497 --- .../at/bitfire/davdroid/authorization/IdentityProvider.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt b/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt index f7fce1c16..868529719 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt @@ -45,7 +45,7 @@ enum class IdentityProvider( clientSecret = BuildConfig.MURENA_CLIENT_SECRET, redirectUri = BuildConfig.MURENA_REDIRECT_URI + ":/redirect", logoutRedirectUri = BuildConfig.MURENA_LOGOUT_REDIRECT_URI + ":/redirect", - scope = "openid address profile email phone roles offline_access web-origins microprofile-jwt", + scope = "openid profile email", userInfoEndpoint = null, baseUrl = BuildConfig.MURENA_BASE_URL, ), -- GitLab From 9f7c3a7121a3a67cdf3f222fdf601ff12577ece0 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 30 Sep 2024 19:37:09 +0600 Subject: [PATCH 05/31] fixup --- .../at/bitfire/davdroid/authorization/IdentityProvider.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt b/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt index 868529719..c7cdbf441 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/authorization/IdentityProvider.kt @@ -45,7 +45,7 @@ enum class IdentityProvider( clientSecret = BuildConfig.MURENA_CLIENT_SECRET, redirectUri = BuildConfig.MURENA_REDIRECT_URI + ":/redirect", logoutRedirectUri = BuildConfig.MURENA_LOGOUT_REDIRECT_URI + ":/redirect", - scope = "openid profile email", + scope = "openid profile email offline_access", userInfoEndpoint = null, baseUrl = BuildConfig.MURENA_BASE_URL, ), -- GitLab From 5792b76a92e4d07d7c8860e4fb66ec1fae78f429 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 17 Oct 2024 19:29:21 +0600 Subject: [PATCH 06/31] chore: improve according to code review - update constants variable name - fix log level --- .../main/kotlin/at/bitfire/davdroid/network/HttpClient.kt | 2 +- .../davdroid/ui/setup/DetectConfigurationFragment.kt | 6 ++---- .../davdroid/ui/setup/EeloAuthenticatorFragment.kt | 8 ++++---- .../bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClient.kt b/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClient.kt index e540e17f9..d61ba172a 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClient.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/network/HttpClient.kt @@ -93,7 +93,7 @@ class HttpClient private constructor( okHttpClient.cache?.close() authService?.dispose() } catch (e: Exception) { - Logger.log.log(Level.SEVERE, "failed to clear resource on close httpClient", e) + Logger.log.log(Level.INFO, "failed to clear resource on close httpClient", e) } } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt index 92114462c..be7d2750e 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.content.ContextCompat import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels @@ -18,14 +17,13 @@ import androidx.fragment.app.viewModels import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData -import at.bitfire.davdroid.Constants +import at.bitfire.davdroid.ECloudAccountHelper import at.bitfire.davdroid.R import at.bitfire.davdroid.db.Credentials import at.bitfire.davdroid.log.Logger import at.bitfire.davdroid.servicedetection.DavResourceFinder import at.bitfire.davdroid.ui.DebugInfoActivity import com.google.android.material.dialog.MaterialAlertDialogBuilder -import at.bitfire.davdroid.ECloudAccountHelper import java.lang.ref.WeakReference import java.net.URI import java.util.logging.Level @@ -47,7 +45,7 @@ class DetectConfigurationFragment: Fragment() { return } - val blockOnUnauthorizedException = (accountType == getString(R.string.eelo_account_type)) && !EeloAuthenticatorModel.enableOpenIdSupport + val blockOnUnauthorizedException = (accountType == getString(R.string.eelo_account_type)) && !EeloAuthenticatorModel.ENABLE_OIDC_SUPPORT val baseURI = loginModel.baseURI ?: return diff --git a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt index 77b0252c7..47bbafcf0 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorFragment.kt @@ -79,7 +79,7 @@ class EeloAuthenticatorFragment : Fragment() { passwordEditText = v.root.findViewById(R.id.urlpwd_password) passwordHolder = v.root.findViewById(R.id.password_holder) - passwordHolder.isVisible = !EeloAuthenticatorModel.enableOpenIdSupport + passwordHolder.isVisible = !EeloAuthenticatorModel.ENABLE_OIDC_SUPPORT serverToggleButton.setOnClickListener { expandCollapse() } @@ -87,7 +87,7 @@ class EeloAuthenticatorFragment : Fragment() { val tfaButton = v.root.findViewById(R.id.twofa_info_button) tfaButton.setOnClickListener { show2FAInfoDialog() } - tfaButton.isVisible = !EeloAuthenticatorModel.enableOpenIdSupport + tfaButton.isVisible = !EeloAuthenticatorModel.ENABLE_OIDC_SUPPORT userIdEditText.doOnTextChanged { text, _, _, _ -> val domain = computeDomain(text) @@ -205,7 +205,7 @@ class EeloAuthenticatorFragment : Fragment() { private fun login() { handleNoNetworkAvailable() - val handleOpenIdAuth = EeloAuthenticatorModel.enableOpenIdSupport && !toggleButtonState + val handleOpenIdAuth = EeloAuthenticatorModel.ENABLE_OIDC_SUPPORT && !toggleButtonState val userId = userIdEditText.text.toString() val password = passwordEditText.text.toString() @@ -306,7 +306,7 @@ class EeloAuthenticatorFragment : Fragment() { serverUrlEditText.isEnabled = false toggleButtonState = false - if(!EeloAuthenticatorModel.enableOpenIdSupport) { + if(!EeloAuthenticatorModel.ENABLE_OIDC_SUPPORT) { return } diff --git a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt index 53691500e..9b05b2e60 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/ui/setup/EeloAuthenticatorModel.kt @@ -27,7 +27,7 @@ class EeloAuthenticatorModel(application: Application) : AndroidViewModel(applic companion object { // as https://gitlab.e.foundation/e/backlog/-/issues/6287 is blocked, the openId implementation is not ready yet. // But we want to push the changes so later we won't face any conflict. So we are disabling the openId feature for now. - const val enableOpenIdSupport = true + const val ENABLE_OIDC_SUPPORT = true } private var initialized = false -- GitLab From 405cb5a6c620f98896159099b86d14bd242a2dfa Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 14 Oct 2024 23:15:40 +0600 Subject: [PATCH 07/31] ci: added release job for test build --- .gitlab-ci.yml | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b951e172..a06756be5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ variables: UNSIGNED_APK: "davx5-ose-release-unsigned.apk" COMMUNITY_APK: "Account_manager_community.apk" OFFICIAL_APK: "Account_manager_official.apk" + TEST_APK: "Account_manager_test.apk" stages: - update-from-upstream @@ -74,12 +75,13 @@ generate-apks: script: - | ./systemAppsUpdateInfo/scripts/generate-apks.sh \ - "$APK_PATH" "$UNSIGNED_APK" "$COMMUNITY_APK" "$OFFICIAL_APK" + "$APK_PATH" "$UNSIGNED_APK" "$COMMUNITY_APK" "$OFFICIAL_APK" "$TEST_APK" artifacts: paths: - $APK_PATH/$UNSIGNED_APK - $APK_PATH/$COMMUNITY_APK - $APK_PATH/$OFFICIAL_APK + - $APK_PATH/$TEST_APK create-json-files: stage: gitlab_release @@ -91,17 +93,37 @@ create-json-files: - generate-apks rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' - when: manual + when: on_success before_script: - apt update && apt install jq aapt -y script: - | ./systemAppsUpdateInfo/scripts/create-json-files.sh \ - "$APK_PATH" "$UNSIGNED_APK" "$COMMUNITY_APK" "$OFFICIAL_APK" + "$APK_PATH" "$UNSIGNED_APK" "$COMMUNITY_APK" "$OFFICIAL_APK" "$TEST_APK" artifacts: paths: - community.json - official.json + - test.json + +create-test-release: + stage: gitlab_release + dependencies: + - init_submodules + needs: + - init_submodules + - create-json-files + - generate-apks + rules: + - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' + when: manual + before_script: + - apt update && apt install jq -y + script: + - | + ./systemAppsUpdateInfo/scripts/create-test-release.sh \ + "$APK_PATH" "$TEST_APK" + allow_failure: true create-release: stage: gitlab_release @@ -113,13 +135,14 @@ create-release: - generate-apks rules: - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' - when: on_success + when: manual before_script: - apt update && apt install jq -y script: - | ./systemAppsUpdateInfo/scripts/create-release.sh \ "$APK_PATH" "$UNSIGNED_APK" "$COMMUNITY_APK" "$OFFICIAL_APK" + allow_failure: true .update-from-upstream: stage: update-from-upstream -- GitLab From df7cda79228a15c8c70b05bc14a9f33db14aaa0f Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 6 Nov 2024 16:18:55 +0100 Subject: [PATCH 08/31] feature: Add very basic code structure to notifiy a request to user to switch to openID for /e/ account --- app/src/main/AndroidManifest.xml | 6 ++ .../receiver/BootCompletedReceiver.kt | 71 +++++++++++++++++++ .../davdroid/receiver/LogoutReceiver.kt | 11 +++ 3 files changed, 88 insertions(+) create mode 100644 app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 30e04639b..2299dfee3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -703,6 +703,12 @@ + + + + try { + val token = future.result.getString(AccountManager.KEY_AUTHTOKEN) + } catch (e: Exception) { + println("Error retrieving token for account ${account.name}: ${e.message}") } + }, null) + + val isPasswordNull = accountManager.getPassword(account).isNullOrEmpty() + + return isPasswordNull && authToken != null } + private fun notifyOpenIdSwitchRequest(account: Account, + notificationManager: NotificationManager, + context: Context) { + val notifId = 3310 + val notifTitle = "${account.name}: Switch to OpenId" + val notifText = "Now that OpenId is available, you should log out and re-loggin your account." + val notifIntent = generateLogOutIntent(account.name, context) + + val notification = NotificationCompat.Builder(context, "your_channel_id") + .setContentTitle(notifTitle) + .setContentText(notifText) + .setSmallIcon(R.drawable.ic_info) + .setContentIntent(notifIntent) + .setAutoCancel(true) + .build() + + notificationManager.notify(notifId, notification) + } + + private fun generateLogOutIntent(accountName: String, context: Context): PendingIntent { + val logoutIntent = Intent(context, LogoutReceiver::class.java).apply { + putExtra("ACCOUNT_NAME", accountName) + } + + return PendingIntent.getBroadcast(context, + 0, + logoutIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) + } } \ No newline at end of file diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt new file mode 100644 index 000000000..0b953b20a --- /dev/null +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt @@ -0,0 +1,11 @@ +package at.bitfire.davdroid.receiver + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent + +class LogoutReceiver(): BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + TODO("Not yet implemented") + } +} \ No newline at end of file -- GitLab From a1c399c4f738890663d9abf81ca21c7b0ebc28e9 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 7 Nov 2024 16:24:45 +0100 Subject: [PATCH 09/31] refactor: replace checking AUTH_TOKEN by checking if auth_state is in user data refactor: minor various refactoring like adding notification title & text in strings.xml --- .../receiver/BootCompletedReceiver.kt | 41 ++++++------------- app/src/main/res/values/strings.xml | 3 ++ 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt index 40bc90967..9e36dbd45 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt @@ -6,18 +6,17 @@ package at.bitfire.davdroid.receiver import android.accounts.Account import android.accounts.AccountManager -import android.app.NotificationManager import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import android.os.Bundle import androidx.core.app.NotificationCompat +import androidx.core.app.NotificationManagerCompat import at.bitfire.davdroid.R import at.bitfire.davdroid.log.Logger import at.bitfire.davdroid.settings.AccountSettings import at.bitfire.davdroid.syncadapter.AccountUtils -import com.owncloud.android.lib.common.accounts.AccountTypeUtils +import at.bitfire.davdroid.ui.NotificationUtils.notifyIfPossible /** * There are circumstances when Android drops automatic sync of accounts and resets them @@ -30,7 +29,6 @@ class BootCompletedReceiver: BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { Logger.log.info("Device has been rebooted; checking sync intervals etc.") - val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val isOpenIdAvailable = isOpenIdAvailable() val eAccountType = context.getString(R.string.eelo_account_type) @@ -44,41 +42,27 @@ class BootCompletedReceiver: BroadcastReceiver() { accountSettings.initSync() if (it.type.equals(eAccountType) && !isLoggedWithOpenId(it, accountManager)) { - notifyOpenIdSwitchRequest(it, notificationManager, context) + notifySwitchToOpenId(it, context) } } } - /** - * Check if OpenID is implemented in current version of AccountManager - */ private fun isOpenIdAvailable(): Boolean { return false } private fun isLoggedWithOpenId(account: Account, accountManager: AccountManager): Boolean { - val authTokenType = AccountTypeUtils.getAuthTokenTypePass(account.type) - - val authToken = accountManager.getAuthToken(account, authTokenType, Bundle(), false, { future -> - try { - val token = future.result.getString(AccountManager.KEY_AUTHTOKEN) - } catch (e: Exception) { - println("Error retrieving token for account ${account.name}: ${e.message}") - } - }, null) - + val hasAuthStateData = accountManager.getUserData(account, AccountSettings.KEY_AUTH_STATE) != null val isPasswordNull = accountManager.getPassword(account).isNullOrEmpty() - - return isPasswordNull && authToken != null + return isPasswordNull && hasAuthStateData } - private fun notifyOpenIdSwitchRequest(account: Account, - notificationManager: NotificationManager, - context: Context) { + private fun notifySwitchToOpenId(account: Account, context: Context) { + val notifTag = "Switch to openID" val notifId = 3310 - val notifTitle = "${account.name}: Switch to OpenId" - val notifText = "Now that OpenId is available, you should log out and re-loggin your account." - val notifIntent = generateLogOutIntent(account.name, context) + val notifTitle = context.getString(R.string.notification_account_title) + val notifText = context.getString(R.string.notification_switch_to_openId_text) + val notifIntent = generateLogoutIntent(account.name, context) val notification = NotificationCompat.Builder(context, "your_channel_id") .setContentTitle(notifTitle) @@ -88,10 +72,11 @@ class BootCompletedReceiver: BroadcastReceiver() { .setAutoCancel(true) .build() - notificationManager.notify(notifId, notification) + val notificationManager = NotificationManagerCompat.from(context) + notificationManager.notifyIfPossible(notifTag, notifId, notification) } - private fun generateLogOutIntent(accountName: String, context: Context): PendingIntent { + private fun generateLogoutIntent(accountName: String, context: Context): PendingIntent { val logoutIntent = Intent(context, LogoutReceiver::class.java).apply { putExtra("ACCOUNT_NAME", accountName) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47579443b..e08b3c004 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -43,6 +43,7 @@ Database corrupted All accounts have been removed locally. + Debugging Other important messages Low-priority status messages @@ -53,6 +54,8 @@ Non-fatal synchronization problems like certain invalid files Network and I/O errors Timeouts, connection problems, etc. (often temporary) + Your account %1$s + A new login service for a better experience is available. Tap the notification to start using it. Your data. Your choice. -- GitLab From 8336465c40c1ded136053bcfdd2525b388275029 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 8 Nov 2024 11:54:23 +0100 Subject: [PATCH 10/31] feature: start to implement the LogoutReceiver chore: add small refactoring about the notification --- .../receiver/BootCompletedReceiver.kt | 16 +++++++------- .../davdroid/receiver/LogoutReceiver.kt | 22 ++++++++++++++++++- .../bitfire/davdroid/ui/NotificationUtils.kt | 1 + 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt index 9e36dbd45..25d0ee1a0 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt @@ -16,6 +16,7 @@ import at.bitfire.davdroid.R import at.bitfire.davdroid.log.Logger import at.bitfire.davdroid.settings.AccountSettings import at.bitfire.davdroid.syncadapter.AccountUtils +import at.bitfire.davdroid.ui.NotificationUtils.NOTIFY_SWITCH_TO_OPENID import at.bitfire.davdroid.ui.NotificationUtils.notifyIfPossible /** @@ -30,7 +31,7 @@ class BootCompletedReceiver: BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { Logger.log.info("Device has been rebooted; checking sync intervals etc.") - val isOpenIdAvailable = isOpenIdAvailable() +// val isOpenIdAvailable = isOpenIdAvailable() val eAccountType = context.getString(R.string.eelo_account_type) val accountManager = AccountManager.get(context) @@ -46,10 +47,10 @@ class BootCompletedReceiver: BroadcastReceiver() { } } } - - private fun isOpenIdAvailable(): Boolean { - return false - } + //TODO will I need it ? +// private fun isOpenIdAvailable(): Boolean { +// return false +// } private fun isLoggedWithOpenId(account: Account, accountManager: AccountManager): Boolean { val hasAuthStateData = accountManager.getUserData(account, AccountSettings.KEY_AUTH_STATE) != null @@ -59,7 +60,6 @@ class BootCompletedReceiver: BroadcastReceiver() { private fun notifySwitchToOpenId(account: Account, context: Context) { val notifTag = "Switch to openID" - val notifId = 3310 val notifTitle = context.getString(R.string.notification_account_title) val notifText = context.getString(R.string.notification_switch_to_openId_text) val notifIntent = generateLogoutIntent(account.name, context) @@ -73,12 +73,12 @@ class BootCompletedReceiver: BroadcastReceiver() { .build() val notificationManager = NotificationManagerCompat.from(context) - notificationManager.notifyIfPossible(notifTag, notifId, notification) + notificationManager.notifyIfPossible(notifTag, NOTIFY_SWITCH_TO_OPENID, notification) } private fun generateLogoutIntent(accountName: String, context: Context): PendingIntent { val logoutIntent = Intent(context, LogoutReceiver::class.java).apply { - putExtra("ACCOUNT_NAME", accountName) + putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName) } return PendingIntent.getBroadcast(context, diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt index 0b953b20a..f58d6207e 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt @@ -1,11 +1,31 @@ package at.bitfire.davdroid.receiver +import android.accounts.Account +import android.accounts.AccountManager import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import at.bitfire.davdroid.R +import at.bitfire.davdroid.log.Logger class LogoutReceiver(): BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { - TODO("Not yet implemented") + Logger.log.info("LogoutReceiver.onReceive()") + if (context == null) return + + val accountName = intent?.extras?.getString(AccountManager.KEY_ACCOUNT_NAME, null) ?: return + + val accountManager = AccountManager.get(context) + + val eAccounts = accountManager.getAccountsByType(context.getString(R.string.eelo_account_type)) + + eAccounts.forEach { + if (it.name == accountName) { + // todo: https://developer.android.com/reference/android/accounts/AccountManager#removeAccount(android.accounts.Account,%20android.app.Activity,%20android.accounts.AccountManagerCallback%3Candroid.os.Bundle%3E,%20android.os.Handler) + accountManager.removeAccount(it, null,null, null) + } + } + + // todo https://developer.android.com/reference/android/accounts/AccountManager#startAddAccountSession(java.lang.String,%20java.lang.String,%20java.lang.String[],%20android.os.Bundle,%20android.app.Activity,%20android.accounts.AccountManagerCallback%3Candroid.os.Bundle%3E,%20android.os.Handler) } } \ No newline at end of file diff --git a/app/src/main/kotlin/at/bitfire/davdroid/ui/NotificationUtils.kt b/app/src/main/kotlin/at/bitfire/davdroid/ui/NotificationUtils.kt index e41544d53..4e6f04fe5 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/ui/NotificationUtils.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/ui/NotificationUtils.kt @@ -34,6 +34,7 @@ object NotificationUtils { const val NOTIFY_SYNC_EXPEDITED = 14 const val NOTIFY_TASKS_PROVIDER_TOO_OLD = 20 const val NOTIFY_PERMISSIONS = 21 + const val NOTIFY_SWITCH_TO_OPENID = 22 const val NOTIFY_LICENSE = 100 -- GitLab From aa06888562dcdb3940bb354ddc54632683c36b52 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 12 Nov 2024 15:53:08 +0100 Subject: [PATCH 11/31] chore: update notification text and remove useless commented code --- .../at/bitfire/davdroid/receiver/BootCompletedReceiver.kt | 5 ----- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt index 25d0ee1a0..5503fc11c 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt @@ -31,7 +31,6 @@ class BootCompletedReceiver: BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { Logger.log.info("Device has been rebooted; checking sync intervals etc.") -// val isOpenIdAvailable = isOpenIdAvailable() val eAccountType = context.getString(R.string.eelo_account_type) val accountManager = AccountManager.get(context) @@ -47,10 +46,6 @@ class BootCompletedReceiver: BroadcastReceiver() { } } } - //TODO will I need it ? -// private fun isOpenIdAvailable(): Boolean { -// return false -// } private fun isLoggedWithOpenId(account: Account, accountManager: AccountManager): Boolean { val hasAuthStateData = accountManager.getUserData(account, AccountSettings.KEY_AUTH_STATE) != null diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e08b3c004..58f63b7dc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,7 +55,7 @@ Network and I/O errors Timeouts, connection problems, etc. (often temporary) Your account %1$s - A new login service for a better experience is available. Tap the notification to start using it. + A new login service for a better experience is available. Tap the notification to start using it: you'll be logged out and will simply have to log in again. Your data. Your choice. -- GitLab From cb4421881e1e3f1724050c4e634905be14095645 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 12 Nov 2024 17:44:42 +0100 Subject: [PATCH 12/31] refactor: replace LogoutReceiver by ReLoginWithOidcActivity which has no UI --- app/build.gradle | 3 +- app/src/main/AndroidManifest.xml | 447 ++++++++---------- .../davdroid/ReLoginWithOidcActivity.kt | 63 +++ .../receiver/BootCompletedReceiver.kt | 8 +- .../davdroid/receiver/LogoutReceiver.kt | 31 -- 5 files changed, 278 insertions(+), 274 deletions(-) create mode 100644 app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt delete mode 100644 app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt diff --git a/app/build.gradle b/app/build.gradle index 3ef3fa5a1..3214eb1b5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,7 +30,7 @@ android { setProperty "archivesBaseName", "davx5-ose-" + getVersionName() - minSdkVersion 24 // Android 7.0 + minSdkVersion 26 // Android 9.0 targetSdkVersion 33 // Android 13 buildConfigField "String", "userAgent", "\"AccountManager\"" @@ -155,6 +155,7 @@ configurations { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3' + implementation 'androidx.activity:activity:1.9.3' testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2299dfee3..cf503f3c1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,118 +1,168 @@ - + xmlns:tools="http://schemas.android.com/tools" + android:installLocation="internalOnly"> - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - + + + + - - - - + - fine location (Android 10) + --> + + + + + + - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + android:supportsRtl="true" + android:theme="@style/AppTheme" + tools:ignore="UnusedAttribute"> + - + tools:node="remove"> - + - - - - - - + + + - + + + + + android:theme="@style/AppTheme.NoActionBar"> - - + + + - - + android:parentActivityName=".ui.AccountsActivity" + android:theme="@style/AppTheme.NoActionBar" /> + android:parentActivityName=".ui.AccountsActivity"> - + + + android:label="@string/debug_info_title" + android:parentActivityName=".ui.AppSettingsActivity"> - + + @@ -124,43 +174,43 @@ android:name=".ui.TasksActivity" android:label="@string/intro_tasks_title" android:parentActivityName=".ui.AppSettingsActivity" /> - + android:exported="true" + android:label="@string/login_title" + android:parentActivityName=".ui.AccountsActivity"> - + - - - - - - - - + + + + + + + + + + + - - - - + android:theme="@style/AppTheme.NoActionBar"> - + android:parentActivityName=".ui.AccountsActivity" /> - - - - + - + + + android:resource="@xml/account_authenticator" /> - + + + android:resource="@xml/sync_calendars" /> - + + + android:resource="@xml/sync_notes" /> - + + + android:resource="@xml/sync_opentasks" /> - + + + android:resource="@xml/sync_tasks_org" /> + - - - + + android:exported="true"> - + + android:resource="@xml/account_authenticator_address_book" /> + + android:label="@string/address_books_authority_title" /> + - + + android:resource="@xml/sync_address_books" /> - + + android:resource="@xml/sync_contacts" /> - - - + android:resource="@xml/contacts" /> + @@ -313,22 +364,20 @@ android:name="android.accounts.AccountAuthenticator" android:resource="@xml/eelo_account_authenticator" /> - - - + - - - - - - + - - - - - - + - - - - - + @@ -425,7 +466,6 @@ android:name="android.accounts.AccountAuthenticator" android:resource="@xml/account_authenticator_eelo_address_book" /> - - - + - - - + @@ -469,8 +506,7 @@ android:name="android.accounts.AccountAuthenticator" android:resource="@xml/google_account_authenticator" /> - - - - + - - - + @@ -510,7 +543,6 @@ android:name="android.accounts.AccountAuthenticator" android:resource="@xml/account_authenticator_google_address_book" /> - - - + - - - - - + @@ -568,7 +596,6 @@ android:name="android.accounts.AccountAuthenticator" android:resource="@xml/yahoo_account_authenticator" /> - - - - - - + @@ -623,7 +646,6 @@ android:name="android.accounts.AccountAuthenticator" android:resource="@xml/account_authenticator_yahoo_address_book" /> - - - - - - + + + android:exported="false" + android:grantUriPermissions="true"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt new file mode 100644 index 000000000..d53218e97 --- /dev/null +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -0,0 +1,63 @@ +package at.bitfire.davdroid + +import android.accounts.AccountManager +import android.accounts.AccountManager.KEY_BOOLEAN_RESULT +import android.accounts.AccountManagerFuture +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import at.bitfire.davdroid.log.Logger + +class ReLoginWithOidcActivity : AppCompatActivity() { + override fun onStart() { + super.onStart() + + val accountName = intent?.extras?.getString(AccountManager.KEY_ACCOUNT_NAME, null) ?: return + val accountManager = AccountManager.get(this) + + val accountRemovalCallback: (AliasFuture) -> Unit = { future -> + val success = future.result.getBoolean(KEY_BOOLEAN_RESULT) + Logger.log.info("$accountName removal succeed ? $success") + if (success) { + loginAccount(accountManager) + } else { + Logger.log.info("failed to remove account: ${accountName} ") + } + } + + + logoutAccount(accountName, accountManager, accountRemovalCallback) + + + } + + + private fun logoutAccount(accountName: String, + accountManager: AccountManager, + callback : (AliasFuture) -> Unit) + { + val eAccounts= accountManager.getAccountsByType(applicationContext.getString(R.string.eelo_account_type)) + val activity = this + + eAccounts.first { it.name == accountName }.run { + Logger.log.info("try to remove account: ${this.name} ") //todo remove this before merge + accountManager.removeAccount(this, activity, callback, null) + + } ?: finish() + } + + private fun loginAccount(accountManager: AccountManager) { + val eAccountType = applicationContext.getString(R.string.eelo_account_type) + val authTokenType = null + + accountManager.startAddAccountSession(eAccountType, + authTokenType, + arrayOf(), + null, + this, + { _ -> finish() }, + null + ) + } +} + +typealias AliasFuture = AccountManagerFuture \ No newline at end of file diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt index 5503fc11c..901261ac7 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt @@ -13,6 +13,7 @@ import android.content.Intent import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import at.bitfire.davdroid.R +import at.bitfire.davdroid.ReLoginWithOidcActivity import at.bitfire.davdroid.log.Logger import at.bitfire.davdroid.settings.AccountSettings import at.bitfire.davdroid.syncadapter.AccountUtils @@ -72,13 +73,14 @@ class BootCompletedReceiver: BroadcastReceiver() { } private fun generateLogoutIntent(accountName: String, context: Context): PendingIntent { - val logoutIntent = Intent(context, LogoutReceiver::class.java).apply { + val reloginIntent = Intent(context, ReLoginWithOidcActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName) } - return PendingIntent.getBroadcast(context, + return PendingIntent.getActivity(context, 0, - logoutIntent, + reloginIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } } \ No newline at end of file diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt deleted file mode 100644 index f58d6207e..000000000 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/LogoutReceiver.kt +++ /dev/null @@ -1,31 +0,0 @@ -package at.bitfire.davdroid.receiver - -import android.accounts.Account -import android.accounts.AccountManager -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import at.bitfire.davdroid.R -import at.bitfire.davdroid.log.Logger - -class LogoutReceiver(): BroadcastReceiver() { - override fun onReceive(context: Context?, intent: Intent?) { - Logger.log.info("LogoutReceiver.onReceive()") - if (context == null) return - - val accountName = intent?.extras?.getString(AccountManager.KEY_ACCOUNT_NAME, null) ?: return - - val accountManager = AccountManager.get(context) - - val eAccounts = accountManager.getAccountsByType(context.getString(R.string.eelo_account_type)) - - eAccounts.forEach { - if (it.name == accountName) { - // todo: https://developer.android.com/reference/android/accounts/AccountManager#removeAccount(android.accounts.Account,%20android.app.Activity,%20android.accounts.AccountManagerCallback%3Candroid.os.Bundle%3E,%20android.os.Handler) - accountManager.removeAccount(it, null,null, null) - } - } - - // todo https://developer.android.com/reference/android/accounts/AccountManager#startAddAccountSession(java.lang.String,%20java.lang.String,%20java.lang.String[],%20android.os.Bundle,%20android.app.Activity,%20android.accounts.AccountManagerCallback%3Candroid.os.Bundle%3E,%20android.os.Handler) - } -} \ No newline at end of file -- GitLab From 99cf9ac9bf717c8b7bd76f6e1b10388d80d110e9 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 12 Nov 2024 17:45:56 +0100 Subject: [PATCH 13/31] change minimum SDK to reach API 26: required to use AccountManager.startAddAccountSessionActivity --- app/src/main/res/values/strings.xml | 2 +- build.gradle | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 58f63b7dc..92854722d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,7 +55,7 @@ Network and I/O errors Timeouts, connection problems, etc. (often temporary) Your account %1$s - A new login service for a better experience is available. Tap the notification to start using it: you'll be logged out and will simply have to log in again. + A new login service for a better experience is available. Tap the notification to start using it: you\'ll be logged out and will simply have to log in again. Your data. Your choice. diff --git a/build.gradle b/build.gradle index e969706ab..22f24469e 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,7 @@ buildscript { plugins { // see https://github.com/google/ksp/releases for version numbers id 'com.google.devtools.ksp' version '1.9.10-1.0.13' apply false + id 'org.jetbrains.kotlin.android' version '1.9.10' apply false } allprojects { -- GitLab From 245069600da8ad92d9542a966b1b705778df970a Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 14 Nov 2024 11:00:02 +0100 Subject: [PATCH 14/31] fix: use Notification Utils to create the notification builder & to provide notification channel --- .../at/bitfire/davdroid/receiver/BootCompletedReceiver.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt index 901261ac7..ae213e30a 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt @@ -17,6 +17,8 @@ import at.bitfire.davdroid.ReLoginWithOidcActivity import at.bitfire.davdroid.log.Logger import at.bitfire.davdroid.settings.AccountSettings import at.bitfire.davdroid.syncadapter.AccountUtils +import at.bitfire.davdroid.ui.NotificationUtils +import at.bitfire.davdroid.ui.NotificationUtils.CHANNEL_GENERAL import at.bitfire.davdroid.ui.NotificationUtils.NOTIFY_SWITCH_TO_OPENID import at.bitfire.davdroid.ui.NotificationUtils.notifyIfPossible @@ -60,7 +62,8 @@ class BootCompletedReceiver: BroadcastReceiver() { val notifText = context.getString(R.string.notification_switch_to_openId_text) val notifIntent = generateLogoutIntent(account.name, context) - val notification = NotificationCompat.Builder(context, "your_channel_id") + + val notification = NotificationUtils.newBuilder(context, CHANNEL_GENERAL) .setContentTitle(notifTitle) .setContentText(notifText) .setSmallIcon(R.drawable.ic_info) -- GitLab From 4cf4e36c400b432b8cedc1b8183a1337561fb2e0 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 14 Nov 2024 13:38:04 +0100 Subject: [PATCH 15/31] fix: update notification title & content text --- .../at/bitfire/davdroid/receiver/BootCompletedReceiver.kt | 2 +- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt index ae213e30a..95e3f9835 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt @@ -58,7 +58,7 @@ class BootCompletedReceiver: BroadcastReceiver() { private fun notifySwitchToOpenId(account: Account, context: Context) { val notifTag = "Switch to openID" - val notifTitle = context.getString(R.string.notification_account_title) + val notifTitle = context.getString(R.string.notification_account_title, account.name) val notifText = context.getString(R.string.notification_switch_to_openId_text) val notifIntent = generateLogoutIntent(account.name, context) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 92854722d..e08b3c004 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,7 +55,7 @@ Network and I/O errors Timeouts, connection problems, etc. (often temporary) Your account %1$s - A new login service for a better experience is available. Tap the notification to start using it: you\'ll be logged out and will simply have to log in again. + A new login service for a better experience is available. Tap the notification to start using it. Your data. Your choice. -- GitLab From 9911cce974555ae18c094d1c2fa3a2f420094da4 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 14 Nov 2024 13:39:46 +0100 Subject: [PATCH 16/31] refactor: rewrite if to check account type in BootCompleteReceiver and update coding style --- .../bitfire/davdroid/ReLoginWithOidcActivity.kt | 15 ++++++--------- .../davdroid/receiver/BootCompletedReceiver.kt | 11 +++++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index d53218e97..d25332e92 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -16,21 +16,18 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val accountRemovalCallback: (AliasFuture) -> Unit = { future -> val success = future.result.getBoolean(KEY_BOOLEAN_RESULT) - Logger.log.info("$accountName removal succeed ? $success") + if (success) { + Logger.log.info("Vincent: $accountName removed") loginAccount(accountManager) } else { - Logger.log.info("failed to remove account: ${accountName} ") + Logger.log.info("failed to remove account: $accountName ") } } - logoutAccount(accountName, accountManager, accountRemovalCallback) - - } - private fun logoutAccount(accountName: String, accountManager: AccountManager, callback : (AliasFuture) -> Unit) @@ -39,9 +36,8 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val activity = this eAccounts.first { it.name == accountName }.run { - Logger.log.info("try to remove account: ${this.name} ") //todo remove this before merge + Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge accountManager.removeAccount(this, activity, callback, null) - } ?: finish() } @@ -49,6 +45,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val eAccountType = applicationContext.getString(R.string.eelo_account_type) val authTokenType = null + Logger.log.info("Vincent: Will start add Account Session") accountManager.startAddAccountSession(eAccountType, authTokenType, arrayOf(), @@ -60,4 +57,4 @@ class ReLoginWithOidcActivity : AppCompatActivity() { } } -typealias AliasFuture = AccountManagerFuture \ No newline at end of file +typealias AliasFuture = AccountManagerFuture diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt index 95e3f9835..9b28bc658 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt @@ -10,7 +10,6 @@ import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import at.bitfire.davdroid.R import at.bitfire.davdroid.ReLoginWithOidcActivity @@ -44,7 +43,8 @@ class BootCompletedReceiver: BroadcastReceiver() { val accountSettings = AccountSettings(context, it) accountSettings.initSync() - if (it.type.equals(eAccountType) && !isLoggedWithOpenId(it, accountManager)) { + if (eAccountType == it.type && !isLoggedWithOpenId(it, accountManager)) { + Logger.log.info("Vincent: eAccountFound. Will notify") notifySwitchToOpenId(it, context) } } @@ -62,7 +62,6 @@ class BootCompletedReceiver: BroadcastReceiver() { val notifText = context.getString(R.string.notification_switch_to_openId_text) val notifIntent = generateLogoutIntent(account.name, context) - val notification = NotificationUtils.newBuilder(context, CHANNEL_GENERAL) .setContentTitle(notifTitle) .setContentText(notifText) @@ -76,14 +75,14 @@ class BootCompletedReceiver: BroadcastReceiver() { } private fun generateLogoutIntent(accountName: String, context: Context): PendingIntent { - val reloginIntent = Intent(context, ReLoginWithOidcActivity::class.java).apply { + val reLoginIntent = Intent(context, ReLoginWithOidcActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName) } return PendingIntent.getActivity(context, 0, - reloginIntent, + reLoginIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } -} \ No newline at end of file +} -- GitLab From 300024aca99b8ac09f069861a214253653e7590a Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 15 Nov 2024 10:00:14 +0100 Subject: [PATCH 17/31] feature: Start add account session after logout --- .../davdroid/ReLoginWithOidcActivity.kt | 98 ++++++++++++++++--- 1 file changed, 85 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index d25332e92..5f6cfdb70 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -1,35 +1,67 @@ package at.bitfire.davdroid import android.accounts.AccountManager +import android.accounts.AccountManager.KEY_ACCOUNT_SESSION_BUNDLE import android.accounts.AccountManager.KEY_BOOLEAN_RESULT +import android.accounts.AccountManager.KEY_INTENT import android.accounts.AccountManagerFuture +import android.accounts.AuthenticatorException +import android.content.Intent +import android.os.Build import android.os.Bundle +import android.os.PersistableBundle +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import at.bitfire.davdroid.log.Logger +import com.owncloud.android.lib.common.operations.OperationCancelledException +import java.io.IOException class ReLoginWithOidcActivity : AppCompatActivity() { + + private lateinit var addAccountLauncher: ActivityResultLauncher + private lateinit var accountManager : AccountManager + private var sessionBundle: Bundle? = null + + override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { + super.onCreate(savedInstanceState, persistentState) + + accountManager = AccountManager.get(this) + // Initialize the ActivityResultLauncher + addAccountLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + result -> + if (result.resultCode == RESULT_OK) { + // Account was added successfully + // Handle the result here + accountManager.finishSession(sessionBundle, + null, { _ -> + Logger.log.info("Vincent: Account added") + finish() + }, null) + } + } + } + override fun onStart() { super.onStart() val accountName = intent?.extras?.getString(AccountManager.KEY_ACCOUNT_NAME, null) ?: return - val accountManager = AccountManager.get(this) val accountRemovalCallback: (AliasFuture) -> Unit = { future -> val success = future.result.getBoolean(KEY_BOOLEAN_RESULT) if (success) { Logger.log.info("Vincent: $accountName removed") - loginAccount(accountManager) + loginAccount() } else { Logger.log.info("failed to remove account: $accountName ") } } - logoutAccount(accountName, accountManager, accountRemovalCallback) + logoutAccount(accountName, accountRemovalCallback) } private fun logoutAccount(accountName: String, - accountManager: AccountManager, callback : (AliasFuture) -> Unit) { val eAccounts= accountManager.getAccountsByType(applicationContext.getString(R.string.eelo_account_type)) @@ -38,22 +70,62 @@ class ReLoginWithOidcActivity : AppCompatActivity() { eAccounts.first { it.name == accountName }.run { Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge accountManager.removeAccount(this, activity, callback, null) + } ?: finish() } - private fun loginAccount(accountManager: AccountManager) { + private fun loginAccount() { val eAccountType = applicationContext.getString(R.string.eelo_account_type) val authTokenType = null Logger.log.info("Vincent: Will start add Account Session") - accountManager.startAddAccountSession(eAccountType, - authTokenType, - arrayOf(), - null, - this, - { _ -> finish() }, - null - ) + + try { + //todo only work for API 33 ? + accountManager.startAddAccountSession( + eAccountType, + authTokenType, + arrayOf(), + null, + this, + { future -> startAddAccount(future) }, + null + ) + } catch (exception: AuthenticatorException) { + Logger.log.info("Vincent: AuthenticatorException: can't add account: ${exception.message}") + + } catch (exception: IOException) { + Logger.log.info("Vincent: IOException: can't add account: ${exception.message}") + } catch (exception: OperationCancelledException) { + Logger.log.info("Vincent: OperationCancelledException: can't add account: ${exception.message}") + } + } + + + private fun startAddAccount(future: AliasFuture) { + try { + val intent: Intent? + + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + intent = future.result.getParcelable(KEY_INTENT, Intent::class.java) + sessionBundle = future.result.getParcelable(KEY_ACCOUNT_SESSION_BUNDLE, Bundle::class.java) + } else { + intent = future.result.getParcelable(KEY_INTENT) + sessionBundle = future.result.getParcelable(KEY_ACCOUNT_SESSION_BUNDLE) + } + + if (sessionBundle == null) { + Logger.log.info("Vincent: session bundle is null") + } + + + intent?.let { + addAccountLauncher.launch(it) + } + } catch (exception: Exception) { + Logger.log.info("Vincent: StartAddAccount: exception: ${exception.message}") + } } } -- GitLab From 652877fe95b7c5b15da403324b19dae331095796 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 15 Nov 2024 10:53:33 +0100 Subject: [PATCH 18/31] fix: fix exception thrown because of accountManager --- .../main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 5f6cfdb70..94068a50d 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -20,13 +20,12 @@ import java.io.IOException class ReLoginWithOidcActivity : AppCompatActivity() { private lateinit var addAccountLauncher: ActivityResultLauncher - private lateinit var accountManager : AccountManager private var sessionBundle: Bundle? = null override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { super.onCreate(savedInstanceState, persistentState) - accountManager = AccountManager.get(this) + val accountManager = AccountManager.get(this) // Initialize the ActivityResultLauncher addAccountLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> @@ -64,6 +63,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { private fun logoutAccount(accountName: String, callback : (AliasFuture) -> Unit) { + val accountManager = AccountManager.get(this) val eAccounts= accountManager.getAccountsByType(applicationContext.getString(R.string.eelo_account_type)) val activity = this @@ -75,6 +75,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { } private fun loginAccount() { + val accountManager = AccountManager.get(this) val eAccountType = applicationContext.getString(R.string.eelo_account_type) val authTokenType = null -- GitLab From 9e4308e0d1c17e4f6234c9bc63b29d3fc6355854 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Fri, 15 Nov 2024 11:04:44 +0100 Subject: [PATCH 19/31] refactor: prevent syncing /e/ account on murena.io if account is logged with password --- .../at/bitfire/davdroid/receiver/BootCompletedReceiver.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt index 9b28bc658..c79b544f1 100644 --- a/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +++ b/app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt @@ -40,12 +40,12 @@ class BootCompletedReceiver: BroadcastReceiver() { // sync intervals are checked in App.onCreate() AccountUtils.getMainAccounts(context) .forEach { - val accountSettings = AccountSettings(context, it) - accountSettings.initSync() - if (eAccountType == it.type && !isLoggedWithOpenId(it, accountManager)) { Logger.log.info("Vincent: eAccountFound. Will notify") notifySwitchToOpenId(it, context) + } else { + val accountSettings = AccountSettings(context, it) + accountSettings.initSync() } } } -- GitLab From 776c471be2d12e0a0657a2b0d861f56a84fe40ec Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 19 Nov 2024 10:40:03 +0100 Subject: [PATCH 20/31] try to make the accountSession work --- app/src/main/AndroidManifest.xml | 3 +++ .../main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cf503f3c1..38b22ebaa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,8 @@ android:installLocation="internalOnly"> + @@ -355,6 +357,7 @@ diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 94068a50d..44edbf5f0 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -77,15 +77,14 @@ class ReLoginWithOidcActivity : AppCompatActivity() { private fun loginAccount() { val accountManager = AccountManager.get(this) val eAccountType = applicationContext.getString(R.string.eelo_account_type) - val authTokenType = null - Logger.log.info("Vincent: Will start add Account Session") + Logger.log.info("Vincent: Will start add Account Session for: $eAccountType account type") try { //todo only work for API 33 ? accountManager.startAddAccountSession( eAccountType, - authTokenType, + null, arrayOf(), null, this, -- GitLab From 227acd8053fbddcc4652b5fcd72361219611d7d3 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 19 Nov 2024 14:48:48 +0100 Subject: [PATCH 21/31] chore: replace accountManager.startAddAccountSession by addAccount --- app/src/main/AndroidManifest.xml | 5 +- .../davdroid/ReLoginWithOidcActivity.kt | 60 ++++++++++++------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 38b22ebaa..98bccdcca 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,8 +4,8 @@ android:installLocation="internalOnly"> - + @@ -357,7 +357,6 @@ diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 44edbf5f0..01bbf206b 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -1,7 +1,9 @@ package at.bitfire.davdroid import android.accounts.AccountManager +import android.accounts.AccountManager.KEY_ACCOUNT_NAME import android.accounts.AccountManager.KEY_ACCOUNT_SESSION_BUNDLE +import android.accounts.AccountManager.KEY_ACCOUNT_TYPE import android.accounts.AccountManager.KEY_BOOLEAN_RESULT import android.accounts.AccountManager.KEY_INTENT import android.accounts.AccountManagerFuture @@ -20,23 +22,19 @@ import java.io.IOException class ReLoginWithOidcActivity : AppCompatActivity() { private lateinit var addAccountLauncher: ActivityResultLauncher - private var sessionBundle: Bundle? = null override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { super.onCreate(savedInstanceState, persistentState) - val accountManager = AccountManager.get(this) + // Initialize the ActivityResultLauncher addAccountLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> if (result.resultCode == RESULT_OK) { // Account was added successfully // Handle the result here - accountManager.finishSession(sessionBundle, - null, { _ -> - Logger.log.info("Vincent: Account added") - finish() - }, null) + Logger.log.info("Vincent: callback for resultActivity launch") + } } } @@ -44,7 +42,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { override fun onStart() { super.onStart() - val accountName = intent?.extras?.getString(AccountManager.KEY_ACCOUNT_NAME, null) ?: return + val accountName = intent?.extras?.getString(KEY_ACCOUNT_NAME, null) ?: return val accountRemovalCallback: (AliasFuture) -> Unit = { future -> val success = future.result.getBoolean(KEY_BOOLEAN_RESULT) @@ -81,8 +79,19 @@ class ReLoginWithOidcActivity : AppCompatActivity() { Logger.log.info("Vincent: Will start add Account Session for: $eAccountType account type") try { + + accountManager.addAccount(eAccountType, + null, + arrayOf(), + null, + this, + { future -> startAddAccount(future) }, + null + ) + + //todo only work for API 33 ? - accountManager.startAddAccountSession( + /*accountManager.startAddAccountSession( eAccountType, null, arrayOf(), @@ -90,7 +99,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { this, { future -> startAddAccount(future) }, null - ) + )*/ } catch (exception: AuthenticatorException) { Logger.log.info("Vincent: AuthenticatorException: can't add account: ${exception.message}") @@ -103,24 +112,29 @@ class ReLoginWithOidcActivity : AppCompatActivity() { private fun startAddAccount(future: AliasFuture) { - try { - val intent: Intent? + val result = future.result?: run { + Logger.log.info("Vincent: Can't add new account: future.result is null") + return + } + val accountName = result.getString(KEY_ACCOUNT_NAME) + val accountType = result.getString(KEY_ACCOUNT_TYPE, "unexepected account type") - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - intent = future.result.getParcelable(KEY_INTENT, Intent::class.java) - sessionBundle = future.result.getParcelable(KEY_ACCOUNT_SESSION_BUNDLE, Bundle::class.java) - } else { - intent = future.result.getParcelable(KEY_INTENT) - sessionBundle = future.result.getParcelable(KEY_ACCOUNT_SESSION_BUNDLE) - } - - if (sessionBundle == null) { - Logger.log.info("Vincent: session bundle is null") - } + if (accountName != null) { + Logger.log.info("Vincent: ($accountType) account added: $accountName") + finish() + return + } + val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + result.getParcelable(KEY_INTENT, Intent::class.java) + } else { + result.getParcelable(KEY_INTENT) + } + try { intent?.let { + Logger.log.info("Vincent: start activity for result with intent") addAccountLauncher.launch(it) } } catch (exception: Exception) { -- GitLab From 594506a27f998ea68ac4e13ab105e21ae8f89448 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 19 Nov 2024 15:56:19 +0100 Subject: [PATCH 22/31] chore: fix crash due to empty array --- .../davdroid/ReLoginWithOidcActivity.kt | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 01bbf206b..d9279808d 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -58,8 +58,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { logoutAccount(accountName, accountRemovalCallback) } - private fun logoutAccount(accountName: String, - callback : (AliasFuture) -> Unit) + private fun logoutAccount(accountName: String, callback : (AliasFuture) -> Unit) { val accountManager = AccountManager.get(this) val eAccounts= accountManager.getAccountsByType(applicationContext.getString(R.string.eelo_account_type)) @@ -82,27 +81,14 @@ class ReLoginWithOidcActivity : AppCompatActivity() { accountManager.addAccount(eAccountType, null, - arrayOf(), null, - this, - { future -> startAddAccount(future) }, - null - ) - - - //todo only work for API 33 ? - /*accountManager.startAddAccountSession( - eAccountType, - null, - arrayOf(), null, this, { future -> startAddAccount(future) }, null - )*/ + ) } catch (exception: AuthenticatorException) { Logger.log.info("Vincent: AuthenticatorException: can't add account: ${exception.message}") - } catch (exception: IOException) { Logger.log.info("Vincent: IOException: can't add account: ${exception.message}") } catch (exception: OperationCancelledException) { -- GitLab From bbc3f19eee14d27099aaa6d1ff4ea118647b46dc Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 19 Nov 2024 16:50:09 +0100 Subject: [PATCH 23/31] refactor: remove useless code --- .../davdroid/ReLoginWithOidcActivity.kt | 46 ++----------------- 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index d9279808d..51247215f 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -2,18 +2,11 @@ package at.bitfire.davdroid import android.accounts.AccountManager import android.accounts.AccountManager.KEY_ACCOUNT_NAME -import android.accounts.AccountManager.KEY_ACCOUNT_SESSION_BUNDLE import android.accounts.AccountManager.KEY_ACCOUNT_TYPE import android.accounts.AccountManager.KEY_BOOLEAN_RESULT -import android.accounts.AccountManager.KEY_INTENT import android.accounts.AccountManagerFuture import android.accounts.AuthenticatorException -import android.content.Intent -import android.os.Build import android.os.Bundle -import android.os.PersistableBundle -import androidx.activity.result.ActivityResultLauncher -import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import at.bitfire.davdroid.log.Logger import com.owncloud.android.lib.common.operations.OperationCancelledException @@ -21,24 +14,6 @@ import java.io.IOException class ReLoginWithOidcActivity : AppCompatActivity() { - private lateinit var addAccountLauncher: ActivityResultLauncher - - override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { - super.onCreate(savedInstanceState, persistentState) - - - // Initialize the ActivityResultLauncher - addAccountLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - result -> - if (result.resultCode == RESULT_OK) { - // Account was added successfully - // Handle the result here - Logger.log.info("Vincent: callback for resultActivity launch") - - } - } - } - override fun onStart() { super.onStart() @@ -93,6 +68,8 @@ class ReLoginWithOidcActivity : AppCompatActivity() { Logger.log.info("Vincent: IOException: can't add account: ${exception.message}") } catch (exception: OperationCancelledException) { Logger.log.info("Vincent: OperationCancelledException: can't add account: ${exception.message}") + } catch (exception: Exception) { + Logger.log.info("Vincent: catch unexpected exception: ${exception.message}") } } @@ -108,24 +85,9 @@ class ReLoginWithOidcActivity : AppCompatActivity() { if (accountName != null) { Logger.log.info("Vincent: ($accountType) account added: $accountName") - finish() - return - } - - val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - result.getParcelable(KEY_INTENT, Intent::class.java) - } else { - result.getParcelable(KEY_INTENT) - } - - try { - intent?.let { - Logger.log.info("Vincent: start activity for result with intent") - addAccountLauncher.launch(it) - } - } catch (exception: Exception) { - Logger.log.info("Vincent: StartAddAccount: exception: ${exception.message}") } + finish() + return } } -- GitLab From 76f5c2f4d63ad96336d9c9fc0d99ea105c7e0d0b Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 19 Nov 2024 17:31:32 +0100 Subject: [PATCH 24/31] chore: remove return statement useless --- app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 51247215f..eb4cbed36 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -87,7 +87,6 @@ class ReLoginWithOidcActivity : AppCompatActivity() { Logger.log.info("Vincent: ($accountType) account added: $accountName") } finish() - return } } -- GitLab From ff0bdb0ed840b21c7ddcc96de6a313c378d881d2 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 19 Nov 2024 17:47:42 +0100 Subject: [PATCH 25/31] fix: fix NoSuchElementException --- .../main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index eb4cbed36..168a1e782 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -39,7 +39,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val eAccounts= accountManager.getAccountsByType(applicationContext.getString(R.string.eelo_account_type)) val activity = this - eAccounts.first { it.name == accountName }.run { + eAccounts.firstOrNull() { it.name == accountName }?.run { Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge accountManager.removeAccount(this, activity, callback, null) -- GitLab From 144a960265e9740075b252dffca6055440fb2e88 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 19 Nov 2024 17:47:42 +0100 Subject: [PATCH 26/31] fix: fix NoSuchElementException --- .../davdroid/ReLoginWithOidcActivity.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 168a1e782..41b470586 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -4,8 +4,12 @@ import android.accounts.AccountManager import android.accounts.AccountManager.KEY_ACCOUNT_NAME import android.accounts.AccountManager.KEY_ACCOUNT_TYPE import android.accounts.AccountManager.KEY_BOOLEAN_RESULT +import android.accounts.AccountManager.KEY_INTENT import android.accounts.AccountManagerFuture import android.accounts.AuthenticatorException +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Build import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import at.bitfire.davdroid.log.Logger @@ -40,7 +44,6 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val activity = this eAccounts.firstOrNull() { it.name == accountName }?.run { - Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge accountManager.removeAccount(this, activity, callback, null) } ?: finish() @@ -50,15 +53,13 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val accountManager = AccountManager.get(this) val eAccountType = applicationContext.getString(R.string.eelo_account_type) - Logger.log.info("Vincent: Will start add Account Session for: $eAccountType account type") - try { accountManager.addAccount(eAccountType, null, null, null, - this, + null, { future -> startAddAccount(future) }, null ) @@ -80,12 +81,18 @@ class ReLoginWithOidcActivity : AppCompatActivity() { return } - val accountName = result.getString(KEY_ACCOUNT_NAME) - val accountType = result.getString(KEY_ACCOUNT_TYPE, "unexepected account type") + val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + result.getParcelable(KEY_INTENT, Intent::class.java) + } else { + result.getParcelable(KEY_INTENT) + } ?: return - if (accountName != null) { - Logger.log.info("Vincent: ($accountType) account added: $accountName") + try { + startActivity(intent) + } catch (exception: ActivityNotFoundException) { + Logger.log.info("Vincent: can't start add account activity: ${exception.message}") } + finish() } } -- GitLab From 6f5e9a64b4c4872343ac3ef6f5d4cbb1a8f44d85 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 20 Nov 2024 11:27:39 +0100 Subject: [PATCH 27/31] Revert "fix: fix NoSuchElementException" This reverts commit 144a960265e9740075b252dffca6055440fb2e88. --- .../davdroid/ReLoginWithOidcActivity.kt | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 41b470586..168a1e782 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -4,12 +4,8 @@ import android.accounts.AccountManager import android.accounts.AccountManager.KEY_ACCOUNT_NAME import android.accounts.AccountManager.KEY_ACCOUNT_TYPE import android.accounts.AccountManager.KEY_BOOLEAN_RESULT -import android.accounts.AccountManager.KEY_INTENT import android.accounts.AccountManagerFuture import android.accounts.AuthenticatorException -import android.content.ActivityNotFoundException -import android.content.Intent -import android.os.Build import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import at.bitfire.davdroid.log.Logger @@ -44,6 +40,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val activity = this eAccounts.firstOrNull() { it.name == accountName }?.run { + Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge accountManager.removeAccount(this, activity, callback, null) } ?: finish() @@ -53,13 +50,15 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val accountManager = AccountManager.get(this) val eAccountType = applicationContext.getString(R.string.eelo_account_type) + Logger.log.info("Vincent: Will start add Account Session for: $eAccountType account type") + try { accountManager.addAccount(eAccountType, null, null, null, - null, + this, { future -> startAddAccount(future) }, null ) @@ -81,18 +80,12 @@ class ReLoginWithOidcActivity : AppCompatActivity() { return } - val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - result.getParcelable(KEY_INTENT, Intent::class.java) - } else { - result.getParcelable(KEY_INTENT) - } ?: return + val accountName = result.getString(KEY_ACCOUNT_NAME) + val accountType = result.getString(KEY_ACCOUNT_TYPE, "unexepected account type") - try { - startActivity(intent) - } catch (exception: ActivityNotFoundException) { - Logger.log.info("Vincent: can't start add account activity: ${exception.message}") + if (accountName != null) { + Logger.log.info("Vincent: ($accountType) account added: $accountName") } - finish() } } -- GitLab From 136a96d6a76cc36c6bd20ba0598dbc8520ad1cdf Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 20 Nov 2024 11:28:50 +0100 Subject: [PATCH 28/31] Revert "Revert "fix: fix NoSuchElementException"" This reverts commit 6f5e9a64b4c4872343ac3ef6f5d4cbb1a8f44d85. --- .../davdroid/ReLoginWithOidcActivity.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 168a1e782..41b470586 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -4,8 +4,12 @@ import android.accounts.AccountManager import android.accounts.AccountManager.KEY_ACCOUNT_NAME import android.accounts.AccountManager.KEY_ACCOUNT_TYPE import android.accounts.AccountManager.KEY_BOOLEAN_RESULT +import android.accounts.AccountManager.KEY_INTENT import android.accounts.AccountManagerFuture import android.accounts.AuthenticatorException +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Build import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import at.bitfire.davdroid.log.Logger @@ -40,7 +44,6 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val activity = this eAccounts.firstOrNull() { it.name == accountName }?.run { - Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge accountManager.removeAccount(this, activity, callback, null) } ?: finish() @@ -50,15 +53,13 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val accountManager = AccountManager.get(this) val eAccountType = applicationContext.getString(R.string.eelo_account_type) - Logger.log.info("Vincent: Will start add Account Session for: $eAccountType account type") - try { accountManager.addAccount(eAccountType, null, null, null, - this, + null, { future -> startAddAccount(future) }, null ) @@ -80,12 +81,18 @@ class ReLoginWithOidcActivity : AppCompatActivity() { return } - val accountName = result.getString(KEY_ACCOUNT_NAME) - val accountType = result.getString(KEY_ACCOUNT_TYPE, "unexepected account type") + val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + result.getParcelable(KEY_INTENT, Intent::class.java) + } else { + result.getParcelable(KEY_INTENT) + } ?: return - if (accountName != null) { - Logger.log.info("Vincent: ($accountType) account added: $accountName") + try { + startActivity(intent) + } catch (exception: ActivityNotFoundException) { + Logger.log.info("Vincent: can't start add account activity: ${exception.message}") } + finish() } } -- GitLab From fca3f55f5fecca6c8d46ebf7d90df4f7cc1256c8 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 20 Nov 2024 11:29:51 +0100 Subject: [PATCH 29/31] Revert "Revert "Revert "fix: fix NoSuchElementException""" This reverts commit 136a96d6a76cc36c6bd20ba0598dbc8520ad1cdf. --- .../davdroid/ReLoginWithOidcActivity.kt | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 41b470586..168a1e782 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -4,12 +4,8 @@ import android.accounts.AccountManager import android.accounts.AccountManager.KEY_ACCOUNT_NAME import android.accounts.AccountManager.KEY_ACCOUNT_TYPE import android.accounts.AccountManager.KEY_BOOLEAN_RESULT -import android.accounts.AccountManager.KEY_INTENT import android.accounts.AccountManagerFuture import android.accounts.AuthenticatorException -import android.content.ActivityNotFoundException -import android.content.Intent -import android.os.Build import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import at.bitfire.davdroid.log.Logger @@ -44,6 +40,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val activity = this eAccounts.firstOrNull() { it.name == accountName }?.run { + Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge accountManager.removeAccount(this, activity, callback, null) } ?: finish() @@ -53,13 +50,15 @@ class ReLoginWithOidcActivity : AppCompatActivity() { val accountManager = AccountManager.get(this) val eAccountType = applicationContext.getString(R.string.eelo_account_type) + Logger.log.info("Vincent: Will start add Account Session for: $eAccountType account type") + try { accountManager.addAccount(eAccountType, null, null, null, - null, + this, { future -> startAddAccount(future) }, null ) @@ -81,18 +80,12 @@ class ReLoginWithOidcActivity : AppCompatActivity() { return } - val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - result.getParcelable(KEY_INTENT, Intent::class.java) - } else { - result.getParcelable(KEY_INTENT) - } ?: return + val accountName = result.getString(KEY_ACCOUNT_NAME) + val accountType = result.getString(KEY_ACCOUNT_TYPE, "unexepected account type") - try { - startActivity(intent) - } catch (exception: ActivityNotFoundException) { - Logger.log.info("Vincent: can't start add account activity: ${exception.message}") + if (accountName != null) { + Logger.log.info("Vincent: ($accountType) account added: $accountName") } - finish() } } -- GitLab From b137fb3cbbda328762c515b7d4e8c6c878242511 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 20 Nov 2024 12:08:16 +0100 Subject: [PATCH 30/31] fix last minor point --- .../davdroid/ReLoginWithOidcActivity.kt | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index 168a1e782..dabf154da 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -17,7 +17,19 @@ class ReLoginWithOidcActivity : AppCompatActivity() { override fun onStart() { super.onStart() - val accountName = intent?.extras?.getString(KEY_ACCOUNT_NAME, null) ?: return + val accountName = intent?.extras?.getString(KEY_ACCOUNT_NAME, null) ?: run { + finish() + return + } + + logoutAccount(accountName) + } + + private fun logoutAccount(accountName: String) + { + val accountManager = AccountManager.get(this) + val eAccounts= accountManager.getAccountsByType(applicationContext.getString(R.string.eelo_account_type)) + val activity = this val accountRemovalCallback: (AliasFuture) -> Unit = { future -> val success = future.result.getBoolean(KEY_BOOLEAN_RESULT) @@ -30,18 +42,11 @@ class ReLoginWithOidcActivity : AppCompatActivity() { } } - logoutAccount(accountName, accountRemovalCallback) - } - private fun logoutAccount(accountName: String, callback : (AliasFuture) -> Unit) - { - val accountManager = AccountManager.get(this) - val eAccounts= accountManager.getAccountsByType(applicationContext.getString(R.string.eelo_account_type)) - val activity = this eAccounts.firstOrNull() { it.name == accountName }?.run { Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge - accountManager.removeAccount(this, activity, callback, null) + accountManager.removeAccount(this, activity, accountRemovalCallback, null) } ?: finish() } -- GitLab From 764205f947abc9a84849d445f4efe8b391a120ac Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 20 Nov 2024 12:28:28 +0100 Subject: [PATCH 31/31] chore: try to remove callback --- .../davdroid/ReLoginWithOidcActivity.kt | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt index dabf154da..f9fc6f783 100644 --- a/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt +++ b/app/src/main/java/at/bitfire/davdroid/ReLoginWithOidcActivity.kt @@ -64,7 +64,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() { null, null, this, - { future -> startAddAccount(future) }, + null, null ) } catch (exception: AuthenticatorException) { @@ -77,22 +77,6 @@ class ReLoginWithOidcActivity : AppCompatActivity() { Logger.log.info("Vincent: catch unexpected exception: ${exception.message}") } } - - - private fun startAddAccount(future: AliasFuture) { - val result = future.result?: run { - Logger.log.info("Vincent: Can't add new account: future.result is null") - return - } - - val accountName = result.getString(KEY_ACCOUNT_NAME) - val accountType = result.getString(KEY_ACCOUNT_TYPE, "unexepected account type") - - if (accountName != null) { - Logger.log.info("Vincent: ($accountType) account added: $accountName") - } - finish() - } } typealias AliasFuture = AccountManagerFuture -- GitLab