35

我想在工业中使用android,

我可以使用 slickdevlabs.com 库毫无问题地连接到 Profilic 和 Ftdi USB 到串行芯片。

该应用程序有一个服务,它在启动时启动,连接到 USB 串行端口并做其他事情。

我的问题是主机设备与用户没有任何交互,

所以当安卓问

Allow the app "MyAPP" to access the USB device ?
[checkmark]Use by default for this USB device
Cancel            OK

没有人点击ok。

即使我检查了默认使用...复选框,如果我重新插入 USB 或重新启动主机设备,它会在下次启动时再次询问。

我以超级用户模式运行服务和应用程序,但没有区别,它再次询问。

我添加了意图过滤器,但没有区别,它每次都会问我。

        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
        </intent-filter>

        <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
            android:resource="@xml/device_filter" />
        <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
            android:resource="@xml/device_filter" />

任何意见如何绕过或禁用它?

我有 root 和 SU 访问权限。

4

13 回答 13

28

我知道这有点晚了,但仍然...

我有同样的问题,我想我已经设法解决了。Android 内部使用了一项服务,可以管理 USB 设备和配件。此服务对第三方开发人员是隐藏的,并且没有记录在案。如果您检查 UsbPermissionActivity 的源代码,您将能够弄清楚该服务是如何被调用的。为了调用服务 IUsbManager 接口和 ServiceManager 类被使用。这些都是隐藏的,所以你不能直接使用它们。但是您可以做的是在相应的名称空间(包)中创建具有完全相同名称的存根。然后您将能够编译该代码,而运行时环境将使用真实的东西。

唯一的要求您的应用程序必须是系统应用程序- 即它必须位于 /system/app/ 目录中。由于您的设备已植根,这应该不是问题。

所以你必须在你的项目中添加一个包:“ android.hardware.usb ”并在其中放入一个名为“ IUsbManager.java ”的文件,内容如下:

package android.hardware.usb;

public interface IUsbManager extends android.os.IInterface
{
    /** Local-side IPC implementation stub class. */
    public static abstract class Stub extends android.os.Binder implements android.hardware.usb.IUsbManager
    {
        /** Construct the stub at attach it to the interface. */
        public Stub()
        {
            throw new RuntimeException( "Stub!" );
        }
        /**
         * Cast an IBinder object into an android.hardware.usb.IUsbManager interface,
         * generating a proxy if needed.
         */
        public static android.hardware.usb.IUsbManager asInterface( android.os.IBinder obj )
        {
            throw new RuntimeException( "Stub!" );
        }

        public android.os.IBinder asBinder()
        {
            throw new RuntimeException( "Stub!" );
        }

        public boolean onTransact( int code, android.os.Parcel data, android.os.Parcel reply, int flags ) throws android.os.RemoteException
        {
            throw new RuntimeException( "Stub!" );
        }

