Android: Clean up naming in Java_GCAdapter and Java_WiimoteAdapter

This isn't how we name things in Java/Kotlin.
This commit is contained in:
JosJuice 2025-01-02 15:39:41 +01:00
commit 7508842859
5 changed files with 69 additions and 69 deletions

View file

@ -9,8 +9,8 @@ import android.hardware.usb.UsbManager;
import org.dolphinemu.dolphinemu.utils.ActivityTracker; import org.dolphinemu.dolphinemu.utils.ActivityTracker;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.Java_GCAdapter; import org.dolphinemu.dolphinemu.utils.GCAdapter;
import org.dolphinemu.dolphinemu.utils.Java_WiimoteAdapter; import org.dolphinemu.dolphinemu.utils.WiimoteAdapter;
import org.dolphinemu.dolphinemu.utils.VolleyUtil; import org.dolphinemu.dolphinemu.utils.VolleyUtil;
public class DolphinApplication extends Application public class DolphinApplication extends Application
@ -28,8 +28,8 @@ public class DolphinApplication extends Application
VolleyUtil.init(getApplicationContext()); VolleyUtil.init(getApplicationContext());
System.loadLibrary("main"); System.loadLibrary("main");
Java_GCAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE); GCAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE);
Java_WiimoteAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE); WiimoteAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE);
if (DirectoryInitialization.shouldStart(getApplicationContext())) if (DirectoryInitialization.shouldStart(getApplicationContext()))
DirectoryInitialization.start(getApplicationContext()); DirectoryInitialization.start(getApplicationContext());

View file

