Skip to content

Commit

Permalink
v6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BinTianqi authored Oct 26, 2024
2 parents 03a4242 + 5e8ea06 commit 9620e95
Show file tree
Hide file tree
Showing 26 changed files with 851 additions and 774 deletions.
4 changes: 1 addition & 3 deletions Readme-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

### Description

Use Device admin and Device owner privilege to take full control of your device.

This app is renamed to "OwnDroid" from "Android Owner".
Use Device admin and Device owner privilege to take full control of your device.

### Docs

Expand Down
2 changes: 0 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

使用安卓的Device Admin和Device Owner特权,完全掌控你的设备。

这个APP已经改名为"OwnDroid",原名"Android Owner"

### 文档

全新的OwnDroid文档:[owndroid.pages.dev](https://owndroid.pages.dev/zh_CN)
Expand Down
4 changes: 1 addition & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.cc)
alias(libs.plugins.compose)
kotlin("plugin.serialization") version "2.0.0"
}

Expand Down Expand Up @@ -76,8 +76,6 @@ gradle.taskGraph.whenReady {

dependencies {
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.accompanist.drawablepainter)
implementation(libs.androidx.material3)
implementation(libs.androidx.navigation.compose)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<activity
android:name=".ManageSpaceActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:theme="@style/Theme.OwnDroid">
android:theme="@style/Theme.Transparent">
</activity>
<activity
android:name=".AutomationActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ 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", "") ?: ""
if(key.length < 6) {
return "Key length must longer than 6"
}
if(key != intent.getStringExtra("key")) {
val key = sharedPrefs.getString("automation_key", "")
if(key == null || key != intent.getStringExtra("key")) {
return "Wrong key"
}
val operation = intent.getStringExtra("operation")
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/bintianqi/owndroid/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ private fun HomePage(navCtrl:NavHostController) {
val dpm = context.getDPM()
val receiver = context.getReceiver()
val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE)
var activated by remember { mutableStateOf(false) }
var activateType by remember { mutableStateOf("") }
val deviceAdmin = context.isDeviceAdmin
val deviceOwner = context.isDeviceOwner
val profileOwner = context.isProfileOwner
val refreshStatus by dhizukuErrorStatus.collectAsState()
LaunchedEffect(refreshStatus) {
activated = context.isDeviceAdmin
activateType = if(sharedPref.getBoolean("dhizuku", false)) context.getString(R.string.dhizuku) + " - " else ""
activateType += context.getString(
if(deviceOwner) { R.string.device_owner }
Expand Down Expand Up @@ -217,14 +219,14 @@ private fun HomePage(navCtrl:NavHostController) {
) {
Spacer(modifier = Modifier.padding(start = 22.dp))
Icon(
painter = painterResource(if(deviceAdmin) R.drawable.check_circle_fill1 else R.drawable.block_fill0),
painter = painterResource(if(activated) R.drawable.check_circle_fill1 else R.drawable.block_fill0),
contentDescription = null,
tint = colorScheme.onPrimary
)
Spacer(modifier = Modifier.padding(start = 10.dp))
Column {
Text(
text = stringResource(if(deviceAdmin) R.string.activated else R.string.deactivated),
text = stringResource(if(activated) R.string.activated else R.string.deactivated),
style = typography.headlineSmall,
color = colorScheme.onPrimary,
modifier = Modifier.padding(bottom = 2.dp)
Expand Down
89 changes: 30 additions & 59 deletions app/src/main/java/com/bintianqi/owndroid/ManageSpaceActivity.kt
Original file line number Diff line number Diff line change
@@ -1,83 +1,54 @@
package com.bintianqi.owndroid

import android.content.Context
import android.os.Bundle
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.material3.TextButton
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import com.bintianqi.owndroid.ui.theme.OwnDroidTheme
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class ManageSpaceActivity: FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
val sharedPref = applicationContext.getSharedPreferences("data", Context.MODE_PRIVATE)
val sharedPref = applicationContext.getSharedPreferences("data", MODE_PRIVATE)
val materialYou = sharedPref.getBoolean("material_you", true)
val blackTheme = sharedPref.getBoolean("black_theme", false)
val protected = sharedPref.getBoolean("protect_storage", false)
setContent {
OwnDroidTheme(materialYou, blackTheme) {
ManageSpace()
}
}
}

@Composable
fun ManageSpace() {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background)
) {
val sharedPref = applicationContext.getSharedPreferences("data", Context.MODE_PRIVATE)
val protected = sharedPref.getBoolean("protect_storage", false)
if(protected){
Text(
text = stringResource(R.string.storage_is_protected),
color = MaterialTheme.colorScheme.onBackground,
style = MaterialTheme.typography.titleMedium
)
Text(
text = stringResource(R.string.you_cant_clear_storage),
color = MaterialTheme.colorScheme.onBackground
)
}
Button(
onClick = {
lifecycleScope.launch {
sharedPref.edit().clear().apply()
delay(2000)
finishAndRemoveTask()
AlertDialog(
title = {
Text(stringResource(R.string.clear_storage))
},
text = {
if(protected) Text(stringResource(R.string.storage_is_protected))
},
onDismissRequest = { finish() },
dismissButton = {
if(!protected) TextButton(onClick = { finish() }) {
Text(stringResource(R.string.cancel))
}
},
confirmButton = {
TextButton(
onClick = {
if(!protected) {
applicationContext.filesDir.deleteRecursively()
sharedPref.edit().clear().apply()
}
finish()
}
) {
Text(stringResource(if(protected) R.string.cancel else R.string.confirm))
}
}
Toast.makeText(applicationContext, R.string.clear_storage_success, Toast.LENGTH_SHORT).show()
},
enabled = !protected,
colors = ButtonDefaults.buttonColors(
contentColor = MaterialTheme.colorScheme.onError,
containerColor = MaterialTheme.colorScheme.error
),
modifier = Modifier.padding(top = 10.dp)
) {
Text(text = stringResource(R.string.clear_storage))
)
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/com/bintianqi/owndroid/Receiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import android.content.pm.PackageInstaller.STATUS_FAILURE_TIMEOUT
import android.content.pm.PackageInstaller.STATUS_PENDING_USER_ACTION
import android.content.pm.PackageInstaller.STATUS_SUCCESS
import android.os.Build.VERSION
import android.os.PersistableBundle
import android.util.Log
import android.widget.Toast
import com.bintianqi.owndroid.dpm.getDPM
import com.bintianqi.owndroid.dpm.getReceiver
import com.bintianqi.owndroid.dpm.handleNetworkLogs
import com.bintianqi.owndroid.dpm.handleSecurityLogs
import com.bintianqi.owndroid.dpm.isDeviceAdmin
import com.bintianqi.owndroid.dpm.isDeviceOwner
import com.bintianqi.owndroid.dpm.isProfileOwner
Expand Down Expand Up @@ -54,12 +56,26 @@ class Receiver : DeviceAdminReceiver() {

override fun onNetworkLogsAvailable(context: Context, intent: Intent, batchToken: Long, networkLogsCount: Int) {
super.onNetworkLogsAvailable(context, intent, batchToken, networkLogsCount)
if(VERSION.SDK_INT >= 28) {
if(VERSION.SDK_INT >= 26) {
CoroutineScope(Dispatchers.IO).launch {
handleNetworkLogs(context, batchToken)
}
}
}

override fun onSecurityLogsAvailable(context: Context, intent: Intent) {
super.onSecurityLogsAvailable(context, intent)
if(VERSION.SDK_INT >= 24) {
handleSecurityLogs(context)
}
}

override fun onTransferOwnershipComplete(context: Context, bundle: PersistableBundle?) {
super.onTransferOwnershipComplete(context, bundle)
val sp = context.getSharedPreferences("data", Context.MODE_PRIVATE)
sp.edit().putBoolean("dhizuku", false).apply()
context.toggleInstallAppActivity()
}
}

val installAppDone = MutableStateFlow(false)
Expand Down
43 changes: 36 additions & 7 deletions app/src/main/java/com/bintianqi/owndroid/Setting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,44 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build.VERSION
import android.util.Base64
import android.widget.Toast
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.bintianqi.owndroid.ui.*
import com.bintianqi.owndroid.ui.Animations
import com.bintianqi.owndroid.ui.SubPageItem
import com.bintianqi.owndroid.ui.SwitchItem
import com.bintianqi.owndroid.ui.TopBar
import java.security.SecureRandom

@Composable
fun AppSetting(navCtrl:NavHostController, materialYou: MutableState<Boolean>, blackTheme: MutableState<Boolean>) {
Expand Down Expand Up @@ -144,16 +161,28 @@ private fun Automation() {
Text(text = stringResource(R.string.automation_api), style = typography.headlineLarge)
Spacer(Modifier.padding(vertical = 5.dp))
var key by remember { mutableStateOf("") }
TextField(
OutlinedTextField(
value = key, onValueChange = { key = it }, label = { Text("Key")},
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
trailingIcon = {
IconButton(
onClick = {
val charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
val sr = SecureRandom()
key = (1..20).map { charset[sr.nextInt(charset.length)] }.joinToString("")
}
) {
Icon(painter = painterResource(R.drawable.casino_fill0), contentDescription = "Random")
}
}
)
Button(
modifier = Modifier.fillMaxWidth(),
onClick = {
sharedPref.edit().putString("automation_key", key).apply()
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
}
},
enabled = key.length >= 20
) {
Text(stringResource(R.string.apply))
}
Expand Down
Loading

0 comments on commit 9620e95

Please sign in to comment.