fix(ManageSpaceActivity): call clearApplicationUserData() after logout#2971
Conversation
Add step-by-step Setup section, POST_NOTIFICATIONS permission (Android 13+), SalesforceActionableNotificationContent full field list, NotificationsApiClient, PushService subclassing guide, React Native context, actionable notifications section, and PushNotificationsRegistrationChangeWorkerTest in testing table.
This reverts commit fb487d7.
Job Summary for GradlePull Request :: test-android
|
Job Summary for GradlePull Request :: test-android |
…a() to clear app storage
| showLoginPage = false, | ||
| reason = USER_LOGOUT | ||
| ) | ||
| (getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).clearApplicationUserData() |
There was a problem hiding this comment.
What happens if there are multiple users logged in? account = null will only result in the current user being logged out.
And what do we not clear already on logout?
There was a problem hiding this comment.
Good catch — you're right on both counts.
Multiple users: logout(account=null) resolves to clientMgr.account → the current user only. Other accounts never got SDK teardown before clearApplicationUserData() wiped their data at the OS level.
Fix: Now calls UserAccountManager.getAuthenticatedUsers() and loops, calling signoutUser(user, activity, false, USER_LOGOUT) per account so each one goes through proper SDK cleanup (SmartStore, DPoP key deletion, token revocation). Falls back to logout(account=null) only when the user list is null/empty (fresh install / already logged out).
What logout() clears that clearApplicationUserData() would already wipe: The OS call is a superset of SDK logout — it wipes all SharedPrefs, databases, files, caches, then restarts the process. Calling signoutUser first still matters for server-side cleanup (push un-registration, refresh token revocation) and to give the SDK a clean teardown path before the process is killed.
4 unit tests added: single user, 3 users, null list, empty list.
When the user taps "Yes" in the Clear Data dialog, the previous code only logged out the current user (logout(account=null)). With multiple accounts logged in, the other accounts never received SDK-level teardown — their SmartStore databases, DPoP key pairs, and token state were left in a dirty state before clearApplicationUserData() wiped everything at the OS level. Changes: - Replace the single logout(account=null) call with a loop over all authenticated users via UserAccountManager.getAuthenticatedUsers(), calling signoutUser(user, activity, false, USER_LOGOUT) per account so each account goes through proper SDK cleanup (tokens, SmartStore, DPoP). - Fall back to logout(account=null) when no accounts are registered (fresh install / already logged out edge case). - Extract clearApplicationUserData() as an open method so tests can override it without the OS killing the test process. - Extract the confirm logic into a top-level internal function logoutAllUsersAndClearData() with lambda parameters so it can be tested without launching an Activity or mocking framework singletons. - Add ManageSpaceActivityTest with 4 tests covering single user, multiple users, null user list, and empty user list.
Summary
Fixes forcedotcom/SalesforceMobileSDK-ReactNative#425
Test plan