Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 403beab3 authored by Fan Zhang's avatar Fan Zhang Committed by Android (Google) Code Review
Browse files

Merge "Remove hacks to access framework private resources"

parents 3ce67421 24aea5da
Loading
Loading
Loading
Loading
+0 −42
Original line number Diff line number Diff line
@@ -30,18 +30,12 @@ import org.robolectric.android.XmlResourceParserImpl;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.res.StyleData;
import org.robolectric.res.StyleResolver;
import org.robolectric.res.ThemeStyleSet;
import org.robolectric.shadows.ShadowAssetManager;
import org.robolectric.shadows.ShadowResources;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.ReflectionHelpers.ClassParameter;
import org.w3c.dom.Node;

import java.util.List;
import java.util.Map;

/**
 * Shadow Resources and Theme classes to handle resource references that Robolectric shadows cannot
 * handle because they are too new or private.
@@ -207,44 +201,8 @@ public class SettingsShadowResources extends ShadowResources {
                        if (attributeValue.contains("attr/fingerprint_layout_theme")) {
                            // Workaround for https://github.com/robolectric/robolectric/issues/2641
                            node.setNodeValue("@style/FingerprintLayoutTheme");
                        } else if (attributeValue.startsWith("@*android:string")) {
                            node.setNodeValue("PLACEHOLDER");
                        } else if (attributeValue.startsWith("@*android:dimen")) {
                            node.setNodeValue("321dp");
                        } else if (attributeValue.startsWith("@*android:drawable")) {
                            node.setNodeValue("");
                        }
                    }
                        }
                    }

            // Track down all styles and remove all inheritance from private styles.
            final Map<Long, Object /* NativeTheme */> appliedStylesList =
                    ReflectionHelpers.getField(mAssetManager, "nativeThemes");
            synchronized (appliedStylesList) {
                for (Long idx : appliedStylesList.keySet()) {
                    final ThemeStyleSet appliedStyles = ReflectionHelpers.getField(
                            appliedStylesList.get(idx), "themeStyleSet");
                    // The Object's below are actually ShadowAssetManager.OverlayedStyle.
                    // We can't use

                    // it here because it's private.
                    final List<Object /* OverlayedStyle */> overlayedStyles =
                            ReflectionHelpers.getField(appliedStyles, "styles");
                    for (Object appliedStyle : overlayedStyles) {
                        final StyleResolver styleResolver = ReflectionHelpers.getField(appliedStyle,
                                "style");
                        final List<StyleData> styleDatas =
                                ReflectionHelpers.getField(styleResolver, "styles");
                        for (StyleData styleData : styleDatas) {
                            if (styleData.getParent() != null &&
                                    styleData.getParent().startsWith("@*android:style")) {
                                ReflectionHelpers.setField(StyleData.class, styleData, "parent",
                                        null);
                            }
                        }
                    }

                }
            }
            return super.obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);