Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename external_id_roots #908

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions opt/optimize_resources/OptimizeResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,20 @@ void OptimizeResourcesPass::run_pass(DexStoresVector& stores,
// Set of ID's directly accessible from the manifest or anims XML files,
// without walking any reference chains.
std::unordered_set<std::string> explored_xml_files;
std::unordered_set<uint32_t> external_id_roots;
std::unordered_set<uint32_t> manifest_roots;
const auto& xml_files = resources->find_all_xml_files();
for (const std::string& path : xml_files) {
if (path.find("AndroidManifest.xml") == std::string::npos) {
continue;
}
explored_xml_files.emplace(path);
const auto& id_roots = resources->get_xml_reference_attributes(path);
external_id_roots.insert(id_roots.begin(), id_roots.end());
manifest_roots.insert(id_roots.begin(), id_roots.end());
}
TRACE(OPTRES, 2, "Total external_id_roots count: %zu",
external_id_roots.size());
TRACE(OPTRES, 2, "Total manifest_roots count: %zu", manifest_roots.size());

// 4. Get all resources referenced by custom frameworks.
// 4. Get all resources referenced by custom frameworks and configuration
// options.
std::unordered_set<uint32_t> accessible_id_roots;
auto& plugin_registery = opt_res::ReachableResourcesPluginRegistry::get();
for (const auto& p : plugin_registery.get_plugins()) {
Expand All @@ -430,20 +430,28 @@ void OptimizeResourcesPass::run_pass(DexStoresVector& stores,
accessible_id_roots.insert(ids.begin(), ids.end());
}

// Configured roots by prefix.
std::unordered_set<uint32_t> assumed_reachable_roots =
get_resources_by_name_prefix(m_assume_reachable_prefixes,
res_table->name_to_ids);
TRACE(OPTRES, 2, "Total assumed_reachable_roots count: %zu",
assumed_reachable_roots.size());
// Configured roots by resource type. These should be traversed like any other
// reachable root.
std::unordered_set<uint32_t> disallowed_types =
res_table->get_types_by_name(m_disallowed_types);
std::unordered_set<uint32_t> disallowed_resouces =
get_disallowed_resources(res_table->sorted_res_ids, disallowed_types);

// 5a. Merge above resources (2, 3 & 4). These will be the 'roots' of all
// 5. Merge above resources (2, 3 & 4). These will be the 'roots' of all
// referenced resources. Then, compute the transitive closure of all the
// roots. This will be the set of all referenced resources (to be kept).
accessible_id_roots.insert(external_id_roots.begin(),
external_id_roots.end());
accessible_id_roots.insert(manifest_roots.begin(), manifest_roots.end());
accessible_id_roots.insert(ids_from_code.begin(), ids_from_code.end());
accessible_id_roots.insert(assumed_reachable_roots.begin(),
assumed_reachable_roots.end());
accessible_id_roots.insert(disallowed_resouces.begin(),
disallowed_resouces.end());

TRACE(OPTRES, 2, "Root resource count: %zu", accessible_id_roots.size());

Expand All @@ -452,16 +460,6 @@ void OptimizeResourcesPass::run_pass(DexStoresVector& stores,
accessible_id_roots, &nodes_visited,
&explored_xml_files);

// 5b. "Visit" all resources for any disallowed types. This will prevent any
// cleanup within the disallowed types.
std::unordered_set<uint32_t> disallowed_types =
res_table->get_types_by_name(m_disallowed_types);

std::unordered_set<uint32_t> disallowed_resouces =
get_disallowed_resources(res_table->sorted_res_ids, disallowed_types);

nodes_visited.insert(disallowed_resouces.begin(), disallowed_resouces.end());

// 6. Remove any unvisited resources. The removal of the unused
// files happens in step 11 (if configured) and cleanup of unused strings
// will happen from main.cpp (if configured by global options).
Expand Down
Loading