mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 03:32:38 +08:00
perf: KClass componentName
This commit is contained in:
parent
9b51845240
commit
90c6559e0f
|
@ -24,6 +24,7 @@ import li.songe.gkd.notif.initChannel
|
||||||
import li.songe.gkd.permission.shizukuOkState
|
import li.songe.gkd.permission.shizukuOkState
|
||||||
import li.songe.gkd.service.A11yService
|
import li.songe.gkd.service.A11yService
|
||||||
import li.songe.gkd.util.SafeR
|
import li.songe.gkd.util.SafeR
|
||||||
|
import li.songe.gkd.util.componentName
|
||||||
import li.songe.gkd.util.initAppState
|
import li.songe.gkd.util.initAppState
|
||||||
import li.songe.gkd.util.initFolder
|
import li.songe.gkd.util.initFolder
|
||||||
import li.songe.gkd.util.initStore
|
import li.songe.gkd.util.initStore
|
||||||
|
@ -56,7 +57,7 @@ data object META {
|
||||||
val debuggable by lazy { applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0 }
|
val debuggable by lazy { applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0 }
|
||||||
val versionCode by lazy { selfAppInfo.versionCode.toInt() }
|
val versionCode by lazy { selfAppInfo.versionCode.toInt() }
|
||||||
val versionName by lazy { selfAppInfo.versionName!! }
|
val versionName by lazy { selfAppInfo.versionName!! }
|
||||||
val appId by lazy { selfAppInfo.id }
|
val appId by lazy { app.packageName!! }
|
||||||
val appName by lazy { app.getString(SafeR.app_name) }
|
val appName by lazy { app.getString(SafeR.app_name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +164,7 @@ private fun getA11yServiceEnabled(): Boolean {
|
||||||
if (value.isNullOrEmpty()) return false
|
if (value.isNullOrEmpty()) return false
|
||||||
val colonSplitter = TextUtils.SimpleStringSplitter(':')
|
val colonSplitter = TextUtils.SimpleStringSplitter(':')
|
||||||
colonSplitter.setString(value)
|
colonSplitter.setString(value)
|
||||||
val name = ComponentName(app, A11yService::class.java)
|
val name = A11yService::class.componentName
|
||||||
while (colonSplitter.hasNext()) {
|
while (colonSplitter.hasNext()) {
|
||||||
if (ComponentName.unflattenFromString(colonSplitter.next()) == name) {
|
if (ComponentName.unflattenFromString(colonSplitter.next()) == name) {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -2,7 +2,6 @@ package li.songe.gkd
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.ActivityManager
|
import android.app.ActivityManager
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
@ -48,6 +47,7 @@ import li.songe.gkd.ui.theme.AppTheme
|
||||||
import li.songe.gkd.util.LocalNavController
|
import li.songe.gkd.util.LocalNavController
|
||||||
import li.songe.gkd.util.UpgradeDialog
|
import li.songe.gkd.util.UpgradeDialog
|
||||||
import li.songe.gkd.util.appInfoCacheFlow
|
import li.songe.gkd.util.appInfoCacheFlow
|
||||||
|
import li.songe.gkd.util.componentName
|
||||||
import li.songe.gkd.util.initFolder
|
import li.songe.gkd.util.initFolder
|
||||||
import li.songe.gkd.util.launchTry
|
import li.songe.gkd.util.launchTry
|
||||||
import li.songe.gkd.util.map
|
import li.songe.gkd.util.map
|
||||||
|
@ -136,7 +136,7 @@ fun isActivityVisible() = activityVisibleFlow.value > 0
|
||||||
fun Activity.navToMainActivity() {
|
fun Activity.navToMainActivity() {
|
||||||
val intent = this.intent?.cloneFilter()
|
val intent = this.intent?.cloneFilter()
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
intent.component = ComponentName(this, MainActivity::class.java)
|
intent.component = MainActivity::class.componentName
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
intent.putExtra("source", this::class.qualifiedName)
|
intent.putExtra("source", this::class.qualifiedName)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package li.songe.gkd.debug
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.blankj.utilcode.util.LogUtils
|
import com.blankj.utilcode.util.LogUtils
|
||||||
|
@ -11,6 +10,7 @@ import li.songe.gkd.app
|
||||||
import li.songe.gkd.notif.notifyService
|
import li.songe.gkd.notif.notifyService
|
||||||
import li.songe.gkd.notif.screenshotNotif
|
import li.songe.gkd.notif.screenshotNotif
|
||||||
import li.songe.gkd.util.ScreenshotUtil
|
import li.songe.gkd.util.ScreenshotUtil
|
||||||
|
import li.songe.gkd.util.componentName
|
||||||
|
|
||||||
class ScreenshotService : Service() {
|
class ScreenshotService : Service() {
|
||||||
override fun onBind(intent: Intent?) = null
|
override fun onBind(intent: Intent?) = null
|
||||||
|
@ -47,7 +47,7 @@ class ScreenshotService : Service() {
|
||||||
private var screenshotUtil: ScreenshotUtil? = null
|
private var screenshotUtil: ScreenshotUtil? = null
|
||||||
|
|
||||||
fun start(context: Context = app, intent: Intent) {
|
fun start(context: Context = app, intent: Intent) {
|
||||||
intent.component = ComponentName(context, ScreenshotService::class.java)
|
intent.component = ScreenshotService::class.componentName
|
||||||
context.startForegroundService(intent)
|
context.startForegroundService(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package li.songe.gkd.service
|
package li.songe.gkd.service
|
||||||
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
|
@ -9,6 +8,7 @@ import android.service.quicksettings.TileService
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import li.songe.gkd.app
|
import li.songe.gkd.app
|
||||||
import li.songe.gkd.permission.writeSecureSettingsState
|
import li.songe.gkd.permission.writeSecureSettingsState
|
||||||
|
import li.songe.gkd.util.componentName
|
||||||
import li.songe.gkd.util.lastRestartA11yServiceTimeFlow
|
import li.songe.gkd.util.lastRestartA11yServiceTimeFlow
|
||||||
import li.songe.gkd.util.storeFlow
|
import li.songe.gkd.util.storeFlow
|
||||||
import li.songe.gkd.util.toast
|
import li.songe.gkd.util.toast
|
||||||
|
@ -135,6 +135,4 @@ fun fixRestartService(): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private val a11yClsName by lazy {
|
val a11yClsName by lazy { A11yService::class.componentName.flattenToShortString() }
|
||||||
ComponentName(app, A11yService::class.java).flattenToShortString()
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,11 +18,11 @@ import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import li.songe.gkd.META
|
import li.songe.gkd.META
|
||||||
import li.songe.gkd.app
|
|
||||||
import li.songe.gkd.appScope
|
import li.songe.gkd.appScope
|
||||||
import li.songe.gkd.data.DeviceInfo
|
import li.songe.gkd.data.DeviceInfo
|
||||||
import li.songe.gkd.permission.shizukuOkState
|
import li.songe.gkd.permission.shizukuOkState
|
||||||
import li.songe.gkd.service.TopActivity
|
import li.songe.gkd.service.TopActivity
|
||||||
|
import li.songe.gkd.util.componentName
|
||||||
import li.songe.gkd.util.json
|
import li.songe.gkd.util.json
|
||||||
import li.songe.gkd.util.storeFlow
|
import li.songe.gkd.util.storeFlow
|
||||||
import li.songe.gkd.util.toast
|
import li.songe.gkd.util.toast
|
||||||
|
@ -168,14 +168,12 @@ data class UserServiceWrapper(
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun serviceWrapper(): UserServiceWrapper = suspendCoroutine { continuation ->
|
private suspend fun serviceWrapper(): UserServiceWrapper = suspendCoroutine { continuation ->
|
||||||
val serviceArgs = Shizuku.UserServiceArgs(
|
val serviceArgs = Shizuku
|
||||||
ComponentName(
|
.UserServiceArgs(UserService::class.componentName)
|
||||||
app,
|
.daemon(false)
|
||||||
UserService::class.java
|
.processNameSuffix("shizuku-user-service")
|
||||||
)
|
.debuggable(META.debuggable)
|
||||||
).daemon(false).processNameSuffix(
|
.version(META.versionCode)
|
||||||
"service-for-${if (META.debuggable) "gkd-debug" else "gkd-release"}"
|
|
||||||
).debuggable(META.debuggable).version(META.versionCode)
|
|
||||||
|
|
||||||
var resumeFc: ((UserServiceWrapper) -> Unit)? = { continuation.resume(it) }
|
var resumeFc: ((UserServiceWrapper) -> Unit)? = { continuation.resume(it) }
|
||||||
|
|
||||||
|
|
|
@ -393,7 +393,7 @@ fun AdvancedPage() {
|
||||||
|
|
||||||
TextSwitch(
|
TextSwitch(
|
||||||
title = "清除订阅",
|
title = "清除订阅",
|
||||||
subtitle = "当HTTP服务关闭时,删除内存订阅",
|
subtitle = "服务关闭时,删除内存订阅",
|
||||||
checked = store.autoClearMemorySubs
|
checked = store.autoClearMemorySubs
|
||||||
) {
|
) {
|
||||||
storeFlow.value = store.copy(
|
storeFlow.value = store.copy(
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
package li.songe.gkd.util
|
package li.songe.gkd.util
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import li.songe.gkd.META
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.jvm.jvmName
|
||||||
|
|
||||||
inline fun <T, R> Iterable<T>.mapHashCode(transform: (T) -> R): Int {
|
inline fun <T, R> Iterable<T>.mapHashCode(transform: (T) -> R): Int {
|
||||||
return fold(0) { acc, t -> 31 * acc + transform(t).hashCode() }
|
return fold(0) { acc, t -> 31 * acc + transform(t).hashCode() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val componentNameCache by lazy { HashMap<String, ComponentName>() }
|
||||||
|
|
||||||
|
val KClass<*>.componentName
|
||||||
|
get() = componentNameCache.getOrPut(jvmName) { ComponentName(META.appId, jvmName) }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user