add static method to test apk

This commit is contained in:
Jean-Marie 'Histausse' Mineau 2025-03-04 16:36:59 +01:00
parent 82e1ee2223
commit a365022185
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
2 changed files with 60 additions and 2 deletions

View file

@ -67,6 +67,14 @@ public class MainActivity extends Activity {
b7.generateViewId();
linLayout.addView(b7);
Button b8 = new Button(this);
b8.generateViewId();
linLayout.addView(b8);
Button b9 = new Button(this);
b9.generateViewId();
linLayout.addView(b9);
relLayout.addView(linLayout);
setContentView(relLayout);
@ -147,6 +155,28 @@ public class MainActivity extends Activity {
}
}
});
b8.setText("Static control");
b8.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
callStaticMethod();
} catch(Exception e) {
Log.e("THESEUS", "Error: ", e);
}
}
});
b9.setText("Static rflct");
b9.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
callStaticMethodReflectCall();
} catch(Exception e) {
Log.e("THESEUS", "Error: ", e);
}
}
});
}
// A normal virtual method call
@ -267,7 +297,29 @@ public class MainActivity extends Activity {
Utils.sink(this, newData);
}
// A normal virtual method call
public void callStaticMethod() {
String data = Utils.source("R7 no reflect");
String newData = Reflectee.staticTransfer(data);
Utils.sink(this, newData);
}
// A call to a virtual method through reflection
public void callStaticMethodReflectCall() throws
ClassNotFoundException,
NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
{
String data = Utils.source("R8 reflect");
ClassLoader cl = MainActivity.class.getClassLoader();
Class clz = cl.loadClass("com.example.theseus.reflection.Reflectee");
Method mth = clz.getMethod("staticTransfer", String.class);
String newData = (String) mth.invoke(null, data);
Utils.sink(this, newData);
}
// TODO: Interface, Inheritance
// TODO: many argument methods
// TODO: static
// TODO: factory patern
// TODO: factory patern
}

View file

@ -40,4 +40,10 @@ public class Reflectee {
}
return val;
}
public static String staticTransfer(
String data
) {
return "Static Transfer: " + data;
}
}