1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_TOOLS_VERIDEX_HIDDEN_API_H_ 18 #define ART_TOOLS_VERIDEX_HIDDEN_API_H_ 19 20 #include "base/hiddenapi_flags.h" 21 #include "dex/method_reference.h" 22 23 #include <map> 24 #include <ostream> 25 #include <string> 26 27 namespace art { 28 29 class DexFile; 30 31 /** 32 * Helper class for logging if a method/field is in a hidden API list. 33 */ 34 class HiddenApi { 35 public: 36 HiddenApi(const char* flags_file, bool sdk_uses_only); 37 GetApiList(const std::string & name)38 hiddenapi::ApiList GetApiList(const std::string& name) const { 39 auto it = api_list_.find(name); 40 return (it == api_list_.end()) ? hiddenapi::ApiList() : it->second; 41 } 42 IsInAnyList(const std::string & name)43 bool IsInAnyList(const std::string& name) const { 44 return !GetApiList(name).IsEmpty(); 45 } 46 47 static std::string GetApiMethodName(const DexFile& dex_file, uint32_t method_index); 48 49 static std::string GetApiFieldName(const DexFile& dex_file, uint32_t field_index); 50 GetApiMethodName(MethodReference ref)51 static std::string GetApiMethodName(MethodReference ref) { 52 return HiddenApi::GetApiMethodName(*ref.dex_file, ref.index); 53 } 54 ToInternalName(const std::string & str)55 static std::string ToInternalName(const std::string& str) { 56 std::string val = str; 57 std::replace(val.begin(), val.end(), '.', '/'); 58 return "L" + val + ";"; 59 } 60 61 private: 62 void AddSignatureToApiList(const std::string& signature, hiddenapi::ApiList membership); 63 64 std::map<std::string, hiddenapi::ApiList> api_list_; 65 }; 66 67 struct HiddenApiStats { 68 uint32_t count = 0; 69 uint32_t reflection_count = 0; 70 uint32_t linking_count = 0; 71 uint32_t api_counts[hiddenapi::ApiList::kValueCount] = {}; // initialize all to zero 72 }; 73 74 } // namespace art 75 76 #endif // ART_TOOLS_VERIDEX_HIDDEN_API_H_ 77