/** * 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); }
/** * 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); }
/** * 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); }
/** Constructs a {@link Sensor} with a given type. */ public static Sensor newInstance(int type) { Sensor sensor = Shadow.newInstanceOf(Sensor.class); reflector(_Sensor_.class, sensor).setTypeCompat(type); return sensor; }
private void setMask(int mask) { _Sensor_ _sensor_ = reflector(_Sensor_.class, realSensor); _sensor_.setFlags(_sensor_.getFlags() | mask); }
private Asset getAsset() { int apiLevel = RuntimeEnvironment.getApiLevel(); long assetPtr; if (apiLevel >= LOLLIPOP) { assetPtr = reflector(_AssetInputStream_.class, realObject).getNativeAsset(); } else { assetPtr = reflector(_AssetInputStream_.class, realObject).getAssetInt(); } return Registries.NATIVE_ASSET_REGISTRY.getNativeObject(assetPtr); }
private static void resetStateApi26() { Handler queuedWorkHandler = ReflectionHelpers.getStaticField(QueuedWork.class, "sHandler"); if (queuedWorkHandler != null) { queuedWorkHandler.removeCallbacksAndMessages(null); } _QueuedWork_ _queuedWorkStatic_ = reflector(_QueuedWork_.class); _queuedWorkStatic_.getFinishers().clear(); _queuedWorkStatic_.getWork().clear(); _queuedWorkStatic_.setNumWaits(0); }
public void callDispatchResized() { Display display = getDisplay(); Rect frame = new Rect(); display.getRectSize(frame); reflector(_ViewRootImpl_.class, realObject).dispatchResized(frame); }
@Resetter public static void reset() { // todo: ShadowPicker doesn't discriminate properly between concrete shadow classes for resetters... if (useLegacy()) { if (RuntimeEnvironment.getApiLevel() >= P) { _AssetManager28_ _assetManagerStatic_ = reflector(_AssetManager28_.class); _assetManagerStatic_.setSystemApkAssetsSet(null); _assetManagerStatic_.setSystemApkAssets(null); } reflector(_AssetManager_.class).setSystem(null); } }
/** Controls the return value of {@link Sensor#isWakeUpSensor()}. */ public void setWakeUpFlag(boolean wakeup) { int wakeUpSensorMask = reflector(_Sensor_.class).getWakeUpSensorFlag(); if (wakeup) { setMask(wakeUpSensorMask); } else { clearMask(wakeUpSensorMask); } }
public static WindowId getWindowId(ShadowView shadowView) { if (shadowView.isAttachedToWindow()) { Object attachInfo = shadowView.getAttachInfo(); if (getField(attachInfo, "mWindowId") == null) { IWindowId iWindowId = new MyIWindowIdStub(); reflector(_AttachInfo_.class, attachInfo).setWindowId(new WindowId(iWindowId)); reflector(_AttachInfo_.class, attachInfo).setIWindowId(iWindowId); } } return shadowView.directly().getWindowId(); }
@Resetter public static void reset() { int apiLevel = RuntimeEnvironment.getApiLevel(); _InputMethodManager_ _reflector = reflector(_InputMethodManager_.class); if (apiLevel <= VERSION_CODES.JELLY_BEAN_MR1) { _reflector.setMInstance(null); } else if (apiLevel <= VERSION_CODES.P) { _reflector.setInstance(null); } }
@Resetter public static void reset() { if (RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.O) { resetStateApi26(); } else { QueuedWork.waitToFinish(); reflector(_QueuedWork_.class).setSingleThreadExecutor(null); } }
@Resetter public static void reset() { _BackgroundThread_ _backgroundThreadStatic_ = reflector(_BackgroundThread_.class); BackgroundThread instance = _backgroundThreadStatic_.getInstance(); if (instance != null) { instance.quit(); _backgroundThreadStatic_.setInstance(null); _backgroundThreadStatic_.setHandler(null); } }
@Resetter public static void reset() { // todo: ShadowPicker doesn't discriminate properly between concrete shadow classes for resetters... if (!useLegacy() && RuntimeEnvironment.getApiLevel() >= P) { _AssetManager28_ _assetManagerStatic_ = reflector(_AssetManager28_.class); _assetManagerStatic_.setSystemApkAssetsSet(null); _assetManagerStatic_.setSystemApkAssets(null); _assetManagerStatic_.setSystem(null); } }
@Override public void handleMessage(Message msg) { boolean inUse = callInstanceMethod(msg, "isInUse"); assertThat(inUse).named(msg.what + ":inUse").isTrue(); Message next = reflector(_Message_.class, msg).getNext(); assertThat(next).named(msg.what + ":next").isNull(); } };