From e223016c606a47f41112d1fc6e1897eab6644886 Mon Sep 17 00:00:00 2001 From: nift4 Date: Thu, 1 Aug 2024 23:42:13 +0200 Subject: [PATCH] rework simulator flow --- app/build.gradle.kts | 1 - app/src/main/AndroidManifest.xml | 5 +- app/src/main/cpp/droidboot_gui | 2 +- .../main/java/org/andbootmgr/app/Simulator.kt | 51 +++++++++++-------- .../main/java/org/andbootmgr/app/Themes.kt | 12 ++++- app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 6 ++- 7 files changed, 52 insertions(+), 26 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 181f20f7..46a96603 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -134,7 +134,6 @@ dependencies { // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.) implementation("androidx.compose.foundation:foundation:1.6.8") // Material Design - implementation("androidx.compose.material:material:1.6.8") implementation("androidx.compose.material3:material3:1.2.1") // Material design icons implementation("androidx.compose.material:material-icons-core:1.6.8") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2068ccac..aac16948 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,8 +38,11 @@ android:process=":simulator" android:taskAffinity="" android:noHistory="true" + android:screenOrientation="nosensor" android:excludeFromRecents="true" - android:theme="@style/AppTheme" /> + android:configChanges="keyboard|keyboardHidden|uiMode" + android:theme="@style/Simulator" + tools:ignore="DiscouragedApi" /> \ No newline at end of file diff --git a/app/src/main/cpp/droidboot_gui b/app/src/main/cpp/droidboot_gui index 1cdf80a8..53b44ca9 160000 --- a/app/src/main/cpp/droidboot_gui +++ b/app/src/main/cpp/droidboot_gui @@ -1 +1 @@ -Subproject commit 1cdf80a8de733fdde944d6401dd2c3454b6f609d +Subproject commit 53b44ca95ba539d0f08e1dc980d3378f1e63cbb3 diff --git a/app/src/main/java/org/andbootmgr/app/Simulator.kt b/app/src/main/java/org/andbootmgr/app/Simulator.kt index 7787aa6d..50c93bcc 100644 --- a/app/src/main/java/org/andbootmgr/app/Simulator.kt +++ b/app/src/main/java/org/andbootmgr/app/Simulator.kt @@ -12,6 +12,8 @@ import android.view.View import android.widget.LinearLayout import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.ipc.RootService import com.topjohnwu.superuser.nio.FileSystemManager @@ -20,6 +22,7 @@ import java.io.File import java.nio.ByteBuffer import java.nio.channels.FileChannel import kotlin.math.min +import kotlin.system.exitProcess class Simulator : AppCompatActivity() { init { @@ -49,29 +52,9 @@ class Simulator : AppCompatActivity() { w = 1080 //TODO make size fullscreen and hide sysui h = 1920 bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888) - f = File("/dev/block/mmcblk1") // TODO + f = File(intent.getStringExtra("sdCardBlock")!!) // TODO make keys work val intent = Intent(this, RootFsService::class.java) - RootService.bind(intent, object : ServiceConnection { - override fun onServiceConnected(componentName: ComponentName?, service: IBinder?) { - this@Simulator.fs = FileSystemManager.getRemote(service!!) - fi = fs!!.openChannel(f, FileSystemManager.MODE_READ_ONLY) - if (firstTime) { - Thread { - Log.i("Simulator","going to call start()") - start(bitmap, w, h) - }.run { - name = "droidboot0" - start() - } - firstTime = false - } - } - - override fun onServiceDisconnected(componentName: ComponentName?) { - this@Simulator.fs = null - } - }) val l = LinearLayout(this) v = object : View(this) { override fun onDraw(canvas: Canvas) { @@ -94,6 +77,30 @@ class Simulator : AppCompatActivity() { l.addView(v, LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)) setContentView(l) + WindowInsetsControllerCompat(window, l).apply { + systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + hide(WindowInsetsCompat.Type.systemBars()) + } + RootService.bind(intent, object : ServiceConnection { + override fun onServiceConnected(componentName: ComponentName?, service: IBinder?) { + this@Simulator.fs = FileSystemManager.getRemote(service!!) + fi = fs!!.openChannel(f, FileSystemManager.MODE_READ_ONLY) + if (firstTime) { + Thread { + Log.i("Simulator","going to call start()") + start(bitmap, w, h) + }.run { + name = "droidboot0" + start() + } + firstTime = false + } + } + + override fun onServiceDisconnected(componentName: ComponentName?) { + this@Simulator.fs = null + } + }) } private fun blockCount(): Long { @@ -123,5 +130,7 @@ class Simulator : AppCompatActivity() { override fun onStop() { Log.i("Simulator", "goodbye") super.onStop() + // droidboot cannot cope with starting twice in same process due to static variables + exitProcess(0) } } \ No newline at end of file diff --git a/app/src/main/java/org/andbootmgr/app/Themes.kt b/app/src/main/java/org/andbootmgr/app/Themes.kt index 7a41dded..60281881 100644 --- a/app/src/main/java/org/andbootmgr/app/Themes.kt +++ b/app/src/main/java/org/andbootmgr/app/Themes.kt @@ -1,6 +1,10 @@ package org.andbootmgr.app +import android.content.Intent +import androidx.compose.material3.Button +import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource /* uint32_t win_bg_color; @@ -24,5 +28,11 @@ import androidx.compose.runtime.Composable */ @Composable fun Themes(vm: MainActivityState) { - + Button(onClick = { + vm.activity!!.startActivity(Intent(vm.activity!!, Simulator::class.java).apply { + putExtra("sdCardBlock", vm.deviceInfo!!.bdev) + }) + }) { + Text(text = stringResource(id = R.string.simulator)) + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 59e92b58..9fff1c48 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -231,4 +231,5 @@ Failed loading list of ROMs from Open ROM Project Installer shell script Themes + Start simulator diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 61cf5cb4..366fcc3e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,17 +1,21 @@ - + #FE9200 #FE9200 #FE9F11 + #000000