Merge "Set ApkAssets path for fabricated rros" into sc-dev

This commit is contained in:
Ryan Mitchell
2021-05-13 22:33:17 +00:00
committed by Android (Google) Code Review
6 changed files with 42 additions and 26 deletions

View File

@@ -88,7 +88,7 @@ std::unique_ptr<ApkAssets> ApkAssets::LoadOverlay(const std::string& idmap_path,
if (IsFabricatedOverlay(overlay_path)) { if (IsFabricatedOverlay(overlay_path)) {
// Fabricated overlays do not contain resource definitions. All of the overlay resource values // Fabricated overlays do not contain resource definitions. All of the overlay resource values
// are defined inline in the idmap. // are defined inline in the idmap.
overlay_assets = EmptyAssetsProvider::Create(); overlay_assets = EmptyAssetsProvider::Create(overlay_path);
} else { } else {
// The overlay should be an APK. // The overlay should be an APK.
overlay_assets = ZipAssetsProvider::Create(overlay_path); overlay_assets = ZipAssetsProvider::Create(overlay_path);

View File

@@ -612,6 +612,11 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry(
result->entry = overlay_entry.GetInlineValue(); result->entry = overlay_entry.GetInlineValue();
result->dynamic_ref_table = id_map.overlay_res_maps_.GetOverlayDynamicRefTable(); result->dynamic_ref_table = id_map.overlay_res_maps_.GetOverlayDynamicRefTable();
result->cookie = id_map.cookie; result->cookie = id_map.cookie;
if (UNLIKELY(logging_enabled)) {
last_resolution_.steps.push_back(
Resolution::Step{Resolution::Step::Type::OVERLAID_INLINE, String8(), result->cookie});
}
continue; continue;
} }
@@ -640,7 +645,6 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry(
if (UNLIKELY(logging_enabled)) { if (UNLIKELY(logging_enabled)) {
last_resolution_.steps.push_back( last_resolution_.steps.push_back(
Resolution::Step{Resolution::Step::Type::OVERLAID, overlay_result->config.toString(), Resolution::Step{Resolution::Step::Type::OVERLAID, overlay_result->config.toString(),
overlay_result->package_name,
overlay_result->cookie}); overlay_result->cookie});
} }
} }
@@ -723,7 +727,6 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
if (UNLIKELY(logging_enabled)) { if (UNLIKELY(logging_enabled)) {
resolution_steps.push_back(Resolution::Step{Resolution::Step::Type::SKIPPED, resolution_steps.push_back(Resolution::Step{Resolution::Step::Type::SKIPPED,
this_config.toString(), this_config.toString(),
&loaded_package->GetPackageName(),
cookie}); cookie});
} }
continue; continue;
@@ -741,7 +744,6 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
if (UNLIKELY(logging_enabled)) { if (UNLIKELY(logging_enabled)) {
resolution_steps.push_back(Resolution::Step{Resolution::Step::Type::NO_ENTRY, resolution_steps.push_back(Resolution::Step{Resolution::Step::Type::NO_ENTRY,
this_config.toString(), this_config.toString(),
&loaded_package->GetPackageName(),
cookie}); cookie});
} }
continue; continue;
@@ -756,7 +758,6 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
if (UNLIKELY(logging_enabled)) { if (UNLIKELY(logging_enabled)) {
last_resolution_.steps.push_back(Resolution::Step{resolution_type, last_resolution_.steps.push_back(Resolution::Step{resolution_type,
this_config.toString(), this_config.toString(),
&loaded_package->GetPackageName(),
cookie}); cookie});
} }
@@ -839,16 +840,16 @@ std::string AssetManager2::GetLastResourceResolution() const {
} }
std::stringstream log_stream; std::stringstream log_stream;
log_stream << base::StringPrintf("Resolution for 0x%08x ", resid) log_stream << base::StringPrintf("Resolution for 0x%08x %s\n"
<< resource_name_string "\tFor config - %s", resid, resource_name_string.c_str(),
<< "\n\tFor config -" configuration_.toString().c_str());
<< configuration_.toString();
for (const Resolution::Step& step : last_resolution_.steps) { for (const Resolution::Step& step : last_resolution_.steps) {
const static std::unordered_map<Resolution::Step::Type, const char*> kStepStrings = { const static std::unordered_map<Resolution::Step::Type, const char*> kStepStrings = {
{Resolution::Step::Type::INITIAL, "Found initial"}, {Resolution::Step::Type::INITIAL, "Found initial"},
{Resolution::Step::Type::BETTER_MATCH, "Found better"}, {Resolution::Step::Type::BETTER_MATCH, "Found better"},
{Resolution::Step::Type::OVERLAID, "Overlaid"}, {Resolution::Step::Type::OVERLAID, "Overlaid"},
{Resolution::Step::Type::OVERLAID_INLINE, "Overlaid inline"},
{Resolution::Step::Type::SKIPPED, "Skipped"}, {Resolution::Step::Type::SKIPPED, "Skipped"},
{Resolution::Step::Type::NO_ENTRY, "No entry"} {Resolution::Step::Type::NO_ENTRY, "No entry"}
}; };
@@ -858,8 +859,7 @@ std::string AssetManager2::GetLastResourceResolution() const {
continue; continue;
} }
log_stream << "\n\t" << prefix->second << ": " << *step.package_name << " (" log_stream << "\n\t" << prefix->second << ": " << apk_assets_[step.cookie]->GetDebugName();
<< apk_assets_[step.cookie]->GetDebugName() << ")";
if (!step.config_name.isEmpty()) { if (!step.config_name.isEmpty()) {
log_stream << " - " << step.config_name; log_stream << " - " << step.config_name;
} }

View File

@@ -386,8 +386,15 @@ bool MultiAssetsProvider::IsUpToDate() const {
return primary_->IsUpToDate() && secondary_->IsUpToDate(); return primary_->IsUpToDate() && secondary_->IsUpToDate();
} }
EmptyAssetsProvider::EmptyAssetsProvider(std::optional<std::string>&& path) :
path_(std::move(path)) {}
std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create() { std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create() {
return std::make_unique<EmptyAssetsProvider>(); return std::unique_ptr<EmptyAssetsProvider>(new EmptyAssetsProvider({}));
}
std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create(const std::string& path) {
return std::unique_ptr<EmptyAssetsProvider>(new EmptyAssetsProvider(path));
} }
std::unique_ptr<Asset> EmptyAssetsProvider::OpenInternal(const std::string& /* path */, std::unique_ptr<Asset> EmptyAssetsProvider::OpenInternal(const std::string& /* path */,
@@ -406,10 +413,16 @@ bool EmptyAssetsProvider::ForEachFile(
} }
std::optional<std::string_view> EmptyAssetsProvider::GetPath() const { std::optional<std::string_view> EmptyAssetsProvider::GetPath() const {
if (path_.has_value()) {
return *path_;
}
return {}; return {};
} }
const std::string& EmptyAssetsProvider::GetDebugName() const { const std::string& EmptyAssetsProvider::GetDebugName() const {
if (path_.has_value()) {
return *path_;
}
const static std::string kEmpty = kEmptyDebugString; const static std::string kEmpty = kEmptyDebugString;
return kEmpty; return kEmpty;
} }

View File

@@ -458,6 +458,7 @@ class AssetManager2 {
INITIAL, INITIAL,
BETTER_MATCH, BETTER_MATCH,
OVERLAID, OVERLAID,
OVERLAID_INLINE,
SKIPPED, SKIPPED,
NO_ENTRY, NO_ENTRY,
}; };
@@ -468,10 +469,6 @@ class AssetManager2 {
// Built name of configuration for this step. // Built name of configuration for this step.
String8 config_name; String8 config_name;
// Marks the package name of the better resource found in this step.
const std::string* package_name;
//
ApkAssetsCookie cookie = kInvalidCookie; ApkAssetsCookie cookie = kInvalidCookie;
}; };

