Skip to content

Commit

Permalink
Merge pull request #45 from GuoXiCheng/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GuoXiCheng authored Oct 5, 2023
2 parents 0009f88 + ef3431a commit 586d22a
Show file tree
Hide file tree
Showing 23 changed files with 448 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.ap_
*.aab
*.json

!/app/src/main/res/raw/*.json
# Files for the ART/Dalvik VM
*.dex

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![GitHub](https://img.shields.io/github/license/GuoXiCheng/SKIP) ![GitHub all releases](https://img.shields.io/github/downloads/GuoXiCheng/SKIP/total) ![GitHub Repo stars](https://img.shields.io/github/stars/GuoXiCheng/SKIP)

## SKIP 介绍

SKIP 是一款免费开源的安卓应用,旨在利用 Android 无障碍服务帮助用户快速点击 APP 开屏广告的跳过按钮,让你的使用体验更加流畅。
Expand Down
Binary file added apk/SKIP-v1.3.1.apk
Binary file not shown.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdk 24
targetSdk 32
versionCode 1
versionName "1.3"
versionName "1.3.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -50,7 +50,7 @@ android {
}

dependencies {

implementation 'com.google.code.gson:gson:2.8.9'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.4.0'
Expand All @@ -66,4 +66,5 @@ dependencies {
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"

}
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.android.skip">
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<application
android:allowBackup="true"
Expand All @@ -26,6 +27,13 @@
</intent-filter>
</activity>

<activity
android:name=".WhitelistActivity"
android:exported="false"
android:theme="@style/Theme.AppCompat.DayNight">

</activity>

<service
android:name="com.android.skip.service.MyAccessibilityService"
android:exported="true"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/android/skip/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.android.skip.manager.RectManager
import com.android.skip.manager.SkipConfigManager
import com.android.skip.ui.theme.OneClickTheme
import com.android.skip.ui.theme.green
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand Down Expand Up @@ -164,6 +167,10 @@ class MainActivity : ComponentActivity() {
}

}

RectManager.setMaxRect(this)
val skipConfig = resources.openRawResource(R.raw.skip_config_v1).bufferedReader().use{it.readText()}
SkipConfigManager.setConfig(skipConfig)
}

override fun onResume() {
Expand All @@ -174,6 +181,7 @@ class MainActivity : ComponentActivity() {


@Composable
@Preview(showBackground = true)
fun MainSurface() {
OneClickTheme {

Expand Down
50 changes: 48 additions & 2 deletions app/src/main/java/com/android/skip/MyUtils.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.android.skip

import android.accessibilityservice.AccessibilityService
import android.accessibilityservice.GestureDescription
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.Path
import android.graphics.Rect
import android.provider.Settings
import android.text.TextUtils
import android.widget.Toast
import com.android.skip.manager.AnalyticsManager
import com.android.skip.service.MyAccessibilityService

object MyUtils {
Expand Down Expand Up @@ -40,4 +46,44 @@ object MyUtils {
return false
}

fun isExcludeApplication (appName: String, packageName: String, packageManager: PackageManager): Boolean {
if (appName == packageName) return true
return try {
// 获取应用程序的 ApplicationInfo
val applicationInfo = packageManager.getApplicationInfo(packageName, 0)

// 判断应用是否来自系统预装或者是用户手动安装的
(applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
} catch (e: PackageManager.NameNotFoundException) {
// 应用未找到,可能是无效的包名
true
}
}

fun click(accessibilityService: AccessibilityService, rect: Rect) {
val path = Path()
path.reset()
path.moveTo(rect.exactCenterX(), rect.exactCenterY())
path.lineTo(rect.exactCenterX(), rect.exactCenterY())

val builder = GestureDescription.Builder()
builder.addStroke(GestureDescription.StrokeDescription(path, 0, 1))
val gesture = builder.build()

accessibilityService.dispatchGesture(
gesture,
object : AccessibilityService.GestureResultCallback() {
override fun onCompleted(gestureDescription: GestureDescription) {
super.onCompleted(gestureDescription)

if (AnalyticsManager.isShowToast()) {
Toast.makeText(accessibilityService, "已为您跳过广告", Toast.LENGTH_SHORT).show()
AnalyticsManager.setShowToastCount()
}

}
},
null
)
}
}
87 changes: 87 additions & 0 deletions app/src/main/java/com/android/skip/WhitelistActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.android.skip

import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.graphics.drawable.toBitmap

val mutableList = mutableListOf<AppData>()

class WhitelistActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mutableList.clear()

val packages = packageManager.getInstalledPackages(PackageManager.GET_META_DATA)
packages.forEach {
val appName = it.applicationInfo.loadLabel(packageManager).toString()
val packageName = it.packageName

if (!MyUtils.isExcludeApplication(appName, packageName, packageManager)) {
mutableList.add(AppData(it.applicationInfo.loadIcon(packageManager), appName, false))
}


}

setContent {
Whitelist(mutableList)
}

}
}
data class AppData(
val icon: Drawable,
val name: String,
var enabled: Boolean
)
@Composable
fun Whitelist (appList: List<AppData>) {
Surface(
modifier = Modifier.fillMaxSize()
) {
LazyColumn {

items(appList.size) { index ->
val item = appList[index]
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(30.dp, 10.dp)) {

Image(
bitmap = item.icon.toBitmap().asImageBitmap(),
contentDescription = "${item.name} Icon", // 添加图标的描述,通常用于辅助功能
modifier = Modifier.size(48.dp) // 可选:设置图标的大小
)

Text(item.name, modifier = Modifier.weight(1f).padding(10.dp, 0.dp), fontSize = 20.sp, fontWeight = FontWeight.Bold)

Switch(checked = item.enabled, onCheckedChange = {
item.enabled = it
})

}
}
}
}
}




7 changes: 7 additions & 0 deletions app/src/main/java/com/android/skip/dataclass/PackageInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.android.skip.dataclass

data class PackageInfo(
val package_name: String, val skip_text: String?,
val skip_id: String?, val start_page_node: Int?,
val skip_point: String?
)
20 changes: 20 additions & 0 deletions app/src/main/java/com/android/skip/handler/AbstractHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.android.skip.handler

import android.graphics.Rect
import android.view.accessibility.AccessibilityNodeInfo

abstract class AbstractHandler: NodeHandler {
private var nextHandler: NodeHandler? = null

override fun handle(node: AccessibilityNodeInfo): List<Rect> {
if (nextHandler != null) {
return nextHandler!!.handle(node)
}
return listOf()
}

override fun setNextHandler(handler: NodeHandler): NodeHandler {
nextHandler = handler
return handler
}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/android/skip/handler/IdNodeHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.android.skip.handler

import android.graphics.Rect
import android.view.accessibility.AccessibilityNodeInfo
import com.android.skip.manager.SkipConfigManager

class IdNodeHandler: AbstractHandler() {
override fun handle(node: AccessibilityNodeInfo): List<Rect> {
val listOfRect = node.findAccessibilityNodeInfosByViewId(
SkipConfigManager.getSkipId(node.packageName.toString())
).map {
val rect = Rect()
it.getBoundsInScreen(rect)
rect
}

return listOfRect.ifEmpty {
super.handle(node)
}
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/android/skip/handler/NodeHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.android.skip.handler

import android.graphics.Rect
import android.view.accessibility.AccessibilityNodeInfo

interface NodeHandler {
fun handle(node: AccessibilityNodeInfo): List<Rect>
fun setNextHandler (handler: NodeHandler): NodeHandler
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/android/skip/handler/PointHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.android.skip.handler

import android.graphics.Rect
import android.view.accessibility.AccessibilityNodeInfo
import com.android.skip.manager.SkipConfigManager

class PointHandler: AbstractHandler() {
override fun handle(node: AccessibilityNodeInfo): List<Rect> {
val skipPoint = SkipConfigManager.getSkipPoint(node.packageName.toString())
return if (skipPoint != null) {
listOf(skipPoint)
} else {
super.handle(node)
}
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/android/skip/handler/TextNodeHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.android.skip.handler

import android.graphics.Rect
import android.view.accessibility.AccessibilityNodeInfo
import com.android.skip.manager.SkipConfigManager

class TextNodeHandler : AbstractHandler() {
override fun handle(node: AccessibilityNodeInfo): List<Rect> {
val listOfRect = node.findAccessibilityNodeInfosByText(
SkipConfigManager.getSkipText(node.packageName.toString())
).map {
val rect = Rect()
it.getBoundsInScreen(rect)
rect
}
return listOfRect.ifEmpty {
super.handle(node)
}
}
}
Loading

0 comments on commit 586d22a

Please sign in to comment.