        static final int TRANSACTION_getDeviceList = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
        static final int TRANSACTION_openDevice = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
        static final int TRANSACTION_getCurrentAccessory = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
        static final int TRANSACTION_openAccessory = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
        static final int TRANSACTION_setDevicePackage = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
        static final int TRANSACTION_setAccessoryPackage = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5);
        static final int TRANSACTION_hasDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6);
        static final int TRANSACTION_hasAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 7);
        static final int TRANSACTION_requestDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 8);
        static final int TRANSACTION_requestAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 9);
        static final int TRANSACTION_grantDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 10);
        static final int TRANSACTION_grantAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 11);
        static final int TRANSACTION_hasDefaults = (android.os.IBinder.FIRST_CALL_TRANSACTION + 12);
        static final int TRANSACTION_clearDefaults = (android.os.IBinder.FIRST_CALL_TRANSACTION + 13);
        static final int TRANSACTION_setCurrentFunction = (android.os.IBinder.FIRST_CALL_TRANSACTION + 14);
        static final int TRANSACTION_setMassStorageBackingFile = (android.os.IBinder.FIRST_CALL_TRANSACTION + 15);
    }

    /* Returns a list of all currently attached USB devices */
    public void getDeviceList( android.os.Bundle devices ) throws android.os.RemoteException;
    /* Returns a file descriptor for communicating with the USB device.
         * The native fd can be passed to usb_device_new() in libusbhost.
         */
    public android.os.ParcelFileDescriptor openDevice( java.lang.String deviceName ) throws android.os.RemoteException;
    /* Returns the currently attached USB accessory */
    public android.hardware.usb.UsbAccessory getCurrentAccessory() throws android.os.RemoteException;
    /* Returns a file descriptor for communicating with the USB accessory.
         * This file descriptor can be used with standard Java file operations.
         */
    public android.os.ParcelFileDescriptor openAccessory( android.hardware.usb.UsbAccessory accessory ) throws android.os.RemoteException;
    /* Sets the default package for a USB device
         * (or clears it if the package name is null)
         */
    public void setDevicePackage( android.hardware.usb.UsbDevice device, java.lang.String packageName ) throws android.os.RemoteException;
    /* Sets the default package for a USB accessory
         * (or clears it if the package name is null)
         */
    public void setAccessoryPackage( android.hardware.usb.UsbAccessory accessory, java.lang.String packageName ) throws android.os.RemoteException;
    /* Returns true if the caller has permission to access the device. */
    public boolean hasDevicePermission(android.hardware.usb.UsbDevice device) throws android.os.RemoteException;
    /* Returns true if the caller has permission to access the accessory. */
    public boolean hasAccessoryPermission( android.hardware.usb.UsbAccessory accessory ) throws android.os.RemoteException;
    /* Requests permission for the given package to access the device.
         * Will display a system dialog to query the user if permission
         * had not already been given.
         */
    public void requestDevicePermission( android.hardware.usb.UsbDevice device, java.lang.String packageName, android.app.PendingIntent pi ) throws android.os.RemoteException;
    /* Requests permission for the given package to access the accessory.
         * Will display a system dialog to query the user if permission
         * had not already been given. Result is returned via pi.
         */
    public void requestAccessoryPermission( android.hardware.usb.UsbAccessory accessory, java.lang.String packageName, android.app.PendingIntent pi ) throws android.os.RemoteException;
    /* Grants permission for the given UID to access the device */
    public void grantDevicePermission( android.hardware.usb.UsbDevice device, int uid ) throws android.os.RemoteException;
    /* Grants permission for the given UID to access the accessory */
    public void grantAccessoryPermission( android.hardware.usb.UsbAccessory accessory, int uid ) throws android.os.RemoteException;
    /* Returns true if the USB manager has default preferences or permissions for the package */
    public boolean hasDefaults( java.lang.String packageName ) throws android.os.RemoteException;
    /* Clears default preferences and permissions for the package */
    public void clearDefaults( java.lang.String packageName ) throws android.os.RemoteException;
    /* Sets the current USB function. */
    public void setCurrentFunction( java.lang.String function, boolean makeDefault ) throws android.os.RemoteException;
    /* Sets the file path for USB mass storage backing file. */
    public void setMassStorageBackingFile( java.lang.String path ) throws android.os.RemoteException;
}

然后是另一个包:“ android.os ”和“ ServiceManager.java ”:

package android.os;

import java.util.Map;

public final class ServiceManager
{
    public static IBinder getService( String name )
    {
        throw new RuntimeException( "Stub!" );
    }

    /**
     * Place a new @a service called @a name into the service
     * manager.
     * 
     * @param name the name of the new service
     * @param service the service object
     */
    public static void addService( String name, IBinder service )
    {
        throw new RuntimeException( "Stub!" );
    }

    /**
     * Retrieve an existing service called @a name from the
     * service manager.  Non-blocking.
     */
    public static IBinder checkService( String name )
    {
        throw new RuntimeException( "Stub!" );
    }

