Skip to content

Commit

Permalink
Merge branch 'develop_libva_usb' into 'develop_libva_zhangsong'
Browse files Browse the repository at this point in the history
USB适配

See merge request zhangsong/va_official!188
  • Loading branch information
limingle committed Nov 6, 2020
2 parents 10b29e4 + d54eefc commit b7f3bfa
Show file tree
Hide file tree
Showing 16 changed files with 708 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
Expand Down Expand Up @@ -42,7 +39,6 @@
import com.lody.virtual.client.env.Constants;
import com.lody.virtual.client.ipc.VActivityManager;
import com.lody.virtual.client.stub.ChooseTypeAndAccountActivity;
import com.lody.virtual.client.stub.InstallerActivity;
import com.lody.virtual.client.stub.InstallerSetting;
import com.lody.virtual.client.stub.OutsideProxyContentProvider;
import com.lody.virtual.helper.utils.BitmapUtils;
Expand Down
35 changes: 35 additions & 0 deletions VirtualApp/lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

<uses-feature android:name="android.hardware.nfc" android:required="false" />
<uses-permission android:name="android.hardware.usb.host"/>
<uses-permission android:name="android.permission.HARDWARE_TEST"
tools:ignore="ProtectedPermissions" />

<application
android:vmSafeMode="true"><!-- false:性能提升,但是微信,QQ等应用会出现jit错误-->

Expand Down Expand Up @@ -3539,6 +3543,37 @@
</intent-filter>
</activity>

<activity
android:name="com.lody.virtual.client.stub.usb.ShadowUsbActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|fontScale"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:taskAffinity="com.lody.virtual.choose"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/usb_llvision_device_filter" />
</activity>
<activity
android:name=".client.stub.usb.UsbListChooserActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
android:excludeFromRecents="true"
android:exported="true"
android:finishOnCloseSystemDialogs="true"
android:permission="${PERMISSION_PREFIX}.permission.SAFE_ACCESS"
android:process="@string/engine_process_name"
android:taskAffinity="com.lody.virtual.choose"
android:theme="@style/VAAlertTheme" />

<meta-data android:name="android.vivo_nightmode_support" android:value="false"/>
<meta-data android:name="com.coloros.DisableSystemDarkMode" android:value="true"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.lody.virtual.client.hook.proxies.telephony.TelephonyRegistryStub;
import com.lody.virtual.client.hook.proxies.telephony.TelephonyStub;
import com.lody.virtual.client.hook.proxies.usage.UsageStatsManagerStub;
import com.lody.virtual.client.hook.proxies.usb.UsbManagerStub;
import com.lody.virtual.client.hook.proxies.user.UserManagerStub;
import com.lody.virtual.client.hook.proxies.vibrator.VibratorStub;
import com.lody.virtual.client.hook.proxies.view.AutoFillManagerStub;
Expand Down Expand Up @@ -229,6 +230,7 @@ private void injectInternal() throws Throwable {
addInjector(new RoleStub());
}
addInjector(new NfcAdapterStub());
addInjector(new UsbManagerStub());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.hardware.usb.UsbManager;
import android.text.TextUtils;
import android.util.Log;

Expand Down Expand Up @@ -84,6 +85,11 @@ public final class SpecialComponentList {
//图标广播
SYSTEM_BROADCAST_ACTION.add(Constants.ACTION_BADGER_CHANGE);
SYSTEM_BROADCAST_ACTION.add("com.android.mms.PROGRESS_STATUS");
//usb
SYSTEM_BROADCAST_ACTION.add(UsbManager.ACTION_USB_DEVICE_ATTACHED);
SYSTEM_BROADCAST_ACTION.add(UsbManager.ACTION_USB_DEVICE_DETACHED);
SYSTEM_BROADCAST_ACTION.add(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
SYSTEM_BROADCAST_ACTION.add(UsbManager.ACTION_USB_ACCESSORY_DETACHED);

ACTION_BLACK_LIST.add(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
ACTION_BLACK_LIST.add(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Expand Down
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);
}
}
}
Loading

0 comments on commit b7f3bfa

Please sign in to comment.