[go: up one dir, main page]

Skip to content

Commit

Permalink
Rename ApkManager to AssetManager
Browse files Browse the repository at this point in the history
Summary: This class seems to only exist to put files into the assets folder. Since we're going to work on .apk files and .aab files, the name `ApkManager` doesn't quite fit, so rename it (even though "AssetManager" is something specific within the Android SDK, I don't think it's that confusing to use it here too).

Reviewed By: ssj933

Differential Revision: D28917350

fbshipit-source-id: a4dda7b4364b948de5f749c881935aebe4d4c7ac
  • Loading branch information
wsanville authored and facebook-github-bot committed Jun 7, 2021
1 parent af38617 commit 1b51a88
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ libredex_la_SOURCES = \
libredex/AnalysisUsage.cpp \
libredex/AnnoUtils.cpp \
libredex/ApiLevelChecker.cpp \
libredex/ApkManager.cpp \
libredex/ApkResources.cpp \
libredex/AssetManager.cpp \
libredex/BigBlocks.cpp \
libredex/BundleResources.cpp \
libredex/CFGMutation.cpp \
Expand Down
10 changes: 5 additions & 5 deletions libredex/ApkManager.cpp → libredex/AssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include "ApkManager.h"
#include "AssetManager.h"

#include <boost/filesystem.hpp>
#include <iostream>
Expand Down Expand Up @@ -33,7 +33,7 @@ void check_directory(std::string& dir) {

} // namespace

