Ported: Add parameters for the Godot Activity starting intent to allow restarting or force-quitting the engine

Follow-up code cleanup for #78130
- m4gr3d
5cf0ba88e3
This commit is contained in:
Relintai 2023-06-28 18:58:29 +02:00
parent 5f4bc29d13
commit ae92596f9b
3 changed files with 37 additions and 23 deletions

View File

@ -41,7 +41,7 @@
android:name=".PandemoniumApp"
android:label="@string/pandemonium_project_name_string"
android:theme="@style/PandemoniumAppSplashTheme"
android:launchMode="singleTask"
android:launchMode="singleInstance"
android:excludeFromRecents="false"
android:exported="true"
android:screenOrientation="landscape"

View File

@ -63,7 +63,7 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
private val TAG = PandemoniumEditor::class.java.simpleName
private const val WAIT_FOR_DEBUGGER = false
private const val EXTRA_FORCE_QUIT = "force_quit_requested"
private const val EXTRA_COMMAND_LINE_PARAMS = "command_line_params"
private const val EDITOR_ID = 777
@ -97,7 +97,9 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
// requested on demand based on use-cases.
PermissionsUtil.requestManifestPermissions(this, setOf(Manifest.permission.RECORD_AUDIO))
handleIntentParams(intent)
val params = intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
Log.d(TAG, "Received parameters ${params.contentToString()}")
updateCommandLineParams(params)
if (BuildConfig.BUILD_TYPE == "dev" && WAIT_FOR_DEBUGGER) {
Debug.waitForDebugger();
@ -106,25 +108,6 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
super.onCreate(savedInstanceState);
}
override fun onNewIntent(newIntent: Intent) {
intent = newIntent
handleIntentParams(newIntent)
super.onNewIntent(newIntent)
}
private fun handleIntentParams(receivedIntent: Intent) {
val forceQuitRequested = receivedIntent.getBooleanExtra(EXTRA_FORCE_QUIT, false)
if (forceQuitRequested) {
Log.d(TAG, "Force quit requested, terminating..")
ProcessPhoenix.forceQuit(this)
return
}
val params = receivedIntent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
Log.d(TAG, "Received parameters ${params.contentToString()}")
updateCommandLineParams(params)
}
override fun onPandemoniumSetupCompleted() {
super.onPandemoniumSetupCompleted()
val longPressEnabled = enableLongPressGestures()
@ -155,7 +138,7 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
private fun updateCommandLineParams(args: Array<String>?) {
// Update the list of command line params with the new args
commandLineParams.clear()
if (args != null && args.isNotEmpty()) {
if (!args.isNullOrEmpty()) {
commandLineParams.addAll(listOf(*args))
}
if (BuildConfig.BUILD_TYPE == "dev") {
@ -202,6 +185,7 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
ProcessPhoenix.triggerRebirth(this, newInstance)
} else {
Log.d(TAG, "Starting $targetClass with parameters ${args.contentToString()}")
newInstance.putExtra(EXTRA_NEW_LAUNCH, true)
startActivity(newInstance)
}

View File

@ -50,6 +50,9 @@ import androidx.fragment.app.FragmentActivity;
public abstract class FullScreenPandemoniumApp extends FragmentActivity implements PandemoniumHost {
private static final String TAG = FullScreenPandemoniumApp.class.getSimpleName();
protected static final String EXTRA_FORCE_QUIT = "force_quit_requested";
protected static final String EXTRA_NEW_LAUNCH = "new_launch_requested";
@Nullable
private Pandemonium pandemoniumFragment;
@ -58,6 +61,8 @@ public abstract class FullScreenPandemoniumApp extends FragmentActivity implemen
super.onCreate(savedInstanceState);
setContentView(R.layout.pandemonium_app_layout);
handleStartIntent(getIntent(), true);
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.pandemonium_fragment_container);
if (currentFragment instanceof Pandemonium) {
@ -109,11 +114,36 @@ public abstract class FullScreenPandemoniumApp extends FragmentActivity implemen
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleStartIntent(intent, false);
if (pandemoniumFragment != null) {
pandemoniumFragment.onNewIntent(intent);
}
}
private void handleStartIntent(Intent intent, boolean newLaunch) {
boolean forceQuitRequested = intent.getBooleanExtra(EXTRA_FORCE_QUIT, false);
if (forceQuitRequested) {
Log.d(TAG, "Force quit requested, terminating..");
ProcessPhoenix.forceQuit(this);
return;
}
if (!newLaunch) {
boolean newLaunchRequested = intent.getBooleanExtra(EXTRA_NEW_LAUNCH, false);
if (newLaunchRequested) {
Log.d(TAG, "New launch requested, restarting..");
Intent restartIntent = new Intent(intent).putExtra(EXTRA_NEW_LAUNCH, false);
ProcessPhoenix.triggerRebirth(this, restartIntent);
return;
}
}
}
@CallSuper
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {