Skip to content

Commit

Permalink
Complete demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Houvven committed May 14, 2024
1 parent aa8e577 commit 32b4cb7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 50 deletions.
6 changes: 1 addition & 5 deletions demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ android {
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.6"
kotlinCompilerExtensionVersion = "1.5.11"
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.material3)
implementation(project(":lservice"))
}
Binary file added demo/src/main/assets/lsposed-manager.apk
Binary file not shown.
107 changes: 68 additions & 39 deletions demo/src/main/kotlin/com/houvven/lsposed/scope/demo/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,57 +1,86 @@
package com.houvven.lsposed.scope.demo

import android.content.ComponentName
import android.content.ServiceConnection
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import androidx.activity.ComponentActivity
import io.github.houvven.lservice.ILSPosedBridgeService
import io.github.houvven.lservice.LSPosedBridgeRootService
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import io.github.houvven.lservice.LServiceBridgeRootService
import kotlinx.coroutines.delay
import org.lsposed.lspd.ILSPManagerService
import org.lsposed.lspd.service.ILSPApplicationService
import java.util.Optional

class MainActivity : ComponentActivity() {

private var managerService: ILSPManagerService? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
LSPosedBridgeRootService.bindRootService(this, LSPosedBridgeServiceConnection)
Thread {
while (!LSPosedBridgeServiceConnection.serviceOptional.isPresent) {
Thread.sleep(200)
}

LSPosedBridgeServiceConnection.serviceOptional.ifPresent { bridgeService ->
val applicationServiceBinder =
bridgeService.obtainLSPosedApplicationServiceBinder() ?: return@ifPresent
val applicationService =
ILSPApplicationService.Stub.asInterface(applicationServiceBinder)

val managerServiceBinder =
bridgeService.obtainLSPosedManagerServiceBinder(applicationService)
?: return@ifPresent
val managerService = ILSPManagerService.Stub.asInterface(managerServiceBinder)
val xposedApiVersion = managerService.xposedApiVersion
Log.i("MainActivity", "xposedApiVersion: $xposedApiVersion")
}
}.start()
}
val connection = LServiceBridgeRootService.DefaultServiceConnection()
LServiceBridgeRootService.bind(this.applicationContext, connection, apkFile)

setContent {
var isBinderAlive by remember { mutableStateOf(false) }
var api by remember { mutableStateOf("") }
var xposedApiVersion by remember { mutableStateOf("") }
var xposedVersionName by remember { mutableStateOf("") }
var xposedVersionCode by remember { mutableStateOf("") }

object LSPosedBridgeServiceConnection : ServiceConnection {
MaterialTheme {
Column(
verticalArrangement = Arrangement.Top,
modifier = Modifier
) {
Text(text = "api: $api")
Text(text = "xposedApiVersion: $xposedApiVersion")
Text(text = "xposedVersionName: $xposedVersionName")
Text(text = "xposedVersionCode: $xposedVersionCode")
}
}

private const val TAG = "LSPosedBridgeServiceConnection"
LaunchedEffect(key1 = this) {
while (connection.lServiceBridge == null) {
delay(200)
}
isBinderAlive = true
}

var serviceOptional: Optional<ILSPosedBridgeService> = Optional.empty()
private set
LaunchedEffect(key1 = isBinderAlive) {
while (managerService == null) {
runCatching {
managerService = connection.getManagerService(connection.applicationService)
}.onFailure { delay(200) }
}
managerService!!.let {
api = it.api
xposedApiVersion = it.xposedApiVersion.toString()
xposedVersionName = it.xposedVersionName
xposedVersionCode = it.xposedVersionCode.toString()
}
}

override fun onServiceConnected(name: ComponentName, service: IBinder) {
Log.i(TAG, "onServiceConnected: $name, ${service.interfaceDescriptor}")
serviceOptional = Optional.of(ILSPosedBridgeService.Stub.asInterface(service))
}
}

override fun onServiceDisconnected(name: ComponentName?) {
Log.i(TAG, "onServiceDisconnected: $name")
serviceOptional = Optional.empty()
private val apkFile: String
get() {
val file = cacheDir.resolve("lsposed.apk")
if (!file.exists()) {
assets.open("lsposed-manager.apk").use { inputStream ->
file.outputStream().use { out ->
out.write(inputStream.readBytes())
out.flush()
}
}
}
return file.absolutePath
}
}
}
6 changes: 0 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ activityCompose = "1.9.0"
agp = "8.4.0"
composeBom = "2024.05.00"
kotlin = "1.9.23"
coreKtx = "1.13.1"
libsu = "5.2.2"
lifecycleRuntimeKtx = "2.7.0"


[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
libsu-service = { module = "com.github.topjohnwu.libsu:service", version.ref = "libsu" }
rikkax-parcelablelist = { module = "dev.rikka.rikkax.parcelablelist:parcelablelist", version = "2.0.1" }
Expand Down

0 comments on commit 32b4cb7

Please sign in to comment.