From 7c2be690f4949abc4d547627d8d856231e2fa4e7 Mon Sep 17 00:00:00 2001 From: d34d Date: Mon, 18 Jan 2016 19:41:38 -0800 Subject: [PATCH] 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. Change-Id: Ic00b5d91fc651a29a8c3ab341e5494107acd0463 TICKET: CYNGNOS-1645 --- cmds/installd/commands.cpp | 58 ++++++++++++++++++++++---------------- cmds/installd/installd.cpp | 8 +++--- cmds/installd/installd.h | 2 +- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp index 322d537ee..50346c836 100644 --- a/cmds/installd/commands.cpp +++ b/cmds/installd/commands.cpp @@ -1721,7 +1721,8 @@ fail: } 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 *MANIFEST = "/data/app/AndroidManifest.xml"; @@ -1735,40 +1736,48 @@ static void run_aapt(const char *source_apk, const char *internal_path, snprintf(resapk_str, sizeof(resapk_str), "%d", resapk_fd); snprintf(pkgId_str, sizeof(pkgId_str), "%d", pkgId); snprintf(minSdkVersion_str, sizeof(minSdkVersion_str), "%d", min_sdk_version); + bool hasCommonResources = (common_res_path != NULL && common_res_path[0] != '\0'); + bool hasAppResources = (app_res_path != NULL && app_res_path[0] != '\0'); if (hasCommonResources) { execl(AAPT_BIN, AAPT_BIN, "package", - "--min-sdk-version", minSdkVersion_str, - "-M", MANIFEST, - "-S", source_apk, - "-X", internal_path, - "-I", FRAMEWORK_RES, - "-I", common_res_path, - "-r", resapk_str, - "-x", pkgId_str, - "-f", - (char*)NULL); + "--min-sdk-version", minSdkVersion_str, + "-M", MANIFEST, + "-S", source_apk, + "-X", internal_path, + "-I", FRAMEWORK_RES, + "-r", resapk_str, + "-x", pkgId_str, + "-f", + "-I", common_res_path, + hasAppResources ? "-I" : (char*)NULL, + hasAppResources ? app_res_path : (char*) NULL, + (char*)NULL); } else { execl(AAPT_BIN, AAPT_BIN, "package", - "--min-sdk-version", minSdkVersion_str, - "-M", MANIFEST, - "-S", source_apk, - "-X", internal_path, - "-I", FRAMEWORK_RES, - "-r", resapk_str, - "-x", pkgId_str, - "-f", - (char*)NULL); + "--min-sdk-version", minSdkVersion_str, + "-M", MANIFEST, + "-S", source_apk, + "-X", internal_path, + "-I", FRAMEWORK_RES, + "-r", resapk_str, + "-x", pkgId_str, + "-f", + hasAppResources ? "-I" : (char*)NULL, + hasAppResources ? app_res_path : (char*) NULL, + (char*)NULL); } 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 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", - source_apk, internal_path, out_restable, uid, pkgId, min_sdk_version, common_res_path); + ALOGD("aapt source_apk=%s internal_path=%s out_restable=%s uid=%d, pkgId=%d,min_sdk_version=%d,\ + 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 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); if (pipefd[CHILD_WRITE_PIPE] > 0) { diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp index c92bed020..df159e364 100644 --- a/cmds/installd/installd.cpp +++ b/cmds/installd/installd.cpp @@ -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) { - 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) { - 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))) @@ -223,8 +223,8 @@ struct cmdinfo cmds[] = { { "mkuserconfig", 1, do_mk_user_config }, { "rmuser", 2, do_rm_user }, { "idmap", 6, do_idmap }, - { "aapt", 6, do_aapt }, - { "aapt_with_common", 7, do_aapt_with_common }, + { "aapt", 7, do_aapt }, + { "aapt_with_common", 8, do_aapt_with_common }, { "restorecondata", 4, do_restorecon_data }, { "createoatdir", 2, do_create_oat_dir }, { "rmpackagedir", 1, do_rm_package_dir }, diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h index 70e5e16c8..b4c5961d3 100644 --- a/cmds/installd/installd.h +++ b/cmds/installd/installd.h @@ -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, 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 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 create_oat_dir(const char* oat_dir, const char *instruction_set); int rm_package_dir(const char* apk_path);