From 03ecf3e5acf5627850121c34aef942637be0a7b9 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 10 Feb 2018 16:56:01 -0800 Subject: [PATCH] Fix crash on Knox devices with USB blocking policies --- .../binding/input/driver/UsbDriverService.java | 14 +++++++++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/limelight/binding/input/driver/UsbDriverService.java b/app/src/main/java/com/limelight/binding/input/driver/UsbDriverService.java index 1adaf582..d4f16275 100644 --- a/app/src/main/java/com/limelight/binding/input/driver/UsbDriverService.java +++ b/app/src/main/java/com/limelight/binding/input/driver/UsbDriverService.java @@ -14,8 +14,10 @@ import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.view.InputDevice; +import android.widget.Toast; import com.limelight.LimeLog; +import com.limelight.R; import java.util.ArrayList; @@ -121,7 +123,17 @@ public class UsbDriverService extends Service implements UsbDriverListener { // Do we have permission yet? if (!usbManager.hasPermission(device)) { // Let's ask for permission - usbManager.requestPermission(device, PendingIntent.getBroadcast(UsbDriverService.this, 0, new Intent(ACTION_USB_PERMISSION), 0)); + try { + // This function is not documented as throwing any exceptions (denying access + // is indicated by calling the PendingIntent with a false result). However, + // Samsung Knox has some policies which block this request, but rather than + // just returning a false result or returning 0 enumerated devices, + // they throw an undocumented SecurityException from this call, crashing + // the whole app. :( + usbManager.requestPermission(device, PendingIntent.getBroadcast(UsbDriverService.this, 0, new Intent(ACTION_USB_PERMISSION), 0)); + } catch (SecurityException e) { + Toast.makeText(this, this.getText(R.string.error_usb_prohibited), Toast.LENGTH_LONG).show(); + } return; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b81b333..01399fe5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,6 +51,7 @@ Moonlight has crashed due to a problem with this device\'s video decoder. Try adjusting the streaming settings if the crashes continue. Video Settings Reset Your device\'s video decoder continues to crash at your selected streaming settings. Your streaming settings have been reset to default. + USB access is prohibited by your device administrator. Check your Knox or MDM settings. Establishing Connection