Skip to content

Conversation

@pm-dimagi
Copy link
Contributor

@pm-dimagi pm-dimagi commented Jun 6, 2025

Product Description

https://console.firebase.google.com/u/0/project/commcare-a57e4/crashlytics/app/android:org.commcare.dalvik/issues/667e13a8b58e0f10f71204d14f2f7e26?time=last-seven-days&versions=2.57%20(15);2.57%20(3);2.57%20(1)&sessionEventKey=68428B0B017400014660C0ADDCF532FC_2091174946019441139
fixed navigation issue and put logs if it reappears in future

Technical Summary

Feature Flag

Safety Assurance

Safety story

Automated test coverage

QA Plan

Labels and Review

  • Do we need to enhance the manual QA test coverage ? If yes, the "QA Note" label is set correctly
  • Does the PR introduce any major changes worth communicating ? If yes, the "Release Note" label is set and a "Release Note" is specified in PR description.
  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@pm-dimagi pm-dimagi added the skip-integration-tests Skip android tests. label Jun 6, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 6, 2025

📝 Walkthrough

Walkthrough

The change updates the navigation logic in the navigateToMessageDisplayForSecurityConfigurationFailure method within the PersonalIdBiometricConfigFragment class. Instead of always navigating to the message display screen upon failure, the method now checks the current navigation destination. If the user is already on the message display screen, the navigation action is skipped, avoiding redundant navigation calls. The update also includes logging the current navigation destination label for debugging purposes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Fragment
    participant NavController

    User->>Fragment: Triggers navigation to message display (on failure)
    Fragment->>NavController: Get current destination
    NavController-->>Fragment: Return current destination
    Fragment->>Fragment: Check if current destination is message display
    alt Not on message display
        Fragment->>NavController: Navigate to message display
    else Already on message display
        Fragment->>Fragment: Skip navigation
    end
Loading

Possibly related PRs

  • Added safe navigation #3045: Centralizes safe navigation logic into a utility method to prevent redundant navigation, similar in intent to the current PR but implemented in a different class.

Suggested reviewers

  • shubham1g5
  • OrangeAndGreen
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 11a0b7c and 87847ae.