    public static String[] listServices() throws RemoteException
    {
        throw new RuntimeException( "Stub!" );
    }

    /**
     * This is only intended to be called when the process is first being brought
     * up and bound by the activity manager. There is only one thread in the process
     * at that time, so no locking is done.
     * 
     * @param cache the cache of service references
     * @hide
     */
    public static void initServiceCache( Map<String, IBinder> cache )
    {
        throw new RuntimeException( "Stub!" );
    }
}

请注意,这些类的接口可能会根据 Android 的版本而变化。在我的情况下,版本是4.0.3。因此,如果您有另一个版本的 Android 并且此代码不起作用,您将必须检查您的特定操作系统版本的源代码。

以下是使用该服务向所有 FTDI 设备授予权限的示例:

import java.util.HashMap;
import java.util.Iterator;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.hardware.usb.IUsbManager;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.IBinder;
import android.os.ServiceManager;

public class LaunchReceiver extends BroadcastReceiver
{
    public void onReceive( Context context, Intent intent )
    {
        String action = intent.getAction();
        if( action != null && action.equals( Intent.ACTION_BOOT_COMPLETED ) )
        {
            try
            {
                PackageManager pm = context.getPackageManager();
                ApplicationInfo ai = pm.getApplicationInfo( YOUR_APP_PACKAGE_NAMESPACE, 0 );
                if( ai != null )
                {
                    UsbManager manager = (UsbManager) context.getSystemService( Context.USB_SERVICE );
                    IBinder b = ServiceManager.getService( Context.USB_SERVICE );
                    IUsbManager service = IUsbManager.Stub.asInterface( b );

                    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
                    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
                    while( deviceIterator.hasNext() )
                    {
                            UsbDevice device = deviceIterator.next();
                            if( device.getVendorId() == 0x0403 )
                            {
                                service.grantDevicePermission( device, ai.uid );
                                service.setDevicePackage( device, YOUR_APP_PACKAGE_NAMESPACE );
                            }
                    }
                }
            }
            catch( Exception e )
            {
                trace( e.toString() );
            }
        }
    }
}

还有一件事 - 您必须在清单中添加以下权限(Lint 可能不喜欢它,但您始终可以在项目属性中更改严重级别):

<uses-permission android:name="android.permission.MANAGE_USB" />
于 2013-03-13T06:00:43.487 回答
13

@d_d_t aswer is great, but it dosen't work on Android > 4.2.2. Use this interface:

public interface IUsbManager extends android.os.IInterface
{
/** Local-side IPC implementation stub class. */
public static abstract class Stub extends android.os.Binder implements android.hardware.usb.IUsbManager {
    private static final java.lang.String DESCRIPTOR = "android.hardware.usb.IUsbManager";

    /** Construct the stub at attach it to the interface. */
    public Stub()         {
        throw new RuntimeException( "Stub!" );
    }

    /**
     * Cast an IBinder object into an android.hardware.usb.IUsbManager
     * interface, generating a proxy if needed.
     */
    public static android.hardware.usb.IUsbManager asInterface( android.os.IBinder obj) {
        throw new RuntimeException( "Stub!" );
    }

    @Override
    public android.os.IBinder asBinder() {
        throw new RuntimeException( "Stub!" );
    }

    @Override
    public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException {
        throw new RuntimeException( "Stub!" );
    }

