Skip to content

Commit

Permalink
[Android] Support arguments from Activity Monitor.
Browse files Browse the repository at this point in the history
Activity Monitor can start activities by using adb to invoke it.
This will allow us to set the user directory and autostart file from adb.

adb shell am start -n org.dolphinemu.dolphinemu/.gamelist.GameListActivity -e AutoStartFile /sdcard/AC.gcz -e UserDir /sdcard/dolphin-emu2/

This allows more automated testing to be done with Dolphin on Android.
  • Loading branch information
Sonicadvance1 committed Feb 28, 2015
1 parent c792d45 commit 09478a1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ public AssetCopyService()
@Override
protected void onHandleIntent(Intent intent)
{
String BaseDir = Environment.getExternalStorageDirectory() + File.separator + "dolphin-emu";
String BaseDir = NativeLibrary.GetUserDirectory();
final String DefaultDir = Environment.getExternalStorageDirectory() + File.separator + "dolphin-emu";
if (BaseDir.isEmpty())
BaseDir = DefaultDir;

String ConfigDir = BaseDir + File.separator + "Config";
String GCDir = BaseDir + File.separator + "GC";

// Copy assets if needed
File file = new File(GCDir + File.separator + "font_sjis.bin");
if(!file.exists())
{
NativeLibrary.SetUserDirectory(BaseDir);
NativeLibrary.CreateUserFolders();
copyAsset("dsp_coef.bin", GCDir + File.separator + "dsp_coef.bin");
copyAsset("dsp_rom.bin", GCDir + File.separator + "dsp_rom.bin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ private NativeLibrary()
*/
public static native void SetUserDirectory(String directory);

/**
* Returns the current working user directory
*/
public static native String GetUserDirectory();

/**
* Begins emulation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -28,6 +31,7 @@
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.about.AboutActivity;
import org.dolphinemu.dolphinemu.emulation.EmulationActivity;
import org.dolphinemu.dolphinemu.folderbrowser.FolderBrowser;
import org.dolphinemu.dolphinemu.settings.PrefsActivity;
import org.dolphinemu.dolphinemu.sidemenu.SideMenuAdapter;
Expand All @@ -49,6 +53,8 @@ public final class GameListActivity extends Activity
private DrawerLayout mDrawerLayout;
private SideMenuAdapter mDrawerAdapter;
private ListView mDrawerList;
private boolean mAutoStart = false;
private String mAutoStartFile = "";

/**
* Called from the {@link GameListFragment}.
Expand All @@ -65,6 +71,7 @@ public void onZeroFiles()
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.gamelist_activity);

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
Expand Down Expand Up @@ -104,6 +111,7 @@ public void onDrawerOpened(View drawerView) {
};
mDrawerLayout.setDrawerListener(mDrawerToggle);

CheckForIntent();

// Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
if (savedInstanceState == null)
Expand All @@ -118,7 +126,6 @@ public void onDrawerOpened(View drawerView) {
ft.replace(R.id.content_frame, gameList);
ft.commit();
}


// Create an alert telling them that their phone sucks
if (Build.CPU_ABI.contains("arm") && !NativeLibrary.SupportsNEON())
Expand All @@ -135,6 +142,48 @@ public void onClick(DialogInterface dialog, int which)
});
builder.show();
}

if (mAutoStart)
{
// Start the emulation activity
Intent intent = new Intent(this, EmulationActivity.class);
intent.putExtra("SelectedGame", mAutoStartFile);
startActivity(intent);
}
}

private void CheckForIntent()
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean handled = prefs.getBoolean("HandledIntent", false);

// Get an editor.
SharedPreferences.Editor editor = prefs.edit();

Bundle extras = getIntent().getExtras();

if (!handled && extras != null)
{
// Application got passed extra data
editor.putBoolean("HandledIntent", true);
editor.apply();

// Did we get passed a new user directory?
String user_dir = extras.getString("UserDir");
if (user_dir != null && user_dir.length() != 0)
NativeLibrary.SetUserDirectory(user_dir);

// Did we get passed a file?
String start_file = extras.getString("AutoStartFile");
if (start_file != null && start_file.length() != 0)
{
mAutoStart = true;
mAutoStartFile = start_file;
}
}

editor.putBoolean("HandledIntent", false);
editor.apply();
}

/**
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/DolphinWX/MainAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JN
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv *env, jobject obj, jint slot);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_CreateUserFolders(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(JNIEnv *env, jobject obj, jstring jDirectory);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf);

JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv *env, jobject obj)
Expand Down Expand Up @@ -370,6 +371,11 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirec
UICommon::SetUserDirectory(directory);
}

JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv *env, jobject obj)
{
return env->NewStringUTF(File::GetUserPath(D_USER_IDX).c_str());
}

JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf)
{
surf = ANativeWindow_fromSurface(env, _surf);
Expand Down

0 comments on commit 09478a1

Please sign in to comment.