Skip to content

Commit 1216b0e

Browse files
committed
Resolve all review
1 parent b41c8e3 commit 1216b0e

2 files changed

Lines changed: 43 additions & 49 deletions

File tree

app/src/main/java/io/github/libxposed/example/App.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class App : Application(), XposedServiceHelper.OnServiceListener {
1212
companion object {
1313
@Volatile
1414
var mService: XposedService? = null
15+
private set
1516
private val serviceStateListeners =
1617
CopyOnWriteArraySet<ServiceStateListener>()
1718

app/src/main/java/io/github/libxposed/example/MainActivity.kt

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package io.github.libxposed.example
33
import android.annotation.SuppressLint
44
import android.app.Activity
55
import android.os.Bundle
6-
import android.os.Handler
7-
import android.os.Looper
86
import android.widget.Toast
97
import io.github.libxposed.example.databinding.ActivityMainBinding
108
import io.github.libxposed.service.XposedService
@@ -15,7 +13,7 @@ import kotlin.random.Random
1513
@SuppressLint("SetTextI18n")
1614
class MainActivity : Activity(), App.ServiceStateListener {
1715
private var mService: XposedService? = null
18-
private var binding: ActivityMainBinding? = null
16+
private lateinit var binding: ActivityMainBinding
1917

2018
private val mCallback = object : OnScopeEventListener {
2119
override fun onScopeRequestApproved(approved: List<String>) {
@@ -25,7 +23,7 @@ class MainActivity : Activity(), App.ServiceStateListener {
2523
"onScopeRequestApproved: $approved",
2624
Toast.LENGTH_SHORT
2725
).show()
28-
binding?.scope?.text = "Scope: " + mService?.scope
26+
binding.scope.text = "Scope: " + mService?.scope
2927
}
3028
}
3129

@@ -36,15 +34,15 @@ class MainActivity : Activity(), App.ServiceStateListener {
3634
"onScopeRequestFailed: $message",
3735
Toast.LENGTH_SHORT
3836
).show()
39-
binding?.scope?.text = "Scope: " + mService?.scope
37+
binding.scope.text = "Scope: " + mService?.scope
4038
}
4139
}
4240
}
4341

4442
override fun onCreate(savedInstanceState: Bundle?) {
4543
super.onCreate(savedInstanceState)
4644
binding = ActivityMainBinding.inflate(layoutInflater)
47-
binding?.let {
45+
binding.let {
4846
setContentView(it.root)
4947
it.binder.text = "Loading"
5048
}
@@ -62,52 +60,47 @@ class MainActivity : Activity(), App.ServiceStateListener {
6260

6361
override fun onServiceStateChanged(service: XposedService?) {
6462
mService = service
65-
val handler = Handler(Looper.getMainLooper())
66-
binding?.let {
67-
handler.post {
68-
it.binder.text = "Binder acquired"
69-
it.api.text = "API " + service?.apiVersion
70-
it.framework.text = "Framework " + service?.frameworkName
71-
it.frameworkVersion.text = "Framework version " + service?.frameworkVersion
72-
it.frameworkVersionCode.text =
73-
"Framework version code " + service?.frameworkVersionCode
74-
val cap = service?.frameworkProperties
75-
val capStringList = mutableListOf<String>()
76-
if (cap != null && cap.and(XposedService.PROP_CAP_SYSTEM) != 0L) {
77-
capStringList.add("PROP_CAP_SYSTEM")
78-
}
79-
if (cap != null && cap.and(XposedService.PROP_CAP_REMOTE) != 0L) {
80-
capStringList.add("PROP_CAP_REMOTE")
81-
}
82-
if (cap != null && cap.and(XposedService.PROP_RT_API_PROTECTION) != 0L) {
83-
capStringList.add("PROP_RT_API_PROTECTION")
84-
}
85-
it.frameworkProperties.text =
86-
"Framework properties: $capStringList"
87-
it.scope.text = "Scope: " + service?.scope
63+
runOnUiThread {
64+
binding.binder.text = "Binder acquired"
65+
binding.api.text = "API " + service?.apiVersion
66+
binding.framework.text = "Framework " + service?.frameworkName
67+
binding.frameworkVersion.text = "Framework version " + service?.frameworkVersion
68+
binding.frameworkVersionCode.text =
69+
"Framework version code " + service?.frameworkVersionCode
70+
val cap = service?.frameworkProperties
71+
val capStringList = mutableListOf<String>()
72+
if (cap != null && cap.and(XposedService.PROP_CAP_SYSTEM) != 0L) {
73+
capStringList.add("PROP_CAP_SYSTEM")
74+
}
75+
if (cap != null && cap.and(XposedService.PROP_CAP_REMOTE) != 0L) {
76+
capStringList.add("PROP_CAP_REMOTE")
77+
}
78+
if (cap != null && cap.and(XposedService.PROP_RT_API_PROTECTION) != 0L) {
79+
capStringList.add("PROP_RT_API_PROTECTION")
80+
}
81+
binding.frameworkProperties.text =
82+
"Framework properties: $capStringList"
83+
binding.scope.text = "Scope: " + service?.scope
8884

89-
it.requestScope.setOnClickListener {
90-
service?.requestScope(listOf("com.android.settings"), mCallback)
91-
}
92-
it.randomPrefs.setOnClickListener {
93-
val prefs = service?.getRemotePreferences("test")
94-
val old = prefs?.getInt("test", -1)
95-
val new = Random.nextInt()
96-
Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show()
97-
prefs?.edit()?.putInt("test", new)?.apply()
98-
}
99-
it.remoteFile.setOnClickListener {
100-
service?.openRemoteFile("test.txt").use { pfd ->
101-
pfd?.let { fileDescriptor ->
102-
FileWriter(fileDescriptor.fileDescriptor).use { writer ->
103-
writer.append("Hello World!")
104-
}
105-
}
85+
binding.requestScope.setOnClickListener {
86+
service?.requestScope(listOf("com.android.settings"), mCallback)
87+
}
88+
binding.randomPrefs.setOnClickListener {
89+
val prefs = service?.getRemotePreferences("test")
90+
val old = prefs?.getInt("test", -1)
91+
val new = Random.nextInt()
92+
Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show()
93+
prefs?.edit()?.putInt("test", new)?.apply()
94+
}
95+
binding.remoteFile.setOnClickListener {
96+
service?.openRemoteFile("test.txt").use {
97+
FileWriter(it?.fileDescriptor).use { writer ->
98+
writer.append("Hello World!")
10699
}
107100
}
108-
if (service == null) {
109-
it.let { binding -> binding.binder.text = "Binder is null" }
110-
}
101+
}
102+
if (service == null) {
103+
binding.binder.text = "Binder is null"
111104
}
112105
}
113106
}

0 commit comments

Comments
 (0)