Skip to content

Check for cached identity on cold opens#1336

Open
gdeluna-branch wants to merge 3 commits intomasterfrom
gdeluna-branch/CheckForCachedIdentity
Open

Check for cached identity on cold opens#1336
gdeluna-branch wants to merge 3 commits intomasterfrom
gdeluna-branch/CheckForCachedIdentity

Conversation

@gdeluna-branch
Copy link
Copy Markdown
Contributor

Reference

SDK-XXX -- <TITLE>.

Description

Testing Instructions

Risk Assessment [HIGH || MEDIUM || LOW]

  • I, the PR creator, have tested — integration, unit, or otherwise — this code.

Reviewer Checklist (To be checked off by the reviewer only)

  • JIRA Ticket is referenced in PR title.
  • Correctness & Style
    • Conforms to AOSP Style Guides
    • Mission critical pieces are documented in code and out of code as needed.
  • Unit Tests reviewed and test issue sufficiently.
  • Functionality was reviewed in QA independently by another engineer on the team.

cc @BranchMetrics/saas-sdk-devs for visibility.

@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Jan 9, 2026

Code Quality bug fix

Reference

SDK-XXX -- Check for cached identity on cold opens.

Description

Summary By MatterAI MatterAI logo

🔄 What Changed

Synchronized the clearing of Branch.installDeveloperId within QueueOperationLogout.kt to ensure the global SDK state is reset during logout. This complements the previous change in ServerRequestInitSession.java which implemented identity retrieval from cache on cold opens.

🔍 Impact of the Change

Ensures that the in-memory developer identity is fully purged during logout, preventing stale data from persisting in the static SDK state and maintaining consistency with the cleared local preferences.

📁 Total Files Changed

Click to Expand
File ChangeLog
Logout State Sync QueueOperationLogout.kt Updates Branch.installDeveloperId to match the cleared identity value during logout.
Identity Fallback ServerRequestInitSession.java (Previous) Added logic to check and apply cached identity from preferences in setPost.

🧪 Test Added/Recommended

Recommended

  • Unit Test: Verify Branch.installDeveloperId is set to NO_STRING_VALUE immediately after QueueOperationLogout executes.
  • Integration Test: Ensure subsequent session initializations after logout do not inadvertently use the previous user's identity.

🔒 Security Vulnerabilities

N/A

Testing Instructions

N/A

Risk Assessment [LOW]

  • I, the PR creator, have tested — integration, unit, or otherwise — this code.

Reviewer Checklist (To be checked off by the reviewer only)

  • JIRA Ticket is referenced in PR title.
  • Correctness & Style
    • Conforms to AOSP Style Guides
    • Mission critical pieces are documented in code and out of code as needed.
  • Unit Tests reviewed and test issue sufficiently.
  • Functionality was reviewed in QA independently by another engineer on the team.

Total Score: 2

cc @BranchMetrics/saas-sdk-devs for visibility.

⏳ Estimated code review effort

LOW (~5 minutes)

Tip

Quality Recommendations

  1. Verify if Branch.installDeveloperId requires volatile marking or synchronized access if the logout operation can occur on a non-main thread while other SDK components read it.

♫ Tanka Poem

The state is now purged, 🧪
Static variables find peace, 🧹
Identity gone.
A cold open starts anew, ❄️
Clean code for the user's path. ✨

Sequence Diagram

sequenceDiagram
    participant Q as QueueOperationLogout
    participant P as PrefHelper
    participant B as Branch
    
    Q->>P: getInstance(context)
    P-->>Q: prefHelper
    
    Note over Q, P: Set local identity to NO_STRING_VALUE
    Q->>B: installDeveloperId = prefHelper.identity
    Note right of B: Global state cleared
    
    Q->>P: clearUserValues()
    P-->>Q: success
Loading

@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Jan 9, 2026

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use MatterAI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with MatterAI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Copy link
Copy Markdown

@bboothe-branch bboothe-branch left a comment

Choose a reason for hiding this comment

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

Hi Gabe. Tested by commenting out Branch.getInstance().setIdentity("Identity1"); in the Branch-SDK-TestBet main activity. Added Branch Loggers to the If and Else If statements to confirm their firing. In most scenarios the code seemed to work fine, but I found one issue.

If I set an identity using the setIdentity Method, upon first Cold Open, the code sometimes successfully fires and I was able to see the previously set ID. However, when I force closed it again and restarted from cold open, neither IF statement was called.

Despite neither being called (assuming no ID was found), when I click Clear User ID (I was able to see the previously set ID still there. This indicates that the currentUserId value was still there on cold open, but the new code didn't recognize it. Is this expected or am I misunderstanding some part of the logout button code? Video attached in next comment.

  • Tested Cold Open without an Identity set in onCreate
  • Tested Warm Open without an identity set in onCrete
  • Tested Cold Open with identity set in onCreate
  • Tested Warm Open with Identity set in onCreate
  • Force closed app and re-ran tests to ensure ID was cleared

logout Button Code
` findViewById(R.id.cmdClearUser).setOnClickListener(new OnClickListener() {
@OverRide
public void onClick(View v) {
String currentUserId = PrefHelper.getInstance(MainActivity.this).getIdentity();
Branch.getInstance().logout(new Branch.LogoutStatusListener() {
@OverRide
public void onLogoutFinished(boolean loggedOut, BranchError error) {
if (error != null) {
Log.e("BranchSDK_Tester", "onLogoutFinished Error: " + error);
Toast.makeText(getApplicationContext(), "Error Logging Out: " + error.getMessage(), Toast.LENGTH_LONG).show();
} else {
Log.d("BranchSDK_Tester", "onLogoutFinished succeeded: " + loggedOut);
Toast.makeText(getApplicationContext(), "Cleared User ID: " + currentUserId, Toast.LENGTH_LONG).show();
}
}
});

        }
    });`

@bboothe-branch
Copy link
Copy Markdown

Cold Open check potentially malfunctioning

Check.for.cached.Identity.on.cold.open.mp4

@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Jan 21, 2026

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use MatterAI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with MatterAI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Copy link
Copy Markdown

@bboothe-branch bboothe-branch left a comment

Choose a reason for hiding this comment

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

Hey @gdeluna-branch I tested this update and I'm finding that the two blocks of code in ServerRequestInitSession.java only fire on warm open. I believe this is intended, but wanted to confirm before approving.

I have found that the first IF statement fires when the String identity = Branch.installDeveloperId; value is already populated, and the ELSE IF statement fires when only the prefHelper_.getIdentity() code is populated but the String identity = Branch.installDeveloperId; is empty.

If this is the intended flow, then we're good to approve.

Also side note, I found that we have Branch.getInstance().setIdentity("Identity1"); in the Testbed app's MainActivity. I commented this out to test, but it initially confused me as to why my ID kept being set to Identity1. Do we want to keep this code in the MainActivity or comment it / remove it? I think commenting it out would make the most sense so that we remember we have the option, but to set it to this as standard when we have the setIdentity() buttons seems redundant and potentially confusing for other devs.

Videos attached:

Identity1.Example.mp4
ExampleIDs.used.mp4

@bboothe-branch bboothe-branch self-requested a review January 21, 2026 18:44
Copy link
Copy Markdown

@bboothe-branch bboothe-branch left a comment

Choose a reason for hiding this comment

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

Approved after confirming intended behavior after discussion.

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.

2 participants