Skip to content

Commit

Permalink
Merge pull request #254 from GuoXiCheng/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GuoXiCheng authored Sep 25, 2024
2 parents cad615d + dfcd409 commit 85bff99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import javax.inject.Inject

Expand Down Expand Up @@ -91,15 +92,17 @@ class MyAccessibilityService : AccessibilityService() {
appPackageName = rootNodePackageName
}

if (!whiteListRepository.isAppInWhiteList(rootNodePackageName) && scanTimes < 30) {
if (!whiteListRepository.isAppInWhiteList(rootNodePackageName) && scanTimes < 50) {
val that = this
serviceScope.launch {
val targetRect =
configLoadRepository.getTargetRect(rootNode, appActivityName, isStrict)
targetRect?.let { rect ->
val rectStr = rect.toString()
if (!clickedRect.contains(rectStr)) {
click(that, rect)
withContext(Dispatchers.Main) {
click(that, rect)
}
clickedRect.add(rectStr)
LogUtils.d("clicked: packageName is $rootNodePackageName rect is $rectStr")
}
Expand All @@ -120,7 +123,7 @@ class MyAccessibilityService : AccessibilityService() {

scanTimes++
} catch (e: Exception) {
// LogUtils.e(e)
LogUtils.e(e)
}
}

Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/android/skip/service/MyForegroundService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.skip.service

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
Expand All @@ -12,6 +13,8 @@ import com.android.skip.R
import com.android.skip.ui.main.MainActivity

class MyForegroundService : Service() {
private lateinit var notification: Notification

override fun onBind(p0: Intent?): IBinder? {
TODO("Not yet implemented")
}
Expand All @@ -28,8 +31,8 @@ class MyForegroundService : Service() {
manager.createNotificationChannel(channel)

val intent = Intent(this, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0 , intent, PendingIntent.FLAG_IMMUTABLE)
val notification = NotificationCompat.Builder(this, "SKIP_FOREGROUND_SERVICE")
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
notification = NotificationCompat.Builder(this, "SKIP_FOREGROUND_SERVICE")
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.notification_accessibility_service_running))
.setSmallIcon(R.drawable.favicon32)
Expand All @@ -40,4 +43,10 @@ class MyForegroundService : Service() {

startForeground(2, notification)
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
startForeground(2, notification)
return START_STICKY
}
}

0 comments on commit 85bff99

Please sign in to comment.