mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-23 17:05:36 +00:00
Handle failure to load hidapi gracefully
This commit is contained in:
parent
c4918db580
commit
e6068b5b15
|
@ -1,5 +1,7 @@
|
||||||
package org.libsdl.app;
|
package org.libsdl.app;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
@ -8,6 +10,7 @@ import android.bluetooth.BluetoothProfile;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -98,14 +101,36 @@ public class HIDDeviceManager {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private HIDDeviceManager(Context context) {
|
private HIDDeviceManager(final Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
|
||||||
// Make sure we have the HIDAPI library loaded with the native functions
|
// Make sure we have the HIDAPI library loaded with the native functions
|
||||||
try {
|
try {
|
||||||
SDL.loadLibrary("hidapi");
|
SDL.loadLibrary("hidapi");
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
Log.w(TAG, "Couldn't load hidapi: " + e.toString());
|
Log.w(TAG, "Couldn't load hidapi: " + e.toString());
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setCancelable(false);
|
||||||
|
builder.setTitle("SDL HIDAPI Error");
|
||||||
|
builder.setMessage("Please report the following error to the SDL maintainers: " + e.getMessage());
|
||||||
|
builder.setNegativeButton("Quit", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
try {
|
||||||
|
// If our context is an activity, exit rather than crashing when we can't
|
||||||
|
// call our native functions.
|
||||||
|
Activity activity = (Activity)context;
|
||||||
|
|
||||||
|
activity.finish();
|
||||||
|
}
|
||||||
|
catch (ClassCastException cce) {
|
||||||
|
// Context wasn't an activity, there's nothing we can do. Give up and return.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class SDL {
|
||||||
Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass);
|
Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass);
|
||||||
loadMethod.invoke(relinkInstance, mContext, libraryName, null, null);
|
loadMethod.invoke(relinkInstance, mContext, libraryName, null, null);
|
||||||
}
|
}
|
||||||
catch (final Exception e) {
|
catch (final Throwable e) {
|
||||||
// Fall back
|
// Fall back
|
||||||
try {
|
try {
|
||||||
System.loadLibrary(libraryName);
|
System.loadLibrary(libraryName);
|
||||||
|
|
Loading…
Reference in a new issue