View File

@@ -176,6 +176,7 @@ struct MultiAssetsProvider : public AssetsProvider {
// Does not provide any assets. // Does not provide any assets.
struct EmptyAssetsProvider : public AssetsProvider { struct EmptyAssetsProvider : public AssetsProvider {
static std::unique_ptr<AssetsProvider> Create(); static std::unique_ptr<AssetsProvider> Create();
static std::unique_ptr<AssetsProvider> Create(const std::string& path);
bool ForEachFile(const std::string& path, bool ForEachFile(const std::string& path,
const std::function<void(const StringPiece&, FileType)>& f) const override; const std::function<void(const StringPiece&, FileType)>& f) const override;
@@ -188,6 +189,10 @@ struct EmptyAssetsProvider : public AssetsProvider {
protected: protected:
std::unique_ptr<Asset> OpenInternal(const std::string& path, Asset::AccessMode mode, std::unique_ptr<Asset> OpenInternal(const std::string& path, Asset::AccessMode mode,
bool* file_exists) const override; bool* file_exists) const override;
private:
explicit EmptyAssetsProvider(std::optional<std::string>&& path);
std::optional<std::string> path_;
}; };
} // namespace android } // namespace android

View File

@@ -765,7 +765,8 @@ TEST_F(AssetManager2Test, GetLastPathWithSingleApkAssets) {
auto result = assetmanager.GetLastResourceResolution(); auto result = assetmanager.GetLastResourceResolution();
EXPECT_EQ("Resolution for 0x7f030000 com.android.basic:string/test1\n" EXPECT_EQ("Resolution for 0x7f030000 com.android.basic:string/test1\n"
"\tFor config -de\n\tFound initial: com.android.basic (basic/basic.apk)", result); "\tFor config - de\n"
"\tFound initial: basic/basic.apk", result);
} }
TEST_F(AssetManager2Test, GetLastPathWithMultipleApkAssets) { TEST_F(AssetManager2Test, GetLastPathWithMultipleApkAssets) {
@@ -785,8 +786,8 @@ TEST_F(AssetManager2Test, GetLastPathWithMultipleApkAssets) {
auto result = assetmanager.GetLastResourceResolution(); auto result = assetmanager.GetLastResourceResolution();
EXPECT_EQ("Resolution for 0x7f030000 com.android.basic:string/test1\n" EXPECT_EQ("Resolution for 0x7f030000 com.android.basic:string/test1\n"
"\tFor config - de\n" "\tFor config - de\n"
"\tFound initial: com.android.basic (basic/basic.apk)\n" "\tFound initial: basic/basic.apk\n"
"\tFound better: com.android.basic (basic/basic_de_fr.apk) -de", result); "\tFound better: basic/basic_de_fr.apk - de", result);
} }
TEST_F(AssetManager2Test, GetLastPathAfterDisablingReturnsEmpty) { TEST_F(AssetManager2Test, GetLastPathAfterDisablingReturnsEmpty) {