bool ApkManager::has_asset_dir() {
bool AssetManager::has_asset_dir() {
if (m_apk_dir.empty()) {
return false;
}
Expand All @@ -44,9 +44,9 @@ bool ApkManager::has_asset_dir() {
return boost::filesystem::is_directory(assets_dir.c_str());
}

std::shared_ptr<FILE*> ApkManager::new_asset_file(const char* filename,
const char* dir_path,
bool new_dir) {
std::shared_ptr<FILE*> AssetManager::new_asset_file(const char* filename,
const char* dir_path,
bool new_dir) {
check_directory(m_apk_dir);
std::ostringstream path;
path << m_apk_dir << dir_path;
Expand Down
6 changes: 3 additions & 3 deletions libredex/ApkManager.h → libredex/AssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#include <string>
#include <vector>

class ApkManager {
class AssetManager {
public:
explicit ApkManager(std::string apk_dir) : m_apk_dir(std::move(apk_dir)) {}
explicit AssetManager(std::string apk_dir) : m_apk_dir(std::move(apk_dir)) {}

virtual ~ApkManager() {
virtual ~AssetManager() {
for (auto& fd : m_files) {
if (*fd != nullptr) {
fclose(*fd);
Expand Down
4 changes: 2 additions & 2 deletions libredex/PassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "AnalysisUsage.h"
#include "ApiLevelChecker.h"
#include "ApkManager.h"
#include "AssetManager.h"
#include "CommandProfiling.h"
#include "ConfigFiles.h"
#include "Debug.h"
Expand Down Expand Up @@ -819,7 +819,7 @@ PassManager::PassManager(
std::unique_ptr<keep_rules::ProguardConfiguration> pg_config,
const Json::Value& config,
const RedexOptions& options)
: m_apk_mgr(get_apk_dir(config)),
: m_asset_mgr(get_apk_dir(config)),
m_registered_passes(passes),
m_current_pass_info(nullptr),
m_pg_config(std::move(pg_config)),
Expand Down
6 changes: 3 additions & 3 deletions libredex/PassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <vector>

#include "AnalysisUsage.h"
#include "ApkManager.h"
#include "AssetManager.h"
#include "DexHasher.h"
#include "JsonWrapper.h"
#include "ProguardConfiguration.h"
Expand Down Expand Up @@ -88,7 +88,7 @@ class PassManager {

const PassInfo* get_current_pass_info() const { return m_current_pass_info; }

ApkManager& apk_manager() { return m_apk_mgr; }
AssetManager& asset_manager() { return m_asset_mgr; }

void record_running_regalloc() { m_regalloc_has_run = true; }
bool regalloc_has_run() const { return m_regalloc_has_run; }
Expand Down Expand Up @@ -122,7 +122,7 @@ class PassManager {

void eval_passes(DexStoresVector&, ConfigFiles&);

ApkManager m_apk_mgr;
AssetManager m_asset_mgr;
std::vector<Pass*> m_registered_passes;
std::vector<Pass*> m_activated_passes;
std::unordered_map<AnalysisID, Pass*> m_preserved_analysis_passes;
Expand Down
2 changes: 1 addition & 1 deletion libredex/PostLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NoopPostLowering : public PostLowering {
public:
void sync() override {}
void run(const DexStoresVector& stores) override {}
void finalize(ApkManager& mgr) override {}
void finalize(AssetManager& mgr) override {}

std::unordered_map<DexClass*, std::vector<DexMethod*>> get_detached_methods()
override {
Expand Down
4 changes: 2 additions & 2 deletions libredex/PostLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <boost/optional/optional.hpp>
#include <string>

#include "ApkManager.h"
#include "AssetManager.h"
#include "DexClass.h"
#include "DexStore.h"
#include "IODIMetadata.h"
Expand All @@ -21,7 +21,7 @@ class PostLowering {

virtual void sync() = 0;
virtual void run(const DexStoresVector& stores) = 0;
virtual void finalize(ApkManager& mgr) = 0;
virtual void finalize(AssetManager& mgr) = 0;

virtual std::unordered_map<DexClass*, std::vector<DexMethod*>>
get_detached_methods() = 0;
Expand Down
4 changes: 2 additions & 2 deletions opt/interdex/InterDex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,8 @@ void InterDex::run() {
}

// Emit dex info manifest
if (m_apk_manager.has_asset_dir()) {
auto mixed_mode_file = m_apk_manager.new_asset_file("dex_manifest.txt");
if (m_asset_manager.has_asset_dir()) {
auto mixed_mode_file = m_asset_manager.new_asset_file("dex_manifest.txt");
auto mixed_mode_fh = FileHandle(*mixed_mode_file);
mixed_mode_fh.seek_end();
std::stringstream ss;
Expand Down
8 changes: 4 additions & 4 deletions opt/interdex/InterDex.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <unordered_set>

#include "ApkManager.h"
#include "AssetManager.h"
#include "CrossDexRefMinimizer.h"
#include "CrossDexRelocator.h"
#include "DexClass.h"
Expand All @@ -27,7 +27,7 @@ class InterDex {
public:
InterDex(const Scope& original_scope,
const DexClassesVector& dexen,
ApkManager& apk_manager,
AssetManager& asset_manager,
ConfigFiles& conf,
std::vector<std::unique_ptr<InterDexPassPlugin>>& plugins,
int64_t linear_alloc_limit,
Expand All @@ -47,7 +47,7 @@ class InterDex {
int min_sdk,
bool sort_remaining_classes)
: m_dexen(dexen),
m_apk_manager(apk_manager),
m_asset_manager(asset_manager),
m_conf(conf),
m_plugins(plugins),
m_static_prune_classes(static_prune_classes),
Expand Down Expand Up @@ -156,7 +156,7 @@ class InterDex {

const DexClassesVector& m_dexen;
DexClassesVector m_outdex;
ApkManager& m_apk_manager;
AssetManager& m_asset_manager;
ConfigFiles& m_conf;
std::vector<std::unique_ptr<InterDexPassPlugin>>& m_plugins;
// TODO: Encapsulate (primary|all) dex flags under one config.
Expand Down
4 changes: 2 additions & 2 deletions opt/interdex/InterDexPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void InterDexPass::run_pass(
mgr.set_metric(METRIC_RESERVED_MREFS, refs_info.mrefs);

bool force_single_dex = conf.get_json_config().get("force_single_dex", false);
InterDex interdex(original_scope, dexen, mgr.apk_manager(), conf, plugins,
InterDex interdex(original_scope, dexen, mgr.asset_manager(), conf, plugins,
m_linear_alloc_limit, m_static_prune, m_normal_primary_dex,
m_keep_primary_order, force_single_dex, m_emit_canaries,
m_minimize_cross_dex_refs, m_minimize_cross_dex_refs_config,
Expand Down Expand Up @@ -205,7 +205,7 @@ void InterDexPass::run_pass_on_nonroot_store(const Scope& original_scope,
CrossDexRelocatorConfig cross_dex_relocator_config;

// Initialize interdex and run for nonroot store
InterDex interdex(original_scope, dexen, mgr.apk_manager(), conf, plugins,
InterDex interdex(original_scope, dexen, mgr.asset_manager(), conf, plugins,
m_linear_alloc_limit, m_static_prune, m_normal_primary_dex,
m_keep_primary_order, false /* force single dex */,
false /* emit canaries */,
Expand Down
2 changes: 1 addition & 1 deletion opt/interdex/MixedModeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <unordered_set>

#include "ApkManager.h"
#include "AssetManager.h"
#include "DexClass.h"

namespace interdex {
Expand Down
2 changes: 1 addition & 1 deletion tools/redex-all/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ void redex_backend(ConfigFiles& conf,
signatures);
}
post_lowering->run(stores);
post_lowering->finalize(manager.apk_manager());
post_lowering->finalize(manager.asset_manager());
}

{
Expand Down

0 comments on commit 1b51a88

Please sign in to comment.