automation: unsuspend app

This commit is contained in:
BinTianqi
2024-06-29 10:59:36 +08:00
parent 0b39bdc788
commit 015c571546
2 changed files with 10 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ on:
push:
paths-ignore:
- '**.md'
branches: [ "master" ]
jobs:
build:

View File

@@ -11,28 +11,16 @@ import androidx.activity.ComponentActivity
class TaskReceiver: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.d("OwnDroid", ("TaskReceiver: pkgName: " + intent.component?.packageName))
Log.d("OwnDroid", ("TaskReceiver: pkg: " + intent.`package`))
val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE)
if(sharedPref.getString("AutomationApp", "") != intent.component?.packageName) return
val category = intent.getStringExtra("category")
if(category == "app") {
val action = intent.getStringExtra("action")
if(action == "suspend") {
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val app = intent.getStringExtra("app")
val mode = intent.getBooleanExtra("mode", false)
if(VERSION.SDK_INT >= 24) {
dpm.setPackagesSuspended(receiver, arrayOf(app), mode)
} else {
Log.d("OwnDroid", "unsupported")
}
if(action == "suspend") {
dpm.setPackagesSuspended(receiver, arrayOf(app), true)
} else if(action == "unsuspend") {
dpm.setPackagesSuspended(receiver, arrayOf(app), false)
} else {
Log.d("OwnDroid", "unknown action")
}
} else {
Log.d("OwnDroid", "unknown category")
}
}
}