Skip to content

Commit 55efdf9

Browse files
committed
Add two methods for constructors
1 parent 5458273 commit 55efdf9

8 files changed

Lines changed: 62 additions & 21 deletions

File tree

api/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ plugins {
66

77
android {
88
namespace = "io.github.libxposed.api"
9-
compileSdk = 34
10-
buildToolsVersion = "34.0.0"
9+
compileSdk = 35
10+
buildToolsVersion = "35.0.0"
1111

1212
defaultConfig {
1313
minSdk = 24
@@ -20,8 +20,8 @@ android {
2020
}
2121

2222
compileOptions {
23-
targetCompatibility = JavaVersion.VERSION_21
24-
sourceCompatibility = JavaVersion.VERSION_21
23+
targetCompatibility = JavaVersion.VERSION_1_8
24+
sourceCompatibility = JavaVersion.VERSION_1_8
2525
}
2626

2727
publishing {

api/src/main/java/io/github/libxposed/api/XposedInterface.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,17 @@ interface MethodUnhooker<T> {
365365
@Nullable
366366
Object invokeOrigin(@NonNull Method method, @Nullable Object thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException;
367367

368+
/**
369+
* Basically the same as {@link Constructor#newInstance(Object...)}, but calls the original constructor
370+
* as it was before the interception by Xposed.
371+
* @param constructor The constructor to create and initialize a new instance
372+
* @param thisObject The instance to be constructed
373+
* @param args The arguments used for the construction
374+
* @param <T> The type of the instance
375+
* @see Constructor#newInstance(Object...)
376+
*/
377+
<T> void invokeOrigin(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException;
378+
368379
/**
369380
* Invokes a special (non-virtual) method on a given object instance, similar to the functionality of
370381
* {@code CallNonVirtual<type>Method} in JNI, which invokes an instance (nonstatic) method on a Java
@@ -382,6 +393,21 @@ interface MethodUnhooker<T> {
382393
@Nullable
383394
Object invokeSpecial(@NonNull Method method, @NonNull Object thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException;
384395

396+
/**
397+
* Invokes a special (non-virtual) method on a given object instance, similar to the functionality of
398+
* {@code CallNonVirtual<type>Method} in JNI, which invokes an instance (nonstatic) method on a Java
399+
* object. This method is useful when you need to call a specific method on an object, bypassing any
400+
* overridden methods in subclasses and directly invoking the method defined in the specified class.
401+
*
402+
* <p>This method is useful when you need to call {@code super.xxx()} in a hooked constructor.</p>
403+
*
404+
* @param constructor The constructor to create and initialize a new instance
405+
* @param thisObject The instance to be constructed
406+
* @param args The arguments used for the construction
407+
* @see Constructor#newInstance(Object...)
408+
*/
409+
<T> void invokeSpecial(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException;
410+
385411
/**
386412
* Basically the same as {@link Constructor#newInstance(Object...)}, but calls the original constructor
387413
* as it was before the interception by Xposed.

api/src/main/java/io/github/libxposed/api/XposedInterfaceWrapper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,22 @@ public final Object invokeOrigin(@NonNull Method method, @Nullable Object thisOb
8989
return mBase.invokeOrigin(method, thisObject, args);
9090
}
9191

92+
@Override
93+
public <T> void invokeOrigin(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
94+
mBase.invokeOrigin(constructor, thisObject, args);
95+
}
96+
9297
@Nullable
9398
@Override
9499
public final Object invokeSpecial(@NonNull Method method, @NonNull Object thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
95100
return mBase.invokeSpecial(method, thisObject, args);
96101
}
97102

103+
@Override
104+
public <T> void invokeSpecial(@NonNull Constructor<T> constructor, @NonNull T thisObject, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException {
105+
mBase.invokeSpecial(constructor, thisObject, args);
106+
}
107+
98108
@NonNull
99109
@Override
100110
public final <T> T newInstanceOrigin(@NonNull Constructor<T> constructor, Object... args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException {

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[versions]
2-
annotation = "1.7.1"
3-
kotlin = "1.9.23"
4-
lint = "31.3.2"
5-
agp = "8.3.2"
2+
annotation = "1.8.0"
3+
kotlin = "2.0.0"
4+
lint = "31.5.1"
5+
agp = "8.5.1"
66

77
[plugins]
88
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

gradle/wrapper/gradle-wrapper.jar

-19.7 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)