xref: /aosp_15_r20/art/tools/hiddenapi/README.md (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard WorkerHiddenApi
2*795d594fSAndroid Build Coastguard Worker=========
3*795d594fSAndroid Build Coastguard Worker
4*795d594fSAndroid Build Coastguard WorkerThis tool iterates over all class members inside given DEX files and modifies
5*795d594fSAndroid Build Coastguard Workertheir access flags if their signatures appear on one of two lists - unsupported and
6*795d594fSAndroid Build Coastguard Workerblocklist - provided as text file inputs. These access flags denote to the
7*795d594fSAndroid Build Coastguard Workerruntime that the marked methods/fields should be treated as internal APIs with
8*795d594fSAndroid Build Coastguard Workeraccess restricted only to platform code. Methods/fields not mentioned on the two
9*795d594fSAndroid Build Coastguard Workerlists are assumed to be part of the SDK and left accessible by all code.
10*795d594fSAndroid Build Coastguard Worker
11*795d594fSAndroid Build Coastguard WorkerAPI signatures
12*795d594fSAndroid Build Coastguard Worker==============
13*795d594fSAndroid Build Coastguard Worker
14*795d594fSAndroid Build Coastguard WorkerThe methods/fields to be marked are specified in two text files (unsupported,
15*795d594fSAndroid Build Coastguard Workerblocklist) provided an input. Only one signature per line is allowed.
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard WorkerTypes are expected in their DEX format - class descriptors are to be provided in
18*795d594fSAndroid Build Coastguard Worker"slash" form, e.g. "Ljava/lang/Object;", primitive types in their shorty form,
19*795d594fSAndroid Build Coastguard Workere.g. "I" for "int", and a "[" prefix denotes an array type. Lists of types do
20*795d594fSAndroid Build Coastguard Workernot use any separators, e.g. "ILxyz;F" for "int, xyz, float".
21*795d594fSAndroid Build Coastguard Worker
22*795d594fSAndroid Build Coastguard WorkerMethods are encoded as:
23*795d594fSAndroid Build Coastguard Worker    `class_descriptor->method_name(parameter_types)return_type`
24*795d594fSAndroid Build Coastguard Worker
25*795d594fSAndroid Build Coastguard WorkerFields are encoded as:
26*795d594fSAndroid Build Coastguard Worker    `class_descriptor->field_name:field_type`
27*795d594fSAndroid Build Coastguard Worker
28*795d594fSAndroid Build Coastguard WorkerBit encoding
29*795d594fSAndroid Build Coastguard Worker============
30*795d594fSAndroid Build Coastguard Worker
31*795d594fSAndroid Build Coastguard WorkerTwo bits of information are encoded in the DEX access flags. These are encoded
32*795d594fSAndroid Build Coastguard Workeras unsigned LEB128 values in DEX and so as to not increase the size of the DEX,
33*795d594fSAndroid Build Coastguard Workerdifferent modifiers were chosen for different kinds of methods/fields.
34*795d594fSAndroid Build Coastguard Worker
35*795d594fSAndroid Build Coastguard WorkerFirst bit is encoded as the inversion of visibility access flags (bits 2:0).
36*795d594fSAndroid Build Coastguard WorkerAt most one of these flags can be set at any given time. Inverting these bits
37*795d594fSAndroid Build Coastguard Workertherefore produces a value where at least two bits are set and there is never
38*795d594fSAndroid Build Coastguard Workerany loss of information.
39*795d594fSAndroid Build Coastguard Worker
40*795d594fSAndroid Build Coastguard WorkerSecond bit is encoded differently for each given type of class member as there
41*795d594fSAndroid Build Coastguard Workeris no single unused bit such that setting it would not increase the size of the
42*795d594fSAndroid Build Coastguard WorkerLEB128 encoding. The following bits are used:
43*795d594fSAndroid Build Coastguard Worker
44*795d594fSAndroid Build Coastguard Worker * bit 5 for fields as it carries no other meaning
45*795d594fSAndroid Build Coastguard Worker * bit 5 for non-native methods, as `synchronized` can only be set on native
46*795d594fSAndroid Build Coastguard Worker   methods (the Java `synchronized` modifier is bit 17)
47*795d594fSAndroid Build Coastguard Worker * bit 9 for native methods, as it carries no meaning and bit 8 (`native`) will
48*795d594fSAndroid Build Coastguard Worker   make the LEB128 encoding at least two bytes long
49*795d594fSAndroid Build Coastguard Worker
50*795d594fSAndroid Build Coastguard WorkerTwo following bit encoding is used to denote the membership of a method/field:
51*795d594fSAndroid Build Coastguard Worker
52*795d594fSAndroid Build Coastguard Worker * sdk: `false`, `false`
53*795d594fSAndroid Build Coastguard Worker * unsupported: `true`, `false`
54*795d594fSAndroid Build Coastguard Worker * blocklist: `true`, `true`
55