Merge pull request #9836 from JosJuice/android-getemulationactivity

Android: Don't use getEmulationActivity in GCAdapter/Wiimote code
This commit is contained in:
Mai M 2021-06-22 11:59:25 -04:00 committed by GitHub
commit be2ec728e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 53 deletions

View File

@ -1,6 +1,5 @@
package org.dolphinemu.dolphinemu.utils;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@ -16,7 +15,8 @@ import android.widget.Toast;
import androidx.annotation.Keep;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.DolphinApplication;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.services.USBPermService;
import java.util.HashMap;
@ -35,9 +35,6 @@ public class Java_GCAdapter
static UsbEndpoint usb_out;
private static void RequestPermission()
{
Context context = NativeLibrary.getEmulationActivity();
if (context != null)
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
@ -47,6 +44,7 @@ public class Java_GCAdapter
{
if (!manager.hasPermission(dev))
{
Context context = DolphinApplication.getAppContext();
Intent intent = new Intent(context, USBPermService.class);
int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ?
@ -58,12 +56,6 @@ public class Java_GCAdapter
}
}
}
else
{
Log.warning("Cannot request GameCube Adapter permission as EmulationActivity is null.");
}
}
public static void Shutdown()
{
@ -153,17 +145,8 @@ public class Java_GCAdapter
}
}
final Activity emulationActivity = NativeLibrary.getEmulationActivity();
if (emulationActivity != null)
{
emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity,
"GameCube Adapter couldn't be opened. Please re-plug the device.",
Toast.LENGTH_LONG).show());
}
else
{
Log.warning("Cannot show toast for GameCube Adapter failure.");
}
Toast.makeText(DolphinApplication.getAppContext(), R.string.replug_gc_adapter,
Toast.LENGTH_LONG).show();
usb_con.close();
}
}

View File

@ -13,7 +13,7 @@ import android.os.Build;
import androidx.annotation.Keep;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.DolphinApplication;
import org.dolphinemu.dolphinemu.services.USBPermService;
import java.util.Arrays;
@ -37,9 +37,6 @@ public class Java_WiimoteAdapter
public static byte[][] wiimote_payload = new byte[MAX_WIIMOTES][MAX_PAYLOAD];
private static void RequestPermission()
{
Context context = NativeLibrary.getEmulationActivity();
if (context != null)
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
@ -52,6 +49,7 @@ public class Java_WiimoteAdapter
{
Log.warning("Requesting permission for Wii Remote adapter");
Context context = DolphinApplication.getAppContext();
Intent intent = new Intent(context, USBPermService.class);
int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ?
@ -63,11 +61,6 @@ public class Java_WiimoteAdapter
}
}
}
else
{
Log.warning("Cannot request Wiimote adapter permission as EmulationActivity is null.");
}
}
@Keep
public static boolean QueryAdapter()

View File

@ -477,6 +477,7 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="default_values">Default Values</string>
<string name="slider_setting_value">%1$d%2$s</string>
<string name="disc_number">Disc %1$d</string>
<string name="replug_gc_adapter">GameCube Adapter couldn\'t be opened. Please re-plug the device.</string>
<string name="disabled_gc_overlay_notice">GameCube Controller 1 is set to \"None\"</string>
<string name="ignore_warning_alert_messages">Ignore for this session</string>
<string name="make_sure_continuous_scan_enabled">Please make sure Continuous Scanning is enabled in Core Settings.</string>