diff options
author | 2023-11-08 12:20:24 -0800 | |
---|---|---|
committer | 2023-12-05 13:12:53 -0800 | |
commit | deb46f31bf04f17e8a636ec2eead8f75268f64ec (patch) | |
tree | b9aa91d5b4d1cd9558e8154cbe96009ee4cc74bb /libs/androidfw/FileStream.cpp | |
parent | 87f82bb9ba06450ebba5b65261dc707761dea54a (diff) |
Handle 9patches being used for frros
This adds an api that allows creation of nine patch frros.
We process them the same as aapt2 does so that
when they are used at runtime they work correctly.
API-Coverage-Bug: 314168567
Test: manual and automatic
Bug: 296324826
Change-Id: I40da020189e9ec914fbea0c17f181209347d83de
Diffstat (limited to 'libs/androidfw/FileStream.cpp')
-rw-r--r-- | libs/androidfw/FileStream.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/libs/androidfw/FileStream.cpp b/libs/androidfw/FileStream.cpp index b86c9cb729d4..e8989490fe2c 100644 --- a/libs/androidfw/FileStream.cpp +++ b/libs/androidfw/FileStream.cpp @@ -22,6 +22,7 @@ #include "android-base/errors.h" #include "android-base/file.h" // for O_BINARY +#include "android-base/logging.h" #include "android-base/macros.h" #include "android-base/utf8.h" @@ -37,9 +38,9 @@ using ::android::base::unique_fd; namespace android { FileInputStream::FileInputStream(const std::string& path, size_t buffer_capacity) - : buffer_capacity_(buffer_capacity) { + : should_close_(true), buffer_capacity_(buffer_capacity) { int mode = O_RDONLY | O_CLOEXEC | O_BINARY; - fd_.reset(TEMP_FAILURE_RETRY(::android::base::utf8::open(path.c_str(), mode))); + fd_ = TEMP_FAILURE_RETRY(::android::base::utf8::open(path.c_str(), mode)); if (fd_ == -1) { error_ = SystemErrorCodeToString(errno); } else { @@ -48,7 +49,17 @@ FileInputStream::FileInputStream(const std::string& path, size_t buffer_capacity } FileInputStream::FileInputStream(int fd, size_t buffer_capacity) - : fd_(fd), buffer_capacity_(buffer_capacity) { + : fd_(fd), should_close_(true), buffer_capacity_(buffer_capacity) { + if (fd_ < 0) { + error_ = "Bad File Descriptor"; + } else { + buffer_.reset(new uint8_t[buffer_capacity_]); + } +} + +FileInputStream::FileInputStream(android::base::borrowed_fd fd, size_t buffer_capacity) + : fd_(fd.get()), should_close_(false), buffer_capacity_(buffer_capacity) { + if (fd_ < 0) { error_ = "Bad File Descriptor"; } else { @@ -56,6 +67,7 @@ FileInputStream::FileInputStream(int fd, size_t buffer_capacity) } } + bool FileInputStream::Next(const void** data, size_t* size) { if (HadError()) { return false; @@ -73,7 +85,12 @@ bool FileInputStream::Next(const void** data, size_t* size) { ssize_t n = TEMP_FAILURE_RETRY(read(fd_, buffer_.get(), buffer_capacity_)); if (n < 0) { error_ = SystemErrorCodeToString(errno); - fd_.reset(); + if (fd_ != -1) { + if (should_close_) { + close(fd_); + } + fd_ = -1; + } buffer_.reset(); return false; } |