Themes: Reference app resource when compiling theme [1/2]

This allows us to pass in the path to the target apk as an additional
included resource apk, allowing theme designers to reference styles
and attributes from the original package without needing to duplicate
them.  Duplicating attributes never worked quite well, and causes
all sorts of issues, including crashing apps.

Instead of a theme declaring attributes, that are app specific, it
simply reference the originals.  This way things like colors that
are style specific get included correctly.

Here's an example of stat_sys_wifi_signal_4_fully.xml using this feature.
By using ?com.android.systemui:attr/ we are able to reference attributes
defined in SystemUI directly in our themed resource.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="17.25dp"
    android:height="18dp"
    android:viewportWidth="46.0"
    android:viewportHeight="48.0">

    <path
        android:fillColor="?com.android.systemui:attr/backgroundColor"
        android:pathData="M20.4,18.0"/>
    <path
        android:fillColor="?com.android.systemui:attr/fillColor"
        android:pathData="M42.0,32.0l0.0,-4.0L26.0,18.0L26.0,7.0c0.0,-1.7 -1.3,-3.0 -3.0,
        -3.0c-1.7,0.0 -3.0,1.3 -3.0,3.0l0.0,11.0L4.0,28.0l0.0,4.0l16.0,-5.0l0.0,11.0l-4.0,
        3.0l0.0,3.0l7.0,-2.0l7.0,2.0l0.0,-3.0l-4.0,-3.0L26.0,27.0L42.0,32.0z"/>
</vector>

Change-Id: Ic00b5d91fc651a29a8c3ab341e5494107acd0463
TICKET: CYNGNOS-1645
This commit is contained in:
d34d 2016-01-18 19:41:38 -08:00 committed by Clark Scheff
parent 8af4e664d9
commit 7c2be690f4
3 changed files with 39 additions and 29 deletions

View File

