-
-
Notifications
You must be signed in to change notification settings - Fork 45
fixed wrong backup code bug #3159
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,15 @@ | |
|
|
||
| import org.commcare.activities.SettingsHelper; | ||
| import org.commcare.activities.connect.PersonalIdActivity; | ||
| import org.commcare.activities.connect.viewmodel.PersonalIdSessionDataViewModel; | ||
| import org.commcare.android.database.connect.models.PersonalIdSessionData; | ||
| import org.commcare.connect.ConnectConstants; | ||
| import org.commcare.connect.PersonalIdManager; | ||
| import org.commcare.connect.database.ConnectDatabaseHelper; | ||
| import org.commcare.dalvik.databinding.ScreenPersonalidMessageBinding; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.lifecycle.ViewModelProvider; | ||
| import androidx.navigation.NavDirections; | ||
| import androidx.navigation.fragment.NavHostFragment; | ||
|
|
||
|
|
@@ -35,13 +38,17 @@ public class PersonalIdMessageFragment extends BottomSheetDialogFragment { | |
| private static final String KEY_CALLING_CLASS = "calling_class"; | ||
| private static final String KEY_IS_CANCELLABLE = "is_cancellable"; | ||
| private ScreenPersonalidMessageBinding binding; | ||
| private PersonalIdSessionData personalIdSessionData; | ||
|
|
||
|
|
||
| @Override | ||
| public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, | ||
| Bundle savedInstanceState) { | ||
| binding = ScreenPersonalidMessageBinding.inflate(inflater, container, false); | ||
| View view = binding.getRoot(); | ||
| loadSavedState(savedInstanceState); | ||
| personalIdSessionData = new ViewModelProvider(requireActivity()).get( | ||
| PersonalIdSessionDataViewModel.class).getPersonalIdSessionData(); | ||
| binding.connectMessageButton.setOnClickListener(v -> handleContinueButtonPress()); | ||
| binding.connectMessageButton2.setOnClickListener(v -> handleContinueButtonPress()); | ||
| loadArguments(); | ||
|
|
@@ -133,6 +140,10 @@ private void finish() { | |
| case ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED: | ||
| directions = navigateToPhoneFragment(); | ||
| break; | ||
| case ConnectConstants.PERSONALID_RECOVERY_ACCOUNT_ORPHANED: | ||
| personalIdSessionData.setAccountExists(false); | ||
| directions = navigateToBackupCode(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can user still try more back up codes after this happens ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no cannot it will landup to set up new code only
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, thanks |
||
| break; | ||
|
Comment on lines
+143
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify null safety and logic correctness for the new case. The new case handling for The logic correctly:
However, ensure Run this script to verify all usages of 🏁 Script executed: #!/bin/bash
# Description: Check for null safety patterns around PersonalIdSessionData usage
# Expected: Find patterns of null checking or initialization
# Search for PersonalIdSessionData usage patterns
rg -A 3 -B 3 "personalIdSessionData\." --type java
# Search for null checks on personalIdSessionData
rg "personalIdSessionData.*null" --type java
# Search for PersonalIdSessionDataViewModel usage patterns
rg -A 5 "PersonalIdSessionDataViewModel" --type javaLength of output: 25193 I’d like to inspect how 🏁 Script executed: #!/bin/bash
# Inspect class declaration and key methods in PersonalIdMessageFragment
rg "class PersonalIdMessageFragment" -n app/src/org/commcare/fragments/personalId/PersonalIdMessageFragment.java
rg "onCreateView" -n -C5 app/src/org/commcare/fragments/personalId/PersonalIdMessageFragment.java
rg "loadArguments" -n -C5 app/src/org/commcare/fragments/personalId/PersonalIdMessageFragment.java
rg "handleContinueButtonPress" -n -C5 app/src/org/commcare/fragments/personalId/PersonalIdMessageFragment.javaLength of output: 3235 I need to inspect the 🏁 Script executed: #!/bin/bash
# Show the finish() implementation around line 120
rg -n -A30 -B5 "private void finish" --context-separator="-" app/src/org/commcare/fragments/personalId/PersonalIdMessageFragment.javaLength of output: 1797 I need to confirm how the 🏁 Script executed: #!/bin/bash
# 1. Dump the ViewModel implementation to see default initialization
sed -n '1,200p' app/src/org/commcare/activities/connect/viewmodel/PersonalIdSessionDataViewModel.java
# 2. Find all call sites for setting the session data
rg -n "setPersonalIdSessionData" --type javaLength of output: 1236 Add null-check for personalIdSessionData to avoid NPE In PersonalIdMessageFragment.finish() (lines 143–146) you call personalIdSessionData.setAccountExists(false);but getPersonalIdSessionData() can return null if setPersonalIdSessionData(...) wasn’t called. Add a non-null assertion or guard immediately after you retrieve it in onCreateView, for example: @@ app/src/org/commcare/fragments/personalId/PersonalIdMessageFragment.java:47
- personalIdSessionData = new ViewModelProvider(requireActivity())
- .get(PersonalIdSessionDataViewModel.class).getPersonalIdSessionData();
+ personalIdSessionData = new ViewModelProvider(requireActivity())
+ .get(PersonalIdSessionDataViewModel.class).getPersonalIdSessionData();
+ Objects.requireNonNull(personalIdSessionData,
+ "PersonalIdSessionData must be initialized before showing this fragment");Or guard its use in finish(): @@ app/src/org/commcare/fragments/personalId/PersonalIdMessageFragment.java:143
- case ConnectConstants.PERSONALID_RECOVERY_ACCOUNT_ORPHANED:
- personalIdSessionData.setAccountExists(false);
- directions = navigateToBackupCode();
- break;
+ case ConnectConstants.PERSONALID_RECOVERY_ACCOUNT_ORPHANED:
+ if (personalIdSessionData == null) {
+ throw new IllegalStateException("Session data unavailable on orphaned recovery");
+ }
+ personalIdSessionData.setAccountExists(false);
+ directions = navigateToBackupCode();
+ break;– File: app/src/org/commcare/fragments/personalId/PersonalIdMessageFragment.java This will prevent a potential NullPointerException when the ViewModel hasn’t been populated. 🤖 Prompt for AI Agents |
||
|
|
||
| } | ||
| if (directions != null) { | ||
|
|
||
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.
🛠️ Refactor suggestion
Add null safety check for ViewModel data.
The
PersonalIdSessionDatais retrieved from the ViewModel without null checking. This could cause issues if the ViewModel doesn't have the data initialized or returns null.Consider adding a null check:
📝 Committable suggestion
🤖 Prompt for AI Agents