Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit 32b4cb7

Browse files
committed
Complete demo
1 parent aa8e577 commit 32b4cb7

File tree

4 files changed

+69
-50
lines changed

4 files changed

+69
-50
lines changed

demo/build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,13 @@ android {
3131
buildConfig = true
3232
}
3333
composeOptions {
34-
kotlinCompilerExtensionVersion = "1.5.6"
34+
kotlinCompilerExtensionVersion = "1.5.11"
3535
}
3636
}
3737

3838
dependencies {
39-
implementation(libs.androidx.core.ktx)
40-
implementation(libs.androidx.lifecycle.runtime.ktx)
4139
implementation(libs.androidx.activity.compose)
4240
implementation(platform(libs.androidx.compose.bom))
43-
implementation(libs.androidx.ui)
44-
implementation(libs.androidx.ui.graphics)
4541
implementation(libs.androidx.material3)
4642
implementation(project(":lservice"))
4743
}
5.54 KB
Binary file not shown.
Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,86 @@
11
package com.houvven.lsposed.scope.demo
22

3-
import android.content.ComponentName
4-
import android.content.ServiceConnection
53
import android.os.Bundle
6-
import android.os.IBinder
7-
import android.util.Log
84
import androidx.activity.ComponentActivity
9-
import io.github.houvven.lservice.ILSPosedBridgeService
10-
import io.github.houvven.lservice.LSPosedBridgeRootService
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.layout.Arrangement
7+
import androidx.compose.foundation.layout.Column
8+
import androidx.compose.material3.MaterialTheme
9+
import androidx.compose.material3.Text
10+
import androidx.compose.runtime.LaunchedEffect
11+
import androidx.compose.runtime.getValue
12+
import androidx.compose.runtime.mutableStateOf
13+
import androidx.compose.runtime.remember
14+
import androidx.compose.runtime.setValue
15+
import androidx.compose.ui.Modifier
16+
import io.github.houvven.lservice.LServiceBridgeRootService
17+
import kotlinx.coroutines.delay
1118
import org.lsposed.lspd.ILSPManagerService
12-
import org.lsposed.lspd.service.ILSPApplicationService
13-
import java.util.Optional
1419

1520
class MainActivity : ComponentActivity() {
21+
22+
private var managerService: ILSPManagerService? = null
23+
1624
override fun onCreate(savedInstanceState: Bundle?) {
1725
super.onCreate(savedInstanceState)
18-
LSPosedBridgeRootService.bindRootService(this, LSPosedBridgeServiceConnection)
19-
Thread {
20-
while (!LSPosedBridgeServiceConnection.serviceOptional.isPresent) {
21-
Thread.sleep(200)
22-
}
2326

24-
LSPosedBridgeServiceConnection.serviceOptional.ifPresent { bridgeService ->
25-
val applicationServiceBinder =
26-
bridgeService.obtainLSPosedApplicationServiceBinder() ?: return@ifPresent
27-
val applicationService =
28-
ILSPApplicationService.Stub.asInterface(applicationServiceBinder)
29-
30-
val managerServiceBinder =
31-
bridgeService.obtainLSPosedManagerServiceBinder(applicationService)
32-
?: return@ifPresent
33-
val managerService = ILSPManagerService.Stub.asInterface(managerServiceBinder)
34-
val xposedApiVersion = managerService.xposedApiVersion
35-
Log.i("MainActivity", "xposedApiVersion: $xposedApiVersion")
36-
}
37-
}.start()
38-
}
27+
val connection = LServiceBridgeRootService.DefaultServiceConnection()
28+
LServiceBridgeRootService.bind(this.applicationContext, connection, apkFile)
29+
30+
setContent {
31+
var isBinderAlive by remember { mutableStateOf(false) }
32+
var api by remember { mutableStateOf("") }
33+
var xposedApiVersion by remember { mutableStateOf("") }
34+
var xposedVersionName by remember { mutableStateOf("") }
35+
var xposedVersionCode by remember { mutableStateOf("") }
3936

40-
object LSPosedBridgeServiceConnection : ServiceConnection {
37+
MaterialTheme {
38+
Column(
39+
verticalArrangement = Arrangement.Top,
40+
modifier = Modifier
41+
) {
42+
Text(text = "api: $api")
43+
Text(text = "xposedApiVersion: $xposedApiVersion")
44+
Text(text = "xposedVersionName: $xposedVersionName")
45+
Text(text = "xposedVersionCode: $xposedVersionCode")
46+
}
47+
}
4148

42-
private const val TAG = "LSPosedBridgeServiceConnection"
49+
LaunchedEffect(key1 = this) {
50+
while (connection.lServiceBridge == null) {
51+
delay(200)
52+
}
53+
isBinderAlive = true
54+
}
4355

44-
var serviceOptional: Optional<ILSPosedBridgeService> = Optional.empty()
45-
private set
56+
LaunchedEffect(key1 = isBinderAlive) {
57+
while (managerService == null) {
58+
runCatching {
59+
managerService = connection.getManagerService(connection.applicationService)
60+
}.onFailure { delay(200) }
61+
}
62+
managerService!!.let {
63+
api = it.api
64+
xposedApiVersion = it.xposedApiVersion.toString()
65+
xposedVersionName = it.xposedVersionName
66+
xposedVersionCode = it.xposedVersionCode.toString()
67+
}
68+
}
4669

47-
override fun onServiceConnected(name: ComponentName, service: IBinder) {
48-
Log.i(TAG, "onServiceConnected: $name, ${service.interfaceDescriptor}")
49-
serviceOptional = Optional.of(ILSPosedBridgeService.Stub.asInterface(service))
5070
}
71+
}
5172

52-
override fun onServiceDisconnected(name: ComponentName?) {
53-
Log.i(TAG, "onServiceDisconnected: $name")
54-
serviceOptional = Optional.empty()
73+
private val apkFile: String
74+
get() {
75+
val file = cacheDir.resolve("lsposed.apk")
76+
if (!file.exists()) {
77+
assets.open("lsposed-manager.apk").use { inputStream ->
78+
file.outputStream().use { out ->
79+
out.write(inputStream.readBytes())
80+
out.flush()
81+
}
82+
}
83+
}
84+
return file.absolutePath
5585
}
56-
}
5786
}

gradle/libs.versions.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ activityCompose = "1.9.0"
33
agp = "8.4.0"
44
composeBom = "2024.05.00"
55
kotlin = "1.9.23"
6-
coreKtx = "1.13.1"
76
libsu = "5.2.2"
8-
lifecycleRuntimeKtx = "2.7.0"
97

108

119
[libraries]
12-
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
13-
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
1410
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
1511
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
16-
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
17-
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
1812
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
1913
libsu-service = { module = "com.github.topjohnwu.libsu:service", version.ref = "libsu" }
2014
rikkax-parcelablelist = { module = "dev.rikka.rikkax.parcelablelist:parcelablelist", version = "2.0.1" }

0 commit comments

Comments
 (0)