Merge pull request #2379 from open-keychain/usb-permission
Request missing permission when rescanning USB devices
This commit is contained in:
@@ -17,43 +17,29 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import timber.log.Timber;
|
||||
import org.sufficientlysecure.keychain.securitytoken.UsbConnectionDispatcher;
|
||||
|
||||
|
||||
public class UsbEventReceiverActivity extends Activity {
|
||||
public static final String ACTION_USB_PERMISSION =
|
||||
"org.sufficientlysecure.keychain.ui.USB_PERMISSION";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
final UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) {
|
||||
UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
|
||||
|
||||
Timber.d("Requesting permission for " + usbDevice.getDeviceName());
|
||||
usbManager.requestPermission(usbDevice,
|
||||
PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0));
|
||||
UsbConnectionDispatcher.requestPermissionForUsbDevice(getApplicationContext(), usbDevice);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the activity
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import android.nfc.TagLostException;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
||||
import nordpol.android.OnDiscoveredTagListener;
|
||||
import nordpol.android.TagDispatcher;
|
||||
import nordpol.android.TagDispatcherBuilder;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
@@ -56,8 +55,7 @@ import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public abstract class BaseSecurityTokenActivity extends BaseActivity
|
||||
implements OnDiscoveredTagListener, UsbConnectionDispatcher.OnDiscoveredUsbDeviceListener {
|
||||
public abstract class BaseSecurityTokenActivity extends BaseActivity {
|
||||
public static final int REQUEST_CODE_PIN = 1;
|
||||
|
||||
public static final String EXTRA_TAG_HANDLING_ENABLED = "tag_handling_enabled";
|
||||
@@ -108,8 +106,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
|
||||
onSecurityTokenError(error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tagDiscovered(Tag tag) {
|
||||
private void nfcTagDiscovered(Tag tag) {
|
||||
// Actual NFC operations are executed in doInBackground to not block the UI thread
|
||||
if (!mTagHandlingEnabled) {
|
||||
return;
|
||||
@@ -119,8 +116,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
|
||||
securityTokenDiscovered(nfcTransport);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void usbTransportDiscovered(UsbTransport usbTransport) {
|
||||
private void usbTransportDiscovered(UsbTransport usbTransport) {
|
||||
// Actual USB operations are executed in doInBackground to not block the UI thread
|
||||
if (!mTagHandlingEnabled) {
|
||||
return;
|
||||
@@ -184,14 +180,14 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mNfcTagDispatcher = new TagDispatcherBuilder(this, this)
|
||||
mNfcTagDispatcher = new TagDispatcherBuilder(this, this::nfcTagDiscovered)
|
||||
.enableUnavailableNfcUserPrompt(false)
|
||||
.enableSounds(true)
|
||||
.enableDispatchingOnUiThread(true)
|
||||
.enableBroadcomWorkaround(false)
|
||||
.build();
|
||||
|
||||
mUsbDispatcher = new UsbConnectionDispatcher(this, this);
|
||||
mUsbDispatcher = new UsbConnectionDispatcher(this, this::usbTransportDiscovered);
|
||||
|
||||
// Check whether we're recreating a previously destroyed instance
|
||||
if (savedInstanceState != null) {
|
||||
|
||||
Reference in New Issue
Block a user