Skip to content

fix(ManageSpaceActivity): call clearApplicationUserData() after logout#2971

Merged
brandonpage merged 5 commits into
forcedotcom:devfrom
wmathurin:fix-manage-space-clear-data
Jul 21, 2026
Merged

fix(ManageSpaceActivity): call clearApplicationUserData() after logout#2971
brandonpage merged 5 commits into
forcedotcom:devfrom
wmathurin:fix-manage-space-clear-data

Conversation

@wmathurin

@wmathurin wmathurin commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The "Yes" button in `ManageSpaceActivity` called `logout(account=null)` which only logs out the current user. With multiple accounts logged in, other accounts never received SDK-level teardown (SmartStore cleanup, DPoP key deletion, token revocation) before `clearApplicationUserData()` wiped everything at the OS level.
  • Replaced the single-user logout with a loop over all authenticated users via `UserAccountManager.getAuthenticatedUsers()`, calling `signoutUser()` per account so each account goes through proper SDK cleanup.
  • Falls back to `logout(account=null)` when `getAuthenticatedUsers()` returns null/empty (fresh install / already logged out).
  • Extracted the confirm logic into `logoutAllUsersAndClearData()` with lambda parameters for testability, and `clearApplicationUserData()` as an `open` method so tests can override it without the OS killing the test process.

Fixes forcedotcom/SalesforceMobileSDK-ReactNative#425

Test plan

  • Unit tests: `ManageSpaceActivityTest` (4 tests — single user, multiple users, null list, empty list) — all passing
  • Build a React Native app with the fixed Android SDK
  • Go to Android Settings > Apps > [app name] > Storage > Clear Data
  • Tap "Yes" with a single account logged in — verify app data is cleared and app returns to login screen
  • Tap "Yes" with multiple accounts logged in — verify all accounts are gone and app starts clean
  • Tap "No" — verify app continues running normally

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.
@github-actions

Copy link
Copy Markdown

Job Summary for Gradle

Pull Request :: test-android
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
SalesforceMobileSDK-Android native:NativeSampleApps:AuthFlowTester:assembleDebug 9.4.1 Build Scan not published

@github-actions

Copy link
Copy Markdown

Job Summary for Gradle

Pull Request :: test-android
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
SalesforceMobileSDK-Android libs:SalesforceSDK:lint 9.4.1 Build Scan not published
SalesforceMobileSDK-Android libs:SalesforceSDK:convertCodeCoverage 9.4.1 Build Scan not published
SalesforceMobileSDK-Android libs:SalesforceSDK:assembleAndroidTest 9.4.1 Build Scan not published

showLoginPage = false,
reason = USER_LOGOUT
)
(getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).clearApplicationUserData()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@brandonpage
brandonpage merged commit 75f091a into forcedotcom:dev Jul 21, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clear Data Functionality Not Working in ManageSpaceActivity

2 participants