From cde542b440d15d2f5c458e8f35173985dede5d71 Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Wed, 18 Mar 2026 20:38:59 +0800 Subject: [PATCH 1/7] Run UI updates on main Handler; fix delete task --- .../github/libxposed/example/MainActivity.kt | 21 +++++++++++-------- build.gradle.kts | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/github/libxposed/example/MainActivity.kt b/app/src/main/java/io/github/libxposed/example/MainActivity.kt index ec8d6b7..f54f868 100644 --- a/app/src/main/java/io/github/libxposed/example/MainActivity.kt +++ b/app/src/main/java/io/github/libxposed/example/MainActivity.kt @@ -5,6 +5,7 @@ import android.app.Activity import android.os.Bundle import android.os.Handler import android.os.Looper +import android.util.Log import android.widget.Toast import io.github.libxposed.example.databinding.ActivityMainBinding import io.github.libxposed.service.XposedService @@ -36,18 +37,20 @@ class MainActivity : Activity() { super.onCreate(savedInstanceState) val binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - + val handler = Handler(Looper.getMainLooper()) binding.binder.text = "Loading" XposedServiceHelper.registerListener(object : XposedServiceHelper.OnServiceListener { override fun onServiceBind(service: XposedService) { mService = service - binding.binder.text = "Binder acquired" - binding.api.text = "API " + service.apiVersion - binding.framework.text = "Framework " + service.frameworkName - binding.frameworkVersion.text = "Framework version " + service.frameworkVersion - binding.frameworkVersionCode.text = "Framework version code " + service.frameworkVersionCode - binding.frameworkProperties.text = "Framework properties: " + service.frameworkProperties.toHexString() - binding.scope.text = "Scope: " + service.scope + handler.post { + binding.binder.text = "Binder acquired" + binding.api.text = "API " + service.apiVersion + binding.framework.text = "Framework " + service.frameworkName + binding.frameworkVersion.text = "Framework version " + service.frameworkVersion + binding.frameworkVersionCode.text = "Framework version code " + service.frameworkVersionCode + binding.frameworkProperties.text = "Framework properties: " + service.frameworkProperties.toHexString() + binding.scope.text = "Scope: " + service.scope + } binding.requestScope.setOnClickListener { service.requestScope(listOf("com.android.settings"), mCallback) @@ -72,7 +75,7 @@ class MainActivity : Activity() { } }) - val handler = Handler(Looper.getMainLooper()) + handler.postDelayed({ if (mService == null) { binding.binder.text = "Binder is null" diff --git a/build.gradle.kts b/build.gradle.kts index a596355..7f0594e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,3 @@ tasks.register("Delete", Delete::class) { - delete(rootProject.buildDir) + delete(rootProject.layout.buildDirectory) } From 737c5e412029b215515b7b908a47d5d732c166a0 Mon Sep 17 00:00:00 2001 From: Howard Wu Date: Wed, 18 Mar 2026 21:29:53 +0800 Subject: [PATCH 2/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../github/libxposed/example/MainActivity.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/github/libxposed/example/MainActivity.kt b/app/src/main/java/io/github/libxposed/example/MainActivity.kt index f54f868..8d4c556 100644 --- a/app/src/main/java/io/github/libxposed/example/MainActivity.kt +++ b/app/src/main/java/io/github/libxposed/example/MainActivity.kt @@ -41,8 +41,8 @@ class MainActivity : Activity() { binding.binder.text = "Loading" XposedServiceHelper.registerListener(object : XposedServiceHelper.OnServiceListener { override fun onServiceBind(service: XposedService) { - mService = service handler.post { + mService = service binding.binder.text = "Binder acquired" binding.api.text = "API " + service.apiVersion binding.framework.text = "Framework " + service.frameworkName @@ -50,22 +50,22 @@ class MainActivity : Activity() { binding.frameworkVersionCode.text = "Framework version code " + service.frameworkVersionCode binding.frameworkProperties.text = "Framework properties: " + service.frameworkProperties.toHexString() binding.scope.text = "Scope: " + service.scope - } - binding.requestScope.setOnClickListener { - service.requestScope(listOf("com.android.settings"), mCallback) - } - binding.randomPrefs.setOnClickListener { - val prefs = service.getRemotePreferences("test") - val old = prefs.getInt("test", -1) - val new = Random.nextInt() - Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show() - prefs.edit().putInt("test", new).apply() - } - binding.remoteFile.setOnClickListener { - service.openRemoteFile("test.txt").use { pfd -> - FileWriter(pfd.fileDescriptor).use { - it.append("Hello World!") + binding.requestScope.setOnClickListener { + service.requestScope(listOf("com.android.settings"), mCallback) + } + binding.randomPrefs.setOnClickListener { + val prefs = service.getRemotePreferences("test") + val old = prefs.getInt("test", -1) + val new = Random.nextInt() + Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show() + prefs.edit().putInt("test", new).apply() + } + binding.remoteFile.setOnClickListener { + service.openRemoteFile("test.txt").use { pfd -> + FileWriter(pfd.fileDescriptor).use { + it.append("Hello World!") + } } } } From e40d409b54f4ce993867a6255c9d8ba5aecefcdf Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Mon, 23 Mar 2026 15:50:46 +0800 Subject: [PATCH 3/7] Add example for get cap --- app/src/main/AndroidManifest.xml | 1 + .../java/io/github/libxposed/example/App.kt | 77 ++++++++++++ .../github/libxposed/example/MainActivity.kt | 118 +++++++++++------- 3 files changed, 150 insertions(+), 46 deletions(-) create mode 100644 app/src/main/java/io/github/libxposed/example/App.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ea5e49..c793f25 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools"> () + val mainHandler: Handler = Handler(Looper.getMainLooper()) + private fun dispatchServiceState( + listener: ServiceStateListener, + service: XposedService? + ) { + if (Looper.myLooper() == Looper.getMainLooper()) { + listener.onServiceStateChanged(service) + return + } + mainHandler.post { + listener.onServiceStateChanged( + service + ) + } + } + + fun addServiceStateListener( + listener: ServiceStateListener, + notifyImmediately: Boolean + ) { + serviceStateListeners.add(listener) + if (notifyImmediately) { + dispatchServiceState( + listener, + mService + ) + } + } + + fun removeServiceStateListener(listener: ServiceStateListener) { + serviceStateListeners.remove(listener) + } + } + + private fun notifyServiceStateChanged(service: XposedService?) { + for (listener in serviceStateListeners) { + dispatchServiceState(listener, service) + } + } + + override fun onCreate() { + super.onCreate() + XposedServiceHelper.registerListener(this) + } + + interface ServiceStateListener { + fun onServiceStateChanged(service: XposedService?) + } + + override fun onServiceBind(service: XposedService) { + mService = service + notifyServiceStateChanged(mService) + } + + override fun onServiceDied(service: XposedService) { + mService = null + notifyServiceStateChanged(mService) + } +} diff --git a/app/src/main/java/io/github/libxposed/example/MainActivity.kt b/app/src/main/java/io/github/libxposed/example/MainActivity.kt index 8d4c556..c1203ab 100644 --- a/app/src/main/java/io/github/libxposed/example/MainActivity.kt +++ b/app/src/main/java/io/github/libxposed/example/MainActivity.kt @@ -5,29 +5,34 @@ import android.app.Activity import android.os.Bundle import android.os.Handler import android.os.Looper -import android.util.Log import android.widget.Toast import io.github.libxposed.example.databinding.ActivityMainBinding import io.github.libxposed.service.XposedService import io.github.libxposed.service.XposedService.OnScopeEventListener -import io.github.libxposed.service.XposedServiceHelper import java.io.FileWriter import kotlin.random.Random -class MainActivity : Activity() { - - private var mService: XposedService? = null +class MainActivity : Activity(), App.ServiceStateListener { + private var binding: ActivityMainBinding? = null private val mCallback = object : OnScopeEventListener { override fun onScopeRequestApproved(approved: List) { runOnUiThread { - Toast.makeText(this@MainActivity, "onScopeRequestApproved: $approved", Toast.LENGTH_SHORT).show() + Toast.makeText( + this@MainActivity, + "onScopeRequestApproved: $approved", + Toast.LENGTH_SHORT + ).show() } } override fun onScopeRequestFailed(message: String) { runOnUiThread { - Toast.makeText(this@MainActivity, "onScopeRequestFailed: $message", Toast.LENGTH_SHORT).show() + Toast.makeText( + this@MainActivity, + "onScopeRequestFailed: $message", + Toast.LENGTH_SHORT + ).show() } } } @@ -35,51 +40,72 @@ class MainActivity : Activity() { @SuppressLint("SetTextI18n") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val binding = ActivityMainBinding.inflate(layoutInflater) - setContentView(binding.root) + binding = ActivityMainBinding.inflate(layoutInflater) + binding?.let { + setContentView(it.root) + it.binder.text = "Loading" + } + } + + override fun onStart() { + super.onStart() + App.addServiceStateListener(this, true) + } + + override fun onStop() { + App.removeServiceStateListener(this) + super.onStop() + } + + @SuppressLint("SetTextI18n") + override fun onServiceStateChanged(service: XposedService?) { val handler = Handler(Looper.getMainLooper()) - binding.binder.text = "Loading" - XposedServiceHelper.registerListener(object : XposedServiceHelper.OnServiceListener { - override fun onServiceBind(service: XposedService) { - handler.post { - mService = service - binding.binder.text = "Binder acquired" - binding.api.text = "API " + service.apiVersion - binding.framework.text = "Framework " + service.frameworkName - binding.frameworkVersion.text = "Framework version " + service.frameworkVersion - binding.frameworkVersionCode.text = "Framework version code " + service.frameworkVersionCode - binding.frameworkProperties.text = "Framework properties: " + service.frameworkProperties.toHexString() - binding.scope.text = "Scope: " + service.scope + binding?.let { + handler.post { + it.binder.text = "Binder acquired" + it.api.text = "API " + service?.apiVersion + it.framework.text = "Framework " + service?.frameworkName + it.frameworkVersion.text = "Framework version " + service?.frameworkVersion + it.frameworkVersionCode.text = + "Framework version code " + service?.frameworkVersionCode + val cap = service?.frameworkProperties + val capStringList = mutableListOf() + cap?.and(XposedService.PROP_CAP_SYSTEM)?.let { + capStringList.add("PROP_CAP_SYSTEM") + } + cap?.and(XposedService.PROP_CAP_REMOTE)?.let { + capStringList.add("PROP_CAP_REMOTE") + } + cap?.and(XposedService.PROP_RT_API_PROTECTION)?.let { + capStringList.add("PROP_RT_API_PROTECTION") + } + it.frameworkProperties.text = + "Framework properties: $capStringList" + it.scope.text = "Scope: " + service?.scope - binding.requestScope.setOnClickListener { - service.requestScope(listOf("com.android.settings"), mCallback) - } - binding.randomPrefs.setOnClickListener { - val prefs = service.getRemotePreferences("test") - val old = prefs.getInt("test", -1) - val new = Random.nextInt() - Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show() - prefs.edit().putInt("test", new).apply() - } - binding.remoteFile.setOnClickListener { - service.openRemoteFile("test.txt").use { pfd -> - FileWriter(pfd.fileDescriptor).use { - it.append("Hello World!") + it.requestScope.setOnClickListener { + service?.requestScope(listOf("com.android.settings"), mCallback) + } + it.randomPrefs.setOnClickListener { + val prefs = service?.getRemotePreferences("test") + val old = prefs?.getInt("test", -1) + val new = Random.nextInt() + Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show() + prefs?.edit()?.putInt("test", new)?.apply() + } + it.remoteFile.setOnClickListener { + service?.openRemoteFile("test.txt").use { pfd -> + pfd?.let { fileDescriptor -> + FileWriter(fileDescriptor.fileDescriptor).use { writer -> + writer.append("Hello World!") } } } } + if (service == null) { + it.let { binding -> binding.binder.text = "Binder is null" } + } } - - override fun onServiceDied(service: XposedService) { - } - }) - - - handler.postDelayed({ - if (mService == null) { - binding.binder.text = "Binder is null" - } - }, 5000) + } } } From ae24636fae69629726b867a8f8fa849e65e2f882 Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Mon, 23 Mar 2026 16:00:41 +0800 Subject: [PATCH 4/7] Reload scope when on listener --- .../main/java/io/github/libxposed/example/MainActivity.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/github/libxposed/example/MainActivity.kt b/app/src/main/java/io/github/libxposed/example/MainActivity.kt index c1203ab..799992a 100644 --- a/app/src/main/java/io/github/libxposed/example/MainActivity.kt +++ b/app/src/main/java/io/github/libxposed/example/MainActivity.kt @@ -12,7 +12,9 @@ import io.github.libxposed.service.XposedService.OnScopeEventListener import java.io.FileWriter import kotlin.random.Random +@SuppressLint("SetTextI18n") class MainActivity : Activity(), App.ServiceStateListener { + private var mService: XposedService? = null private var binding: ActivityMainBinding? = null private val mCallback = object : OnScopeEventListener { @@ -23,6 +25,7 @@ class MainActivity : Activity(), App.ServiceStateListener { "onScopeRequestApproved: $approved", Toast.LENGTH_SHORT ).show() + binding?.scope?.text = "Scope: " + mService?.scope } } @@ -33,11 +36,11 @@ class MainActivity : Activity(), App.ServiceStateListener { "onScopeRequestFailed: $message", Toast.LENGTH_SHORT ).show() + binding?.scope?.text = "Scope: " + mService?.scope } } } - @SuppressLint("SetTextI18n") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) @@ -57,8 +60,8 @@ class MainActivity : Activity(), App.ServiceStateListener { super.onStop() } - @SuppressLint("SetTextI18n") override fun onServiceStateChanged(service: XposedService?) { + mService = service val handler = Handler(Looper.getMainLooper()) binding?.let { handler.post { From b41c8e357a0bc6c2a3f3f1971c5e2811e3740ffa Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Mon, 23 Mar 2026 16:10:33 +0800 Subject: [PATCH 5/7] Resolve all review --- .../java/io/github/libxposed/example/App.kt | 19 ++++--------------- .../github/libxposed/example/MainActivity.kt | 6 +++--- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/github/libxposed/example/App.kt b/app/src/main/java/io/github/libxposed/example/App.kt index 58855a9..39823ec 100644 --- a/app/src/main/java/io/github/libxposed/example/App.kt +++ b/app/src/main/java/io/github/libxposed/example/App.kt @@ -1,8 +1,6 @@ package io.github.libxposed.example import android.app.Application -import android.os.Handler -import android.os.Looper import io.github.libxposed.service.XposedService import io.github.libxposed.service.XposedServiceHelper import java.util.concurrent.CopyOnWriteArraySet @@ -14,21 +12,15 @@ class App : Application(), XposedServiceHelper.OnServiceListener { companion object { @Volatile var mService: XposedService? = null - val serviceStateListeners = + private val serviceStateListeners = CopyOnWriteArraySet() - val mainHandler: Handler = Handler(Looper.getMainLooper()) + private fun dispatchServiceState( listener: ServiceStateListener, service: XposedService? ) { - if (Looper.myLooper() == Looper.getMainLooper()) { + if (serviceStateListeners.contains(listener)) { listener.onServiceStateChanged(service) - return - } - mainHandler.post { - listener.onServiceStateChanged( - service - ) } } @@ -38,10 +30,7 @@ class App : Application(), XposedServiceHelper.OnServiceListener { ) { serviceStateListeners.add(listener) if (notifyImmediately) { - dispatchServiceState( - listener, - mService - ) + dispatchServiceState(listener, mService) } } diff --git a/app/src/main/java/io/github/libxposed/example/MainActivity.kt b/app/src/main/java/io/github/libxposed/example/MainActivity.kt index 799992a..06a0d84 100644 --- a/app/src/main/java/io/github/libxposed/example/MainActivity.kt +++ b/app/src/main/java/io/github/libxposed/example/MainActivity.kt @@ -73,13 +73,13 @@ class MainActivity : Activity(), App.ServiceStateListener { "Framework version code " + service?.frameworkVersionCode val cap = service?.frameworkProperties val capStringList = mutableListOf() - cap?.and(XposedService.PROP_CAP_SYSTEM)?.let { + if (cap != null && cap.and(XposedService.PROP_CAP_SYSTEM) != 0L) { capStringList.add("PROP_CAP_SYSTEM") } - cap?.and(XposedService.PROP_CAP_REMOTE)?.let { + if (cap != null && cap.and(XposedService.PROP_CAP_REMOTE) != 0L) { capStringList.add("PROP_CAP_REMOTE") } - cap?.and(XposedService.PROP_RT_API_PROTECTION)?.let { + if (cap != null && cap.and(XposedService.PROP_RT_API_PROTECTION) != 0L) { capStringList.add("PROP_RT_API_PROTECTION") } it.frameworkProperties.text = From 1216b0e328bbbaaf66f307311d7fad2f925ce7e0 Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Mon, 23 Mar 2026 16:30:57 +0800 Subject: [PATCH 6/7] Resolve all review --- .../java/io/github/libxposed/example/App.kt | 1 + .../github/libxposed/example/MainActivity.kt | 91 +++++++++---------- 2 files changed, 43 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/io/github/libxposed/example/App.kt b/app/src/main/java/io/github/libxposed/example/App.kt index 39823ec..af0b12b 100644 --- a/app/src/main/java/io/github/libxposed/example/App.kt +++ b/app/src/main/java/io/github/libxposed/example/App.kt @@ -12,6 +12,7 @@ class App : Application(), XposedServiceHelper.OnServiceListener { companion object { @Volatile var mService: XposedService? = null + private set private val serviceStateListeners = CopyOnWriteArraySet() diff --git a/app/src/main/java/io/github/libxposed/example/MainActivity.kt b/app/src/main/java/io/github/libxposed/example/MainActivity.kt index 06a0d84..7c11a46 100644 --- a/app/src/main/java/io/github/libxposed/example/MainActivity.kt +++ b/app/src/main/java/io/github/libxposed/example/MainActivity.kt @@ -3,8 +3,6 @@ package io.github.libxposed.example import android.annotation.SuppressLint import android.app.Activity import android.os.Bundle -import android.os.Handler -import android.os.Looper import android.widget.Toast import io.github.libxposed.example.databinding.ActivityMainBinding import io.github.libxposed.service.XposedService @@ -15,7 +13,7 @@ import kotlin.random.Random @SuppressLint("SetTextI18n") class MainActivity : Activity(), App.ServiceStateListener { private var mService: XposedService? = null - private var binding: ActivityMainBinding? = null + private lateinit var binding: ActivityMainBinding private val mCallback = object : OnScopeEventListener { override fun onScopeRequestApproved(approved: List) { @@ -25,7 +23,7 @@ class MainActivity : Activity(), App.ServiceStateListener { "onScopeRequestApproved: $approved", Toast.LENGTH_SHORT ).show() - binding?.scope?.text = "Scope: " + mService?.scope + binding.scope.text = "Scope: " + mService?.scope } } @@ -36,7 +34,7 @@ class MainActivity : Activity(), App.ServiceStateListener { "onScopeRequestFailed: $message", Toast.LENGTH_SHORT ).show() - binding?.scope?.text = "Scope: " + mService?.scope + binding.scope.text = "Scope: " + mService?.scope } } } @@ -44,7 +42,7 @@ class MainActivity : Activity(), App.ServiceStateListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) - binding?.let { + binding.let { setContentView(it.root) it.binder.text = "Loading" } @@ -62,52 +60,47 @@ class MainActivity : Activity(), App.ServiceStateListener { override fun onServiceStateChanged(service: XposedService?) { mService = service - val handler = Handler(Looper.getMainLooper()) - binding?.let { - handler.post { - it.binder.text = "Binder acquired" - it.api.text = "API " + service?.apiVersion - it.framework.text = "Framework " + service?.frameworkName - it.frameworkVersion.text = "Framework version " + service?.frameworkVersion - it.frameworkVersionCode.text = - "Framework version code " + service?.frameworkVersionCode - val cap = service?.frameworkProperties - val capStringList = mutableListOf() - if (cap != null && cap.and(XposedService.PROP_CAP_SYSTEM) != 0L) { - capStringList.add("PROP_CAP_SYSTEM") - } - if (cap != null && cap.and(XposedService.PROP_CAP_REMOTE) != 0L) { - capStringList.add("PROP_CAP_REMOTE") - } - if (cap != null && cap.and(XposedService.PROP_RT_API_PROTECTION) != 0L) { - capStringList.add("PROP_RT_API_PROTECTION") - } - it.frameworkProperties.text = - "Framework properties: $capStringList" - it.scope.text = "Scope: " + service?.scope + runOnUiThread { + binding.binder.text = "Binder acquired" + binding.api.text = "API " + service?.apiVersion + binding.framework.text = "Framework " + service?.frameworkName + binding.frameworkVersion.text = "Framework version " + service?.frameworkVersion + binding.frameworkVersionCode.text = + "Framework version code " + service?.frameworkVersionCode + val cap = service?.frameworkProperties + val capStringList = mutableListOf() + if (cap != null && cap.and(XposedService.PROP_CAP_SYSTEM) != 0L) { + capStringList.add("PROP_CAP_SYSTEM") + } + if (cap != null && cap.and(XposedService.PROP_CAP_REMOTE) != 0L) { + capStringList.add("PROP_CAP_REMOTE") + } + if (cap != null && cap.and(XposedService.PROP_RT_API_PROTECTION) != 0L) { + capStringList.add("PROP_RT_API_PROTECTION") + } + binding.frameworkProperties.text = + "Framework properties: $capStringList" + binding.scope.text = "Scope: " + service?.scope - it.requestScope.setOnClickListener { - service?.requestScope(listOf("com.android.settings"), mCallback) - } - it.randomPrefs.setOnClickListener { - val prefs = service?.getRemotePreferences("test") - val old = prefs?.getInt("test", -1) - val new = Random.nextInt() - Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show() - prefs?.edit()?.putInt("test", new)?.apply() - } - it.remoteFile.setOnClickListener { - service?.openRemoteFile("test.txt").use { pfd -> - pfd?.let { fileDescriptor -> - FileWriter(fileDescriptor.fileDescriptor).use { writer -> - writer.append("Hello World!") - } - } + binding.requestScope.setOnClickListener { + service?.requestScope(listOf("com.android.settings"), mCallback) + } + binding.randomPrefs.setOnClickListener { + val prefs = service?.getRemotePreferences("test") + val old = prefs?.getInt("test", -1) + val new = Random.nextInt() + Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show() + prefs?.edit()?.putInt("test", new)?.apply() + } + binding.remoteFile.setOnClickListener { + service?.openRemoteFile("test.txt").use { + FileWriter(it?.fileDescriptor).use { writer -> + writer.append("Hello World!") } } - if (service == null) { - it.let { binding -> binding.binder.text = "Binder is null" } - } + } + if (service == null) { + binding.binder.text = "Binder is null" } } } From 1c454010db8e51e6df00f3047855eb78a782770c Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Mon, 23 Mar 2026 16:42:15 +0800 Subject: [PATCH 7/7] Update MainActivity.kt --- .../github/libxposed/example/MainActivity.kt | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/io/github/libxposed/example/MainActivity.kt b/app/src/main/java/io/github/libxposed/example/MainActivity.kt index 7c11a46..55b8dbc 100644 --- a/app/src/main/java/io/github/libxposed/example/MainActivity.kt +++ b/app/src/main/java/io/github/libxposed/example/MainActivity.kt @@ -61,47 +61,48 @@ class MainActivity : Activity(), App.ServiceStateListener { override fun onServiceStateChanged(service: XposedService?) { mService = service runOnUiThread { - binding.binder.text = "Binder acquired" - binding.api.text = "API " + service?.apiVersion - binding.framework.text = "Framework " + service?.frameworkName - binding.frameworkVersion.text = "Framework version " + service?.frameworkVersion - binding.frameworkVersionCode.text = - "Framework version code " + service?.frameworkVersionCode - val cap = service?.frameworkProperties - val capStringList = mutableListOf() - if (cap != null && cap.and(XposedService.PROP_CAP_SYSTEM) != 0L) { - capStringList.add("PROP_CAP_SYSTEM") - } - if (cap != null && cap.and(XposedService.PROP_CAP_REMOTE) != 0L) { - capStringList.add("PROP_CAP_REMOTE") - } - if (cap != null && cap.and(XposedService.PROP_RT_API_PROTECTION) != 0L) { - capStringList.add("PROP_RT_API_PROTECTION") - } - binding.frameworkProperties.text = - "Framework properties: $capStringList" - binding.scope.text = "Scope: " + service?.scope + if (service == null) { + binding.binder.text = "Binder is null" + } else { + binding.binder.text = "Binder acquired" + binding.api.text = "API " + service.apiVersion + binding.framework.text = "Framework " + service.frameworkName + binding.frameworkVersion.text = "Framework version " + service.frameworkVersion + binding.frameworkVersionCode.text = + "Framework version code " + service.frameworkVersionCode + val cap = service.frameworkProperties + val capStringList = mutableListOf() + if (cap.and(XposedService.PROP_CAP_SYSTEM) != 0L) { + capStringList.add("PROP_CAP_SYSTEM") + } + if (cap.and(XposedService.PROP_CAP_REMOTE) != 0L) { + capStringList.add("PROP_CAP_REMOTE") + } + if (cap.and(XposedService.PROP_RT_API_PROTECTION) != 0L) { + capStringList.add("PROP_RT_API_PROTECTION") + } + binding.frameworkProperties.text = + "Framework properties: $capStringList" + binding.scope.text = "Scope: " + service.scope - binding.requestScope.setOnClickListener { - service?.requestScope(listOf("com.android.settings"), mCallback) - } - binding.randomPrefs.setOnClickListener { - val prefs = service?.getRemotePreferences("test") - val old = prefs?.getInt("test", -1) - val new = Random.nextInt() - Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show() - prefs?.edit()?.putInt("test", new)?.apply() - } - binding.remoteFile.setOnClickListener { - service?.openRemoteFile("test.txt").use { - FileWriter(it?.fileDescriptor).use { writer -> - writer.append("Hello World!") + binding.requestScope.setOnClickListener { + service.requestScope(listOf("com.android.settings"), mCallback) + } + binding.randomPrefs.setOnClickListener { + val prefs = service.getRemotePreferences("test") + val old = prefs.getInt("test", -1) + val new = Random.nextInt() + Toast.makeText(this@MainActivity, "$old -> $new", Toast.LENGTH_SHORT).show() + prefs.edit()?.putInt("test", new)?.apply() + } + binding.remoteFile.setOnClickListener { + service.openRemoteFile("test.txt").use { pfd -> + FileWriter(pfd.fileDescriptor).use { + it.append("Hello World!") + } } } } - if (service == null) { - binding.binder.text = "Binder is null" - } } } }