From c1d527926e1c82828e42bdc0c7abf50f6decc0a7 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Tue, 5 May 2015 09:49:03 -0700 Subject: [PATCH] Add API for obtaining changing configurations bitmask from Theme Required to know when to reload the system context's theme in response to configuration changes, and thus needed to support the DayNight theme. Bug: 20267825 Change-Id: I7df5e28b7a6d8b611ea030032544cf4800788514 --- api/current.txt | 1 + api/system-current.txt | 1 + .../java/android/content/pm/ActivityInfo.java | 24 ++++++++++++++++--- .../android/content/res/AssetManager.java | 1 + core/java/android/content/res/Resources.java | 13 ++++++++++ core/jni/android_util_AssetManager.cpp | 9 +++++++ include/androidfw/ResourceTypes.h | 7 ++++++ libs/androidfw/ResourceTypes.cpp | 10 ++++++++ 8 files changed, 63 insertions(+), 3 deletions(-) diff --git a/api/current.txt b/api/current.txt index 2bbe2f1ffb21e..f3737c11b3a92 100644 --- a/api/current.txt +++ b/api/current.txt @@ -9833,6 +9833,7 @@ package android.content.res { public final class Resources.Theme { method public void applyStyle(int, boolean); method public void dump(int, java.lang.String, java.lang.String); + method public int getChangingConfigurations(); method public android.graphics.drawable.Drawable getDrawable(int) throws android.content.res.Resources.NotFoundException; method public android.content.res.Resources getResources(); method public android.content.res.TypedArray obtainStyledAttributes(int[]); diff --git a/api/system-current.txt b/api/system-current.txt index 0cc763bafcccd..5a529b7c06e44 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -10127,6 +10127,7 @@ package android.content.res { public final class Resources.Theme { method public void applyStyle(int, boolean); method public void dump(int, java.lang.String, java.lang.String); + method public int getChangingConfigurations(); method public android.graphics.drawable.Drawable getDrawable(int) throws android.content.res.Resources.NotFoundException; method public android.content.res.Resources getResources(); method public android.content.res.TypedArray obtainStyledAttributes(int[]); diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java index 16f6b1e633297..43cc63b4a3c85 100644 --- a/core/java/android/content/pm/ActivityInfo.java +++ b/core/java/android/content/pm/ActivityInfo.java @@ -570,19 +570,37 @@ public class ActivityInfo extends ComponentInfo Configuration.NATIVE_CONFIG_DENSITY, // DENSITY Configuration.NATIVE_CONFIG_LAYOUTDIR, // LAYOUT DIRECTION }; - /** @hide + + /** * Convert Java change bits to native. + * + * @hide */ public static int activityInfoConfigToNative(int input) { int output = 0; - for (int i=0; i= 0 ? copyValue(env, outValue, &res, value, ref, block, typeSpecFlags) : block; } +static jint android_content_AssetManager_getThemeChangingConfigurations(JNIEnv* env, jobject clazz, + jlong themeHandle) +{ + ResTable::Theme* theme = reinterpret_cast(themeHandle); + return theme->getChangingConfigurations(); +} + static void android_content_AssetManager_dumpTheme(JNIEnv* env, jobject clazz, jlong themeHandle, jint pri, jstring tag, jstring prefix) @@ -2103,6 +2110,8 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_copyTheme }, { "loadThemeAttributeValue", "(JILandroid/util/TypedValue;Z)I", (void*) android_content_AssetManager_loadThemeAttributeValue }, + { "getThemeChangingConfigurations", "(J)I", + (void*) android_content_AssetManager_getThemeChangingConfigurations }, { "dumpTheme", "(JILjava/lang/String;Ljava/lang/String;)V", (void*) android_content_AssetManager_dumpTheme }, { "applyStyle","(JIIJ[I[I[I)Z", diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h index df278c8bd0f68..587e7fa761d64 100644 --- a/include/androidfw/ResourceTypes.h +++ b/include/androidfw/ResourceTypes.h @@ -1662,6 +1662,12 @@ public: uint32_t* inoutTypeSpecFlags = NULL, ResTable_config* inoutConfig = NULL) const; + /** + * Returns a bit mask of configuration changes that will impact this + * theme (and thus require completely reloading it). + */ + uint32_t getChangingConfigurations() const; + void dumpToLog() const; private: @@ -1688,6 +1694,7 @@ public: const ResTable& mTable; package_info* mPackages[Res_MAXPACKAGE]; + uint32_t mTypeSpecFlags; }; void setParameters(const ResTable_config* params); diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index 04ebe70304a64..19a5bebfc14d7 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -3147,6 +3147,7 @@ struct ResTable::bag_set ResTable::Theme::Theme(const ResTable& table) : mTable(table) + , mTypeSpecFlags(0) { memset(mPackages, 0, sizeof(mPackages)); } @@ -3205,6 +3206,8 @@ status_t ResTable::Theme::applyStyle(uint32_t resID, bool force) return N; } + mTypeSpecFlags |= bagTypeSpecFlags; + uint32_t curPackage = 0xffffffff; ssize_t curPackageIndex = 0; package_info* curPI = NULL; @@ -3323,6 +3326,8 @@ status_t ResTable::Theme::setTo(const Theme& other) } } + mTypeSpecFlags = other.mTypeSpecFlags; + if (kDebugTableTheme) { ALOGI("Final theme:"); dumpToLog(); @@ -3417,6 +3422,11 @@ ssize_t ResTable::Theme::resolveAttributeReference(Res_value* inOutValue, inoutTypeSpecFlags, inoutConfig); } +uint32_t ResTable::Theme::getChangingConfigurations() const +{ + return mTypeSpecFlags; +} + void ResTable::Theme::dumpToLog() const { ALOGI("Theme %p:\n", this);