Class XposedInterfaceWrapper
- All Implemented Interfaces:
XposedInterface
- Direct Known Subclasses:
XposedModule
XposedInterface used by modules to shield framework implementation details.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.libxposed.api.XposedInterface
XposedInterface.Chain, XposedInterface.CtorInvoker<T>, XposedInterface.ExceptionMode, XposedInterface.HookBuilder, XposedInterface.Hooker, XposedInterface.HookHandle, XposedInterface.Invoker<T extends XposedInterface.Invoker<T,U>, U extends Executable> -
Field Summary
Fields inherited from interface io.github.libxposed.api.XposedInterface
API_101, API_102, LIB_API, PRIORITY_DEFAULT, PRIORITY_HIGHEST, PRIORITY_LOWEST, PROP_CAP_REMOTE, PROP_CAP_SYSTEM, PROP_RT_API_PROTECTION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidattachFramework(XposedInterface base, Runnable detachImpl) Attaches the framework interface to the module.final booleandeoptimize(Executable executable) Deoptimizes a method / constructor in case hooked callee is not called because of inline.final voiddetach()Stops all subsequent lifecycle callbacks for the current module entry in the current process.final intGets the runtime Xposed API version.final StringGets the Xposed framework name of current implementation.final longGets the Xposed framework properties.final StringGets the Xposed framework version of current implementation.final longGets the Xposed framework version code of current implementation.final <T> XposedInterface.CtorInvoker<T> getInvoker(Constructor<T> constructor) Get a constructor invoker for the given constructor.final XposedInterface.Invoker<?, Method> getInvoker(Method method) Get a method invoker for the given method.final ApplicationInfoGets the application info of the module.final SharedPreferencesgetRemotePreferences(String name) Gets remote preferences stored in Xposed framework.hook(Executable origin) Hook a method / constructor.hookClassInitializer(Class<?> origin) Hook the static initializer (<clinit>) of a class.final String[]List all files in the module's shared data directory.final voidWrites a message to the Xposed log.final voidWrites a message to the Xposed log.final ParcelFileDescriptoropenRemoteFile(String name) Open a file in the module's shared data directory.
-
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 interfacedetachImpl- The implementation ofdetach()
-
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 asXposedModuleInterface.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; allXposedInterfaceAPIs 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:XposedInterfaceGets the runtime Xposed API version. Framework implementations must not override this method.- Specified by:
getApiVersionin interfaceXposedInterface
-
getFrameworkName
Description copied from interface:XposedInterfaceGets the Xposed framework name of current implementation.- Specified by:
getFrameworkNamein interfaceXposedInterface
-
getFrameworkVersion
Description copied from interface:XposedInterfaceGets the Xposed framework version of current implementation.- Specified by:
getFrameworkVersionin interfaceXposedInterface
-
getFrameworkVersionCode
public final long getFrameworkVersionCode()Description copied from interface:XposedInterfaceGets the Xposed framework version code of current implementation.- Specified by:
getFrameworkVersionCodein interfaceXposedInterface
-
getFrameworkProperties
public final long getFrameworkProperties()Description copied from interface:XposedInterfaceGets the Xposed framework properties. Properties with prefixPROP_RT_may change among launches.- Specified by:
getFrameworkPropertiesin interfaceXposedInterface
-
hook
Description copied from interface:XposedInterfaceHook a method / constructor.- Specified by:
hookin interfaceXposedInterface- Parameters:
origin- The executable to be hooked- Returns:
- The builder for the hook
-
hookClassInitializer
Description copied from interface:XposedInterfaceHook the static initializer (<clinit>) of a class.The static initializer is treated as a regular
static void()method with no parameters. Accordingly, in theXposedInterface.Chainpassed to the hooker:XposedInterface.Chain.getExecutable()returns a syntheticMethodrepresenting the static initializer.XposedInterface.Chain.getThisObject()always returnsnull.XposedInterface.Chain.getArgs()returns an empty list.XposedInterface.Chain.proceed()returnsnull.
Note: If the class is already initialized, the hook will never be called.
- Specified by:
hookClassInitializerin interfaceXposedInterface- Parameters:
origin- The class whose static initializer is to be hooked- Returns:
- The builder for the hook
-
deoptimize
Description copied from interface:XposedInterfaceDeoptimizes 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:
deoptimizein interfaceXposedInterface- Parameters:
executable- The method / constructor to deoptimize- Returns:
- Indicate whether the deoptimizing succeed or not
-
getInvoker
Description copied from interface:XposedInterfaceGet a method invoker for the given method. Invocations through invokers will bypass access checks. The default type of the invoker isXposedInterface.Invoker.Type.Chain.FULL.- Specified by:
getInvokerin interfaceXposedInterface- 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:XposedInterfaceGet a constructor invoker for the given constructor. Invocations through invokers will bypass access checks. The default type of the invoker isXposedInterface.Invoker.Type.Chain.FULL.- Specified by:
getInvokerin interfaceXposedInterface- Type Parameters:
T- The type of the constructor- Parameters:
constructor- The constructor to get the invoker for- Returns:
- The constructor invoker
-
log
Description copied from interface:XposedInterfaceWrites a message to the Xposed log.- Specified by:
login interfaceXposedInterface- Parameters:
priority- The log priority, seeLogtag- The log tagmsg- The log message
-
log
public final void log(int priority, @Nullable String tag, @NonNull String msg, @Nullable Throwable tr) Description copied from interface:XposedInterfaceWrites a message to the Xposed log.- Specified by:
login interfaceXposedInterface- Parameters:
priority- The log priority, seeLogtag- The log tagmsg- The log messagetr- An exception to log
-
getRemotePreferences
Description copied from interface:XposedInterfaceGets remote preferences stored in Xposed framework. Note that those are read-only in hooked apps.- Specified by:
getRemotePreferencesin interfaceXposedInterface- Parameters:
name- Group name- Returns:
- The preferences
-
getModuleApplicationInfo
Description copied from interface:XposedInterfaceGets the application info of the module.- Specified by:
getModuleApplicationInfoin interfaceXposedInterface
-
listRemoteFiles
Description copied from interface:XposedInterfaceList all files in the module's shared data directory.- Specified by:
listRemoteFilesin interfaceXposedInterface- Returns:
- The file list
-
openRemoteFile
@NonNull public final ParcelFileDescriptor openRemoteFile(@NonNull String name) throws FileNotFoundException Description copied from interface:XposedInterfaceOpen a file in the module's shared data directory. The file is opened in read-only mode.- Specified by:
openRemoteFilein interfaceXposedInterface- 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
-