summaryrefslogtreecommitdiffstats
path: root/platform/android/java/lib/src/org/godotengine/godot/GodotService.kt
blob: 795dc921c7fa7fec24df380e1fc2486d54b3c44a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.godotengine.godot

import android.app.Service
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import android.util.Log

/**
 * Godot service responsible for hosting the Godot engine instance.
 *
 * Note: Still in development, so it's made private and inaccessible until completed.
 */
private class GodotService : Service() {

	companion object {
		private val TAG = GodotService::class.java.simpleName
	}

	private var boundIntent: Intent? = null
	private val godot by lazy {
		Godot(applicationContext)
	}

	override fun onCreate() {
		super.onCreate()
	}

	override fun onDestroy() {
		super.onDestroy()
	}

	override fun onBind(intent: Intent?): IBinder? {
		if (boundIntent != null) {
			Log.d(TAG, "GodotService already bound")
			return null
		}

		boundIntent = intent
		return GodotHandle(godot)
	}

	override fun onRebind(intent: Intent?) {
		super.onRebind(intent)
	}

	override fun onUnbind(intent: Intent?): Boolean {
		return super.onUnbind(intent)
	}

	override fun onTaskRemoved(rootIntent: Intent?) {
		super.onTaskRemoved(rootIntent)
	}

	class GodotHandle(val godot: Godot) : Binder()
}