    static final int TRANSACTION_getDeviceList = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
    static final int TRANSACTION_openDevice = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
    static final int TRANSACTION_getCurrentAccessory = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
    static final int TRANSACTION_openAccessory = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
    static final int TRANSACTION_setDevicePackage = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
    static final int TRANSACTION_setAccessoryPackage = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5);
    static final int TRANSACTION_hasDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6);
    static final int TRANSACTION_hasAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 7);
    static final int TRANSACTION_requestDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 8);
    static final int TRANSACTION_requestAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 9);
    static final int TRANSACTION_grantDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 10);
    static final int TRANSACTION_grantAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 11);
    static final int TRANSACTION_hasDefaults = (android.os.IBinder.FIRST_CALL_TRANSACTION + 12);
    static final int TRANSACTION_clearDefaults = (android.os.IBinder.FIRST_CALL_TRANSACTION + 13);
    static final int TRANSACTION_setCurrentFunction = (android.os.IBinder.FIRST_CALL_TRANSACTION + 14);
    static final int TRANSACTION_setMassStorageBackingFile = (android.os.IBinder.FIRST_CALL_TRANSACTION + 15);
    static final int TRANSACTION_allowUsbDebugging = (android.os.IBinder.FIRST_CALL_TRANSACTION + 16);
    static final int TRANSACTION_denyUsbDebugging = (android.os.IBinder.FIRST_CALL_TRANSACTION + 17);
}

/* Returns a list of all currently attached USB devices */
public void getDeviceList(android.os.Bundle devices)
        throws android.os.RemoteException;

/*
 * Returns a file descriptor for communicating with the USB device. The
 * native fd can be passed to usb_device_new() in libusbhost.
 */
public android.os.ParcelFileDescriptor openDevice(
        java.lang.String deviceName) throws android.os.RemoteException;

/* Returns the currently attached USB accessory */
public android.hardware.usb.UsbAccessory getCurrentAccessory()
        throws android.os.RemoteException;

/*
 * Returns a file descriptor for communicating with the USB accessory. This
 * file descriptor can be used with standard Java file operations.
 */
public android.os.ParcelFileDescriptor openAccessory(
        android.hardware.usb.UsbAccessory accessory)
        throws android.os.RemoteException;

/*
 * Sets the default package for a USB device (or clears it if the package
 * name is null)
 */
public void setDevicePackage(android.hardware.usb.UsbDevice device,
        java.lang.String packageName, int userId)
        throws android.os.RemoteException;

/*
 * Sets the default package for a USB accessory (or clears it if the package
 * name is null)
 */
public void setAccessoryPackage(
        android.hardware.usb.UsbAccessory accessory,
        java.lang.String packageName, int userId)
        throws android.os.RemoteException;

/* Returns true if the caller has permission to access the device. */
public boolean hasDevicePermission(android.hardware.usb.UsbDevice device)
        throws android.os.RemoteException;

/* Returns true if the caller has permission to access the accessory. */
public boolean hasAccessoryPermission(
        android.hardware.usb.UsbAccessory accessory)
        throws android.os.RemoteException;

/*
 * Requests permission for the given package to access the device. Will
 * display a system dialog to query the user if permission had not already
 * been given.
 */
public void requestDevicePermission(android.hardware.usb.UsbDevice device,
        java.lang.String packageName, android.app.PendingIntent pi)
        throws android.os.RemoteException;

/*
 * Requests permission for the given package to access the accessory. Will
 * display a system dialog to query the user if permission had not already
 * been given. Result is returned via pi.
 */
public void requestAccessoryPermission(
        android.hardware.usb.UsbAccessory accessory,
        java.lang.String packageName, android.app.PendingIntent pi)
        throws android.os.RemoteException;

/* Grants permission for the given UID to access the device */
public void grantDevicePermission(android.hardware.usb.UsbDevice device,
        int uid) throws android.os.RemoteException;

/* Grants permission for the given UID to access the accessory */
public void grantAccessoryPermission(
        android.hardware.usb.UsbAccessory accessory, int uid)
        throws android.os.RemoteException;

/*
 * Returns true if the USB manager has default preferences or permissions
 * for the package
 */
public boolean hasDefaults(java.lang.String packageName, int userId)
        throws android.os.RemoteException;

/* Clears default preferences and permissions for the package */
public void clearDefaults(java.lang.String packageName, int userId)
        throws android.os.RemoteException;

