Skip to content

Commit 6bb556d

Browse files
committed
Android 12: Fix provider hook
Signed-off-by: tiann <[email protected]>
1 parent 065eea3 commit 6bb556d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

VirtualApp/lib/src/main/java/com/lody/virtual/client/hook/providers/ProviderHook.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import android.os.IInterface;
1010
import android.os.ParcelFileDescriptor;
1111

12+
import com.lody.virtual.client.core.VirtualCore;
1213
import com.lody.virtual.client.hook.base.MethodBox;
1314
import com.lody.virtual.helper.compat.BuildCompat;
15+
import com.lody.virtual.helper.utils.Reflect;
1416
import com.lody.virtual.helper.utils.VLog;
1517

1618
import java.lang.reflect.InvocationHandler;
@@ -153,8 +155,13 @@ public Object invoke(Object proxy, Method method, Object... args) throws Throwab
153155
}
154156
MethodBox methodBox = new MethodBox(method, mBase, args);
155157
int start = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 ? 1 : 0;
156-
// Android 11: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/content/IContentProvider.java?q=IContentProvider&ss=android%2Fplatform%2Fsuperproject
157-
if(Build.VERSION.SDK_INT >= 30) start = 2;
158+
if (BuildCompat.isS()) {
159+
// https://cs.android.com/android/platform/superproject/+/android-12.0.0_r16:frameworks/base/core/java/android/content/IContentProvider.java
160+
start = 1;
161+
} else if (BuildCompat.isR()) {
162+
// Android 11: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/content/IContentProvider.java?q=IContentProvider&ss=android%2Fplatform%2Fsuperproject
163+
start = 2;
164+
}
158165
try {
159166
String name = method.getName();
160167
if ("call".equals(name)) {
@@ -207,6 +214,9 @@ public Object invoke(Object proxy, Method method, Object... args) throws Throwab
207214
String[] selectionArgs = null;
208215
String sortOrder = null;
209216
Bundle queryArgs = null;
217+
if (BuildCompat.isS()) {
218+
fixAttributionSource(args[0]);
219+
}
210220
if (Build.VERSION.SDK_INT >= 26) {
211221
queryArgs = (Bundle) args[start + 2];
212222
if (queryArgs != null) {
@@ -238,4 +248,14 @@ protected void processArgs(Method method, Object... args) {
238248
public interface HookFetcher {
239249
ProviderHook fetch(boolean external, IInterface provider);
240250
}
251+
252+
private void fixAttributionSource(Object attribution) {
253+
try {
254+
Object mAttributionSourceState = Reflect.on(attribution).get("mAttributionSourceState");
255+
Reflect.on(mAttributionSourceState).set("uid", VirtualCore.get().myUid());
256+
Reflect.on(mAttributionSourceState).set("packageName", VirtualCore.get().getHostPkg());
257+
} catch (Throwable e) {
258+
e.printStackTrace();
259+
}
260+
}
241261
}

0 commit comments

Comments
 (0)