Skip to content

Commit

Permalink
Show preview when changing user icon
Browse files Browse the repository at this point in the history
Refresh activate status when ownership transferred to OwnDroid
Set Start user session message and End user session message separately
Set Long support message and Short support message separately
Simplify code
  • Loading branch information
BinTianqi committed Sep 28, 2024
1 parent 47a965e commit 0788634
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 143 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +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 != 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
8 changes: 8 additions & 0 deletions app/src/main/java/com/bintianqi/owndroid/Receiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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
Expand Down Expand Up @@ -68,6 +69,13 @@ class Receiver : DeviceAdminReceiver() {
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
22 changes: 1 addition & 21 deletions app/src/main/java/com/bintianqi/owndroid/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun uriToStream(
operation: (stream: InputStream)->Unit
){
if(uri!=null){
try{
try {
val stream = context.contentResolver.openInputStream(uri)
if(stream != null) { operation(stream) }
stream?.close()
Expand All @@ -44,26 +44,6 @@ fun uriToStream(
}
}

fun List<Any>.toText():String{
var output = ""
var isFirst = true
for(each in listIterator()){
if(isFirst) { isFirst = false } else { output+="\n" }
output+=each
}
return output
}

fun Set<Any>.toText(): String{
var output = ""
var isFirst = true
for(each in iterator()){
if(isFirst) { isFirst = false } else { output+="\n" }
output += each
}
return output
}

fun MutableList<Int>.toggle(status: Boolean, element: Int) {
if(status) add(element) else remove(element)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import com.bintianqi.owndroid.R
import com.bintianqi.owndroid.fileUriFlow
import com.bintianqi.owndroid.getFile
import com.bintianqi.owndroid.selectedPackage
import com.bintianqi.owndroid.toText
import com.bintianqi.owndroid.ui.Animations
import com.bintianqi.owndroid.ui.Information
import com.bintianqi.owndroid.ui.NavIcon
Expand Down Expand Up @@ -358,7 +357,7 @@ private fun UserCtrlDisabledPkg(pkgName:String) {
Spacer(Modifier.padding(vertical = 5.dp))
Text(text = stringResource(R.string.app_list_is))
SelectionContainer(modifier = Modifier.horizontalScroll(rememberScrollState()).animateContentSize()) {
Text(text = if(pkgList.isEmpty()) stringResource(R.string.none) else pkgList.toText())
Text(text = if(pkgList.isEmpty()) stringResource(R.string.none) else pkgList.joinToString(separator = "\n"))
}
Spacer(Modifier.padding(vertical = 5.dp))
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Expand Down Expand Up @@ -510,7 +509,7 @@ private fun CrossProfilePkg(pkgName: String) {
Text(text = stringResource(R.string.cross_profile_package), style = typography.headlineLarge)
Text(text = stringResource(R.string.app_list_is))
SelectionContainer(modifier = Modifier.horizontalScroll(rememberScrollState()).animateContentSize()) {
Text(text = if(crossProfilePkg.isEmpty()) stringResource(R.string.none) else crossProfilePkg.toText())
Text(text = if(crossProfilePkg.isEmpty()) stringResource(R.string.none) else crossProfilePkg.joinToString(separator = "\n"))
}
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Button(
Expand Down Expand Up @@ -567,7 +566,7 @@ private fun CrossProfileWidget(pkgName: String) {
Spacer(Modifier.padding(vertical = 5.dp))
Text(text = stringResource(R.string.app_list_is))
SelectionContainer(modifier = Modifier.horizontalScroll(rememberScrollState()).animateContentSize()) {
Text(text = if(pkgList.isEmpty()) stringResource(R.string.none) else pkgList.toText())
Text(text = if(pkgList.isEmpty()) stringResource(R.string.none) else pkgList.joinToString(separator = "\n"))
}
Spacer(Modifier.padding(vertical = 5.dp))
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Expand Down Expand Up @@ -660,7 +659,7 @@ private fun CredentialManagePolicy(pkgName: String) {
Column {
Text(stringResource(R.string.app_list_is))
SelectionContainer(modifier = Modifier.horizontalScroll(rememberScrollState()).animateContentSize()) {
Text(text = if(credentialList.isEmpty()) stringResource(R.string.none) else credentialList.toText())
Text(text = if(credentialList.isEmpty()) stringResource(R.string.none) else credentialList.joinToString(separator = "\n"))
}
Spacer(Modifier.padding(vertical = 10.dp))
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Expand Down Expand Up @@ -739,7 +738,7 @@ private fun PermittedAccessibility(pkgName: String) {
if (pkgList.isEmpty()) {
Text(stringResource(R.string.only_system_accessibility_allowed))
} else {
Text(stringResource(R.string.permitted_packages_is) + pkgList.toText())
Text(stringResource(R.string.permitted_packages_is) + pkgList.joinToString(separator = "\n"))
}
}
Spacer(Modifier.padding(vertical = 5.dp))
Expand Down Expand Up @@ -819,7 +818,7 @@ private fun PermittedIME(pkgName: String) {
if(permittedIme.isEmpty()) {
Text(stringResource(R.string.only_system_ime_allowed))
} else {
Text(stringResource(R.string.permitted_packages_is) + permittedIme.toText())
Text(stringResource(R.string.permitted_packages_is) + permittedIme.joinToString(separator = "\n"))
}
}
Spacer(Modifier.padding(vertical = 5.dp))
Expand Down Expand Up @@ -882,7 +881,7 @@ private fun KeepUninstalledApp(pkgName: String) {
Spacer(Modifier.padding(vertical = 5.dp))
Text(text = stringResource(R.string.app_list_is))
SelectionContainer(modifier = Modifier.horizontalScroll(rememberScrollState()).animateContentSize()) {
Text(text = if(pkgList.isEmpty()) stringResource(R.string.none) else pkgList.toText())
Text(text = if(pkgList.isEmpty()) stringResource(R.string.none) else pkgList.joinToString(separator = "\n"))
}
Spacer(Modifier.padding(vertical = 5.dp))
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/bintianqi/owndroid/dpm/DPM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ val dhizukuErrorStatus = MutableStateFlow(0)
fun Context.resetDevicePolicy() {
val dpm = getDPM()
val receiver = getReceiver()
RestrictionData.getAllRestrictions(this).forEach {
RestrictionData.getAllRestrictions().forEach {
dpm.clearUserRestriction(receiver, it)
}
dpm.accountTypesWithManagementDisabled?.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import android.app.admin.DevicePolicyManager.PERSONAL_APPS_NOT_SUSPENDED
import android.app.admin.DevicePolicyManager.PERSONAL_APPS_SUSPENDED_PROFILE_TIMEOUT
import android.app.admin.DevicePolicyManager.WIPE_EUICC
import android.app.admin.DevicePolicyManager.WIPE_EXTERNAL_STORAGE
import android.app.admin.DevicePolicyManager.WIPE_SILENTLY
import android.content.*
import android.os.Binder
import android.os.Build.VERSION
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ import com.bintianqi.owndroid.exportFile
import com.bintianqi.owndroid.exportFilePath
import com.bintianqi.owndroid.formatFileSize
import com.bintianqi.owndroid.selectedPackage
import com.bintianqi.owndroid.toText
import com.bintianqi.owndroid.ui.Animations
import com.bintianqi.owndroid.ui.CheckBoxItem
import com.bintianqi.owndroid.ui.RadioButtonItem
Expand Down Expand Up @@ -332,7 +331,7 @@ private fun WifiSsidPolicy() {
Spacer(Modifier.padding(vertical = 5.dp))
Text(stringResource(R.string.ssid_list_is))
SelectionContainer(modifier = Modifier.animateContentSize().horizontalScroll(rememberScrollState())) {
Text(if(ssidList.isEmpty()) stringResource(R.string.none) else ssidList.toText())
Text(if(ssidList.isEmpty()) stringResource(R.string.none) else ssidList.joinToString(separator = "\n"))
}
}
Spacer(Modifier.padding(vertical = 5.dp))
Expand Down
88 changes: 53 additions & 35 deletions app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,13 @@ private fun SupportMsg() {
val context = LocalContext.current
val dpm = context.getDPM()
val receiver = context.getReceiver()
val focusMgr = LocalFocusManager.current
var shortMsg by remember { mutableStateOf(dpm.getShortSupportMessage(receiver)?.toString() ?: "") }
var longMsg by remember { mutableStateOf(dpm.getLongSupportMessage(receiver)?.toString() ?: "") }
var shortMsg by remember { mutableStateOf("") }
var longMsg by remember { mutableStateOf("") }
val refreshMsg = {
shortMsg = dpm.getShortSupportMessage(receiver)?.toString() ?: ""
longMsg = dpm.getLongSupportMessage(receiver)?.toString() ?: ""
}
LaunchedEffect(Unit) { refreshMsg() }
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.support_msg), style = typography.headlineLarge)
Expand All @@ -570,45 +574,59 @@ private fun SupportMsg() {
value = shortMsg,
label = { Text(stringResource(R.string.short_support_msg)) },
onValueChange = { shortMsg = it },
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth().padding(bottom = 2.dp)
)
Spacer(Modifier.padding(vertical = 2.dp))
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Button(
onClick = {
dpm.setShortSupportMessage(receiver, shortMsg)
refreshMsg()
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth(0.49F)
) {
Text(text = stringResource(R.string.apply))
}
Button(
onClick = {
dpm.setShortSupportMessage(receiver, null)
refreshMsg()
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth(0.96F)
) {
Text(text = stringResource(R.string.reset))
}
}
Spacer(Modifier.padding(vertical = 8.dp))
OutlinedTextField(
value = longMsg,
label = { Text(stringResource(R.string.long_support_msg)) },
onValueChange = { longMsg = it },
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth().padding(bottom = 2.dp)
)
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = {
focusMgr.clearFocus()
dpm.setShortSupportMessage(receiver, shortMsg)
dpm.setLongSupportMessage(receiver, longMsg)
shortMsg = dpm.getShortSupportMessage(receiver)?.toString() ?: ""
longMsg = dpm.getLongSupportMessage(receiver)?.toString() ?: ""
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth()
) {
Text(text = stringResource(R.string.apply))
}
Spacer(Modifier.padding(vertical = 1.dp))
Button(
onClick = {
focusMgr.clearFocus()
dpm.setShortSupportMessage(receiver, null)
dpm.setLongSupportMessage(receiver, null)
shortMsg = dpm.getShortSupportMessage(receiver)?.toString() ?: ""
longMsg = dpm.getLongSupportMessage(receiver)?.toString() ?: ""
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth()
) {
Text(text = stringResource(R.string.reset))
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Button(
onClick = {
dpm.setLongSupportMessage(receiver, longMsg)
refreshMsg()
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth(0.49F)
) {
Text(text = stringResource(R.string.apply))
}
Button(
onClick = {
dpm.setLongSupportMessage(receiver, null)
refreshMsg()
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth(0.96F)
) {
Text(text = stringResource(R.string.reset))
}
}
Spacer(Modifier.padding(vertical = 5.dp))
Information{ Text(text = stringResource(R.string.support_msg_desc)) }
Spacer(Modifier.padding(vertical = 30.dp))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ import com.bintianqi.owndroid.formatFileSize
import com.bintianqi.owndroid.getFile
import com.bintianqi.owndroid.prepareForNotification
import com.bintianqi.owndroid.selectedPackage
import com.bintianqi.owndroid.toText
import com.bintianqi.owndroid.toggle
import com.bintianqi.owndroid.ui.Animations
import com.bintianqi.owndroid.ui.CheckBoxItem
Expand Down Expand Up @@ -1115,7 +1114,7 @@ fun FactoryResetProtection() {
CheckBoxItem(R.string.enable_frp, enabled, { enabled = it })
Text(stringResource(R.string.account_list_is))
Text(
text = if(accountList.isEmpty()) stringResource(R.string.none) else accountList.toText(),
text = if(accountList.isEmpty()) stringResource(R.string.none) else accountList.joinToString(separator = "\n"),
modifier = Modifier.animateContentSize()
)
OutlinedTextField(
Expand Down
Loading

0 comments on commit 0788634

Please sign in to comment.