📒 Files selected for processing (1)
  • app/src/org/commcare/fragments/personalId/PersonalIdBiometricConfigFragment.java (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/src/org/commcare/fragments/personalId/PersonalIdBiometricConfigFragment.java (1)
app/src/org/commcare/connect/ConnectConstants.java (1)
  • ConnectConstants (8-54)
🔇 Additional comments (1)
app/src/org/commcare/fragments/personalId/PersonalIdBiometricConfigFragment.java (1)

16-16: LGTM: Import addition is appropriate.

The NavController import is correctly added to support the new navigation logic in the method.

Comment on lines 268 to 281
private void navigateToMessageDisplayForSecurityConfigurationFailure(String errorMessage) {
NavDirections navDirections =
PersonalIdBiometricConfigFragmentDirections.actionPersonalidBiometricConfigToPersonalidMessage(
getString(R.string.configuration_process_failed_title),
errorMessage,
ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED, getString(R.string.ok),
null).setIsCancellable(false);
Navigation.findNavController(requireView()).navigate(navDirections);
Logger.log("NavCheck", "Current destination: " +
Navigation.findNavController(requireView()).getCurrentDestination().getLabel());
NavController navController = Navigation.findNavController(requireView());
if (navController.getCurrentDestination().getId() != R.id.personalid_message_display) {
NavDirections navDirections =
PersonalIdBiometricConfigFragmentDirections.actionPersonalidBiometricConfigToPersonalidMessage(
getString(R.string.configuration_process_failed_title),
errorMessage,
ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED, getString(R.string.ok),
null).setIsCancellable(false);
navController.navigate(navDirections);
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null safety checks to prevent potential crashes.

The navigation logic improvement is sound and addresses the redundant navigation issue. However, there are potential null pointer exceptions that need to be handled:

  1. getCurrentDestination() can return null in certain navigation states
  2. The logging code accesses .getLabel() without null checks
  3. Two separate NavController instances are obtained which could be inconsistent

Apply this diff to add proper null safety:

 private void navigateToMessageDisplayForSecurityConfigurationFailure(String errorMessage) {
-        Logger.log("NavCheck", "Current destination: " +
-                Navigation.findNavController(requireView()).getCurrentDestination().getLabel());
         NavController navController = Navigation.findNavController(requireView());
-        if (navController.getCurrentDestination().getId() != R.id.personalid_message_display) {
+        NavDestination currentDestination = navController.getCurrentDestination();
+        if (currentDestination != null) {
+            Logger.log("NavCheck", "Current destination: " + currentDestination.getLabel());
+            if (currentDestination.getId() != R.id.personalid_message_display) {
+                NavDirections navDirections =
+                        PersonalIdBiometricConfigFragmentDirections.actionPersonalidBiometricConfigToPersonalidMessage(
+                                getString(R.string.configuration_process_failed_title),
+                                errorMessage,
+                                ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED, getString(R.string.ok),
+                                null).setIsCancellable(false);
+                navController.navigate(navDirections);
+            }
+        } else {
+            Logger.log("NavCheck", "Current destination is null, proceeding with navigation");
             NavDirections navDirections =
                     PersonalIdBiometricConfigFragmentDirections.actionPersonalidBiometricConfigToPersonalidMessage(
                             getString(R.string.configuration_process_failed_title),
                             errorMessage,
                             ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED, getString(R.string.ok),
                             null).setIsCancellable(false);
             navController.navigate(navDirections);
+        }
-        }
     }

Also add the required import:

+import androidx.navigation.NavDestination;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private void navigateToMessageDisplayForSecurityConfigurationFailure(String errorMessage) {
NavDirections navDirections =
PersonalIdBiometricConfigFragmentDirections.actionPersonalidBiometricConfigToPersonalidMessage(
getString(R.string.configuration_process_failed_title),
errorMessage,
ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED, getString(R.string.ok),
null).setIsCancellable(false);
Navigation.findNavController(requireView()).navigate(navDirections);
Logger.log("NavCheck", "Current destination: " +
Navigation.findNavController(requireView()).getCurrentDestination().getLabel());
NavController navController = Navigation.findNavController(requireView());
if (navController.getCurrentDestination().getId() != R.id.personalid_message_display) {
NavDirections navDirections =
PersonalIdBiometricConfigFragmentDirections.actionPersonalidBiometricConfigToPersonalidMessage(
getString(R.string.configuration_process_failed_title),
errorMessage,
ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED, getString(R.string.ok),
null).setIsCancellable(false);
navController.navigate(navDirections);
}
}
// Add at the top of the file
import androidx.navigation.NavDestination;
private void navigateToMessageDisplayForSecurityConfigurationFailure(String errorMessage) {
NavController navController = Navigation.findNavController(requireView());
NavDestination currentDestination = navController.getCurrentDestination();
if (currentDestination != null) {
Logger.log("NavCheck", "Current destination: " + currentDestination.getLabel());
if (currentDestination.getId() != R.id.personalid_message_display) {
NavDirections navDirections =
PersonalIdBiometricConfigFragmentDirections
.actionPersonalidBiometricConfigToPersonalidMessage(
getString(R.string.configuration_process_failed_title),
errorMessage,
ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED,
getString(R.string.ok),
null
)
.setIsCancellable(false);
navController.navigate(navDirections);
}
} else {
Logger.log("NavCheck", "Current destination is null, proceeding with navigation");
NavDirections navDirections =
PersonalIdBiometricConfigFragmentDirections
.actionPersonalidBiometricConfigToPersonalidMessage(
getString(R.string.configuration_process_failed_title),
errorMessage,
ConnectConstants.PERSONALID_DEVICE_CONFIGURATION_FAILED,
getString(R.string.ok),
null
)
.setIsCancellable(false);
navController.navigate(navDirections);
}
}
🤖 Prompt for AI Agents
In
app/src/org/commcare/fragments/personalId/PersonalIdBiometricConfigFragment.java
around lines 268 to 281, add null checks for getCurrentDestination() before
accessing its methods to prevent null pointer exceptions. Store the
NavController instance once and reuse it to avoid inconsistencies. Check if
getCurrentDestination() is null before logging its label and before comparing
its ID. Only proceed with navigation if getCurrentDestination() is non-null and
its ID differs from R.id.personalid_message_display.

@shubham1g5
Copy link
Contributor

I don't understand what issue is this fixing ? The linked ticket doesn't link to any individual issue.

Logger.log("NavCheck", "Current destination: " +
Navigation.findNavController(requireView()).getCurrentDestination().getLabel());
NavController navController = Navigation.findNavController(requireView());
if (navController.getCurrentDestination().getId() != R.id.personalid_message_display) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't be a fix here, I prefer crashing to user clicking on a button that doesn't take them to the next page.

@Jignesh-dimagi
Copy link
Contributor

@pm-dimagi What is the issue? Mentioned QA ticket doesn't provide the issue information

@pm-dimagi
Copy link
Contributor Author

pm-dimagi commented Jun 6, 2025

Sorry i have put the wrong link mentioned the correct one now

The issue i understand here is the biometric page is showing message display and the calling the navigateToMessage again so I put the check to avoid this and log the page for future refreence
@shubham1g5 @Jignesh-dimagi

@Jignesh-dimagi
Copy link
Contributor

@pm-dimagi That's strange! Do we know reason why its calling to navigate again to message only? If we find it, we can correct that probably.

@pm-dimagi
Copy link
Contributor Author

@Jignesh-dimagi i am not able to reproduce this case but as far i understand from the crash i put up this solution

@shubham1g5
Copy link
Contributor

@pm-dimagi We should close this out as this is not a solution but just hides the issue further.

Base automatically changed from commcare_2.57 to master June 14, 2025 06:00
@shubham1g5 shubham1g5 closed this Jun 17, 2025
@shubham1g5 shubham1g5 deleted the pm_navigation_fix branch June 17, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-integration-tests Skip android tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants