Skip to content
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

[FragmentStrictMode] Detect <fragment> tag usage #141

Conversation

simonschiller
Copy link
Contributor

Proposed Changes

  • Detect <fragment> tag usage inside XML layouts

Testing

Test: See FragmentStrictModeTest#detectFragmentTagUsage

Issues Fixed

Fixes: 153738235

@dlam dlam requested a review from jbw0033 March 15, 2021 19:19
@@ -130,6 +131,7 @@ public View onCreateView(@Nullable final View parent, @NonNull String name,
+ "re-attached via the <fragment> tag: id=0x" + Integer.toHexString(id));
}
}
FragmentStrictMode.onFragmentTagUsage(fragment);
Copy link

Choose a reason for hiding this comment

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

I think we should make the call on line 74 before we check the ID and tag. The idea being that if you are using strict mode, we should throw this before we even check if you are using tag correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to do that originally, but the problem there is that we don't have a Fragment instance yet. If there is a reliable way to traverse up the FragmentManager hierarchy without a concrete Fragment instance, that would also work, but I couldn't find one. We need the traversal to figure out the correct policy.

Copy link

Choose a reason for hiding this comment

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

There is a package private findFragmentManager that finds the FragmentManager associated with a given view, but I don't think that helps here much.

@simonschiller simonschiller deleted the feature/fragment-tag branch March 23, 2021 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants