summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2018-10-16 12:48:38 -0700
committerRyan Mitchell <rtmitchell@google.com>2018-11-01 17:01:28 -0700
commitb3ae42e9762a826b1591ab932a6a092ad3e6c3a7 (patch)
tree0ca9b27919cb30c1d07dfcb4c0365d92768b6eef /core/java
parentcfc152af9cbfc47ed4c8ab8a8b6e9ee4214206ea (diff)
Copy common resources between styles
The docuemntation of setTo states that the resources two styles from different AssetManagers have in common will be set in the destination theme. This change adds this functionality. The package ids of the attributes, the package ids of reference values, and the cookie of attribute values have to be rewritten to match the destination AssetManager. This change can later be made more generic if rewriting references between packages is needed elsewhere. Bug: 115897657 Test: libandroidfw_tests and manual test of app specified in the bug Change-Id: Iee999ea2cc8473168cac11aaf3c34e14c958e5ae
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/content/res/AssetManager.java14
-rw-r--r--core/java/android/content/res/ResourcesImpl.java2
2 files changed, 14 insertions, 2 deletions
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index 0350effd84b8..5f2374995775 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -1064,6 +1064,17 @@ public final class AssetManager implements AutoCloseable {
}
}
+ @UnsupportedAppUsage
+ void setThemeTo(long dstThemePtr, @NonNull AssetManager srcAssetManager, long srcThemePtr) {
+ synchronized (this) {
+ ensureValidLocked();
+ synchronized (srcAssetManager) {
+ srcAssetManager.ensureValidLocked();
+ nativeThemeCopy(mObject, dstThemePtr, srcAssetManager.mObject, srcThemePtr);
+ }
+ }
+ }
+
@Override
protected void finalize() throws Throwable {
if (DEBUG_REFS && mNumRefs != 0) {
@@ -1375,7 +1386,8 @@ public final class AssetManager implements AutoCloseable {
private static native void nativeThemeDestroy(long themePtr);
private static native void nativeThemeApplyStyle(long ptr, long themePtr, @StyleRes int resId,
boolean force);
- static native void nativeThemeCopy(long destThemePtr, long sourceThemePtr);
+ private static native void nativeThemeCopy(long dstAssetManagerPtr, long dstThemePtr,
+ long srcAssetManagerPtr, long srcThemePtr);
static native void nativeThemeClear(long themePtr);
private static native int nativeThemeGetAttributeValue(long ptr, long themePtr,
@AttrRes int resId, @NonNull TypedValue outValue, boolean resolve);
diff --git a/core/java/android/content/res/ResourcesImpl.java b/core/java/android/content/res/ResourcesImpl.java
index dfa30a22597e..0f5546b79fef 100644
--- a/core/java/android/content/res/ResourcesImpl.java
+++ b/core/java/android/content/res/ResourcesImpl.java
@@ -1335,7 +1335,7 @@ public class ResourcesImpl {
void setTo(ThemeImpl other) {
synchronized (mKey) {
synchronized (other.mKey) {
- AssetManager.nativeThemeCopy(mTheme, other.mTheme);
+ mAssets.setThemeTo(mTheme, other.mAssets, other.mTheme);
mThemeResId = other.mThemeResId;
mKey.setTo(other.getKey());