1
1
package li.songe.gkd.service
2
2
3
- import android.content.BroadcastReceiver
4
3
import android.content.ComponentName
5
- import android.content.Context
6
- import android.content.Intent
7
- import android.content.IntentFilter
8
4
import android.graphics.Bitmap
9
5
import android.graphics.PixelFormat
10
6
import android.os.Build
@@ -16,7 +12,6 @@ import android.view.WindowManager
16
12
import android.view.accessibility.AccessibilityEvent
17
13
import android.view.accessibility.AccessibilityNodeInfo
18
14
import com.blankj.utilcode.util.LogUtils
19
- import com.blankj.utilcode.util.ScreenUtils
20
15
import kotlinx.coroutines.Dispatchers
21
16
import kotlinx.coroutines.Job
22
17
import kotlinx.coroutines.asCoroutineDispatcher
@@ -46,7 +41,6 @@ import li.songe.gkd.shizuku.useSafeGetTasksFc
46
41
import li.songe.gkd.shizuku.useSafeInputTapFc
47
42
import li.songe.gkd.shizuku.useShizukuAliveState
48
43
import li.songe.gkd.util.UpdateTimeOption
49
- import li.songe.gkd.util.VOLUME_CHANGED_ACTION
50
44
import li.songe.gkd.util.checkSubsUpdate
51
45
import li.songe.gkd.util.launchTry
52
46
import li.songe.gkd.util.map
@@ -182,7 +176,7 @@ class GkdAbService : CompositionAbService({
182
176
latestEvent?.let { n ->
183
177
val refreshOk = try {
184
178
n.refresh()
185
- } catch (e : Exception ) {
179
+ } catch (_ : Exception ) {
186
180
false
187
181
}
188
182
if (!refreshOk) {
@@ -433,52 +427,6 @@ class GkdAbService : CompositionAbService({
433
427
}
434
428
}
435
429
436
-
437
- fun createVolumeReceiver(): BroadcastReceiver {
438
- return object : BroadcastReceiver () {
439
- var lastTriggerTime = -1L
440
- override fun onReceive(context: Context ? , intent: Intent ? ) {
441
- if (intent?.action == VOLUME_CHANGED_ACTION ) {
442
- val t = System .currentTimeMillis()
443
- if (t - lastTriggerTime > 3000 && !ScreenUtils .isScreenLock()) {
444
- lastTriggerTime = t
445
- scope.launchTry(Dispatchers .IO ) {
446
- SnapshotExt .captureSnapshot()
447
- toast("快照成功")
448
- }
449
- }
450
- }
451
- }
452
- }
453
- }
454
-
455
- var captureVolumeReceiver : BroadcastReceiver ? = null
456
- scope.launch {
457
- storeFlow.map(scope) { s -> s.captureVolumeChange }.collect {
458
- if (captureVolumeReceiver != null) {
459
- context.unregisterReceiver(captureVolumeReceiver)
460
- }
461
- captureVolumeReceiver = if (it) {
462
- createVolumeReceiver().apply {
463
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
464
- context.registerReceiver(
465
- this, IntentFilter (VOLUME_CHANGED_ACTION ), Context .RECEIVER_EXPORTED
466
- )
467
- } else {
468
- context.registerReceiver(this, IntentFilter (VOLUME_CHANGED_ACTION ))
469
- }
470
- }
471
- } else {
472
- null
473
- }
474
- }
475
- }
476
- onDestroy {
477
- if (captureVolumeReceiver != null) {
478
- context.unregisterReceiver(captureVolumeReceiver)
479
- }
480
- }
481
-
482
430
onAccessibilityEvent { e ->
483
431
if (!storeFlow.value.captureScreenshot) return @onAccessibilityEvent
484
432
val appId = e.packageName ? : return @onAccessibilityEvent
0 commit comments