Note that there are some explanatory texts on larger screens.

plurals
  1. POUSB permission obtained via android.hardware.usb does not apply to NDK
    primarykey
    data
    text
    <p>I was able to obtain a permission to communicate with a device via Android's USB Host API. </p> <pre><code>private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; protected void execute(Context ctxt) { UsbManager manager = (UsbManager) viewer.getSystemService(Context.USB_SERVICE); HashMap&lt;String, UsbDevice&gt; deviceList = manager.getDeviceList(); UsbDevice d = null; for (String s : deviceList.keySet()) { d = deviceList.get(s); } PendingIntent mPermissionIntent = PendingIntent.getBroadcast(ctxt, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); viewer.registerReceiver(mUsbReceiver, filter); manager.requestPermission(d, mPermissionIntent); } private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION_USB_PERMISSION.equals(action)) { synchronized (this) { UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { if(device != null){ Log.d(TAG, "Permission granted!"); } } else { Log.d(TAG, "permission denied for device " + device); } } } } }; </code></pre> <p>Unfortunately that doesn't give my NDK code permission to directly communicate with this device (which is needed for libusb). Is there any way to "transfer" the permissions from Java to NDK without root?</p> <p>P.S. I ended up using UNIX sockets to transfer the original File Descirptor from Java to an Android native executable (I have GNU-ed the project at <a href="https://github.com/martinmarinov/rtl_tcp_andro-" rel="noreferrer">https://github.com/martinmarinov/rtl_tcp_andro-</a> ). For some people it would be even easier since they might be using NDK to connect with the device directly (not a third party app) and therefore the pointer that they use in Java may be still accessible by the NDK without having to mess around with UNIX sockets.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload