work in progress

This commit is contained in:
2026-01-16 12:43:06 +01:00
parent 77a9579025
commit c8ee7defe8
236 changed files with 11405 additions and 28 deletions

View File

@@ -1,8 +1,11 @@
package com.omixlab.mosis
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.ServiceConnection
import android.content.res.AssetManager
import android.os.Bundle
@@ -30,6 +33,20 @@ class MainActivity : ComponentActivity() {
init {
System.loadLibrary("mosis-test")
}
companion object {
// Singleton for test access
@Volatile
var instance: MainActivity? = null
private set
// Intent actions for event injection via broadcast
const val ACTION_INJECT_TOUCH = "com.omixlab.mosis.INJECT_TOUCH"
const val EXTRA_TOUCH_TYPE = "touch_type" // "down", "move", "up", "click"
const val EXTRA_X = "x" // Normalized 0.0-1.0
const val EXTRA_Y = "y" // Normalized 0.0-1.0
}
var remote_service: IMosisService? = null
var statusText = mutableStateOf("Status: idle")
var buttonText = mutableStateOf("Init OS")
@@ -79,11 +96,35 @@ class MainActivity : ComponentActivity() {
Log.e("ServiceTester", "Bind failed", e)
}
}
// Broadcast receiver for event injection (for testing)
private val touchInjectionReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == ACTION_INJECT_TOUCH) {
val touchType = intent.getStringExtra(EXTRA_TOUCH_TYPE) ?: return
val x = intent.getFloatExtra(EXTRA_X, 0.5f)
val y = intent.getFloatExtra(EXTRA_Y, 0.5f)
Log.d("MosisTest", "Injecting touch: $touchType at ($x, $y)")
when (touchType) {
"down" -> injectTouchDown(x, y)
"move" -> injectTouchMove(x, y)
"up" -> injectTouchUp(x, y)
"click" -> injectClick(x, y)
}
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
instance = this
setAssetManager(assets)
startRemoteService()
enableEdgeToEdge()
// Register broadcast receiver for touch injection (testing)
val filter = IntentFilter(ACTION_INJECT_TOUCH)
registerReceiver(touchInjectionReceiver, filter, RECEIVER_EXPORTED)
setContent {
Column(
modifier = Modifier.fillMaxSize(),
@@ -102,6 +143,51 @@ class MainActivity : ComponentActivity() {
}
}
}
override fun onDestroy() {
super.onDestroy()
instance = null
try {
unregisterReceiver(touchInjectionReceiver)
} catch (e: Exception) {
Log.w("MosisTest", "Receiver not registered", e)
}
}
/**
* Inject a touch down event at normalized coordinates (0.0-1.0)
*/
fun injectTouchDown(x: Float, y: Float) {
Log.d("MosisTest", "Inject touch down: ($x, $y)")
remote_service?.onTouchDown(x, y)
}
/**
* Inject a touch move event at normalized coordinates (0.0-1.0)
*/
fun injectTouchMove(x: Float, y: Float) {
Log.d("MosisTest", "Inject touch move: ($x, $y)")
remote_service?.onTouchMove(x, y)
}
/**
* Inject a touch up event at normalized coordinates (0.0-1.0)
*/
fun injectTouchUp(x: Float, y: Float) {
Log.d("MosisTest", "Inject touch up: ($x, $y)")
remote_service?.onTouchUp(x, y)
}
/**
* Inject a complete click (down + up) at normalized coordinates
*/
fun injectClick(x: Float, y: Float, delayMs: Long = 50) {
Log.d("MosisTest", "Inject click: ($x, $y)")
remote_service?.onTouchDown(x, y)
android.os.Handler(mainLooper).postDelayed({
remote_service?.onTouchUp(x, y)
}, delayMs)
}
@SuppressLint("ClickableViewAccessibility")
@Composable
fun NativeViewport(modifier: Modifier = Modifier) {