MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / HiddenApiAccessFlags

Class HiddenApiAccessFlags

Bcore/src/main/cpp/dex/hidden_api_access_flags.h:58–146  ·  view source on GitHub ↗

This class is used for encoding and decoding access flags of class members * from the boot class path. These access flags might contain additional two bits * of information on whether the given class member should be hidden from apps * and under what circumstances. * * The encoding is different inside DexFile, where we are concerned with size, * and at runtime where we want to optimize for s

Source from the content-addressed store, hash-verified

56 *
57 */
58class HiddenApiAccessFlags {
59 public:
60 enum ApiList {
61 kWhitelist = 0,
62 kLightGreylist,
63 kDarkGreylist,
64 kBlacklist,
65 };
66
67 static ALWAYS_INLINE ApiList DecodeFromDex(uint32_t dex_access_flags) {
68 DexHiddenAccessFlags flags(dex_access_flags);
69 uint32_t int_value = (flags.IsFirstBitSet() ? 1 : 0) + (flags.IsSecondBitSet() ? 2 : 0);
70 return static_cast<ApiList>(int_value);
71 }
72
73 static ALWAYS_INLINE uint32_t RemoveFromDex(uint32_t dex_access_flags) {
74 DexHiddenAccessFlags flags(dex_access_flags);
75 flags.SetFirstBit(false);
76 flags.SetSecondBit(false);
77 return flags.GetEncoding();
78 }
79
80 static ALWAYS_INLINE uint32_t EncodeForDex(uint32_t dex_access_flags, ApiList value) {
81 DexHiddenAccessFlags flags(RemoveFromDex(dex_access_flags));
82 uint32_t int_value = static_cast<uint32_t>(value);
83 flags.SetFirstBit((int_value & 1) != 0);
84 flags.SetSecondBit((int_value & 2) != 0);
85 return flags.GetEncoding();
86 }
87
88 static ALWAYS_INLINE ApiList DecodeFromRuntime(uint32_t runtime_access_flags) {
89 // This is used in the fast path, only DCHECK here.
90 DCHECK_EQ(runtime_access_flags & kAccIntrinsic, 0u);
91 uint32_t int_value = (runtime_access_flags & kAccHiddenApiBits) >> kAccFlagsShift;
92 return static_cast<ApiList>(int_value);
93 }
94
95 static ALWAYS_INLINE uint32_t EncodeForRuntime(uint32_t runtime_access_flags, ApiList value) {
96 CHECK_EQ(runtime_access_flags & kAccIntrinsic, 0u);
97
98 uint32_t hidden_api_flags = static_cast<uint32_t>(value) << kAccFlagsShift;
99 CHECK_EQ(hidden_api_flags & ~kAccHiddenApiBits, 0u);
100
101 runtime_access_flags &= ~kAccHiddenApiBits;
102 return runtime_access_flags | hidden_api_flags;
103 }
104
105 private:
106 static const int kAccFlagsShift = CTZ(kAccHiddenApiBits);
107 static_assert(IsPowerOfTwo((kAccHiddenApiBits >> kAccFlagsShift) + 1),
108 "kAccHiddenApiBits are not continuous");
109
110 struct DexHiddenAccessFlags {
111 explicit DexHiddenAccessFlags(uint32_t access_flags) : access_flags_(access_flags) {}
112
113 ALWAYS_INLINE uint32_t GetSecondFlag() {
114 return ((access_flags_ & kAccNative) != 0) ? kAccDexHiddenBitNative : kAccDexHiddenBit;
115 }

Callers

nothing calls this directly

Calls 2

CTZFunction · 0.85
IsPowerOfTwoFunction · 0.85

Tested by

no test coverage detected