Revert^4: Add dex item for hiddenapi flags

Move hiddenapi access flags to own data section so as to:
(a) increase amount of information stored per method/field
(b) use encoding which can be supported long-term.

The dex item is implemented as:
 - array of offsets indexed by class def index
 - streams of uleb-128 encoded flags.
Offsets in array point to the beginning of the flags stream
for the given class def. Flags are encoded in the same order
as fields and methods are encoded in class data. Zero offset
means that the class either does not have class data, or all
of its flags are zero.

The patch updates:
(a) libdexfile with data structure declarations and accessor
    methods,
(b) hiddenapi tool to create the new item from hiddenapi lists
    and insert it into the given dex file,
(c) dexlayout to copy the flags into compact dex,
(d) dex file verifier to verify the item.
It also removes skipping of verification for boot class path
dex files as those now pass DexFileVerifier, and removes the
need for removing the flags for JVMTI.

The size increase is 450 KB.

This reverts commit d33d318685ec4a1c9e7995c914c104ab6487513b.

Change-Id: Id00e0efb38ee1eab8d7ed5c645a7778b6b94b849
Test: phone boots
Test: m test-art
diff --git a/dexlayout/dex_ir_builder.cc b/dexlayout/dex_ir_builder.cc
index 947d3d5..433f100 100644
--- a/dexlayout/dex_ir_builder.cc
+++ b/dexlayout/dex_ir_builder.cc
@@ -170,6 +170,7 @@
   void AddAnnotationsFromMapListSection(const DexFile& dex_file,
                                         uint32_t start_offset,
                                         uint32_t count);
+  void AddHiddenapiClassDataFromMapListSection(const DexFile& dex_file, uint32_t offset);
 
   void CheckAndSetRemainingOffsets(const DexFile& dex_file, const Options& options);
 
@@ -408,6 +409,10 @@
       case DexFile::kDexTypeAnnotationsDirectoryItem:
         header_->AnnotationsDirectoryItems().SetOffset(item->offset_);
         break;
+      case DexFile::kDexTypeHiddenapiClassData:
+        header_->HiddenapiClassDatas().SetOffset(item->offset_);
+        AddHiddenapiClassDataFromMapListSection(dex_file, item->offset_);
+        break;
       default:
         LOG(ERROR) << "Unknown map list item type.";
     }
@@ -624,6 +629,44 @@
   }
 }
 
+void BuilderMaps::AddHiddenapiClassDataFromMapListSection(const DexFile& dex_file,
+                                                          uint32_t offset) {
+  const DexFile::HiddenapiClassData* hiddenapi_class_data =
+      dex_file.GetHiddenapiClassDataAtOffset(offset);
+  DCHECK(hiddenapi_class_data == dex_file.GetHiddenapiClassData());
+
+  for (auto& class_def : header_->ClassDefs()) {
+    uint32_t index = class_def->GetIndex();
+    ClassData* class_data = class_def->GetClassData();
+    const uint8_t* ptr = hiddenapi_class_data->GetFlagsPointer(index);
+
+    std::unique_ptr<HiddenapiFlagsMap> flags = nullptr;
+    if (ptr != nullptr) {
+      DCHECK(class_data != nullptr);
+      flags = std::make_unique<HiddenapiFlagsMap>();
+      for (const dex_ir::FieldItem& field : *class_data->StaticFields()) {
+        flags->emplace(&field, DecodeUnsignedLeb128(&ptr));
+      }
+      for (const dex_ir::FieldItem& field : *class_data->InstanceFields()) {
+        flags->emplace(&field, DecodeUnsignedLeb128(&ptr));
+      }
+      for (const dex_ir::MethodItem& method : *class_data->DirectMethods()) {
+        flags->emplace(&method, DecodeUnsignedLeb128(&ptr));
+      }
+      for (const dex_ir::MethodItem& method : *class_data->VirtualMethods()) {
+        flags->emplace(&method, DecodeUnsignedLeb128(&ptr));
+      }
+    }
+
+    CreateAndAddIndexedItem(header_->HiddenapiClassDatas(),
+                            header_->HiddenapiClassDatas().GetOffset() +
+                                hiddenapi_class_data->flags_offset_[index],
+                            index,
+                            class_def.get(),
+                            std::move(flags));
+  }
+}
+
 AnnotationItem* BuilderMaps::CreateAnnotationItem(const DexFile& dex_file,
                                                   const DexFile::AnnotationItem* annotation) {
   const uint8_t* const start_data = reinterpret_cast<const uint8_t*>(annotation);
@@ -908,13 +951,13 @@
     FieldItemVector* static_fields = new FieldItemVector();
     for (const ClassAccessor::Field& field : accessor.GetStaticFields()) {
       FieldId* field_item = header_->FieldIds()[field.GetIndex()];
-      uint32_t access_flags = field.GetRawAccessFlags();
+      uint32_t access_flags = field.GetAccessFlags();
       static_fields->emplace_back(access_flags, field_item);
     }
     FieldItemVector* instance_fields = new FieldItemVector();
     for (const ClassAccessor::Field& field : accessor.GetInstanceFields()) {
       FieldId* field_item = header_->FieldIds()[field.GetIndex()];
-      uint32_t access_flags = field.GetRawAccessFlags();
+      uint32_t access_flags = field.GetAccessFlags();
       instance_fields->emplace_back(access_flags, field_item);
     }
     // Direct methods.
@@ -1180,7 +1223,7 @@
 MethodItem BuilderMaps::GenerateMethodItem(const DexFile& dex_file,
                                            const ClassAccessor::Method& method) {
   MethodId* method_id = header_->MethodIds()[method.GetIndex()];
-  uint32_t access_flags = method.GetRawAccessFlags();
+  uint32_t access_flags = method.GetAccessFlags();
   const DexFile::CodeItem* disk_code_item = method.GetCodeItem();
   // Temporary hack to prevent incorrectly deduping code items if they have the same offset since
   // they may have different debug info streams.