summaryrefslogtreecommitdiff
path: root/libs/androidfw/AssetsProvider.cpp
diff options
context:
space:
mode:
author Yurii Zubrytskyi <zyy@google.com> 2022-11-30 16:47:23 -0800
committer Yurii Zubrytskyi <zyy@google.com> 2022-11-30 17:46:04 -0800
commit801c44115ecdee5511160f1837b514dd274f6a32 (patch)
tree8e6f4e47a20843b917ea0152af3b3b89a7072788 /libs/androidfw/AssetsProvider.cpp
parent29764a29995ecfaeabc8ac5f957dadcc0c827f59 (diff)
[res] Properly create ZipAssetsProvider with fd
Bug: 237583012 Test: atest com.android.overlaytest Change-Id: If79b4297edfcefe72bf579b50931a40f73bdfd58
Diffstat (limited to 'libs/androidfw/AssetsProvider.cpp')
-rw-r--r--libs/androidfw/AssetsProvider.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/libs/androidfw/AssetsProvider.cpp b/libs/androidfw/AssetsProvider.cpp
index 80e560747a3e..24460a4c0867 100644
--- a/libs/androidfw/AssetsProvider.cpp
+++ b/libs/androidfw/AssetsProvider.cpp
@@ -92,16 +92,19 @@ ZipAssetsProvider::ZipAssetsProvider(ZipArchiveHandle handle, PathOrDebugName&&
last_mod_time_(last_mod_time) {}
std::unique_ptr<ZipAssetsProvider> ZipAssetsProvider::Create(std::string path,
- package_property_t flags) {
+ package_property_t flags,
+ base::unique_fd fd) {
+ const auto released_fd = fd.ok() ? fd.release() : -1;
ZipArchiveHandle handle;
- if (int32_t result = OpenArchive(path.c_str(), &handle); result != 0) {
+ if (int32_t result = released_fd < 0 ? OpenArchive(path.c_str(), &handle)
+ : OpenArchiveFd(released_fd, path.c_str(), &handle)) {
LOG(ERROR) << "Failed to open APK '" << path << "': " << ::ErrorCodeString(result);
CloseArchive(handle);
return {};
}
struct stat sb{.st_mtime = -1};
- if (stat(path.c_str(), &sb) < 0) {
+ if ((released_fd < 0 ? stat(path.c_str(), &sb) : fstat(released_fd, &sb)) < 0) {
// Stat requires execute permissions on all directories path to the file. If the process does
// not have execute permissions on this file, allow the zip to be opened but IsUpToDate() will
// always have to return true.