nextcloud / nextcloud/android

Migrate user account management to UserAccountManager

Open
#4,676 1 comment 1 reaction 2 assignees Assigned to @ezaquarii View on GitHub
enhancement feature: authentication overview technical debt
Dominant language
Kotlin
Stars
5.6k
Forks
2k
Avg merge
2d 18h
Merged PRs (30d)
92

Description

### Situation

Currently user account can be represented by 4 different types:

* `android.accounts.Account`
* `com.owncloud.android.lib.common.OwnCloudAccount`
* `String` id
* `int` id

Accounts are being juggled in activities that try to track which account is currently active and perform ad-hoc reinitialization of UI on change.

The logic responsible for reconciliation of currently selected account and UI state is virtually impossible to track due to large amount of flags, conditions and out-of-band state modification.

Additionally, we discovered some issues with android account manager, causing accounts to disappear from the `android.accounts.AccountManager` on phones that allow installing the application on external storage (despite we forbid it in the manifest).

### Solution

1. Make `UserAccountManager` a single point of truth regarding currently selected account
2. Eliminate ad-hoc UI patching in life cycle callbacks
3. Seal `OwnCloudAccount` and `Account` behind new unified interface
4. Migrate application components to new unified account type

No visible user impact, or impact minimized up to this point.

5. Make decision about new account manager implementation (platform? custom? library? app? sso?)

### Roadmap

Due to current state of code, extensive refactoring and cleanup around account handling is necessary, as it contains too much state mutation dispersed through many functional areas.
Managing risk in such environment is not economical.

Proposal (incomplete):

- [x] Deprecate `setAccount` and `onAccountSet` logic: ~#4677~
- [x] Remove deprecated onAccountSet callback from activities: ~#4685 #4686 #4687 #4688 #4689 #4693 #4694 #4700~
- [x] Eliminate account status flags from `BaseActivity` and derived classes ~#4710~
- [ ] Refactor all activities performing or reacting to account switch to stop using `setAccount` and manually calling `onAccountSet` callback out of band. #4713
- [ ] Extend `UserAccountManager` with notification API, allowing UI layer to react on account swap
- [ ] Finish activities stack and restart with new account instead of trying to switch internal state
Enable assumption that account cannot change while being inside lifecycle activity.
- [ ] Start migrating to new account type (details to follow...)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.