@ -1721,7 +1721,8 @@ fail:
} }
static void run_aapt(const char *source_apk, const char *internal_path, static void run_aapt(const char *source_apk, const char *internal_path,
int resapk_fd, int pkgId, int min_sdk_version, const char *common_res_path) int resapk_fd, int pkgId, int min_sdk_version,
const char *app_res_path, const char *common_res_path)
{ {
static const char *AAPT_BIN = "/system/bin/aapt"; static const char *AAPT_BIN = "/system/bin/aapt";
static const char *MANIFEST = "/data/app/AndroidManifest.xml"; static const char *MANIFEST = "/data/app/AndroidManifest.xml";
@ -1735,7 +1736,9 @@ static void run_aapt(const char *source_apk, const char *internal_path,
snprintf(resapk_str, sizeof(resapk_str), "%d", resapk_fd); snprintf(resapk_str, sizeof(resapk_str), "%d", resapk_fd);
snprintf(pkgId_str, sizeof(pkgId_str), "%d", pkgId); snprintf(pkgId_str, sizeof(pkgId_str), "%d", pkgId);
snprintf(minSdkVersion_str, sizeof(minSdkVersion_str), "%d", min_sdk_version); snprintf(minSdkVersion_str, sizeof(minSdkVersion_str), "%d", min_sdk_version);
bool hasCommonResources = (common_res_path != NULL && common_res_path[0] != '\0'); bool hasCommonResources = (common_res_path != NULL && common_res_path[0] != '\0');
bool hasAppResources = (app_res_path != NULL && app_res_path[0] != '\0');
if (hasCommonResources) { if (hasCommonResources) {
execl(AAPT_BIN, AAPT_BIN, "package", execl(AAPT_BIN, AAPT_BIN, "package",
@ -1744,10 +1747,12 @@ static void run_aapt(const char *source_apk, const char *internal_path,
"-S", source_apk, "-S", source_apk,
"-X", internal_path, "-X", internal_path,
"-I", FRAMEWORK_RES, "-I", FRAMEWORK_RES,
"-I", common_res_path,
"-r", resapk_str, "-r", resapk_str,
"-x", pkgId_str, "-x", pkgId_str,
"-f", "-f",
"-I", common_res_path,
hasAppResources ? "-I" : (char*)NULL,
hasAppResources ? app_res_path : (char*) NULL,
(char*)NULL); (char*)NULL);
} else { } else {
execl(AAPT_BIN, AAPT_BIN, "package", execl(AAPT_BIN, AAPT_BIN, "package",
@ -1759,16 +1764,20 @@ static void run_aapt(const char *source_apk, const char *internal_path,
"-r", resapk_str, "-r", resapk_str,
"-x", pkgId_str, "-x", pkgId_str,
"-f", "-f",
hasAppResources ? "-I" : (char*)NULL,
hasAppResources ? app_res_path : (char*) NULL,
(char*)NULL); (char*)NULL);
} }
ALOGE("execl(%s) failed: %s\n", AAPT_BIN, strerror(errno)); ALOGE("execl(%s) failed: %s\n", AAPT_BIN, strerror(errno));
} }
int aapt(const char *source_apk, const char *internal_path, const char *out_restable, uid_t uid, int aapt(const char *source_apk, const char *internal_path, const char *out_restable, uid_t uid,
int pkgId, int min_sdk_version, const char *common_res_path) int pkgId, int min_sdk_version, const char *app_res_path, const char *common_res_path)
{ {
ALOGD("aapt source_apk=%s internal_path=%s out_restable=%s uid=%d, pkgId=%d,min_sdk_version=%d, common_res_path=%s", ALOGD("aapt source_apk=%s internal_path=%s out_restable=%s uid=%d, pkgId=%d,min_sdk_version=%d,\
source_apk, internal_path, out_restable, uid, pkgId, min_sdk_version, common_res_path); app_res_path=%s, common_res_path=%s",
source_apk, internal_path, out_restable, uid, pkgId, min_sdk_version, app_res_path,
common_res_path);
static const int PARENT_READ_PIPE = 0; static const int PARENT_READ_PIPE = 0;
static const int CHILD_WRITE_PIPE = 1; static const int CHILD_WRITE_PIPE = 1;
@ -1828,7 +1837,8 @@ int aapt(const char *source_apk, const char *internal_path, const char *out_rest
} }
} }
run_aapt(source_apk, internal_path, resapk_fd, pkgId, min_sdk_version, common_res_path); run_aapt(source_apk, internal_path, resapk_fd, pkgId, min_sdk_version, app_res_path,
common_res_path);
close(resapk_fd); close(resapk_fd);
if (pipefd[CHILD_WRITE_PIPE] > 0) { if (pipefd[CHILD_WRITE_PIPE] > 0) {

View File

@ -163,12 +163,12 @@ static int do_idmap(char **arg, char reply[REPLY_MAX] __unused)
static int do_aapt(char **arg, char reply[REPLY_MAX] __unused) static int do_aapt(char **arg, char reply[REPLY_MAX] __unused)
{ {
return aapt(arg[0], arg[1], arg[2], atoi(arg[3]), atoi(arg[4]), atoi(arg[5]), ""); return aapt(arg[0], arg[1], arg[2], atoi(arg[3]), atoi(arg[4]), atoi(arg[5]), arg[6], "");
} }
static int do_aapt_with_common(char **arg, char reply[REPLY_MAX] __unused) static int do_aapt_with_common(char **arg, char reply[REPLY_MAX] __unused)
{ {
return aapt(arg[0], arg[1], arg[2], atoi(arg[3]), atoi(arg[4]), atoi(arg[5]), arg[6]); return aapt(arg[0], arg[1], arg[2], atoi(arg[3]), atoi(arg[4]), atoi(arg[5]), arg[6], arg[7]);
} }
static int do_restorecon_data(char **arg, char reply[REPLY_MAX] __attribute__((unused))) static int do_restorecon_data(char **arg, char reply[REPLY_MAX] __attribute__((unused)))
@ -223,8 +223,8 @@ struct cmdinfo cmds[] = {
{ "mkuserconfig", 1, do_mk_user_config }, { "mkuserconfig", 1, do_mk_user_config },
{ "rmuser", 2, do_rm_user }, { "rmuser", 2, do_rm_user },
{ "idmap", 6, do_idmap }, { "idmap", 6, do_idmap },
{ "aapt", 6, do_aapt }, { "aapt", 7, do_aapt },
{ "aapt_with_common", 7, do_aapt_with_common }, { "aapt_with_common", 8, do_aapt_with_common },
{ "restorecondata", 4, do_restorecon_data }, { "restorecondata", 4, do_restorecon_data },
{ "createoatdir", 2, do_create_oat_dir }, { "createoatdir", 2, do_create_oat_dir },
{ "rmpackagedir", 1, do_rm_package_dir }, { "rmpackagedir", 1, do_rm_package_dir },

View File

@ -253,7 +253,7 @@ int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int u
int idmap(const char *target_path, const char *overlay_path, const char *cache_path, uid_t uid, int idmap(const char *target_path, const char *overlay_path, const char *cache_path, uid_t uid,
uint32_t target_hash, uint32_t overlay_hash); uint32_t target_hash, uint32_t overlay_hash);
int aapt(const char *source_apk, const char *internal_path, const char *out_restable, uid_t uid, int aapt(const char *source_apk, const char *internal_path, const char *out_restable, uid_t uid,
int pkgId, int min_sdk_version, const char *common_res_path); int pkgId, int min_sdk_version, const char *app_res_path, const char *common_res_path);
int restorecon_data(const char *uuid, const char* pkgName, const char* seinfo, uid_t uid); int restorecon_data(const char *uuid, const char* pkgName, const char* seinfo, uid_t uid);
int create_oat_dir(const char* oat_dir, const char *instruction_set); int create_oat_dir(const char* oat_dir, const char *instruction_set);
int rm_package_dir(const char* apk_path); int rm_package_dir(const char* apk_path);