You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Provide a delegate implementation for the killProcess logic on Android
The implementation forwards the kill request to the Godot host for handling. If the Godot host is unable to handle the request, it falls back to the `OS_Unix::kill(...)` implementation.
This commit is contained in:
@@ -31,12 +31,11 @@
|
||||
package org.godotengine.editor
|
||||
|
||||
import android.Manifest
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Debug
|
||||
import android.os.Environment
|
||||
import android.os.*
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.window.layout.WindowMetricsCalculator
|
||||
@@ -64,11 +63,18 @@ open class GodotEditor : FullScreenGodotApp() {
|
||||
|
||||
private const val COMMAND_LINE_PARAMS = "command_line_params"
|
||||
|
||||
private const val EDITOR_ID = 777
|
||||
private const val EDITOR_ARG = "--editor"
|
||||
private const val EDITOR_ARG_SHORT = "-e"
|
||||
private const val EDITOR_PROCESS_NAME_SUFFIX = ":GodotEditor"
|
||||
|
||||
private const val GAME_ID = 667
|
||||
private const val GAME_PROCESS_NAME_SUFFIX = ":GodotGame"
|
||||
|
||||
private const val PROJECT_MANAGER_ID = 555
|
||||
private const val PROJECT_MANAGER_ARG = "--project-manager"
|
||||
private const val PROJECT_MANAGER_ARG_SHORT = "-p"
|
||||
private const val PROJECT_MANAGER_PROCESS_NAME_SUFFIX = ":GodotProjectManager"
|
||||
}
|
||||
|
||||
private val commandLineParams = ArrayList<String>()
|
||||
@@ -102,9 +108,10 @@ open class GodotEditor : FullScreenGodotApp() {
|
||||
|
||||
override fun getCommandLine() = commandLineParams
|
||||
|
||||
override fun onNewGodotInstanceRequested(args: Array<String>) {
|
||||
override fun onNewGodotInstanceRequested(args: Array<String>): Int {
|
||||
// Parse the arguments to figure out which activity to start.
|
||||
var targetClass: Class<*> = GodotGame::class.java
|
||||
var instanceId = GAME_ID
|
||||
|
||||
// Whether we should launch the new godot instance in an adjacent window
|
||||
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT
|
||||
@@ -115,12 +122,14 @@ open class GodotEditor : FullScreenGodotApp() {
|
||||
if (EDITOR_ARG == arg || EDITOR_ARG_SHORT == arg) {
|
||||
targetClass = GodotEditor::class.java
|
||||
launchAdjacent = false
|
||||
instanceId = EDITOR_ID
|
||||
break
|
||||
}
|
||||
|
||||
if (PROJECT_MANAGER_ARG == arg || PROJECT_MANAGER_ARG_SHORT == arg) {
|
||||
targetClass = GodotProjectManager::class.java
|
||||
launchAdjacent = false
|
||||
instanceId = PROJECT_MANAGER_ID
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -139,6 +148,37 @@ open class GodotEditor : FullScreenGodotApp() {
|
||||
Log.d(TAG, "Starting $targetClass")
|
||||
startActivity(newInstance)
|
||||
}
|
||||
return instanceId
|
||||
}
|
||||
|
||||
override fun onGodotForceQuit(godotInstanceId: Int): Boolean {
|
||||
val processNameSuffix = when (godotInstanceId) {
|
||||
GAME_ID -> {
|
||||
GAME_PROCESS_NAME_SUFFIX
|
||||
}
|
||||
EDITOR_ID -> {
|
||||
EDITOR_PROCESS_NAME_SUFFIX
|
||||
}
|
||||
PROJECT_MANAGER_ID -> {
|
||||
PROJECT_MANAGER_PROCESS_NAME_SUFFIX
|
||||
}
|
||||
else -> ""
|
||||
}
|
||||
if (processNameSuffix.isBlank()) {
|
||||
return false
|
||||
}
|
||||
|
||||
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
val runningProcesses = activityManager.runningAppProcesses
|
||||
for (runningProcess in runningProcesses) {
|
||||
if (runningProcess.processName.endsWith(processNameSuffix)) {
|
||||
Log.v(TAG, "Killing Godot process ${runningProcess.processName}")
|
||||
Process.killProcess(runningProcess.pid)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Get the screen's density scale
|
||||
|
||||
Reference in New Issue
Block a user