diff --git a/api/src/main/java/io/github/libxposed/XposedContextWrapper.java b/api/src/main/java/io/github/libxposed/XposedContextWrapper.java index 8e5dd5c..d228ad3 100644 --- a/api/src/main/java/io/github/libxposed/XposedContextWrapper.java +++ b/api/src/main/java/io/github/libxposed/XposedContextWrapper.java @@ -80,73 +80,73 @@ public class XposedContextWrapper extends ContextWrapper implements XposedInterf return getBaseContext().featuredMethod(name, args); } - @Nullable + @NonNull @Override final public MethodUnhooker, Method> hookBefore(@NonNull Method origin, @NonNull BeforeHooker hooker) { return getBaseContext().hookBefore(origin, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker, Method> hookAfter(@NonNull Method origin, @NonNull AfterHooker hooker) { return getBaseContext().hookAfter(origin, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker, Method> hook(@NonNull Method origin, @NonNull Hooker hooker) { return getBaseContext().hook(origin, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker, Method> hookBefore(@NonNull Method origin, int priority, @NonNull BeforeHooker hooker) { return getBaseContext().hookBefore(origin, priority, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker, Method> hookAfter(@NonNull Method origin, int priority, @NonNull AfterHooker hooker) { return getBaseContext().hookAfter(origin, priority, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker, Method> hook(@NonNull Method origin, int priority, @NonNull Hooker hooker) { return getBaseContext().hook(origin, priority, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker>, Constructor> hookBefore(@NonNull Constructor origin, @NonNull BeforeHooker> hooker) { return getBaseContext().hookBefore(origin, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker>, Constructor> hookAfter(@NonNull Constructor origin, @NonNull AfterHooker> hooker) { return getBaseContext().hookAfter(origin, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker>, Constructor> hook(@NonNull Constructor origin, @NonNull Hooker> hooker) { return getBaseContext().hook(origin, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker>, Constructor> hookBefore(@NonNull Constructor origin, int priority, @NonNull BeforeHooker> hooker) { return getBaseContext().hookBefore(origin, priority, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker>, Constructor> hookAfter(@NonNull Constructor origin, int priority, @NonNull AfterHooker> hooker) { return getBaseContext().hookAfter(origin, priority, hooker); } - @Nullable + @NonNull @Override final public MethodUnhooker>, Constructor> hook(@NonNull Constructor origin, int priority, @NonNull Hooker> hooker) { return getBaseContext().hook(origin, priority, hooker); diff --git a/api/src/main/java/io/github/libxposed/XposedInterface.java b/api/src/main/java/io/github/libxposed/XposedInterface.java index 6ca2e9c..541afc3 100644 --- a/api/src/main/java/io/github/libxposed/XposedInterface.java +++ b/api/src/main/java/io/github/libxposed/XposedInterface.java @@ -45,6 +45,19 @@ public interface XposedInterface { */ int FRAMEWORK_PRIVILEGE_EMBEDDED = 3; + /** + * The default hook priority. + */ + int PRIORITY_DEFAULT = 50; + /** + * Execute the hook callback late. + */ + int PRIORITY_LOWEST = -10000; + /** + * Execute the hook callback early. + */ + int PRIORITY_HIGHEST = 10000; + /** * The interface Before hook callback. * @@ -306,6 +319,24 @@ public interface XposedInterface { void unhook(); } + /** + * The exception thrown when a hook fails + */ + class HookFailedException extends RuntimeException { + + public HookFailedException(String message) { + super(message); + } + + public HookFailedException(Throwable cause) { + super(cause); + } + + public HookFailedException(String message, Throwable cause) { + super(message, cause); + } + } + /** * Gets framework name. * @@ -343,6 +374,7 @@ public interface XposedInterface { * @param args the args * @return the object */ + @Nullable Object featuredMethod(String name, Object... args); /** @@ -351,8 +383,9 @@ public interface XposedInterface { * @param origin the origin * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker, Method> hookBefore(@NonNull Method origin, @NonNull BeforeHooker hooker); /** @@ -361,8 +394,9 @@ public interface XposedInterface { * @param origin the origin * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker, Method> hookAfter(@NonNull Method origin, @NonNull AfterHooker hooker); /** @@ -371,8 +405,9 @@ public interface XposedInterface { * @param origin the origin * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker, Method> hook(@NonNull Method origin, @NonNull Hooker hooker); /** @@ -382,8 +417,9 @@ public interface XposedInterface { * @param priority the priority * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker, Method> hookBefore(@NonNull Method origin, int priority, @NonNull BeforeHooker hooker); /** @@ -393,8 +429,9 @@ public interface XposedInterface { * @param priority the priority * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker, Method> hookAfter(@NonNull Method origin, int priority, @NonNull AfterHooker hooker); /** @@ -404,8 +441,9 @@ public interface XposedInterface { * @param priority the priority * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker, Method> hook(@NonNull Method origin, int priority, @NonNull Hooker hooker); /** @@ -415,8 +453,9 @@ public interface XposedInterface { * @param origin the origin * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker>, Constructor> hookBefore(@NonNull Constructor origin, @NonNull BeforeHooker> hooker); /** @@ -426,8 +465,9 @@ public interface XposedInterface { * @param origin the origin * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker>, Constructor> hookAfter(@NonNull Constructor origin, @NonNull AfterHooker> hooker); /** @@ -437,8 +477,9 @@ public interface XposedInterface { * @param origin the origin * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker>, Constructor> hook(@NonNull Constructor origin, @NonNull Hooker> hooker); /** @@ -449,8 +490,9 @@ public interface XposedInterface { * @param priority the priority * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker>, Constructor> hookBefore(@NonNull Constructor origin, int priority, @NonNull BeforeHooker> hooker); /** @@ -461,8 +503,9 @@ public interface XposedInterface { * @param priority the priority * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker>, Constructor> hookAfter(@NonNull Constructor origin, int priority, @NonNull AfterHooker> hooker); /** @@ -473,8 +516,9 @@ public interface XposedInterface { * @param priority the priority * @param hooker the hooker * @return the method unhooker + * @throws HookFailedException if hook fails */ - @Nullable + @NonNull MethodUnhooker>, Constructor> hook(@NonNull Constructor origin, int priority, @NonNull Hooker> hooker); /**