@ -24,19 +24,19 @@ import org.dolphinemu.dolphinemu.services.USBPermService;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class Java_GCAdapter public class GCAdapter
{ {
public static UsbManager manager; public static UsbManager manager;
@Keep @Keep
static byte[] controller_payload = new byte[37]; static byte[] controllerPayload = new byte[37];
static UsbDeviceConnection usb_con; static UsbDeviceConnection usbConnection;
static UsbInterface usb_intf; static UsbInterface usbInterface;
static UsbEndpoint usb_in; static UsbEndpoint usbIn;
static UsbEndpoint usb_out; static UsbEndpoint usbOut;
private static void RequestPermission() private static void requestPermission()
{ {
HashMap<String, UsbDevice> devices = manager.getDeviceList(); HashMap<String, UsbDevice> devices = manager.getDeviceList();
for (Map.Entry<String, UsbDevice> pair : devices.entrySet()) for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
@ -59,19 +59,19 @@ public class Java_GCAdapter
} }
} }
public static void Shutdown() public static void shutdown()
{ {
usb_con.close(); usbConnection.close();
} }
@Keep @Keep
public static int GetFD() public static int getFd()
{ {
return usb_con.getFileDescriptor(); return usbConnection.getFileDescriptor();
} }
@Keep @Keep
public static boolean QueryAdapter() public static boolean queryAdapter()
{ {
HashMap<String, UsbDevice> devices = manager.getDeviceList(); HashMap<String, UsbDevice> devices = manager.getDeviceList();
for (Map.Entry<String, UsbDevice> pair : devices.entrySet()) for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
@ -82,32 +82,32 @@ public class Java_GCAdapter
if (manager.hasPermission(dev)) if (manager.hasPermission(dev))
return true; return true;
else else
RequestPermission(); requestPermission();
} }
} }
return false; return false;
} }
public static void InitAdapter() public static void initAdapter()
{ {
byte[] init = {0x13}; byte[] init = {0x13};
usb_con.bulkTransfer(usb_out, init, init.length, 0); usbConnection.bulkTransfer(usbOut, init, init.length, 0);
} }
@Keep @Keep
public static int Input() public static int input()
{ {
return usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16); return usbConnection.bulkTransfer(usbIn, controllerPayload, controllerPayload.length, 16);
} }
@Keep @Keep
public static int Output(byte[] rumble) public static int output(byte[] rumble)
{ {
return usb_con.bulkTransfer(usb_out, rumble, 5, 16); return usbConnection.bulkTransfer(usbOut, rumble, 5, 16);
} }
@Keep @Keep
public static boolean OpenAdapter() public static boolean openAdapter()
{ {
HashMap<String, UsbDevice> devices = manager.getDeviceList(); HashMap<String, UsbDevice> devices = manager.getDeviceList();
for (Map.Entry<String, UsbDevice> pair : devices.entrySet()) for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
@ -117,7 +117,7 @@ public class Java_GCAdapter
{ {
if (manager.hasPermission(dev)) if (manager.hasPermission(dev))
{ {
usb_con = manager.openDevice(dev); usbConnection = manager.openDevice(dev);
Log.info("GCAdapter: Number of configurations: " + dev.getConfigurationCount()); Log.info("GCAdapter: Number of configurations: " + dev.getConfigurationCount());
Log.info("GCAdapter: Number of interfaces: " + dev.getInterfaceCount()); Log.info("GCAdapter: Number of interfaces: " + dev.getInterfaceCount());
@ -125,31 +125,31 @@ public class Java_GCAdapter
if (dev.getConfigurationCount() > 0 && dev.getInterfaceCount() > 0) if (dev.getConfigurationCount() > 0 && dev.getInterfaceCount() > 0)
{ {
UsbConfiguration conf = dev.getConfiguration(0); UsbConfiguration conf = dev.getConfiguration(0);
usb_intf = conf.getInterface(0); usbInterface = conf.getInterface(0);
usb_con.claimInterface(usb_intf, true); usbConnection.claimInterface(usbInterface, true);
Log.info("GCAdapter: Number of endpoints: " + usb_intf.getEndpointCount()); Log.info("GCAdapter: Number of endpoints: " + usbInterface.getEndpointCount());
if (usb_intf.getEndpointCount() == 2) if (usbInterface.getEndpointCount() == 2)
{ {
for (int i = 0; i < usb_intf.getEndpointCount(); ++i) for (int i = 0; i < usbInterface.getEndpointCount(); ++i)
if (usb_intf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) if (usbInterface.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)
usb_in = usb_intf.getEndpoint(i); usbIn = usbInterface.getEndpoint(i);
else else
usb_out = usb_intf.getEndpoint(i); usbOut = usbInterface.getEndpoint(i);
InitAdapter(); initAdapter();
return true; return true;
} }
else else
{ {
usb_con.releaseInterface(usb_intf); usbConnection.releaseInterface(usbInterface);
} }
} }
Toast.makeText(DolphinApplication.getAppContext(), R.string.replug_gc_adapter, Toast.makeText(DolphinApplication.getAppContext(), R.string.replug_gc_adapter,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
usb_con.close(); usbConnection.close();
} }
} }
} }

View file

@ -22,7 +22,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class Java_WiimoteAdapter public class WiimoteAdapter
{ {
final static int MAX_PAYLOAD = 23; final static int MAX_PAYLOAD = 23;
final static int MAX_WIIMOTES = 4; final static int MAX_WIIMOTES = 4;
@ -31,14 +31,14 @@ public class Java_WiimoteAdapter
final static short NINTENDO_WIIMOTE_PRODUCT_ID = 0x0306; final static short NINTENDO_WIIMOTE_PRODUCT_ID = 0x0306;
public static UsbManager manager; public static UsbManager manager;
static UsbDeviceConnection usb_con; static UsbDeviceConnection usbConnection;
static UsbInterface[] usb_intf = new UsbInterface[MAX_WIIMOTES]; static UsbInterface[] usbInterface = new UsbInterface[MAX_WIIMOTES];
static UsbEndpoint[] usb_in = new UsbEndpoint[MAX_WIIMOTES]; static UsbEndpoint[] usbIn = new UsbEndpoint[MAX_WIIMOTES];
@Keep @Keep
public static byte[][] wiimote_payload = new byte[MAX_WIIMOTES][MAX_PAYLOAD]; public static byte[][] wiimotePayload = new byte[MAX_WIIMOTES][MAX_PAYLOAD];
private static void RequestPermission() private static void requestPermission()
{ {
HashMap<String, UsbDevice> devices = manager.getDeviceList(); HashMap<String, UsbDevice> devices = manager.getDeviceList();
for (Map.Entry<String, UsbDevice> pair : devices.entrySet()) for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
@ -65,7 +65,7 @@ public class Java_WiimoteAdapter
} }
@Keep @Keep
public static boolean QueryAdapter() public static boolean queryAdapter()
{ {
HashMap<String, UsbDevice> devices = manager.getDeviceList(); HashMap<String, UsbDevice> devices = manager.getDeviceList();
for (Map.Entry<String, UsbDevice> pair : devices.entrySet()) for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
@ -77,20 +77,20 @@ public class Java_WiimoteAdapter
if (manager.hasPermission(dev)) if (manager.hasPermission(dev))
return true; return true;
else else
RequestPermission(); requestPermission();
} }
} }
return false; return false;
} }
@Keep @Keep
public static int Input(int index) public static int input(int index)
{ {
return usb_con.bulkTransfer(usb_in[index], wiimote_payload[index], MAX_PAYLOAD, TIMEOUT); return usbConnection.bulkTransfer(usbIn[index], wiimotePayload[index], MAX_PAYLOAD, TIMEOUT);
} }
@Keep @Keep
public static int Output(int index, byte[] buf, int size) public static int output(int index, byte[] buf, int size)
{ {
byte report_number = buf[0]; byte report_number = buf[0];
@ -105,7 +105,7 @@ public class Java_WiimoteAdapter
final int HID_SET_REPORT = 0x9; final int HID_SET_REPORT = 0x9;
final int HID_OUTPUT = (2 << 8); final int HID_OUTPUT = (2 << 8);
int write = usb_con.controlTransfer( int write = usbConnection.controlTransfer(
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT, LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT,
HID_SET_REPORT, HID_SET_REPORT,
HID_OUTPUT | report_number, HID_OUTPUT | report_number,
@ -120,10 +120,10 @@ public class Java_WiimoteAdapter
} }
@Keep @Keep
public static boolean OpenAdapter() public static boolean openAdapter()
{ {
// If the adapter is already open. Don't attempt to do it again // If the adapter is already open. Don't attempt to do it again
if (usb_con != null && usb_con.getFileDescriptor() != -1) if (usbConnection != null && usbConnection.getFileDescriptor() != -1)
return true; return true;
HashMap<String, UsbDevice> devices = manager.getDeviceList(); HashMap<String, UsbDevice> devices = manager.getDeviceList();
@ -135,7 +135,7 @@ public class Java_WiimoteAdapter
{ {
if (manager.hasPermission(dev)) if (manager.hasPermission(dev))
{ {
usb_con = manager.openDevice(dev); usbConnection = manager.openDevice(dev);
UsbConfiguration conf = dev.getConfiguration(0); UsbConfiguration conf = dev.getConfiguration(0);
Log.info("Number of configurations: " + dev.getConfigurationCount()); Log.info("Number of configurations: " + dev.getConfigurationCount());
@ -149,20 +149,20 @@ public class Java_WiimoteAdapter
for (int i = 0; i < MAX_WIIMOTES; ++i) for (int i = 0; i < MAX_WIIMOTES; ++i)
{ {
// One interface per Wii Remote // One interface per Wii Remote
usb_intf[i] = dev.getInterface(i); usbInterface[i] = dev.getInterface(i);
usb_con.claimInterface(usb_intf[i], true); usbConnection.claimInterface(usbInterface[i], true);
// One endpoint per Wii Remote. Input only // One endpoint per Wii Remote. Input only
// Output reports go through the control channel. // Output reports go through the control channel.
usb_in[i] = usb_intf[i].getEndpoint(0); usbIn[i] = usbInterface[i].getEndpoint(0);
Log.info("Interface " + i + " endpoint count:" + usb_intf[i].getEndpointCount()); Log.info("Interface " + i + " endpoint count:" + usbInterface[i].getEndpointCount());
} }
return true; return true;
} }
else else
{ {
// XXX: Message that the device was found, but it needs to be unplugged and plugged back in? // XXX: Message that the device was found, but it needs to be unplugged and plugged back in?
usb_con.close(); usbConnection.close();
} }
} }
} }

View file

@ -30,8 +30,8 @@ void WiimoteScannerAndroid::FindWiimotes(std::vector<Wiimote*>& found_wiimotes,
JNIEnv* env = IDCache::GetEnvForThread(); JNIEnv* env = IDCache::GetEnvForThread();
jmethodID openadapter_func = env->GetStaticMethodID(s_adapter_class, "OpenAdapter", "()Z"); jmethodID openadapter_func = env->GetStaticMethodID(s_adapter_class, "openAdapter", "()Z");
jmethodID queryadapter_func = env->GetStaticMethodID(s_adapter_class, "QueryAdapter", "()Z"); jmethodID queryadapter_func = env->GetStaticMethodID(s_adapter_class, "queryAdapter", "()Z");
if (env->CallStaticBooleanMethod(s_adapter_class, queryadapter_func) && if (env->CallStaticBooleanMethod(s_adapter_class, queryadapter_func) &&
env->CallStaticBooleanMethod(s_adapter_class, openadapter_func)) env->CallStaticBooleanMethod(s_adapter_class, openadapter_func))
@ -55,15 +55,15 @@ bool WiimoteAndroid::ConnectInternal()
{ {
m_env = IDCache::GetEnvForThread(); m_env = IDCache::GetEnvForThread();
jfieldID payload_field = m_env->GetStaticFieldID(s_adapter_class, "wiimote_payload", "[[B"); jfieldID payload_field = m_env->GetStaticFieldID(s_adapter_class, "wiimotePayload", "[[B");
jobjectArray payload_object = jobjectArray payload_object =
reinterpret_cast<jobjectArray>(m_env->GetStaticObjectField(s_adapter_class, payload_field)); reinterpret_cast<jobjectArray>(m_env->GetStaticObjectField(s_adapter_class, payload_field));
m_java_wiimote_payload = m_java_wiimote_payload =
(jbyteArray)m_env->GetObjectArrayElement(payload_object, m_mayflash_index); (jbyteArray)m_env->GetObjectArrayElement(payload_object, m_mayflash_index);
// Get function pointers // Get function pointers
m_input_func = m_env->GetStaticMethodID(s_adapter_class, "Input", "(I)I"); m_input_func = m_env->GetStaticMethodID(s_adapter_class, "input", "(I)I");
m_output_func = m_env->GetStaticMethodID(s_adapter_class, "Output", "(I[BI)I"); m_output_func = m_env->GetStaticMethodID(s_adapter_class, "output", "(I[BI)I");
is_connected = true; is_connected = true;
@ -110,7 +110,7 @@ int WiimoteAndroid::IOWrite(u8 const* buf, size_t len)
void InitAdapterClass() void InitAdapterClass()
{ {
JNIEnv* env = IDCache::GetEnvForThread(); JNIEnv* env = IDCache::GetEnvForThread();
jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Java_WiimoteAdapter"); jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/WiimoteAdapter");
s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class)); s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class));
} }
} // namespace WiimoteReal } // namespace WiimoteReal

