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

Commit ab631cf2 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

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 c89d8748
Loading
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@
    <!-- android.permission-group.CALENDAR -->
    <uses-permission android:name="android.permission.READ_CALENDAR"/>
    <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
    <!-- android.permission.eDrive -->
    <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" />

    <!-- android.permission-group.LOCATION -->
    <!-- getting the WiFi name (for "sync in Wifi only") requires
+4 −9
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ class AccountDetailsFragment : Fragment() {
                            if (isSsoMigrationRunning) {
                                handlePostMurenaSsoMigrationOperations()
                            } else {
                                notifyEdriveWithAccountAdded(name)
                                notifyListeners(name)
                            }
                        }
                        handlePostAuthOperations()
@@ -240,18 +240,13 @@ class AccountDetailsFragment : Fragment() {
        requireContext().stopService(serviceIntent)
    }

    private fun notifyEdriveWithAccountAdded(name: String) {
        val intent = Intent("foundation.e.drive.action.ADD_ACCOUNT")
    private fun notifyListeners(name: String) {
        val intent = Intent("foundation.e.accountmanager.action.ACCOUNT_ADDED")
        intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
        intent.component =
            ComponentName(
                getString(R.string.e_drive_package_name), 
                "foundation.e.drive.account.receivers.AccountAddedReceiver"
            )

        intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, name)
        intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, getString(R.string.eelo_account_type))
        requireActivity().sendBroadcast(intent)
        requireActivity().sendBroadcast(intent, "foundation.e.accountmanager.permission.ADD_ACCOUNT")
    }