usb-serial-for-android: React to usb "permit granted" intent (stub)

When a user is downloading from a DC for the first time (without using
the "usb device connected" popup), the user is requested to grant
permission to use the USB device.

This is done asynchronously, thus the download is aborted. To be more
user-friendly, we now react to the intent with the "usb granted" result.
The plan here is to start the download again.

Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Christof Arnosti 2020-03-14 18:17:05 +01:00 committed by Dirk Hohndel
parent ce7d4d1ca6
commit d953c645e9

View file

@ -50,6 +50,11 @@ public class SubsurfaceMobileActivity extends QtActivity
isIntentPending = true; isIntentPending = true;
} }
} }
// Register the usb permission intent filter.
IntentFilter filter = new IntentFilter("org.subsurfacedivelog.mobile.USB_PERMISSION");
registerReceiver(usbReceiver, filter);
} // onCreate } // onCreate
// if we are opened from other apps: // if we are opened from other apps:
@ -104,6 +109,23 @@ public class SubsurfaceMobileActivity extends QtActivity
} // processIntent } // processIntent
private final BroadcastReceiver usbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ("org.subsurfacedivelog.mobile.USB_PERMISSION".equals(action)) {
synchronized (this) {
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
Log.d(TAG, "USB device permission granted");
// Stub: press the download button here :)
}
else {
Log.d(TAG, "USB device permission granted");
}
}
}
}
};
public static Context getAppContext() public static Context getAppContext()
{ {
return appContext; return appContext;