mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
update Automation API
This commit is contained in:
@@ -55,8 +55,9 @@
|
||||
android:name=".AutomationActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:excludeFromRecents="true"
|
||||
android:windowSoftInputMode="adjustResize|stateHidden"
|
||||
android:theme="@style/Theme.OwnDroid">
|
||||
android:theme="@style/Theme.Transparent">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
@@ -67,7 +68,7 @@
|
||||
android:windowSoftInputMode="adjustResize|stateHidden"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:theme="@style/Theme.OwnDroidAppInstaller">
|
||||
android:theme="@style/Theme.Transparent">
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.bintianqi.owndroid
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
class AutomationActivity: ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -14,9 +14,11 @@ class AutomationActivity: ComponentActivity() {
|
||||
val sharedPrefs = applicationContext.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
if(sharedPrefs.getBoolean("automation_debug", false)) {
|
||||
setContent {
|
||||
SelectionContainer {
|
||||
Text(result)
|
||||
}
|
||||
AlertDialog.Builder(LocalContext.current)
|
||||
.setMessage(result)
|
||||
.setOnDismissListener { finish() }
|
||||
.setPositiveButton(R.string.confirm) { _, _ -> finish() }
|
||||
.show()
|
||||
}
|
||||
} else {
|
||||
finish()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.bintianqi.owndroid
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
|
||||
class AutomationReceiver: BroadcastReceiver() {
|
||||
@@ -14,6 +14,7 @@ class AutomationReceiver: BroadcastReceiver() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun handleTask(context: Context, intent: Intent): String {
|
||||
val sharedPrefs = context.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
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 receiver = ComponentName(context,Receiver::class.java)
|
||||
val app = intent.getStringExtra("app")
|
||||
val restriction = intent.getStringExtra("restriction")
|
||||
try {
|
||||
when(operation) {
|
||||
"suspend" -> dpm.setPackagesSuspended(receiver, arrayOf(app), true)
|
||||
@@ -35,6 +37,8 @@ fun handleTask(context: Context, intent: Intent): String {
|
||||
"unhide" -> dpm.setApplicationHidden(receiver, app, false)
|
||||
"lock" -> dpm.lockNow()
|
||||
"reboot" -> dpm.reboot(receiver)
|
||||
"addUserRestriction" -> dpm.addUserRestriction(receiver, restriction)
|
||||
"clearUserRestriction" -> dpm.clearUserRestriction(receiver, restriction)
|
||||
else -> return "Operation not defined"
|
||||
}
|
||||
} catch(e: Exception) {
|
||||
|
||||
@@ -57,7 +57,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.automation_api, "", R.drawable.apps_fill0) { navCtrl.navigate("Automation") }
|
||||
SubPageItem(R.string.about, "", R.drawable.info_fill0) { navCtrl.navigate("About") }
|
||||
}
|
||||
}
|
||||
@@ -132,10 +132,10 @@ private fun Automation() {
|
||||
val context = LocalContext.current
|
||||
val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
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("") }
|
||||
LaunchedEffect(Unit) {
|
||||
key = sharedPref.getString("automation_key", "")?: ""
|
||||
}
|
||||
TextField(
|
||||
value = key, onValueChange = { key = it }, label = { Text("Key")},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
|
||||
@@ -536,7 +536,7 @@
|
||||
<string name="clear_storage">清除存储空间</string>
|
||||
<string name="clear_storage_success">清除存储空间成功\n应用即将退出</string>
|
||||
|
||||
<string name="automation">自动化</string>
|
||||
<string name="automation_api">自动化API</string>
|
||||
<string name="automation_debug">调试模式</string>
|
||||
|
||||
<!--AndroidPermission-->
|
||||
|
||||
@@ -552,7 +552,7 @@
|
||||
<string name="clear_storage">Clear storage</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>
|
||||
|
||||
<!--AndroidPermission-->
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<item name="android:navigationBarColor">#FFFFFF</item>
|
||||
<item name="android:statusBarColor">#FFFFFF</item>
|
||||
</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:colorBackgroundCacheHint">@null</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
|
||||
Reference in New Issue
Block a user