Class XposedInterfaceWrapper

java.lang.Object
io.github.libxposed.api.XposedInterfaceWrapper
All Implemented Interfaces:
XposedInterface
Direct Known Subclasses:
XposedModule

public class XposedInterfaceWrapper extends Object implements XposedInterface
Wrapper of XposedInterface used by modules to shield framework implementation details.
  • Constructor Details

    • XposedInterfaceWrapper

      public XposedInterfaceWrapper()
  • Method Details

    • attachFramework

      @InternalApi public final void attachFramework(@NonNull XposedInterface base, @NonNull Runnable detachImpl)
      Attaches the framework interface to the module. Modules must not call this method. It is reserved for framework implementations and may change without compatibility guarantees.
      Parameters:
      base - The framework interface
      detachImpl - The implementation of detach()
    • detach

      @SinceApi(102) public final void detach()
      Stops all subsequent lifecycle callbacks for the current module entry in the current process. After this method is called, the framework removes its reference to the entry instance and will no longer invoke any lifecycle callbacks (such as XposedModuleInterface.onPackageLoaded(io.github.libxposed.api.XposedModuleInterface.PackageLoadedParam), XposedModuleInterface.onHotReloading(io.github.libxposed.api.XposedModuleInterface.HotReloadingParam), etc.) on the entry instance that called this method. Only lifecycle callbacks are affected; all XposedInterface APIs remain fully functional.

      If the module declares multiple entry classes, only the entry that calls this method is affected. Other entries continue to receive their lifecycle callbacks as normal.

      This method is idempotent. Calling it multiple times has the same effect as calling it once.

      If the module expects its classloader to become collectible after detaching, it must also remove module-owned references and execution contexts that keep module objects reachable, such as installed hooks, Java threads, and callbacks held by system or app objects. If native code is still running after all Java references to the module classloader are cleared, later runtime unloading of native libraries may crash the process; this is a module lifecycle bug.

      Typical use cases include:

      • The module entry has finished all its initialization work and no longer needs to respond to further package loading events.
      • For modules that target multiple apps with a dedicated entry class per app: if the entry detects it is not loaded in its target app, it can call this method immediately to avoid receiving any further callbacks.
      • Calling this method together with unhooking all registered hooks, so that the module classloader can be garbage collected when no longer needed.
    • getApiVersion

      public final int getApiVersion()
      Description copied from interface: XposedInterface
      Gets the runtime Xposed API version. Framework implementations must not override this method.
      Specified by:
      getApiVersion in interface XposedInterface
    • getFrameworkName

      @NonNull public final String getFrameworkName()
      Description copied from interface: XposedInterface
      Gets the Xposed framework name of current implementation.
      Specified by:
      getFrameworkName in interface XposedInterface
    • getFrameworkVersion

      @NonNull public final String getFrameworkVersion()
      Description copied from interface: XposedInterface
      Gets the Xposed framework version of current implementation.
      Specified by:
      getFrameworkVersion in interface XposedInterface
    • getFrameworkVersionCode

      public final long getFrameworkVersionCode()
      Description copied from interface: XposedInterface
      Gets the Xposed framework version code of current implementation.
      Specified by:
      getFrameworkVersionCode in interface XposedInterface
    • getFrameworkProperties

      public final long getFrameworkProperties()
      Description copied from interface: XposedInterface
      Gets the Xposed framework properties. Properties with prefix PROP_RT_ may change among launches.
      Specified by:
      getFrameworkProperties in interface XposedInterface
    • hook

      @NonNull public final XposedInterface.HookBuilder hook(@NonNull Executable origin)
      Description copied from interface: XposedInterface
      Hook a method / constructor.
      Specified by:
      hook in interface XposedInterface
      Parameters:
      origin - The executable to be hooked
      Returns:
      The builder for the hook
    • hookClassInitializer

      @NonNull public final XposedInterface.HookBuilder hookClassInitializer(@NonNull Class<?> origin)
      Description copied from interface: XposedInterface
      Hook the static initializer (<clinit>) of a class.

      The static initializer is treated as a regular static void() method with no parameters. Accordingly, in the XposedInterface.Chain passed to the hooker:

      Note: If the class is already initialized, the hook will never be called.

      Specified by:
      hookClassInitializer in interface XposedInterface
      Parameters:
      origin - The class whose static initializer is to be hooked
      Returns:
      The builder for the hook
    • deoptimize

      public final boolean deoptimize(@NonNull Executable executable)
      Description copied from interface: XposedInterface
      Deoptimizes a method / constructor in case hooked callee is not called because of inline.

      By deoptimizing the method, the runtime will fall back to calling all callees without inlining. For example, when a short hooked method B is invoked by method A, the callback to B is not invoked after hooking, which may mean A has inlined B inside its method body. To force A to call the hooked B, you can deoptimize A and then your hook can take effect.

      Generally, you need to find all the callers of your hooked callee, and that can hardly be achieved (but you can still search all callers by using DexKit). Use this method if you are sure the deoptimized callers are all you need. Otherwise, it would be better to change the hook point or to deoptimize the whole app manually (by simply reinstalling the app without uninstall).

      Specified by:
      deoptimize in interface XposedInterface
      Parameters:
      executable - The method / constructor to deoptimize
      Returns:
      Indicate whether the deoptimizing succeed or not
    • getInvoker

      @NonNull public final XposedInterface.Invoker<?,Method> getInvoker(@NonNull Method method)
      Description copied from interface: XposedInterface
      Get a method invoker for the given method. Invocations through invokers will bypass access checks. The default type of the invoker is XposedInterface.Invoker.Type.Chain.FULL.
      Specified by:
      getInvoker in interface XposedInterface
      Parameters:
      method - The method to get the invoker for
      Returns:
      The method invoker
    • getInvoker

      @NonNull public final <T> XposedInterface.CtorInvoker<T> getInvoker(@NonNull Constructor<T> constructor)
      Description copied from interface: XposedInterface
      Get a constructor invoker for the given constructor. Invocations through invokers will bypass access checks. The default type of the invoker is XposedInterface.Invoker.Type.Chain.FULL.
      Specified by:
      getInvoker in interface XposedInterface
      Type Parameters:
      T - The type of the constructor
      Parameters:
      constructor - The constructor to get the invoker for
      Returns:
      The constructor invoker
    • log

      public final void log(int priority, @Nullable String tag, @NonNull String msg)
      Description copied from interface: XposedInterface
      Writes a message to the Xposed log.
      Specified by:
      log in interface XposedInterface
      Parameters:
      priority - The log priority, see Log
      tag - The log tag
      msg - The log message
    • log

      public final void log(int priority, @Nullable String tag, @NonNull String msg, @Nullable Throwable tr)
      Description copied from interface: XposedInterface
      Writes a message to the Xposed log.
      Specified by:
      log in interface XposedInterface
      Parameters:
      priority - The log priority, see Log
      tag - The log tag
      msg - The log message
      tr - An exception to log
    • getRemotePreferences

      @NonNull public final SharedPreferences getRemotePreferences(@NonNull String name)
      Description copied from interface: XposedInterface
      Gets remote preferences stored in Xposed framework. Note that those are read-only in hooked apps.
      Specified by:
      getRemotePreferences in interface XposedInterface
      Parameters:
      name - Group name
      Returns:
      The preferences
    • getModuleApplicationInfo

      @NonNull public final ApplicationInfo getModuleApplicationInfo()
      Description copied from interface: XposedInterface
      Gets the application info of the module.
      Specified by:
      getModuleApplicationInfo in interface XposedInterface
    • listRemoteFiles

      @NonNull public final String[] listRemoteFiles()
      Description copied from interface: XposedInterface
      List all files in the module's shared data directory.
      Specified by:
      listRemoteFiles in interface XposedInterface
      Returns:
      The file list
    • openRemoteFile

      @NonNull public final ParcelFileDescriptor openRemoteFile(@NonNull String name) throws FileNotFoundException
      Description copied from interface: XposedInterface
      Open a file in the module's shared data directory. The file is opened in read-only mode.
      Specified by:
      openRemoteFile in interface XposedInterface
      Parameters:
      name - File name, must not contain path separators and . or ..
      Returns:
      The file descriptor
      Throws:
      FileNotFoundException - If the file does not exist or the path is forbidden