mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-24 03:16:00 +00:00
Set default Affiliation ID while app launch
Wipe data warning timer Display profile owner entry in non-system users Fix some UI bugs
This commit is contained in:
@@ -470,9 +470,9 @@ private fun PermissionManage(pkgName: String) {
|
||||
Text(selectedPermission.permission)
|
||||
Spacer(Modifier.padding(vertical = 4.dp))
|
||||
if(!(VERSION.SDK_INT >=31 && context.isProfileOwner && selectedPermission.profileOwnerRestricted)) {
|
||||
GrantPermissionItem(R.string.grant, PERMISSION_GRANT_STATE_GRANTED)
|
||||
GrantPermissionItem(R.string.granted, PERMISSION_GRANT_STATE_GRANTED)
|
||||
}
|
||||
GrantPermissionItem(R.string.deny, PERMISSION_GRANT_STATE_DENIED)
|
||||
GrantPermissionItem(R.string.denied, PERMISSION_GRANT_STATE_DENIED)
|
||||
GrantPermissionItem(R.string.default_stringres, PERMISSION_GRANT_STATE_DEFAULT)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.content.pm.IPackageInstaller
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build.VERSION
|
||||
import android.os.UserManager
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.RequiresApi
|
||||
@@ -401,3 +402,24 @@ data class SecurityEventItem(
|
||||
@SerialName("log_level") val logLevel: Int?,
|
||||
val data: String
|
||||
)
|
||||
|
||||
fun setDefaultAffiliationID(context: Context) {
|
||||
if(VERSION.SDK_INT < 26) return
|
||||
val sharedPrefs = context.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
if(!sharedPrefs.getBoolean("default_affiliation_id_set", false)) {
|
||||
try {
|
||||
val um = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
if(context.isDeviceOwner || (!um.isSystemUser && context.isProfileOwner)) {
|
||||
val dpm = context.getDPM()
|
||||
val receiver = context.getReceiver()
|
||||
val affiliationIDs = dpm.getAffiliationIds(receiver)
|
||||
if(affiliationIDs.isEmpty()) {
|
||||
dpm.setAffiliationIds(receiver, setOf("OwnDroid_default_affiliation_id"))
|
||||
sharedPrefs.edit().putBoolean("default_affiliation_id_set", true).apply()
|
||||
}
|
||||
}
|
||||
} catch(e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,7 +700,7 @@ private fun WifiAuthKeypair() {
|
||||
Spacer(Modifier.padding(vertical = 5.dp))
|
||||
OutlinedTextField(
|
||||
value = keyPair,
|
||||
label = { Text(stringResource(R.string.keypair)) },
|
||||
label = { Text(stringResource(R.string.alias)) },
|
||||
onValueChange = { keyPair = it },
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
|
||||
@@ -723,7 +723,7 @@ private fun WifiAuthKeypair() {
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(0.49F)
|
||||
) {
|
||||
Text(stringResource(R.string.add))
|
||||
Text(stringResource(R.string.grant))
|
||||
}
|
||||
Button(
|
||||
onClick = {
|
||||
@@ -732,7 +732,7 @@ private fun WifiAuthKeypair() {
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(0.96F)
|
||||
) {
|
||||
Text(stringResource(R.string.remove))
|
||||
Text(stringResource(R.string.revoke))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Binder
|
||||
import android.os.Build.VERSION
|
||||
import android.os.RemoteException
|
||||
import android.os.UserManager
|
||||
import android.widget.Toast
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.*
|
||||
@@ -90,6 +92,7 @@ private fun Home(localNavCtrl:NavHostController,listScrollState:ScrollState) {
|
||||
val deviceAdmin = context.isDeviceAdmin
|
||||
val deviceOwner = context.isDeviceOwner
|
||||
val profileOwner = context.isProfileOwner
|
||||
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
var dialog by remember { mutableIntStateOf(0) }
|
||||
val enrollmentSpecificId = if(VERSION.SDK_INT >= 31 && (deviceOwner || profileOwner)) dpm.enrollmentSpecificId else ""
|
||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(listScrollState)) {
|
||||
@@ -110,13 +113,13 @@ private fun Home(localNavCtrl:NavHostController,listScrollState:ScrollState) {
|
||||
R.string.device_admin, stringResource(if(deviceAdmin) R.string.activated else R.string.deactivated),
|
||||
operation = { localNavCtrl.navigate("DeviceAdmin") }
|
||||
)
|
||||
if(profileOwner) {
|
||||
if(profileOwner || !userManager.isSystemUser) {
|
||||
SubPageItem(
|
||||
R.string.profile_owner, stringResource(R.string.activated),
|
||||
R.string.profile_owner, stringResource(if(profileOwner) R.string.activated else R.string.deactivated),
|
||||
operation = { localNavCtrl.navigate("ProfileOwner") }
|
||||
)
|
||||
}
|
||||
if(!profileOwner) {
|
||||
if(!profileOwner && userManager.isSystemUser) {
|
||||
SubPageItem(
|
||||
R.string.device_owner, stringResource(if(deviceOwner) R.string.activated else R.string.deactivated),
|
||||
operation = { localNavCtrl.navigate("DeviceOwner") }
|
||||
@@ -376,7 +379,13 @@ private fun ProfileOwner() {
|
||||
Text(stringResource(R.string.deactivate))
|
||||
}
|
||||
}
|
||||
InfoCard(R.string.profile_owner)
|
||||
if(!profileOwner) {
|
||||
val command = context.getString(R.string.activate_profile_owner_command, (Binder.getCallingUid() / 100000).toString())
|
||||
SelectionContainer {
|
||||
Text(command)
|
||||
}
|
||||
CopyTextButton(R.string.copy_command, command)
|
||||
}
|
||||
}
|
||||
if(deactivateDialog && VERSION.SDK_INT >= 24) {
|
||||
AlertDialog(
|
||||
@@ -394,7 +403,8 @@ private fun ProfileOwner() {
|
||||
onClick = {
|
||||
dpm.clearProfileOwner(receiver)
|
||||
deactivateDialog = false
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.textButtonColors(contentColor = colorScheme.error)
|
||||
) {
|
||||
Text(stringResource(R.string.confirm))
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.compose.foundation.horizontalScroll
|
||||
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.text.selection.SelectionContainer
|
||||
@@ -192,9 +193,7 @@ fun ShizukuActivate() {
|
||||
}
|
||||
}
|
||||
|
||||
SelectionContainer(modifier = Modifier
|
||||
.align(Alignment.Start)
|
||||
.horizontalScroll(outputTextScrollState)) {
|
||||
SelectionContainer(modifier = Modifier.fillMaxWidth().horizontalScroll(outputTextScrollState)) {
|
||||
Text(text = outputText, softWrap = false, modifier = Modifier.padding(4.dp))
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,7 @@ import com.bintianqi.owndroid.ui.SubPageItem
|
||||
import com.bintianqi.owndroid.ui.SwitchItem
|
||||
import com.bintianqi.owndroid.ui.TopBar
|
||||
import com.bintianqi.owndroid.uriToStream
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.Json
|
||||
@@ -1255,7 +1256,6 @@ private fun WipeData() {
|
||||
val context = LocalContext.current
|
||||
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
val dpm = context.getDPM()
|
||||
val receiver = context.getReceiver()
|
||||
val focusMgr = LocalFocusManager.current
|
||||
var warning by remember { mutableStateOf(false) }
|
||||
var wipeDevice by remember { mutableStateOf(false) }
|
||||
@@ -1333,6 +1333,14 @@ private fun WipeData() {
|
||||
},
|
||||
onDismissRequest = { warning = false },
|
||||
confirmButton = {
|
||||
var timer by remember { mutableIntStateOf(6) }
|
||||
LaunchedEffect(Unit) {
|
||||
while(timer > 0) {
|
||||
timer -= 1
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
val timerText = if(timer > 0) "(${timer}s)" else ""
|
||||
TextButton(
|
||||
onClick = {
|
||||
var flag = 0
|
||||
@@ -1350,9 +1358,11 @@ private fun WipeData() {
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.textButtonColors(contentColor = colorScheme.error)
|
||||
colors = ButtonDefaults.textButtonColors(contentColor = colorScheme.error),
|
||||
modifier = Modifier.animateContentSize(),
|
||||
enabled = timer == 0
|
||||
) {
|
||||
Text(stringResource(R.string.confirm))
|
||||
Text(stringResource(R.string.confirm) + timerText)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
@@ -1392,27 +1402,30 @@ private fun SysUpdatePolicy() {
|
||||
RadioButtonItem(R.string.none, selectedPolicy == null, { selectedPolicy = null })
|
||||
var windowedPolicyStart by remember { mutableStateOf("") }
|
||||
var windowedPolicyEnd by remember { mutableStateOf("") }
|
||||
if(selectedPolicy == 2) {
|
||||
Spacer(Modifier.padding(vertical = 3.dp))
|
||||
OutlinedTextField(
|
||||
value = windowedPolicyStart,
|
||||
label = { Text(stringResource(R.string.start_time)) },
|
||||
onValueChange = { windowedPolicyStart = it },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
|
||||
modifier = Modifier.fillMaxWidth(0.5F)
|
||||
)
|
||||
Spacer(Modifier.padding(horizontal = 3.dp))
|
||||
OutlinedTextField(
|
||||
value = windowedPolicyEnd,
|
||||
onValueChange = {windowedPolicyEnd = it },
|
||||
label = { Text(stringResource(R.string.end_time)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
Spacer(Modifier.padding(vertical = 3.dp))
|
||||
Text(text = stringResource(R.string.minutes_in_one_day))
|
||||
AnimatedVisibility(selectedPolicy == 2) {
|
||||
Column {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = windowedPolicyStart,
|
||||
label = { Text(stringResource(R.string.start_time)) },
|
||||
onValueChange = { windowedPolicyStart = it },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
|
||||
modifier = Modifier.fillMaxWidth(0.49F)
|
||||
)
|
||||
OutlinedTextField(
|
||||
value = windowedPolicyEnd,
|
||||
onValueChange = {windowedPolicyEnd = it },
|
||||
label = { Text(stringResource(R.string.end_time)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
|
||||
modifier = Modifier.fillMaxWidth(0.96F).padding(bottom = 2.dp)
|
||||
)
|
||||
}
|
||||
Text(text = stringResource(R.string.minutes_in_one_day))
|
||||
}
|
||||
}
|
||||
Button(
|
||||
onClick = {
|
||||
@@ -1426,7 +1439,7 @@ private fun SysUpdatePolicy() {
|
||||
dpm.setSystemUpdatePolicy(receiver,policy)
|
||||
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 8.dp)
|
||||
) {
|
||||
Text(stringResource(R.string.apply))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user