/* Sets the current USB function. */
public void setCurrentFunction(java.lang.String function,
        boolean makeDefault) throws android.os.RemoteException;

/* Sets the file path for USB mass storage backing file. */
public void setMassStorageBackingFile(java.lang.String path)
        throws android.os.RemoteException;

/*
 * Allow USB debugging from the attached host. If alwaysAllow is true, add
 * the the public key to list of host keys that the user has approved.
 */
public void allowUsbDebugging(boolean alwaysAllow,
        java.lang.String publicKey) throws android.os.RemoteException;

/* Deny USB debugging from the attached host */
public void denyUsbDebugging() throws android.os.RemoteException;
}

And modify the code adding user id:

...
service.setDevicePackage( usbDevice, YOUR_APP_PACKAGE_NAMESPACE, ai.uid ); 
....
于 2013-10-30T12:09:13.663 回答
9

我对弹出窗口有同样的问题,没有人点击它。但我找到了一个不同的解决方案(针对有根设备)。弹出窗口由 android 在UsbPermissionActivity类中生成(并且 UsbPermissionActivity 由 UsbSettingsManager 启动)。查看 Android 源代码以了解发生了什么。这里的好处是,我们可以操纵 UsbPermissionActivity 的字节码来接受所有的 UsbDevices。您需要Smali/Baksmali工具来执行此操作。https://code.google.com/p/smali/

  1. 在您的设备上找到文件SystemUI.apk
  2. 将其复制到您的计算机adb pull path/to/SystemUI.apk
  3. 解压apk
  4. 反汇编 classes.dex 文件java -jar baksmali.jar classes.dex
  5. 找到文件 UsbPermissionActivity 并在其中找到说

    invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->setupAlert()V

  6. 通过将其注释掉并添加两个新行来更改它

#invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->setupAlert()V const/4 v0, 0x1 iput-boolean v0, p0, Lcom/android/systemui/usb/UsbPermissionActivity;->mPermissionGranted:Z invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->finish()V

  1. 组装它java -jar smali.jar -o classes.dex out
  2. 替换原来的 classes.dex 并将所有内容再次压缩到 SystemUI.apk
  3. 将您设备上的原始 SystemUI.apk 替换adb push services.jar path/to/SystemUI.apk为文件管理器 ap 或如果它不适用于文件管理器 ap
于 2015-05-31T22:10:11.950 回答
5

如果你有编译安卓系统的选项,那么没有什么是你做不到的。

你可以加

public void onStart() {
    super.onStart();
    mPermissionGranted = true;

    finish();
}

到 frameworks/base/packages/SystemUI/src/com/android/systemui/usb/UsbPermissionActivity.java

绕过权限确认弹出窗口。

于 2014-11-17T08:09:08.553 回答
5

解决方案是使用意图过滤器并将android:directBootAware="true"属性添加到关联的活动中,以便USB_DEVICE_ATTACHED在启动/重新启动后正确接收事件。重要的是不要USB在代码中请求设备权限,只使用意图过滤器,如下所示:

<manifest>
    <uses-feature android:name="android.hardware.usb.host" />
    <activity
        ...
        android:directBootAware="true">

        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
        </intent-filter>

        <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
        android:resource="@xml/device_filter" />

    </activity>
</manifest>

使用与此类似的 device_filter XML资源文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <usb-device vendor-id="1234" product-id="5678" />
</resources>
于 2020-03-19T22:31:54.093 回答
4

Android 并不是为了支持这种开箱即用的使用而设计的。就个人而言,对于非交互式使用,我很想考虑在 linux 内核中使用 USB 串行驱动程序并跳过 android USB api。但是您必须能够认真修改 android 安装 - 更改内核配置和/或加载模块,创建设备文件并设置其权限或所有者,可能为允许的应用添加 unix 组和 android 权限访问它。

