Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 997dd8c4 authored by Jonathan Klee's avatar Jonathan Klee Committed by Mohammed Althaf T
Browse files

AM: Notify all components listening for account added

We want other components to be able to get notified
when a new account is added in AccountManger.

We moved the permission declaration to AccountManager and
the subscribers who want to get notified should use
the new ADD_ACCOUNT permission.
parent 92577708
Loading
Loading
Loading
Loading
Loading
+9 −13
Original line number Diff line number Diff line
@@ -33,10 +33,8 @@ object AccountHelper {
    private const val MAIL_PACKAGE = "foundation.e.mail"
    private const val MAIL_RECEIVER_CLASS = "com.fsck.k9.account.AccountSyncReceiver"
    private const val MAIL_ACTION_PREFIX = "foundation.e.accountmanager.account."

    private const val DRIVE_PACKAGE_NAME = "foundation.e.drive"
    private const val DRIVE_ACTION_ADD_ACCOUNT = "$DRIVE_PACKAGE_NAME.action.ADD_ACCOUNT"
    private const val DRIVE_RECEIVER_CLASS = "$DRIVE_PACKAGE_NAME.account.receivers.AccountAddedReceiver"
    private const val ACTION_ADD_ACCOUNT = "foundation.e.accountmanager.action.ACCOUNT_ADDED"
    private const val PERMISSION_ADD_ACCOUNT = "foundation.e.accountmanager.permission.ADD_ACCOUNT"

    fun getAllAccounts(accountManager: AccountManager): Array<Account> {
        val allAccounts = mutableListOf<Account>()
@@ -101,18 +99,16 @@ object AccountHelper {
        }
    }

    private fun notifyEDriveAccountAdded(context: Context, name: String) {
        val intent = Intent(DRIVE_ACTION_ADD_ACCOUNT).apply {
            addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
            component = ComponentName(DRIVE_PACKAGE_NAME, DRIVE_RECEIVER_CLASS)
            putExtra(AccountManager.KEY_ACCOUNT_NAME, name)
            putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountTypes.Murena.accountType)
        }
        context.sendBroadcast(intent)
    private fun notifyListeners(context: Context, name: String) {
        val intent = Intent(ACTION_ADD_ACCOUNT)
        intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
        intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, name)
        intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountTypes.Murena.accountType)
        context.sendBroadcast(intent, PERMISSION_ADD_ACCOUNT)
    }

    fun notifyEApps(context: Context, name: String) {
        notifyEDriveAccountAdded(context, name)
        notifyListeners(context, name)
        notifyMailAccountAdded(context)
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
    <uses-permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"
            tools:ignore="ProtectedPermissions" />

    <uses-permission android:name="foundation.e.permission.ADD_ACCOUNT"/>
    <!-- permission to use to be notified about account being added -->
    <permission android:name="foundation.e.accountmanager.permission.ADD_ACCOUNT"
            android:protectionLevel="signature" />

    <application>