-
-
Notifications
You must be signed in to change notification settings - Fork 45
Fix app sandbox setup #3401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix app sandbox setup #3401
Conversation
📝 WalkthroughWalkthroughThe changes modify Sequence DiagramsequenceDiagram
participant VM as PersonalIdWorkHistoryViewModel
participant FF as Feature Flag<br/>Checker
participant AR as ApplicationRecord<br/>Iterator
participant SB as Sandbox
participant WH as PersonalIdWorkHistory<br/>Extractor
VM->>FF: Check if WORK_HISTORY_PENDING_TAB<br/>enabled?
alt Feature Flag Enabled
VM->>VM: Collect earned work history<br/>from all app records
VM->>AR: Iterate through app records
loop For each app record
AR->>SB: setupSandbox(record)
SB->>WH: Extract work history
WH-->>AR: Return PersonalIdWorkHistory list
AR->>SB: teardownSandbox()
end
AR-->>VM: Return all earned histories
VM->>VM: getPendingWorkHistory(earned)
VM->>VM: Compute pending items
VM->>VM: Post _pendingWorkHistory
else Feature Flag Disabled
VM->>VM: Skip pending logic
end
VM-->>VM: Expose computed work histories
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/src/org/commcare/activities/connect/viewmodel/PersonalIdWorkHistoryViewModel.kt(3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-08T11:08:18.530Z
Learnt from: shubham1g5
Repo: dimagi/commcare-android PR: 0
File: :0-0
Timestamp: 2025-05-08T11:08:18.530Z
Learning: PR #3048 "Phase 4 Connect PR" introduces a substantial feature called "Connect" to the CommCare Android app, which includes messaging, job management, delivery tracking, payment processing, authentication flows, and learning modules. It follows a modern architecture using Navigation Components with three navigation graphs, segregated business logic in Manager classes, and proper database persistence.
Applied to files:
app/src/org/commcare/activities/connect/viewmodel/PersonalIdWorkHistoryViewModel.kt
🧬 Code graph analysis (1)
app/src/org/commcare/activities/connect/viewmodel/PersonalIdWorkHistoryViewModel.kt (2)
app/src/org/commcare/personalId/PersonalIdFeatureFlagChecker.kt (1)
isFeatureEnabled(20-29)app/src/org/commcare/CommCareApp.java (1)
CommCareApp(58-473)
app/src/org/commcare/activities/connect/viewmodel/PersonalIdWorkHistoryViewModel.kt
Show resolved
Hide resolved
884b5f6 to
f326af0
Compare
|
@shubham1g5 I think I have less context here but has question why its complicated to teardown, restore the sandbox. May be I will go through code more in details so its ok. |
conroy-ricketts
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - I don't have any concerns. I'd like another set of eyes though
| private fun getWorkHistoryForAppRecord(record: ApplicationRecord): Iterable<PersonalIdWorkHistory> { | ||
| val commcareApp = CommCareApp(record) | ||
| try { | ||
| commcareApp.setupSandbox() | ||
| val profile = commcareApp.initApplicationProfile(); | ||
| profile.credentials.map { credential -> | ||
| val profile = commcareApp.initApplicationProfile() | ||
| return profile.credentials.map { credential -> | ||
| PersonalIdWorkHistory().apply { | ||
| appId = record.applicationId | ||
| title = record.displayName ?: "" | ||
| level = credential.level | ||
| } | ||
| } | ||
| } finally { | ||
| commcareApp.teardownSandbox() | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very interesting use of try/finally that I haven't seen before
OrangeAndGreen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this all looks good, but just making sure I understand:
The issue is that we need to load the sandbox for each app that we have locally in order to check for pending work history, so when we're done we need to make sure to put the previously seated app back. Is that correct?
I'm curious as to why this would cause a crash specifically when trying to download/install a new app (as described by QA)?
Yes.
This is the related stack trace for that, if we don't tear the sandbox and call setup on the same sandbox, it errors with this. |
@Jignesh-dimagi The compication is mostly that we don't parse HQ App xml files in DB and setting up sandbox initializes the file paths for thes to get parsed correctly and loaded into memory , due to these constraints we also don't support multi-login into more than one HQ app (you will have to logout to login into another one) |
Product Description
Fixes https://dimagi.atlassian.net/browse/QA-8210
Technical Summary
We were not restoring the last app sandbox state correctly leading to this crash
I added more sandbox handling to reset to the initial state and could verify the issue is fixed.
Labels and Review