Favor post-Gingerbread instantiation mechanism.
pre-Gingerbread is now a small subset of the Android OS distribution and is constantly shrinking toward zero.
This commit is contained in:
parent
6a3e83a741
commit
f1f838cf20
@ -51,25 +51,6 @@ public abstract class UnsafeAllocator {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// try dalvikvm, pre-gingerbread
|
||||
// public class ObjectInputStream {
|
||||
// private static native Object newInstance(
|
||||
// Class<?> instantiationClass, Class<?> constructorClass);
|
||||
// }
|
||||
try {
|
||||
final Method newInstance = ObjectInputStream.class
|
||||
.getDeclaredMethod("newInstance", Class.class, Class.class);
|
||||
newInstance.setAccessible(true);
|
||||
return new UnsafeAllocator() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T newInstance(Class<T> c) throws Exception {
|
||||
return (T) newInstance.invoke(null, c, Object.class);
|
||||
}
|
||||
};
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// try dalvikvm, post-gingerbread
|
||||
// public class ObjectStreamClass {
|
||||
// private static native int getConstructorId(Class<?> c);
|
||||
@ -93,6 +74,25 @@ public abstract class UnsafeAllocator {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// try dalvikvm, pre-gingerbread
|
||||
// public class ObjectInputStream {
|
||||
// private static native Object newInstance(
|
||||
// Class<?> instantiationClass, Class<?> constructorClass);
|
||||
// }
|
||||
try {
|
||||
final Method newInstance = ObjectInputStream.class
|
||||
.getDeclaredMethod("newInstance", Class.class, Class.class);
|
||||
newInstance.setAccessible(true);
|
||||
return new UnsafeAllocator() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T newInstance(Class<T> c) throws Exception {
|
||||
return (T) newInstance.invoke(null, c, Object.class);
|
||||
}
|
||||
};
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// give up
|
||||
return new UnsafeAllocator() {
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user