Loading cmds/idmap2/idmap2/Lookup.cpp +14 −17 Original line number Diff line number Diff line Loading @@ -174,7 +174,7 @@ Result<Unit> Lookup(const std::vector<std::string>& args) { return Error("failed to parse config"); } std::vector<std::unique_ptr<const ApkAssets>> apk_assets; std::vector<AssetManager2::ApkAssetsPtr> apk_assets; std::string target_path; std::string target_package_name; for (size_t i = 0; i < idmap_paths.size(); i++) { Loading Loading @@ -217,13 +217,9 @@ Result<Unit> Lookup(const std::vector<std::string>& args) { apk_assets.push_back(std::move(overlay_apk)); } // AssetManager2::SetApkAssets requires raw ApkAssets pointers, not unique_ptrs std::vector<const ApkAssets*> raw_pointer_apk_assets; std::transform(apk_assets.cbegin(), apk_assets.cend(), std::back_inserter(raw_pointer_apk_assets), [](const auto& p) -> const ApkAssets* { return p.get(); }); AssetManager2 am; am.SetApkAssets(raw_pointer_apk_assets); am.SetConfiguration(config); { // Make sure |apk_assets| vector outlives the asset manager as it doesn't own the assets. AssetManager2 am(apk_assets, config); const Result<ResourceId> resid = ParseResReference(am, resid_str, target_package_name); if (!resid) { Loading @@ -235,6 +231,7 @@ Result<Unit> Lookup(const std::vector<std::string>& args) { return Error(value.GetError(), "resource 0x%08x not found", *resid); } std::cout << *value << std::endl; } return Unit{}; } cmds/idmap2/libidmap2/ResourceContainer.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -262,7 +262,7 @@ OverlayData CreateResourceMappingLegacy(const AssetManager2* overlay_am, } struct ResState { std::unique_ptr<ApkAssets> apk_assets; AssetManager2::ApkAssetsPtr apk_assets; const LoadedArsc* arsc; const LoadedPackage* package; std::unique_ptr<AssetManager2> am; Loading @@ -284,7 +284,7 @@ struct ResState { } state.am = std::make_unique<AssetManager2>(); if (!state.am->SetApkAssets({state.apk_assets.get()})) { if (!state.am->SetApkAssets({state.apk_assets})) { return Error("failed to create asset manager"); } Loading cmds/idmap2/tests/ResourceUtilsTests.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ class ResourceUtilsTests : public Idmap2Tests { apk_assets_ = ApkAssets::Load(GetTargetApkPath()); ASSERT_THAT(apk_assets_, NotNull()); am_.SetApkAssets({apk_assets_.get()}); am_.SetApkAssets({apk_assets_}); } const AssetManager2& GetAssetManager() { Loading @@ -47,7 +47,7 @@ class ResourceUtilsTests : public Idmap2Tests { private: AssetManager2 am_; std::unique_ptr<const ApkAssets> apk_assets_; AssetManager2::ApkAssetsPtr apk_assets_; }; TEST_F(ResourceUtilsTests, ResToTypeEntryName) { Loading core/java/android/content/res/AssetManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -528,6 +528,10 @@ public final class AssetManager implements AutoCloseable { if (!mOpen) { throw new RuntimeException("AssetManager has been closed"); } // Let's still check if the native object exists, given all the memory corruptions. if (mObject == 0) { throw new RuntimeException("AssetManager is open but the native object is gone"); } } /** Loading Loading @@ -1153,6 +1157,7 @@ public final class AssetManager implements AutoCloseable { int[] getAttributeResolutionStack(long themePtr, @AttrRes int defStyleAttr, @StyleRes int defStyleRes, @StyleRes int xmlStyle) { synchronized (this) { ensureValidLocked(); return nativeAttributeResolutionStack( mObject, themePtr, xmlStyle, defStyleAttr, defStyleRes); } Loading core/java/android/content/res/StringBlock.java +2 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ public final class StringBlock implements Closeable { private static final String TAG = "AssetManager"; private static final boolean localLOGV = false; private final long mNative; private long mNative; // final, but gets modified when closed private final boolean mUseSparse; private final boolean mOwnsNative; Loading Loading @@ -207,6 +207,7 @@ public final class StringBlock implements Closeable { if (mOwnsNative) { nativeDestroy(mNative); } mNative = 0; } } } Loading Loading
cmds/idmap2/idmap2/Lookup.cpp +14 −17 Original line number Diff line number Diff line Loading @@ -174,7 +174,7 @@ Result<Unit> Lookup(const std::vector<std::string>& args) { return Error("failed to parse config"); } std::vector<std::unique_ptr<const ApkAssets>> apk_assets; std::vector<AssetManager2::ApkAssetsPtr> apk_assets; std::string target_path; std::string target_package_name; for (size_t i = 0; i < idmap_paths.size(); i++) { Loading Loading @@ -217,13 +217,9 @@ Result<Unit> Lookup(const std::vector<std::string>& args) { apk_assets.push_back(std::move(overlay_apk)); } // AssetManager2::SetApkAssets requires raw ApkAssets pointers, not unique_ptrs std::vector<const ApkAssets*> raw_pointer_apk_assets; std::transform(apk_assets.cbegin(), apk_assets.cend(), std::back_inserter(raw_pointer_apk_assets), [](const auto& p) -> const ApkAssets* { return p.get(); }); AssetManager2 am; am.SetApkAssets(raw_pointer_apk_assets); am.SetConfiguration(config); { // Make sure |apk_assets| vector outlives the asset manager as it doesn't own the assets. AssetManager2 am(apk_assets, config); const Result<ResourceId> resid = ParseResReference(am, resid_str, target_package_name); if (!resid) { Loading @@ -235,6 +231,7 @@ Result<Unit> Lookup(const std::vector<std::string>& args) { return Error(value.GetError(), "resource 0x%08x not found", *resid); } std::cout << *value << std::endl; } return Unit{}; }
cmds/idmap2/libidmap2/ResourceContainer.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -262,7 +262,7 @@ OverlayData CreateResourceMappingLegacy(const AssetManager2* overlay_am, } struct ResState { std::unique_ptr<ApkAssets> apk_assets; AssetManager2::ApkAssetsPtr apk_assets; const LoadedArsc* arsc; const LoadedPackage* package; std::unique_ptr<AssetManager2> am; Loading @@ -284,7 +284,7 @@ struct ResState { } state.am = std::make_unique<AssetManager2>(); if (!state.am->SetApkAssets({state.apk_assets.get()})) { if (!state.am->SetApkAssets({state.apk_assets})) { return Error("failed to create asset manager"); } Loading
cmds/idmap2/tests/ResourceUtilsTests.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ class ResourceUtilsTests : public Idmap2Tests { apk_assets_ = ApkAssets::Load(GetTargetApkPath()); ASSERT_THAT(apk_assets_, NotNull()); am_.SetApkAssets({apk_assets_.get()}); am_.SetApkAssets({apk_assets_}); } const AssetManager2& GetAssetManager() { Loading @@ -47,7 +47,7 @@ class ResourceUtilsTests : public Idmap2Tests { private: AssetManager2 am_; std::unique_ptr<const ApkAssets> apk_assets_; AssetManager2::ApkAssetsPtr apk_assets_; }; TEST_F(ResourceUtilsTests, ResToTypeEntryName) { Loading
core/java/android/content/res/AssetManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -528,6 +528,10 @@ public final class AssetManager implements AutoCloseable { if (!mOpen) { throw new RuntimeException("AssetManager has been closed"); } // Let's still check if the native object exists, given all the memory corruptions. if (mObject == 0) { throw new RuntimeException("AssetManager is open but the native object is gone"); } } /** Loading Loading @@ -1153,6 +1157,7 @@ public final class AssetManager implements AutoCloseable { int[] getAttributeResolutionStack(long themePtr, @AttrRes int defStyleAttr, @StyleRes int defStyleRes, @StyleRes int xmlStyle) { synchronized (this) { ensureValidLocked(); return nativeAttributeResolutionStack( mObject, themePtr, xmlStyle, defStyleAttr, defStyleRes); } Loading
core/java/android/content/res/StringBlock.java +2 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ public final class StringBlock implements Closeable { private static final String TAG = "AssetManager"; private static final boolean localLOGV = false; private final long mNative; private long mNative; // final, but gets modified when closed private final boolean mUseSparse; private final boolean mOwnsNative; Loading Loading @@ -207,6 +207,7 @@ public final class StringBlock implements Closeable { if (mOwnsNative) { nativeDestroy(mNative); } mNative = 0; } } } Loading