/** * Returns an object which provides accessors for invoking otherwise inaccessible static methods * and fields. * * @param iClass an interface with methods matching private methods on the target */ public static <T> T reflector(Class<T> iClass) { return reflector(iClass, null); }
/** * Returns an object which provides accessors for invoking otherwise inaccessible methods and * fields. * * @param iClass an interface with methods matching private methods on the target * @param target the target object */ public static <T> T reflector(Class<T> iClass, Object target) { Class<?> targetClass = determineTargetClass(iClass); Constructor<? extends T> ctor = (Constructor<? extends T>) CACHE.get(iClass); try { if (ctor == null) { Class<? extends T> reflectorClass = createReflectorClass(iClass, targetClass); ctor = reflectorClass.getConstructor(targetClass); ctor.setAccessible(true); } CACHE.put(iClass, ctor); return ctor.newInstance(target); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException(e); } }
private static <T> Class<? extends T> createReflectorClass( Class<T> iClass, Class<?> targetClass) { String reflectorClassName = iClass.getName() + "$$Reflector" + COUNTER.getAndIncrement(); byte[] bytecode = getBytecode(iClass, targetClass, reflectorClassName); if (DEBUG) { File file = new File("/tmp", reflectorClassName + ".class"); System.out.println("Generated reflector: " + file.getAbsolutePath()); try (OutputStream out = new FileOutputStream(file)) { out.write(bytecode); } catch (IOException e) { throw new RuntimeException(e); } } final Class<?> proxyClass; proxyClass = defineViaUnsafe(iClass, reflectorClassName, bytecode); // proxyClass = defineViaNewClassLoader(iClass, reflectorClassName, bytecode); return proxyClass.asSubclass(iClass); }
private ActivityController(T activity, Intent intent) { super(activity, intent); _component_ = reflector(_Activity_.class, component); }
private static <T> Class<? extends T> createReflectorClass( Class<T> iClass, Class<?> targetClass) { String reflectorClassName = iClass.getName() + "$$Reflector" + COUNTER.getAndIncrement(); byte[] bytecode = getBytecode(iClass, targetClass, reflectorClassName); if (DEBUG) { File file = new File("/tmp", reflectorClassName + ".class"); System.out.println("Generated reflector: " + file.getAbsolutePath()); try (OutputStream out = new FileOutputStream(file)) { out.write(bytecode); } catch (IOException e) { throw new RuntimeException(e); } } final Class<?> proxyClass; proxyClass = defineViaUnsafe(iClass, reflectorClassName, bytecode); // proxyClass = defineViaNewClassLoader(iClass, reflectorClassName, bytecode); return proxyClass.asSubclass(iClass); }
/** * Returns an object which provides accessors for invoking otherwise inaccessible methods and * fields. * * @param iClass an interface with methods matching private methods on the target * @param target the target object */ public static <T> T reflector(Class<T> iClass, Object target) { Class<?> targetClass = determineTargetClass(iClass); Constructor<? extends T> ctor = (Constructor<? extends T>) CACHE.get(iClass); try { if (ctor == null) { Class<? extends T> reflectorClass = createReflectorClass(iClass, targetClass); ctor = reflectorClass.getConstructor(targetClass); ctor.setAccessible(true); } CACHE.put(iClass, ctor); return ctor.newInstance(target); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException(e); } }
/** * Convenience method to provide getter access to the private field * {@code Message.next}. * * @return The next message in the current message chain. * @see #setNext(Message) */ public Message getNext() { return reflector(_Message_.class, realMessage).getNext(); }
/** * Exposes {@link ResourcesManager#applyCompatConfigurationLocked(int, Configuration)}. */ public boolean callApplyConfigurationToResourcesLocked(Configuration configuration, CompatibilityInfo compatibilityInfo) { return reflector(_ResourcesManager_.class, realResourcesManager) .applyConfigurationToResourcesLocked(configuration, compatibilityInfo); }
static _ServiceFetcher_ get(String key, Object serviceFetcher) { String serviceFetcherClassName = getConcreteClassName(serviceFetcher); if (serviceFetcherClassName == null) { throw new IllegalStateException("no idea what to do with " + key + " " + serviceFetcher); } switch (serviceFetcherClassName) { case STATIC_SERVICE_FETCHER_CLASS_NAME: return reflector(_StaticServiceFetcher_.class, serviceFetcher); case STATIC_CONTEXT_SERVICE_FETCHER_CLASS_NAME_M: return reflector(_ServiceFetcherM_.class, serviceFetcher); case STATIC_CONTEXT_SERVICE_FETCHER_CLASS_NAME_N: return reflector(_ServiceFetcherN_.class, serviceFetcher); case CACHED_SERVICE_FETCHER_CLASS_NAME: return o -> {}; // these are accessors via the ContextImpl instance, so no reset needed default: if (key.equals(Context.INPUT_METHOD_SERVICE)) { return o -> {}; // handled by ShadowInputMethodManager.reset() } throw new IllegalStateException("no idea what to do with " + key + " " + serviceFetcher); } }
/** * Convenience method to provide setter access to the private field * {@code Message.next}. * * @param next the new next message for the current message. * @see #getNext() */ public void setNext(Message next) { reflector(_Message_.class, realMessage).setNext(next); }
private Object getAttachInfo() { return reflector(_View_.class, realView).getAttachInfo(); }
public void setHead(Message msg) { reflector(_MessageQueue_.class, realQueue).setMessages(msg); }
public void setWindow(Window window) { reflector(_Activity_.class, realActivity).setWindow(window); }
public static void clean(Object cleanable) { reflector(_Cleanable_.class, cleanable).clean(); }
public void callOnAttachedToWindow() { reflector(_View_.class, realView).onAttachedToWindow(); }
private _UsbManager_ _usbManager_() { return reflector(_UsbManager_.class, usbManager); }
public void callOnDetachedFromWindow() { reflector(_View_.class, realView).onDetachedFromWindow(); }
long getNativePtr() { return reflector(_ApkAssets_.class, realApkAssets).getNativePtr(); }
public void setApplication(Application application) { reflector(_Activity_.class, realActivity).setApplication(application); }