tests: Add tests for ScreenRecoveryUI.

In order to support that, this CL adds Paths::set_resource_dir() to
override the default resource dir ("/res/images/") that's only available
under recovery. Note that since there're external modules depending on
libminui, it adds a separate function of res_set_resource_dir(), instead
of requiring the dependency on libotautil for everyone.

Test: mmma -j bootable/recovery
Test: Run recovery_unit_test on marlin.
Change-Id: I0a7dcf4476808bea9e634eaffc9676f6cbaf92b7
This commit is contained in:
Tao Bao
2018-05-08 15:53:56 -07:00
parent 1f3a9c0a43
commit 6cd816859e
10 changed files with 205 additions and 15 deletions
+7 -2
View File
@@ -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) {