summaryrefslogtreecommitdiffstats
path: root/minui
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-05-04 06:53:11 +0200
committerTao Bao <tbao@google.com>2018-05-09 00:53:56 +0200
commit6cd816859e462e8741ced8dc24c00b7cd8304e2a (patch)
treeb4e2e9919eb1d0ed11c6dd330d42ffacd71b3db1 /minui
parentMerge "screen_ui: Drop the parameter in CheckBackgroundTextImages." (diff)
downloadandroid_bootable_recovery-6cd816859e462e8741ced8dc24c00b7cd8304e2a.tar
android_bootable_recovery-6cd816859e462e8741ced8dc24c00b7cd8304e2a.tar.gz
android_bootable_recovery-6cd816859e462e8741ced8dc24c00b7cd8304e2a.tar.bz2
android_bootable_recovery-6cd816859e462e8741ced8dc24c00b7cd8304e2a.tar.lz
android_bootable_recovery-6cd816859e462e8741ced8dc24c00b7cd8304e2a.tar.xz
android_bootable_recovery-6cd816859e462e8741ced8dc24c00b7cd8304e2a.tar.zst
android_bootable_recovery-6cd816859e462e8741ced8dc24c00b7cd8304e2a.zip
Diffstat (limited to '')
-rw-r--r--minui/include/private/resources.h3
-rw-r--r--minui/resources.cpp9
2 files changed, 10 insertions, 2 deletions
diff --git a/minui/include/private/resources.h b/minui/include/private/resources.h
index 2a83a1028..047ebe2e3 100644
--- a/minui/include/private/resources.h
+++ b/minui/include/private/resources.h
@@ -82,3 +82,6 @@ class PngHandler {
// After initialization, we'll keep the file pointer open before destruction of PngHandler.
std::unique_ptr<FILE, decltype(&fclose)> png_fp_{ nullptr, fclose };
};
+
+// Overrides the default resource dir, for testing purpose.
+void res_set_resource_dir(const std::string&);
diff --git a/minui/resources.cpp b/minui/resources.cpp
index 9f67cf844..c018d9b8c 100644
--- a/minui/resources.cpp
+++ b/minui/resources.cpp
@@ -32,7 +32,6 @@
#include <string>
#include <vector>
-#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <png.h>
@@ -40,6 +39,8 @@
#define SURFACE_DATA_ALIGNMENT 8
+static std::string g_resource_dir{ "/res/images" };
+
static GRSurface* malloc_surface(size_t data_size) {
size_t size = sizeof(GRSurface) + data_size + SURFACE_DATA_ALIGNMENT;
unsigned char* temp = static_cast<unsigned char*>(malloc(size));
@@ -51,7 +52,7 @@ static GRSurface* malloc_surface(size_t data_size) {
}
PngHandler::PngHandler(const std::string& name) {
- std::string res_path = android::base::StringPrintf("/res/images/%s.png", name.c_str());
+ std::string res_path = g_resource_dir + "/" + name + ".png";
png_fp_.reset(fopen(res_path.c_str(), "rbe"));
// Try to read from |name| if the resource path does not work.
if (!png_fp_) {
@@ -340,6 +341,10 @@ int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
return 0;
}
+void res_set_resource_dir(const std::string& dirname) {
+ g_resource_dir = dirname;
+}
+
// This function tests if a locale string stored in PNG (prefix) matches
// the locale string provided by the system (locale).
bool matches_locale(const std::string& prefix, const std::string& locale) {