mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-29 21:10:20 +02:00
fix(bridge): supports SDK <30
This commit is contained in:
parent
ee80ab9a3e
commit
19ec7463b0
@ -80,10 +80,9 @@ class SnapEnhance {
|
|||||||
|
|
||||||
@SuppressLint("ObsoleteSdkInt")
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
private fun provideBridgeClient(): AbstractBridgeClient {
|
private fun provideBridgeClient(): AbstractBridgeClient {
|
||||||
//unsafe way for Android 9 devices
|
/*if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
|
|
||||||
return RootBridgeClient()
|
return RootBridgeClient()
|
||||||
}
|
}*/
|
||||||
return ServiceBridgeClient()
|
return ServiceBridgeClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package me.rhunk.snapenhance.bridge.client
|
package me.rhunk.snapenhance.bridge.client
|
||||||
|
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@ -13,6 +12,7 @@ import android.os.HandlerThread
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.Message
|
import android.os.Message
|
||||||
import android.os.Messenger
|
import android.os.Messenger
|
||||||
|
import de.robv.android.xposed.XposedHelpers
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import me.rhunk.snapenhance.BuildConfig
|
import me.rhunk.snapenhance.BuildConfig
|
||||||
@ -33,19 +33,16 @@ import me.rhunk.snapenhance.bridge.common.impl.messagelogger.MessageLoggerResult
|
|||||||
import me.rhunk.snapenhance.bridge.service.BridgeService
|
import me.rhunk.snapenhance.bridge.service.BridgeService
|
||||||
import java.util.concurrent.CompletableFuture
|
import java.util.concurrent.CompletableFuture
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
|
||||||
class ServiceBridgeClient: AbstractBridgeClient(), ServiceConnection {
|
class ServiceBridgeClient: AbstractBridgeClient(), ServiceConnection {
|
||||||
private val handlerThread = HandlerThread("BridgeClient")
|
private val handlerThread = HandlerThread("BridgeClient")
|
||||||
private val lock = ReentrantLock()
|
|
||||||
|
|
||||||
private lateinit var messenger: Messenger
|
private lateinit var messenger: Messenger
|
||||||
private lateinit var future: CompletableFuture<Boolean>
|
private lateinit var future: CompletableFuture<Boolean>
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.Q)
|
|
||||||
override fun start(callback: (Boolean) -> Unit) {
|
override fun start(callback: (Boolean) -> Unit) {
|
||||||
this.future = CompletableFuture()
|
this.future = CompletableFuture()
|
||||||
this.handlerThread.start()
|
this.handlerThread.start()
|
||||||
@ -53,12 +50,24 @@ class ServiceBridgeClient: AbstractBridgeClient(), ServiceConnection {
|
|||||||
with(context.androidContext) {
|
with(context.androidContext) {
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
.setClassName(BuildConfig.APPLICATION_ID, BridgeService::class.java.name)
|
.setClassName(BuildConfig.APPLICATION_ID, BridgeService::class.java.name)
|
||||||
bindService(
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
intent,
|
bindService(
|
||||||
Context.BIND_AUTO_CREATE,
|
intent,
|
||||||
Executors.newSingleThreadExecutor(),
|
Context.BIND_AUTO_CREATE,
|
||||||
this@ServiceBridgeClient
|
Executors.newSingleThreadExecutor(),
|
||||||
)
|
this@ServiceBridgeClient
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
XposedHelpers.callMethod(
|
||||||
|
this,
|
||||||
|
"bindServiceAsUser",
|
||||||
|
intent,
|
||||||
|
this@ServiceBridgeClient,
|
||||||
|
Context.BIND_AUTO_CREATE,
|
||||||
|
Handler(handlerThread.looper),
|
||||||
|
android.os.Process.myUserHandle()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
callback(future.get())
|
callback(future.get())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user