summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/bridge
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2015-05-18 18:47:07 -0700
committerDeepanshu Gupta <deepanshu@google.com>2015-05-19 19:56:20 -0700
commitf8ea750455eec81e4e6d877b3e18e29a86d4ec95 (patch)
tree98759198fabb789eaa05ccd8c893d4dfaa64d3fc /tools/layoutlib/bridge
parent21b564573327b1ed2f7e06146b8a01c47ede3089 (diff)
downloadframeworks_base-f8ea750455eec81e4e6d877b3e18e29a86d4ec95.zip
frameworks_base-f8ea750455eec81e4e6d877b3e18e29a86d4ec95.tar.gz
frameworks_base-f8ea750455eec81e4e6d877b3e18e29a86d4ec95.tar.bz2
Make Context.getClassLoader() work.
Context.getClassLoader() is used by the LayoutInflater and can be used by custom views. However, when called from the LayoutInflater, this needs to return only the Framework classes. This is so that the IDE gets a chance to instantiate the custom views, which helps in better error reporting and better fallback in case of exceptions, like MockView. To workaround this need of the same method returning different results based on where it's called from, the method call in LayoutInflater is renamed to getFrameworkClassLoader() and the new method is injected in Context. The implementation of getFrameworkClassLoader() maintains the existing behaviour of getClassLoader(). Context.getClassLoader() is now modified to return classes from both Framework and the app namespace. Also, update the list of packages to search for Framework views. Change-Id: I1a6be4aa1fc5c1c5520b5440a348a52f10b6eb3b
Diffstat (limited to 'tools/layoutlib/bridge')
-rw-r--r--tools/layoutlib/bridge/src/android/view/BridgeInflater.java7
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java19
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java1
3 files changed, 23 insertions, 4 deletions
diff --git a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
index 87762a6..32ee9e8 100644
--- a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
+++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
@@ -53,9 +53,14 @@ public final class BridgeInflater extends LayoutInflater {
*/
private static final String[] sClassPrefixList = {
"android.widget.",
- "android.webkit."
+ "android.webkit.",
+ "android.app."
};
+ public static String[] getClassPrefixList() {
+ return sClassPrefixList;
+ }
+
protected BridgeInflater(LayoutInflater original, Context newContext) {
super(original, newContext);
newContext = getBaseContext(newContext);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index eb5f597..59f07a7 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -138,8 +138,9 @@ public final class BridgeContext extends Context {
private final Stack<BridgeXmlBlockParser> mParserStack = new Stack<BridgeXmlBlockParser>();
private SharedPreferences mSharedPreferences;
+ private ClassLoader mClassLoader;
- /**
+ /**
* @param projectKey An Object identifying the project. This is used for the cache mechanism.
* @param metrics the {@link DisplayMetrics}.
* @param renderResources the configured resources (both framework and projects) for this
@@ -462,7 +463,21 @@ public final class BridgeContext extends Context {
@Override
public ClassLoader getClassLoader() {
- return this.getClass().getClassLoader();
+ if (mClassLoader == null) {
+ mClassLoader = new ClassLoader(getClass().getClassLoader()) {
+ @Override
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ for (String prefix : BridgeInflater.getClassPrefixList()) {
+ if (name.startsWith(prefix)) {
+ // These are framework classes and should not be loaded from the app.
+ throw new ClassNotFoundException(name + " not found");
+ }
+ }
+ return BridgeContext.this.mLayoutlibCallback.findClass(name);
+ }
+ };
+ }
+ return mClassLoader;
}
@Override
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
index 2b95488..f3a0d58 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
@@ -275,7 +275,6 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
mContext.getRenderResources().setLogger(null);
}
ParserFactory.setParserFactory(null);
-
}
public static BridgeContext getCurrentContext() {