fix(core/security_features): temporary indicator

This commit is contained in:
rhunk 2024-08-29 13:23:06 +02:00
parent 70bd6b7f0e
commit a63dc8725c

View File

@ -1,23 +1,19 @@
package me.rhunk.snapenhance.core.features.impl package me.rhunk.snapenhance.core.features.impl
import android.annotation.SuppressLint
import android.system.Os import android.system.Os
import androidx.compose.foundation.background import android.widget.TextView
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import me.rhunk.snapenhance.common.util.protobuf.ProtoEditor import me.rhunk.snapenhance.common.util.protobuf.ProtoEditor
import me.rhunk.snapenhance.common.util.protobuf.ProtoReader import me.rhunk.snapenhance.common.util.protobuf.ProtoReader
import me.rhunk.snapenhance.core.event.events.impl.UnaryCallEvent import me.rhunk.snapenhance.core.event.events.impl.UnaryCallEvent
import me.rhunk.snapenhance.core.features.Feature import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.util.ktx.getId
import me.rhunk.snapenhance.core.util.ktx.setObjectField import me.rhunk.snapenhance.core.util.ktx.setObjectField
import java.io.FileDescriptor import java.io.FileDescriptor
@ -32,6 +28,7 @@ class SecurityFeatures : Feature("Security Features") {
transact(this, 0)?.toString(2)?.padStart(32, '0')?.count { it == '1' } transact(this, 0)?.toString(2)?.padStart(32, '0')?.count { it == '1' }
} }
@SuppressLint("SetTextI18n")
override fun init() { override fun init() {
token // pre init token token // pre init token
@ -74,41 +71,29 @@ class SecurityFeatures : Feature("Security Features") {
} }
} }
context.inAppOverlay.addCustomComposable { val hovaPageTitleId = context.resources.getId("hova_page_title")
var statusText by remember {
mutableStateOf("") fun findHovaPageTitle(): TextView? {
} return context.mainActivity?.findViewById(hovaPageTitleId)
var textColor by remember {
mutableStateOf(Color.Red)
} }
LaunchedEffect(Unit) { context.coroutineScope.launch {
withContext(Dispatchers.IO) {
while (true) { while (true) {
val status = getStatus() val status = getStatus()
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
val textView = findHovaPageTitle() ?: return@withContext
if (status == null || status == 0) { if (status == null || status == 0) {
textColor = Color.Red textView.text = "SIF not loaded"
statusText = "SIF not loaded!" textView.textSize = 13F
textView.setTextColor(Color.Red.toArgb())
} else { } else {
textColor = Color.Green textView.setTextColor(Color.Green.toArgb())
statusText = "SIF = $status" val prefix = textView.text.toString().substringBeforeLast(" (")
textView.text = "$prefix (${status})"
} }
} }
delay(1000) delay(1000)
} }
} }
} }
Text(
text = statusText,
modifier = Modifier
.align(Alignment.BottomCenter)
.background(Color.Black, shape = RoundedCornerShape(5.dp))
.padding(3.dp),
fontSize = 10.sp,
color = textColor
)
}
}
} }