mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
add TaskReceiver
This commit is contained in:
@@ -90,6 +90,13 @@
|
||||
android:description="@string/app_name"
|
||||
android:permission="android.permission.BIND_DEVICE_ADMIN">
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name=".TaskReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<provider
|
||||
android:name="rikka.shizuku.ShizukuProvider"
|
||||
android:authorities="${applicationId}.shizuku"
|
||||
|
||||
@@ -8,9 +8,11 @@ import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme.typography
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -43,6 +45,7 @@ fun AppSetting(navCtrl:NavHostController, materialYou: MutableState<Boolean>, bl
|
||||
composable(route = "Home") { Home(localNavCtrl) }
|
||||
composable(route = "Theme") { ThemeSettings(materialYou, blackTheme) }
|
||||
composable(route = "Auth") { AuthSettings() }
|
||||
composable(route = "Automation") { Automation() }
|
||||
composable(route = "About") { About() }
|
||||
}
|
||||
}
|
||||
@@ -53,6 +56,7 @@ private fun Home(navCtrl: NavHostController) {
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
SubPageItem(R.string.theme, "", R.drawable.format_paint_fill0) { navCtrl.navigate("Theme") }
|
||||
SubPageItem(R.string.security, "", R.drawable.lock_fill0) { navCtrl.navigate("Auth") }
|
||||
SubPageItem(R.string.automation, "", R.drawable.apps_fill0) { navCtrl.navigate("Automation") }
|
||||
SubPageItem(R.string.about, "", R.drawable.info_fill0) { navCtrl.navigate("About") }
|
||||
}
|
||||
}
|
||||
@@ -122,6 +126,21 @@ private fun AuthSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Automation() {
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {
|
||||
var pkgName by remember { mutableStateOf("") }
|
||||
LaunchedEffect(Unit) {
|
||||
pkgName = sharedPref.getString("AutomationApp", "")?: ""
|
||||
}
|
||||
TextField(value = pkgName, onValueChange = { pkgName = it }, label = { Text("Package name")})
|
||||
Button(onClick = {sharedPref.edit().putString("AutomationApp", pkgName).apply()}) {
|
||||
Text("apply")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun About() {
|
||||
val context = LocalContext.current
|
||||
|
||||
38
app/src/main/java/com/bintianqi/owndroid/TaskReceiver.kt
Normal file
38
app/src/main/java/com/bintianqi/owndroid/TaskReceiver.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.bintianqi.owndroid
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build.VERSION
|
||||
import android.util.Log
|
||||
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")
|
||||
}
|
||||
} else {
|
||||
Log.d("OwnDroid", "unknown action")
|
||||
}
|
||||
} else {
|
||||
Log.d("OwnDroid", "unknown category")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -535,6 +535,7 @@
|
||||
<string name="you_cant_clear_storage">你不能清除OwnDroid的存储空间</string>
|
||||
<string name="clear_storage">清除存储空间</string>
|
||||
<string name="clear_storage_success">清除存储空间成功\n应用即将退出</string>
|
||||
<string name="automation">自动化</string>
|
||||
|
||||
<!--AndroidPermission-->
|
||||
<string name="permission_READ_EXTERNAL_STORAGE">读取外部存储</string>
|
||||
|
||||
@@ -551,6 +551,7 @@
|
||||
<string name="you_cant_clear_storage">You can\'t clear storage of OwnDroid</string>
|
||||
<string name="clear_storage">Clear storage</string>
|
||||
<string name="clear_storage_success">Clear storage success\nApplication will exit</string>
|
||||
<string name="automation">Automation</string>
|
||||
|
||||
<!--AndroidPermission-->
|
||||
<string name="permission_READ_EXTERNAL_STORAGE">Read external storage</string>
|
||||
|
||||
Reference in New Issue
Block a user