Skip to content

Commit

Permalink
rework simulator flow
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Aug 1, 2024
1 parent 87fb484 commit e223016
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 26 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</application>

</manifest>
2 changes: 1 addition & 1 deletion app/src/main/cpp/droidboot_gui
51 changes: 30 additions & 21 deletions app/src/main/java/org/andbootmgr/app/Simulator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
12 changes: 11 additions & 1 deletion app/src/main/java/org/andbootmgr/app/Themes.kt
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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))
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,5 @@
<string name="shop_error">Failed loading list of ROMs from Open ROM Project</string>
<string name="installer_sh">Installer shell script</string>
<string name="themes">Themes</string>
<string name="simulator">Start simulator</string>
</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="AppTheme" parent="@style/Theme.MaterialComponents.DayNight.NoActionBar">
<style name="AppTheme" parent="@style/Theme.Material3.DynamicColors.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorSecondary">@color/colorSecondary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="aboutLibrariesStyle">@style/CustomAboutLibrariesStyle</item>
<item name="android:statusBarColor">@color/colorAccent</item>
</style>
<style name="Simulator" parent="@style/Theme.Material3.DynamicColors.DayNight.NoActionBar">
<item name="android:background">@color/black</item>
</style>

<color name="colorPrimary">#FE9200</color>
<color name="colorSecondary">#FE9200</color>
<color name="colorAccent" tools:ignore="UnusedResources">#FE9F11</color>
<color name="black">#000000</color>

<style name="CustomAboutLibrariesStyle" parent="AppTheme">
<!-- AboutLibraries specific values -->
Expand Down

0 comments on commit e223016

Please sign in to comment.