Implement requesting permission for using the GC Wii U Adapter.

This commit is contained in:
Ryan Houdek 2016-01-23 06:32:07 -06:00
parent a62a9b8161
commit b846ec084e
4 changed files with 51 additions and 4 deletions

View File

@ -3,7 +3,9 @@ package org.dolphinemu.dolphinemu.activities;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@ -30,6 +32,7 @@ import org.dolphinemu.dolphinemu.fragments.MenuFragment;
import org.dolphinemu.dolphinemu.fragments.SaveStateFragment;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.utils.Animations;
import org.dolphinemu.dolphinemu.utils.Java_GCAdapter;
import org.dolphinemu.dolphinemu.utils.Log;
import java.util.List;
@ -115,6 +118,8 @@ public final class EmulationActivity extends AppCompatActivity
setTheme(themeId);
super.onCreate(savedInstanceState);
Java_GCAdapter.our_activity = this;
Java_GCAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE);
// Picasso will take a while to load these big-ass screenshots. So don't run
// the animation until we say so.

View File

@ -0,0 +1,14 @@
package org.dolphinemu.dolphinemu.services;
import android.app.IntentService;
import android.content.Intent;
public final class USBPermService extends IntentService
{
public USBPermService() { super("USBPermService"); }
// Needed when extending IntentService.
// We don't care about the results of the intent handler for this.
@Override
protected void onHandleIntent(Intent intent) {}
}

View File

@ -1,6 +1,9 @@
package org.dolphinemu.dolphinemu.utils;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbConfiguration;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
@ -9,8 +12,11 @@ import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;
import org.dolphinemu.dolphinemu.services.USBPermService;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class Java_GCAdapter {
public static UsbManager manager;
@ -23,6 +29,26 @@ public class Java_GCAdapter {
static UsbEndpoint usb_in;
static UsbEndpoint usb_out;
private static void RequestPermission()
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
{
UsbDevice dev = (UsbDevice) pair.getValue();
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
{
if (!manager.hasPermission(dev))
{
Intent intent = new Intent();
PendingIntent pend_intent;
intent.setClass(our_activity, USBPermService.class);
pend_intent = PendingIntent.getService(our_activity, 0, intent, 0);
manager.requestPermission(dev, pend_intent);
}
}
}
}
public static void Shutdown()
{
usb_con.close();
@ -32,14 +58,16 @@ public class Java_GCAdapter {
public static boolean QueryAdapter()
{
HashMap<String, UsbDevice> devices = manager.getDeviceList();
Iterator it = devices.entrySet().iterator();
while (it.hasNext())
for (Map.Entry<String, UsbDevice> pair : devices.entrySet())
{
HashMap.Entry pair = (HashMap.Entry) it.next();
UsbDevice dev = (UsbDevice) pair.getValue();
if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e)
{
if (manager.hasPermission(dev))
return true;
else
RequestPermission();
}
}
return false;
}

View File

@ -35,7 +35,7 @@ static u8 s_controller_rumble[4];
// Input handling
static std::mutex s_read_mutex;
static u8 s_controller_payload[37];
static std::atomic<int> s_controller_payload_size;
static std::atomic<int> s_controller_payload_size{0};
// Output handling
static std::mutex s_write_mutex;