Skip to content

Commit 58fa5d9

Browse files
author
tiann
committed
[VXP]: refactor code.
1 parent 760e8f9 commit 58fa5d9

File tree

1 file changed

+28
-58
lines changed

1 file changed

+28
-58
lines changed

VirtualApp/lib/src/main/java/com/lody/virtual/client/hook/proxies/view/AutoFillManagerStub.java

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import android.content.ComponentName;
55
import android.util.Log;
66

7-
import com.lody.virtual.client.core.VirtualCore;
87
import com.lody.virtual.client.hook.base.BinderInvocationProxy;
9-
import com.lody.virtual.client.hook.base.MethodProxy;
10-
import com.lody.virtual.client.hook.utils.MethodParameterUtils;
8+
import com.lody.virtual.client.hook.base.ReplaceLastPkgMethodProxy;
119
import com.lody.virtual.helper.utils.ArrayUtils;
1210

1311
import java.lang.reflect.Field;
@@ -48,63 +46,35 @@ public void inject() throws Throwable {
4846
Log.e(TAG, "AutoFillManagerStub inject error.", tr);
4947
return;
5048
}
51-
addMethodProxy(new MethodProxy() {
52-
@Override
53-
public String getMethodName() {
54-
return "startSession";
55-
}
56-
@Override
57-
public boolean beforeCall(Object who, Method method, Object... args) {
58-
if (args == null) {
59-
return super.beforeCall(who, method, args);
60-
}
61-
int length = args.length;
62-
if (length == 0) {
63-
return super.beforeCall(who, method, args);
64-
}
65-
66-
int lastIndex = length - 1;
67-
Object lastParam = args[lastIndex];
68-
if (lastParam instanceof String) {
69-
MethodParameterUtils.replaceLastAppPkg(args);
70-
} else if (lastParam instanceof ComponentName){
71-
ComponentName lastComponent = (ComponentName) lastParam;
72-
ComponentName newComponent = new ComponentName(VirtualCore.get().getHostPkg(),
73-
lastComponent.getClassName());
74-
args[lastIndex] = newComponent;
75-
}
76-
return super.beforeCall(who, method, args);
77-
}
78-
});
7949

80-
addMethodProxy(new MethodProxy() {
81-
@Override
82-
public String getMethodName() {
83-
return "updateOrRestartSession";
84-
}
85-
@Override
86-
public boolean beforeCall(Object who, Method method, Object... args) {
87-
MethodParameterUtils.replaceLastAppPkg(args);
88-
int index = ArrayUtils.indexOfLast(args, ComponentName.class);
89-
if (index > 0) {
90-
ComponentName origComponent = (ComponentName) args[index];
91-
ComponentName newComponent = new ComponentName(getHostPkg(), origComponent.getClassName());
92-
args[index] = newComponent;
93-
}
94-
return super.beforeCall(who, method, args);
95-
}
96-
});
97-
addMethodProxy(new MethodProxy() {
98-
@Override
99-
public String getMethodName() {
100-
return "isServiceEnabled";
101-
}
102-
@Override
103-
public boolean beforeCall(Object who, Method method, Object... args) {
104-
MethodParameterUtils.replaceLastAppPkg(args);
105-
return super.beforeCall(who, method, args);
50+
addMethodProxy(new ReplacePkgAndComponentProxy("startSession"));
51+
addMethodProxy(new ReplacePkgAndComponentProxy("updateOrRestartSession"));
52+
addMethodProxy(new ReplaceLastPkgMethodProxy("isServiceEnabled"));
53+
}
54+
55+
static class ReplacePkgAndComponentProxy extends ReplaceLastPkgMethodProxy {
56+
57+
ReplacePkgAndComponentProxy(String name) {
58+
super(name);
59+
}
60+
61+
@Override
62+
public boolean beforeCall(Object who, Method method, Object... args) {
63+
replaceLastAppComponent(args, getHostPkg());
64+
return super.beforeCall(who, method, args);
65+
}
66+
67+
static ComponentName replaceLastAppComponent(Object[] args, String hostPkg) {
68+
int index = ArrayUtils.indexOfLast(args, ComponentName.class);
69+
if (index != -1) {
70+
ComponentName orig = (ComponentName) args[index];
71+
ComponentName newComponent = new ComponentName(hostPkg, orig.getClassName());
72+
args[index] = newComponent;
73+
return newComponent;
10674
}
107-
});
75+
return null;
76+
}
10877
}
10978

79+
11080
}

0 commit comments

Comments
 (0)