Don't instantiate non-Fragments in Fragment.instantiate

Backport...

Fix for PreferenceActivities being invoked with non-Fragment class
names via extras in the intent. Make sure that the constructor
doesn't get called if the class name is not for a Fragment type.
Bug: 9901133
Change-Id: I227756fb4246deac796cee09077e482237bb5b0d
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java
index 28876d3..32ee601 100644
--- a/core/java/android/app/Fragment.java
+++ b/core/java/android/app/Fragment.java
@@ -572,6 +572,10 @@
             if (clazz == null) {
                 // Class not found in the cache, see if it's real, and try to add it
                 clazz = context.getClassLoader().loadClass(fname);
+                if (!Fragment.class.isAssignableFrom(clazz)) {
+                    throw new InstantiationException("Trying to instantiate a class " + fname
+                        + " that is not a Fragment", new ClassCastException());
+                }
                 sClassMap.put(fname, clazz);
             }
             Fragment f = (Fragment)clazz.newInstance();