OSDN Git Service

AAPT2: Workaround for findViewById with package ID > 0x7f
authorAdam Lesinski <adamlesinski@google.com>
Thu, 27 Apr 2017 22:01:10 +0000 (15:01 -0700)
committerAdam Lesinski <adamlesinski@google.com>
Fri, 28 Apr 2017 19:47:48 +0000 (12:47 -0700)
commit1e4b0e54a3db31bdbcb9385bf22bab4b96096d1f
tree3c87c9080c067aacf8235a07214d3edc35bd86ed
parent0ddca92018da69e7224b63cdedbf1944c63ddc34
AAPT2: Workaround for findViewById with package ID > 0x7f

The entire View code base checks IDs against View.NO_ID except
findViewById(), which checks to see if the ID is negative.

Any package ID > 0x7f is interpreted as a negative number in Java
(no unsigned ints), so this check prevents the use of IDs > 0x7f.

findViewById is final, so support library workarounds are not possible.

Instead, IDs (@id/foo) are just sentinels, their values don't matter.
If building for pre-O devices, rewrite any references to these IDs of
the for 0xPPTTEEEE, where PP > 7f, to 0x7fPPEEEE.

The symbol table will check for potential collisions against the base
APK, so this should be safe.

Bug: 37498913
Test: manual
Change-Id: Ife3bbd29db287757ef8a2ffd83053d97f1db2613
tools/aapt2/Main.cpp
tools/aapt2/cmd/Link.cpp
tools/aapt2/java/JavaClassGenerator.cpp
tools/aapt2/process/SymbolTable.cpp
tools/aapt2/process/SymbolTable.h
tools/aapt2/readme.md