summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Mast <andy@cyngn.com>2014-11-03 18:29:09 -0800
committerAndy Mast <andy@cyngn.com>2014-11-14 19:06:49 +0000
commit9a6496249d68b2b5a72cb14425b53d772b6fe1db (patch)
tree023beb832c2a79a27830ad0839b26c12b11c6170
parent92dec234e5ed18afe5cacaf61bcfbe5f311840d3 (diff)
downloadandroid_frameworks_base-9a6496249d68b2b5a72cb14425b53d772b6fe1db.tar.gz
android_frameworks_base-9a6496249d68b2b5a72cb14425b53d772b6fe1db.tar.bz2
android_frameworks_base-9a6496249d68b2b5a72cb14425b53d772b6fe1db.zip
Protect windowNoTitle and windowActionBar attributes
This patch creates a new method to define "protected" attributes. These are attributes like windowActionBar which should not be modified by a theme. Some apps (eg gmail) use the appcompat library which has its own Actionbar classes. When an app uses its own Actionbar it must not include the default actionbar which is achieved through the windowActionBar attribute. Some themes may try to change these attributes, which can will cause the app to crash. Change-Id: Ie3bb7285eed09f3f13facf9d142ea9eb83796eec
-rw-r--r--include/androidfw/ResourceTypes.h1
-rw-r--r--libs/androidfw/ResourceTypes.cpp31
2 files changed, 32 insertions, 0 deletions
diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h
index 80eec8c66a8..4bb5ac83003 100644
--- a/include/androidfw/ResourceTypes.h
+++ b/include/androidfw/ResourceTypes.h
@@ -1590,6 +1590,7 @@ private:
uint32_t pkgIdOverride);
bool isResTypeAllowed(const char* type) const;
+ bool isProtectedAttr(uint32_t resID) const;
void print_value(const Package* pkg, const Res_value& value) const;
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index ab27348031e..8e6b8c134d7 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -69,6 +69,10 @@ namespace android {
// size measured in sizeof(uint32_t)
#define IDMAP_HEADER_SIZE (ResTable::IDMAP_HEADER_SIZE_BYTES / sizeof(uint32_t))
+// Define attributes to protect from theme changes
+#define ATTR_WINDOW_NO_TITLE 0x01010056 // windowNoTitle
+#define ATTR_WINDOW_ACTION_BAR 0x010102cd // windowActionBar
+
static void printToLogFunc(void* cookie, const char* txt)
{
ALOGV("%s", txt);
@@ -3445,6 +3449,25 @@ void ResTable::unlock() const
mLock.unlock();
}
+// Protected attributes are not permitted to be themed. If a theme
+// does try to change a protected attribute it will be overriden
+// by the app's original value.
+const static uint32_t PROTECTED_ATTRS[] = {
+ ATTR_WINDOW_NO_TITLE,
+ ATTR_WINDOW_ACTION_BAR
+};
+
+bool ResTable::isProtectedAttr(uint32_t resID) const
+{
+ int length = sizeof(PROTECTED_ATTRS) / sizeof(PROTECTED_ATTRS[0]);
+ for(int i=0; i < length; i++) {
+ if (PROTECTED_ATTRS[i] == resID) {
+ return true;
+ }
+ }
+ return false;
+}
+
ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,
uint32_t* outTypeSpecFlags, bool performMapping) const
{
@@ -3812,6 +3835,14 @@ ssize_t ResTable::getBagLocked(uint32_t resID, const bag_entry** outBag,
data=0x%08x\n",
curEntry, cur, cur->stringBlock, cur->map.name.ident,
cur->map.value.dataType, cur->map.value.data));
+ } else if (isProtectedAttr(newName)) {
+ // The attribute exists in both the original and the new theme bags,
+ // furthermore it is an attribute we don't wish themers to theme, so
+ // give our current themed bag the same value as the original
+ bag_entry* cur = entries+curEntry;
+ cur->stringBlock = originalBag[i].stringBlock;
+ cur->map.name.ident = originalBag[i].map.name.ident;
+ cur->map.value = originalBag[i].map.value;
}
};
}