update Automation API

This commit is contained in:
BinTianqi
2024-07-16 21:15:12 +08:00
parent 172f7d081e
commit 97cd7447e4
7 changed files with 22 additions and 15 deletions

View File

@@ -55,8 +55,9 @@
android:name=".AutomationActivity" android:name=".AutomationActivity"
android:exported="true" android:exported="true"
android:launchMode="singleInstance" android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:windowSoftInputMode="adjustResize|stateHidden" android:windowSoftInputMode="adjustResize|stateHidden"
android:theme="@style/Theme.OwnDroid"> android:theme="@style/Theme.Transparent">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
</intent-filter> </intent-filter>
@@ -67,7 +68,7 @@
android:windowSoftInputMode="adjustResize|stateHidden" android:windowSoftInputMode="adjustResize|stateHidden"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:launchMode="singleInstance" android:launchMode="singleInstance"
android:theme="@style/Theme.OwnDroidAppInstaller"> android:theme="@style/Theme.Transparent">
<intent-filter> <intent-filter>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.VIEW"/>

View File

@@ -1,11 +1,11 @@
package com.bintianqi.owndroid package com.bintianqi.owndroid
import android.app.AlertDialog
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.ui.platform.LocalContext
import androidx.compose.material3.Text
class AutomationActivity: ComponentActivity() { class AutomationActivity: ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@@ -14,9 +14,11 @@ class AutomationActivity: ComponentActivity() {
val sharedPrefs = applicationContext.getSharedPreferences("data", Context.MODE_PRIVATE) val sharedPrefs = applicationContext.getSharedPreferences("data", Context.MODE_PRIVATE)
if(sharedPrefs.getBoolean("automation_debug", false)) { if(sharedPrefs.getBoolean("automation_debug", false)) {
setContent { setContent {
SelectionContainer { AlertDialog.Builder(LocalContext.current)
Text(result) .setMessage(result)
} .setOnDismissListener { finish() }
.setPositiveButton(R.string.confirm) { _, _ -> finish() }
.show()
} }
} else { } else {
finish() finish()

View File

@@ -1,11 +1,11 @@
package com.bintianqi.owndroid package com.bintianqi.owndroid
import android.annotation.SuppressLint
import android.app.admin.DevicePolicyManager import android.app.admin.DevicePolicyManager
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
class AutomationReceiver: BroadcastReceiver() { class AutomationReceiver: BroadcastReceiver() {
@@ -14,6 +14,7 @@ class AutomationReceiver: BroadcastReceiver() {
} }
} }
@SuppressLint("NewApi")
fun handleTask(context: Context, intent: Intent): String { fun handleTask(context: Context, intent: Intent): String {
val sharedPrefs = context.getSharedPreferences("data", Context.MODE_PRIVATE) val sharedPrefs = context.getSharedPreferences("data", Context.MODE_PRIVATE)
val key = sharedPrefs.getString("automation_key", "") ?: "" val key = sharedPrefs.getString("automation_key", "") ?: ""
@@ -27,6 +28,7 @@ fun handleTask(context: Context, intent: Intent): String {
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java) val receiver = ComponentName(context,Receiver::class.java)
val app = intent.getStringExtra("app") val app = intent.getStringExtra("app")
val restriction = intent.getStringExtra("restriction")
try { try {
when(operation) { when(operation) {
"suspend" -> dpm.setPackagesSuspended(receiver, arrayOf(app), true) "suspend" -> dpm.setPackagesSuspended(receiver, arrayOf(app), true)
@@ -35,6 +37,8 @@ fun handleTask(context: Context, intent: Intent): String {
"unhide" -> dpm.setApplicationHidden(receiver, app, false) "unhide" -> dpm.setApplicationHidden(receiver, app, false)
"lock" -> dpm.lockNow() "lock" -> dpm.lockNow()
"reboot" -> dpm.reboot(receiver) "reboot" -> dpm.reboot(receiver)
"addUserRestriction" -> dpm.addUserRestriction(receiver, restriction)
"clearUserRestriction" -> dpm.clearUserRestriction(receiver, restriction)
else -> return "Operation not defined" else -> return "Operation not defined"
} }
} catch(e: Exception) { } catch(e: Exception) {

View File

@@ -57,7 +57,7 @@ private fun Home(navCtrl: NavHostController) {
Column(modifier = Modifier.fillMaxSize()) { Column(modifier = Modifier.fillMaxSize()) {
SubPageItem(R.string.theme, "", R.drawable.format_paint_fill0) { navCtrl.navigate("Theme") } 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.security, "", R.drawable.lock_fill0) { navCtrl.navigate("Auth") }
SubPageItem(R.string.automation, "", R.drawable.apps_fill0) { navCtrl.navigate("Automation") } SubPageItem(R.string.automation_api, "", R.drawable.apps_fill0) { navCtrl.navigate("Automation") }
SubPageItem(R.string.about, "", R.drawable.info_fill0) { navCtrl.navigate("About") } SubPageItem(R.string.about, "", R.drawable.info_fill0) { navCtrl.navigate("About") }
} }
} }
@@ -132,10 +132,10 @@ private fun Automation() {
val context = LocalContext.current val context = LocalContext.current
val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE) val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE)
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) { Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.automation_api), style = typography.headlineLarge)
Spacer(Modifier.padding(vertical = 5.dp))
var key by remember { mutableStateOf("") } var key by remember { mutableStateOf("") }
LaunchedEffect(Unit) {
key = sharedPref.getString("automation_key", "")?: ""
}
TextField( TextField(
value = key, onValueChange = { key = it }, label = { Text("Key")}, value = key, onValueChange = { key = it }, label = { Text("Key")},
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()

View File

@@ -536,7 +536,7 @@
<string name="clear_storage">清除存储空间</string> <string name="clear_storage">清除存储空间</string>
<string name="clear_storage_success">清除存储空间成功\n应用即将退出</string> <string name="clear_storage_success">清除存储空间成功\n应用即将退出</string>
<string name="automation">自动化</string> <string name="automation_api">自动化API</string>
<string name="automation_debug">调试模式</string> <string name="automation_debug">调试模式</string>
<!--AndroidPermission--> <!--AndroidPermission-->

View File

@@ -552,7 +552,7 @@
<string name="clear_storage">Clear storage</string> <string name="clear_storage">Clear storage</string>
<string name="clear_storage_success">Clear storage success\nApplication will exit</string> <string name="clear_storage_success">Clear storage success\nApplication will exit</string>
<string name="automation">Automation</string> <string name="automation_api">Automation API</string>
<string name="automation_debug">Debug mode</string> <string name="automation_debug">Debug mode</string>
<!--AndroidPermission--> <!--AndroidPermission-->

View File

@@ -4,7 +4,7 @@
<item name="android:navigationBarColor">#FFFFFF</item> <item name="android:navigationBarColor">#FFFFFF</item>
<item name="android:statusBarColor">#FFFFFF</item> <item name="android:statusBarColor">#FFFFFF</item>
</style> </style>
<style name="Theme.OwnDroidAppInstaller" parent="android:Theme.Material.Light.NoActionBar"> <style name="Theme.Transparent" parent="Theme.OwnDroid">
<item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item> <item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item> <item name="android:windowIsTranslucent">true</item>