View file

@ -180,14 +180,14 @@ static void ReadThreadFunc()
bool first_read = true; bool first_read = true;
JNIEnv* const env = IDCache::GetEnvForThread(); JNIEnv* const env = IDCache::GetEnvForThread();
const jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "controller_payload", "[B"); const jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "controllerPayload", "[B");
jobject payload_object = env->GetStaticObjectField(s_adapter_class, payload_field); jobject payload_object = env->GetStaticObjectField(s_adapter_class, payload_field);
auto* const java_controller_payload = reinterpret_cast<jbyteArray*>(&payload_object); auto* const java_controller_payload = reinterpret_cast<jbyteArray*>(&payload_object);
// Get function pointers // Get function pointers
const jmethodID getfd_func = env->GetStaticMethodID(s_adapter_class, "GetFD", "()I"); const jmethodID getfd_func = env->GetStaticMethodID(s_adapter_class, "getFd", "()I");
const jmethodID input_func = env->GetStaticMethodID(s_adapter_class, "Input", "()I"); const jmethodID input_func = env->GetStaticMethodID(s_adapter_class, "input", "()I");
const jmethodID openadapter_func = env->GetStaticMethodID(s_adapter_class, "OpenAdapter", "()Z"); const jmethodID openadapter_func = env->GetStaticMethodID(s_adapter_class, "openAdapter", "()Z");
const bool connected = env->CallStaticBooleanMethod(s_adapter_class, openadapter_func); const bool connected = env->CallStaticBooleanMethod(s_adapter_class, openadapter_func);
@ -279,7 +279,7 @@ static void WriteThreadFunc()
int size = 0; int size = 0;
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION #elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
JNIEnv* const env = IDCache::GetEnvForThread(); JNIEnv* const env = IDCache::GetEnvForThread();
const jmethodID output_func = env->GetStaticMethodID(s_adapter_class, "Output", "([B)I"); const jmethodID output_func = env->GetStaticMethodID(s_adapter_class, "output", "([B)I");
#endif #endif
while (s_write_adapter_thread_running.IsSet()) while (s_write_adapter_thread_running.IsSet())
@ -394,7 +394,7 @@ static void ScanThreadFunc()
JNIEnv* const env = IDCache::GetEnvForThread(); JNIEnv* const env = IDCache::GetEnvForThread();
const jmethodID queryadapter_func = const jmethodID queryadapter_func =
env->GetStaticMethodID(s_adapter_class, "QueryAdapter", "()Z"); env->GetStaticMethodID(s_adapter_class, "queryAdapter", "()Z");
while (s_adapter_detect_thread_running.IsSet()) while (s_adapter_detect_thread_running.IsSet())
{ {
@ -456,7 +456,7 @@ void Init()
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION #elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
JNIEnv* const env = IDCache::GetEnvForThread(); JNIEnv* const env = IDCache::GetEnvForThread();
const jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Java_GCAdapter"); const jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/GCAdapter");
s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class)); s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class));
#endif #endif