-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
tweak: filter redundant flags in flag attrs #3849
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
Conversation
This trick gets rid of unneeded flags in flag attrs that even contextually don't make sense. Most commonly: android:layout_gravity="bottom|center|left" 000000000000000000000011 (left) 000000000000000000010001 (center) 000000000000000001010000 (bottom) 'left|bottom' already covers the bits set by 'center', and contextually something can't be left, bottom and center all at once. There are very few flag attrs like that, where certain flags overlap, but this fixes this annoyance when editing res XMLs.
Could you provide some background on why this happens? Is Apktool just disassembly what the source application was and this is an improvement? Since generally for static analysis Apktool should match exactly what source is. What are the changes for network-security-config for? |
For some flag attrs, apktool can't perfectly recreate the flag combination that was originally used. The binary XML stores the value as an integer (a bit field), and for most flag attrs it's easy to extract the flags with a simple AND operation. However for some flag attrs defined by Android itself there are flags with overlapping bits:
Just so the test is very specific. Using |
Thanks - must have predated my work on the tool, since didn't even realize that. I think I could sit down with your example and expand a simple unit test to confirm this works and doesn't regress. |
For reference, the output from a demo run I did for
|
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.
Looks good. Just want to get a unit test in for this shortening logic before merge.
Don't have time for a test myself. Just merging as I trust your judgement. |
This trick gets rid of unneeded flags in flag attrs that even contextually don't make sense.
Most commonly:
android:layout_gravity="bottom|center|left"
000000000000000000000011 (left)
000000000000000000010001 (center)
000000000000000001010000 (bottom)
left|bottom
already covers the bits set bycenter
, and contextually something can't be left, bottom and center all at once.There are very few flag attrs like that, where certain flags overlap, but this fixes this annoyance when editing res XMLs.