native service, EGL, native test client
This commit is contained in:
80
src/main/java/com/omixlab/mosis/MainActivity.kt
Normal file
80
src/main/java/com/omixlab/mosis/MainActivity.kt
Normal file
@@ -0,0 +1,80 @@
|
||||
package com.omixlab.mosis
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.os.Bundle
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
init {
|
||||
System.loadLibrary("mosis-test")
|
||||
}
|
||||
var remote_service: IMosisService? = null
|
||||
var statusText = mutableStateOf("Status: idle")
|
||||
var buttonText = mutableStateOf("Init OS")
|
||||
private val connection = object : ServiceConnection {
|
||||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
||||
Log.d("MosisTest", "Service Connected")
|
||||
statusText.value = "Service Connected"
|
||||
remote_service = IMosisService.Stub.asInterface(service)
|
||||
Log.d("MosisTest", "Number: ${remote_service?.number}")
|
||||
serviceConnected(service)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(arg0: ComponentName) {
|
||||
Log.d("MosisTest", "Service Disconnected")
|
||||
statusText.value = "Service Disconnected"
|
||||
}
|
||||
}
|
||||
fun initOS()
|
||||
{
|
||||
remote_service?.let { service ->
|
||||
val result = service.initOS()
|
||||
Log.d("MosisTest", "InitOS returned: $result")
|
||||
buttonText.value = if (result) "OS Initialized" else "OS Not Initialized"
|
||||
}
|
||||
}
|
||||
private fun startRemoteService() {
|
||||
val intent = Intent("com.omixlab.mosis.SERVICE")
|
||||
intent.setPackage("com.omixlab.mosis")
|
||||
try {
|
||||
startForegroundService(intent)
|
||||
val result = bindService(intent, connection, BIND_AUTO_CREATE)
|
||||
Log.d("ServiceTester", "Bind result: $result")
|
||||
} catch (e: Exception) {
|
||||
Log.e("ServiceTester", "Bind failed", e)
|
||||
}
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
startRemoteService()
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text("Welcome to Mosis OS")
|
||||
Button(onClick = { initOS() }) {
|
||||
Text(buttonText.value)
|
||||
}
|
||||
Text(statusText.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
external fun serviceConnected(binder: IBinder)
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import android.app.NotificationManager
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Debug
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.NotificationCompat
|
||||
|
||||
|
||||
Reference in New Issue
Block a user