From c2b2e03f73300f0ac742d63a125b46ec798b2c8c Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 27 Feb 2015 23:20:33 -0600 Subject: [PATCH] [Android] Support arguments from Activity Monitor. 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. --- .../dolphinemu/AssetCopyService.java | 2 +- .../dolphinemu/dolphinemu/NativeLibrary.java | 5 ++ .../dolphinemu/gamelist/GameListActivity.java | 60 ++++++++++++++++++- Source/Core/DolphinWX/MainAndroid.cpp | 6 ++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/AssetCopyService.java b/Source/Android/src/org/dolphinemu/dolphinemu/AssetCopyService.java index 83960433ec..d39bbec59f 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/AssetCopyService.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/AssetCopyService.java @@ -36,7 +36,7 @@ public final class AssetCopyService extends IntentService @Override protected void onHandleIntent(Intent intent) { - String BaseDir = Environment.getExternalStorageDirectory() + File.separator + "dolphin-emu"; + String BaseDir = NativeLibrary.GetUserDirectory(); String ConfigDir = BaseDir + File.separator + "Config"; String GCDir = BaseDir + File.separator + "GC"; diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java index 91b29e4410..ab9f25b306 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -175,6 +175,11 @@ public final class NativeLibrary */ public static native void SetUserDirectory(String directory); + /** + * Returns the current working user directory + */ + public static native String GetUserDirectory(); + /** * Begins emulation. * diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListActivity.java b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListActivity.java index adade82145..3accec11de 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListActivity.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListActivity.java @@ -12,11 +12,15 @@ import android.app.Fragment; 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.os.Environment; +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; @@ -28,11 +32,13 @@ import org.dolphinemu.dolphinemu.AssetCopyService; 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; import org.dolphinemu.dolphinemu.sidemenu.SideMenuItem; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -49,6 +55,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}. @@ -65,6 +73,7 @@ public final class GameListActivity extends Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.gamelist_activity); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); @@ -104,6 +113,13 @@ public final class GameListActivity extends Activity }; mDrawerLayout.setDrawerListener(mDrawerToggle); + CheckForIntent(); + + String BaseDir = NativeLibrary.GetUserDirectory(); + final String DefaultDir = Environment.getExternalStorageDirectory() + File.separator + "dolphin-emu"; + if (BaseDir.isEmpty()) + BaseDir = DefaultDir; + NativeLibrary.SetUserDirectory(BaseDir); // Stuff in this block only happens when this activity is newly created (i.e. not a rotation) if (savedInstanceState == null) @@ -118,7 +134,6 @@ public final class GameListActivity extends Activity 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()) @@ -135,6 +150,49 @@ public final class GameListActivity extends Activity }); 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; + } + return; + } + + editor.putBoolean("HandledIntent", false); + editor.apply(); } /** diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp index 78960533cd..1ab7be8c57 100644 --- a/Source/Core/DolphinWX/MainAndroid.cpp +++ b/Source/Core/DolphinWX/MainAndroid.cpp @@ -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) @@ -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);