或者您可以查看android源并禁用用户确认;但是如果您没有为设备提供源代码 android 构建,这可能比 linux 级别的想法更棘手,因为调整开源 android 以在供应商设备上运行可能并非易事(除非有人已经提供了来自- 对相关设备具有足够功能的源构建)

顺便说一句,root/su 访问权限不适用于应用程序本身 - 它仅意味着知道如何运行您的 root hack 留下的任何工具的应用程序可以启动一个以 root 身份运行的帮助程序,但应用程序本身并不不能。使用 root 在系统分区上安装应用程序可能会获得一些非典型的 android 权限,但您必须检查是否有任何可以帮助您使用 USB 的权限。

于 2012-12-05T15:56:26.183 回答
3

我认为提前将您正在使用的配件列入白名单将是最好的解决方案。为此,您需要在此位置 /data/system/users/0 添加文件 usb_device_manager.xml
// 请注意,0 是用户 ID,如果您没有在 Android 中添加更多用户,则它可能为 0,但如果您确实相应地更改了此 ID

这是文件的外观:

<settings>
<preference package="<PACKAGE NAME OF APP YOU WANT TO START ON CONNECTIONCTION>">
    <usb-accessory manufacturer="<NAME OF MANUFECTURER LIKE ONE REGISTERED IN meta-data in the manifest>" model="<MODEL NAME LIKE ONE REGISTERED IN meta-data in the manifest>" version="<VERSION LIKE ONE REGISTERED IN meta-data in the manifest>" />
</preference>

对于像这样的板http://www.embeddedartists.com/products/app/aoa_kit.php它是:

 <?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<settings>
<preference package="com.embeddedartists.aoa">
    <usb-accessory manufacturer="Embedded Artists AB" model="AOA Board - Basic" version="1.0" />
</preference>

于 2015-07-30T10:11:21.657 回答
2

根据 Android Developers 上的文档,当您的应用通过您的清单意图过滤器启动时,您已经拥有对连接的 USB 设备的权限。也许您应该尝试这种方法并编写一个过滤器以与您要使用的设备完全匹配,以防止其他应用程序也想与该设备通信。

请参阅http://developer.android.com/guide/topics/connectivity/usb/host.html#permission-d上的“注释”

于 2013-03-05T08:43:24.337 回答
1

实现这一点的一种方法,请注意,这实际上并没有摆脱确认,而是精确定位 的位置checkbox并使用机器人类的 Android 等效项来选择它,然后选择OK。您可以编写一个在后台运行的应用程序,它甚至可以由您提到的启动服务调用,专门用于此目的。

于 2013-01-20T22:45:51.857 回答
0

如果您有权访问 Android 源代码,这里是您需要禁用权限对话框的代码

https://gitlab.tubit.tu-berlin.de/justus.beyer/streamagame_platform_frameworks_base/commit/e97b62ed0d4050acacbf54781435686ea28edd73

上面的代码更新创建了一个您可以使用的配置选项,或者您可以使用值 true 代替硬编码mDisablePermissionDialogs来禁用权限对话框。

services/usb/java/com/android/server/usb/UsbSettingsManager.java

于 2019-04-11T04:53:02.790 回答
-1

我遇到了同样的问题,每次插入 USB 电缆时都会出现权限弹出窗口,为了解决这个问题,我只是在清单中添加了过滤器以及 VID 和 PID 的 xml 文件,只需确保您已按照建议设置 USB 设备过滤上面的 SO 链接或这里记录的,你把好的 VID 和 PID。这是我的问题,我没有将与我的设备匹配的 VID 和 PID

于 2018-01-30T18:48:56.393 回答
-1

第一次需要确认的时候,可以选择“always”,这样即使Android设备掉电,再上电,你的app仍然有权限访问USB2Serial。只是说,只有一次确认!

于 2017-01-25T10:52:19.177 回答
-2

我认为我们可以通过在/etc/udev. 我们可以将供应商 ID 和设备 ID 添加到51-android.rules文件中。

于 2013-01-15T08:19:57.840 回答