diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 027f5e61035c2de0352afcd1a8435d81ee8795d8..62e769d28283f260cd4e6317fb79b3c3db3fe8d9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,6 +31,9 @@ + + + + + + + + diff --git a/app/src/main/java/foundation/e/drive/account/AccountUtils.kt b/app/src/main/java/foundation/e/drive/account/AccountUtils.kt index ae3c1118b1f341e911c73d63aa48e4d2615b74d9..5db69912daf4515ef6fed5de435c03480e7b40e2 100644 --- a/app/src/main/java/foundation/e/drive/account/AccountUtils.kt +++ b/app/src/main/java/foundation/e/drive/account/AccountUtils.kt @@ -66,7 +66,9 @@ object AccountUtils { val accountType = context.getString(R.string.eelo_account_type) return accountManager.getAccountsByType(accountType) - .firstOrNull { account -> account.name == accountName } + .firstOrNull { account -> + account.name.substringBefore("@") == accountName.substringBefore("@") + } } @JvmStatic diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt index 7ed75c7a128516cd4b34bd9270be7f26628e87bc..9e908f4378f71d77d6cf905bcb027572a5f5115f 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt @@ -22,6 +22,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import foundation.e.drive.account.AccountAdder +import foundation.e.drive.murenasso.MurenaSsoMigrationPreferences import timber.log.Timber /** @@ -35,6 +36,11 @@ class AccountAddedReceiver : BroadcastReceiver() { if (context == null || intent == null || intent.extras == null) return + if (MurenaSsoMigrationPreferences.isSsoMigrationRunning(context)) { + Timber.i("Murena SSO migration is running, skipping account addition.") + return + } + val extras = intent.extras!! val accountName = extras.getString(AccountManager.KEY_ACCOUNT_NAME, "") val accountType = extras.getString(AccountManager.KEY_ACCOUNT_TYPE, "") diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java index c8f16a69000fcd2364b837f2a1e50d5caa6a1ede..88228651bdba3c5ea6def7401793788df83f9e6b 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java @@ -29,7 +29,9 @@ import androidx.annotation.NonNull; import foundation.e.drive.R; import foundation.e.drive.account.AccountRemover; +import foundation.e.drive.murenasso.MurenaSsoMigrationPreferences; import foundation.e.drive.utils.AppConstants; +import foundation.e.drive.utils.StringUtils; import foundation.e.drive.utils.ViewUtils; import timber.log.Timber; @@ -62,14 +64,20 @@ public class AccountRemoveCallbackReceiver extends BroadcastReceiver { return false; } - String currentAccount = preferences.getString(AccountManager.KEY_ACCOUNT_NAME, ""); - String currentAccountType = context.getString(R.string.eelo_account_type); + final String currentAccount = StringUtils.substringBefore(preferences.getString(AccountManager.KEY_ACCOUNT_NAME, + ""), "@"); // abc@example.com -> abc + final String currentAccountType = context.getString(R.string.eelo_account_type); if (currentAccount.isEmpty()) { Timber.d("No account set up, ignoring account removal"); return false; } + if (MurenaSsoMigrationPreferences.isSsoMigrationRunning(context)) { + Timber.i("Murena SSO migration is running, skipping account removal."); + return false; + } + final String accountType = intent.getExtras().getString(AccountManager.KEY_ACCOUNT_TYPE); final String accountName = intent.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); diff --git a/app/src/main/java/foundation/e/drive/murenasso/MurenaSsoMigrationPreferences.kt b/app/src/main/java/foundation/e/drive/murenasso/MurenaSsoMigrationPreferences.kt new file mode 100644 index 0000000000000000000000000000000000000000..95cde66ea442ea07c0519a770a4ccfd171ff5536 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/murenasso/MurenaSsoMigrationPreferences.kt @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2025 e Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package foundation.e.drive.murenasso + +import android.content.Context +import androidx.core.content.edit +import foundation.e.drive.murenasso.MurenaSsoMigrationPreferences.MigrationStatus.Completed +import foundation.e.drive.murenasso.MurenaSsoMigrationPreferences.MigrationStatus.InProgress + +object MurenaSsoMigrationPreferences { + + private const val PREFERENCES_NAME = "edrive_sso_migration" + private const val KEY_IS_SSO_MIGRATION_RUNNING = "is_sso_migration_running" + + @JvmStatic + fun isSsoMigrationRunning(context: Context): Boolean { + val preferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE) + return preferences.getBoolean(KEY_IS_SSO_MIGRATION_RUNNING, false) + } + + @JvmStatic + fun updateSsoMigrationStatus(context: Context, status: MigrationStatus) { + val preferences = + context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE) + when (status) { + InProgress -> preferences.edit() { putBoolean(KEY_IS_SSO_MIGRATION_RUNNING, true) } + Completed -> preferences.edit() { putBoolean(KEY_IS_SSO_MIGRATION_RUNNING, false) } + } + } + + enum class MigrationStatus { + InProgress, + Completed + } +} diff --git a/app/src/main/java/foundation/e/drive/murenasso/SsoMigrationReceiver.kt b/app/src/main/java/foundation/e/drive/murenasso/SsoMigrationReceiver.kt new file mode 100644 index 0000000000000000000000000000000000000000..f8fc29998977be55e8312002c6d440e70bfcfd9a --- /dev/null +++ b/app/src/main/java/foundation/e/drive/murenasso/SsoMigrationReceiver.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2025 e Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package foundation.e.drive.murenasso + +import android.accounts.AccountManager +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import foundation.e.drive.murenasso.MurenaSsoMigrationPreferences.MigrationStatus.Completed +import foundation.e.drive.murenasso.MurenaSsoMigrationPreferences.MigrationStatus.InProgress +import timber.log.Timber + +class SsoMigrationReceiver : BroadcastReceiver() { + + override fun onReceive(context: Context?, intent: Intent?) { + Timber.i("SSO migration intent received.") + + if (context == null || intent == null || intent.extras == null) return + + val extras = intent.extras!! + val isMigrationRunning = extras.getBoolean(AccountManager.KEY_USERDATA) + + if (isMigrationRunning) { + MurenaSsoMigrationPreferences.updateSsoMigrationStatus( + context, + InProgress + ) + Timber.i("SSO migration is running.") + } else { + MurenaSsoMigrationPreferences.updateSsoMigrationStatus( + context, + Completed + ) + Timber.i("SSO migration is completed.") + } + } +} diff --git a/app/src/main/java/foundation/e/drive/utils/StringUtils.java b/app/src/main/java/foundation/e/drive/utils/StringUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..22bb2ae6012453fb3ad3e917093df0da6922f9b0 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/utils/StringUtils.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2025 e Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package foundation.e.drive.utils; + +import androidx.annotation.NonNull; + +public class StringUtils { + private static String substringBefore(String str, String delimiter, String missingDelimiterValue) { + int index = str.indexOf(delimiter); + return (index == -1) ? missingDelimiterValue : str.substring(0, index); + } + + @NonNull + public static String substringBefore(@NonNull String str, @NonNull String delimiter) { + return substringBefore(str, delimiter, str); + } +}