forked from qq1091192337/VirtualApp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop_libva_usb' into 'develop_libva_zhangsong'
USB适配 See merge request zhangsong/va_official!188
- Loading branch information
Showing
16 changed files
with
708 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
VirtualApp/lib/src/main/java/com/lody/virtual/client/hook/proxies/usb/UsbManagerStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.lody.virtual.client.hook.proxies.usb; | ||
|
||
import android.content.Context; | ||
import android.os.IInterface; | ||
|
||
import com.lody.virtual.client.core.VirtualCore; | ||
import com.lody.virtual.client.hook.base.BinderInvocationProxy; | ||
import com.lody.virtual.client.hook.base.StaticMethodProxy; | ||
import com.lody.virtual.helper.utils.ArrayUtils; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import mirror.android.hardware.usb.IUsbManager; | ||
import mirror.android.hardware.usb.UsbManager; | ||
|
||
public class UsbManagerStub extends BinderInvocationProxy { | ||
public UsbManagerStub() { | ||
super(IUsbManager.Stub.asInterface, Context.USB_SERVICE); | ||
} | ||
|
||
@Override | ||
public void inject() throws Throwable { | ||
super.inject(); | ||
final IInterface hookedService = getInvocationStub().getProxyInterface(); | ||
android.hardware.usb.UsbManager usbManager = (android.hardware.usb.UsbManager) VirtualCore.get().getContext().getSystemService(Context.USB_SERVICE); | ||
if (UsbManager.mService != null && hookedService != null){ | ||
Object mService = UsbManager.mService.get(usbManager); | ||
if (mService != null) { | ||
if (mService != hookedService) { | ||
UsbManager.mService.set(usbManager, hookedService); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onBindMethods() { | ||
super.onBindMethods(); | ||
addMethodProxy(new ReplacePackageNameWithUserId("openDevice")); | ||
addMethodProxy(new ReplacePackageNameWithUserId("setDevicePackage")); | ||
addMethodProxy(new ReplacePackageNameWithUserId("setAccessoryPackage")); | ||
addMethodProxy(new ReplacePackageNameWithUserId("hasDevicePermission")); | ||
addMethodProxy(new ReplacePackageNameWithUserId("hasAccessoryPermission")); | ||
addMethodProxy(new ReplacePackageNameWithUserId("requestDevicePermission")); | ||
addMethodProxy(new ReplacePackageNameWithUserId("requestAccessoryPermission")); | ||
addMethodProxy(new ReplacePackageNameWithUserId("hasDefaults")); | ||
addMethodProxy(new ReplacePackageNameWithUserId("clearDefaults")); | ||
} | ||
|
||
private class ReplacePackageNameWithUserId extends StaticMethodProxy { | ||
public ReplacePackageNameWithUserId(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public Object call(Object who, Method method, Object... args) throws Throwable { | ||
int index = ArrayUtils.indexOfLast(args, String.class); | ||
if (index >= 0) { | ||
String pkg = (String) args[index]; | ||
if (isAppPkg(pkg)) { | ||
args[index] = getHostPkg(); | ||
} | ||
if ((index + 1) < args.length) { | ||
if (args[index + 1] instanceof Integer) { | ||
int userId = (int) args[index + 1]; | ||
if (userId == getAppUserId() && userId != getRealUserId()) { | ||
args[index + 1] = getRealUserId(); | ||
} | ||
} | ||
} | ||
} | ||
return super.call(who, method, args); | ||
} | ||
} | ||
} |
Oops, something went wrong.