clean codes

use res id to make toast
convert class RestrictionData to a object
simplify some UI components
This commit is contained in:
BinTianqi
2024-05-08 19:59:06 +08:00
parent e19a9be2f7
commit b5e3981a41
15 changed files with 153 additions and 174 deletions

View File

@@ -6,7 +6,6 @@ import android.content.ComponentName
import android.content.Context import android.content.Context
import android.os.Build.VERSION import android.os.Build.VERSION
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics
import android.widget.Toast import android.widget.Toast
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
@@ -130,7 +129,7 @@ fun MyScaffold(){
if(profileNotActivated){ if(profileNotActivated){
myDpm.setProfileEnabled(myComponent) myDpm.setProfileEnabled(myComponent)
sharedPref.edit().putBoolean("ManagedProfileActivated",true).apply() sharedPref.edit().putBoolean("ManagedProfileActivated",true).apply()
Toast.makeText(myContext, myContext.getString(R.string.work_profile_activated), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.work_profile_activated, Toast.LENGTH_SHORT).show()
} }
} }
} }

View File

@@ -77,59 +77,54 @@ fun PackageSelector(navCtrl:NavHostController){
Scaffold( Scaffold(
topBar = { topBar = {
TopAppBar( TopAppBar(
title = { actions = {
Row( Icon(
horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth().padding(bottom = 2.dp), painter = painterResource(R.drawable.filter_alt_fill0),
verticalAlignment = Alignment.CenterVertically contentDescription = "filter",
){ modifier = Modifier
Text(text = stringResource(R.string.pkg_selector)) .padding(horizontal = 6.dp)
Row { .clip(RoundedCornerShape(50))
Icon( .combinedClickable(
painter = painterResource(R.drawable.filter_alt_fill0), onClick = {
contentDescription = "filter", when(filter){
modifier = Modifier "data"-> {
.padding(horizontal = 6.dp) filter = "system"; co.launch {scrollState.scrollToItem(0)}
.clip(RoundedCornerShape(50)) Toast.makeText(context, R.string.show_system_app, Toast.LENGTH_SHORT).show()
.combinedClickable(
onClick = {
when(filter){
"data"-> {
filter = "system"; co.launch {scrollState.scrollToItem(0)}
Toast.makeText(context, context.getString(R.string.show_system_app), Toast.LENGTH_SHORT).show()
}
"system"-> {
filter = "priv"; co.launch {scrollState.scrollToItem(0)}
Toast.makeText(context, context.getString(R.string.show_priv_app), Toast.LENGTH_SHORT).show()
}
else-> {
filter = "data"; co.launch {scrollState.scrollToItem(0)}
Toast.makeText(context, context.getString(R.string.show_user_app), Toast.LENGTH_SHORT).show()
}
}
},
onLongClick = {
filter = "apex"
Toast.makeText(context, context.getString(R.string.show_apex_app), Toast.LENGTH_SHORT).show()
} }
) "system"-> {
.padding(5.dp) filter = "priv"; co.launch {scrollState.scrollToItem(0)}
) Toast.makeText(context, R.string.show_priv_app, Toast.LENGTH_SHORT).show()
Icon( }
painter = painterResource(R.drawable.refresh_fill0), else-> {
contentDescription = "refresh", filter = "data"; co.launch {scrollState.scrollToItem(0)}
modifier = Modifier Toast.makeText(context, R.string.show_user_app, Toast.LENGTH_SHORT).show()
.padding(horizontal = 6.dp)
.clip(RoundedCornerShape(50))
.clickable{
co.launch{
delay(100)
getPkgList()
} }
} }
.padding(5.dp) },
onLongClick = {
filter = "apex"
Toast.makeText(context, R.string.show_apex_app, Toast.LENGTH_SHORT).show()
}
) )
} .padding(5.dp)
} )
Icon(
painter = painterResource(R.drawable.refresh_fill0),
contentDescription = "refresh",
modifier = Modifier
.padding(horizontal = 6.dp)
.clip(RoundedCornerShape(50))
.clickable{
co.launch{
delay(100)
getPkgList()
}
}
.padding(5.dp)
)
},
title = {
Text(text = stringResource(R.string.pkg_selector))
}, },
navigationIcon = {NavIcon{navCtrl.navigateUp()}}, navigationIcon = {NavIcon{navCtrl.navigateUp()}},
colors = TopAppBarDefaults.topAppBarColors(containerColor = bgColor) colors = TopAppBarDefaults.topAppBarColors(containerColor = bgColor)

View File

@@ -24,12 +24,12 @@ class Receiver : DeviceAdminReceiver() {
override fun onDisabled(context: Context, intent: Intent) { override fun onDisabled(context: Context, intent: Intent) {
super.onDisabled(context, intent) super.onDisabled(context, intent)
Toast.makeText(context, context.getString(R.string.onDisabled), Toast.LENGTH_SHORT).show() Toast.makeText(context, R.string.onDisabled, Toast.LENGTH_SHORT).show()
} }
override fun onProfileProvisioningComplete(context: Context, intent: Intent) { override fun onProfileProvisioningComplete(context: Context, intent: Intent) {
super.onProfileProvisioningComplete(context, intent) super.onProfileProvisioningComplete(context, intent)
Toast.makeText(context, context.getString(R.string.create_work_profile_success), Toast.LENGTH_SHORT).show() Toast.makeText(context, R.string.create_work_profile_success, Toast.LENGTH_SHORT).show()
} }
} }

View File

@@ -3,16 +3,12 @@ package com.bintianqi.owndroid
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build.VERSION
import android.widget.Toast import android.widget.Toast
import androidx.core.content.ContextCompat.startActivity
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
fun uriToStream( fun uriToStream(
context: Context, context: Context,
uri: Uri?, uri: Uri?,

View File

@@ -186,9 +186,9 @@ private fun Home(navCtrl:NavHostController, pkgName: String){
try { try {
myDpm.setAlwaysOnVpnPackage(myComponent, pkgName, it) myDpm.setAlwaysOnVpnPackage(myComponent, pkgName, it)
} catch(e: UnsupportedOperationException) { } catch(e: UnsupportedOperationException) {
Toast.makeText(myContext, myContext.getString(R.string.unsupported), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.unsupported, Toast.LENGTH_SHORT).show()
} catch(e: NameNotFoundException) { } catch(e: NameNotFoundException) {
Toast.makeText(myContext, myContext.getString(R.string.not_installed), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.not_installed, Toast.LENGTH_SHORT).show()
} }
} }
) )
@@ -196,7 +196,7 @@ private fun Home(navCtrl:NavHostController, pkgName: String){
if(isDeviceOwner(myDpm)||isProfileOwner(myDpm)){ if(isDeviceOwner(myDpm)||isProfileOwner(myDpm)){
SubPageItem(R.string.block_uninstall,"",R.drawable.delete_forever_fill0){navCtrl.navigate("BlockUninstall")} SubPageItem(R.string.block_uninstall,"",R.drawable.delete_forever_fill0){navCtrl.navigate("BlockUninstall")}
} }
if((VERSION.SDK_INT>=30&&isDeviceOwner(myDpm))||(VERSION.SDK_INT>=33&&isProfileOwner(myDpm))){ if((VERSION.SDK_INT>=33&&isProfileOwner(myDpm))||(VERSION.SDK_INT>=30&&isDeviceOwner(myDpm))){
SubPageItem(R.string.ucd,"",R.drawable.do_not_touch_fill0){navCtrl.navigate("UserControlDisabled")} SubPageItem(R.string.ucd,"",R.drawable.do_not_touch_fill0){navCtrl.navigate("UserControlDisabled")}
} }
if(VERSION.SDK_INT>=23&&(isDeviceOwner(myDpm)||isProfileOwner(myDpm))){ if(VERSION.SDK_INT>=23&&(isDeviceOwner(myDpm)||isProfileOwner(myDpm))){
@@ -265,7 +265,7 @@ private fun UserCtrlDisabledPkg(pkgName:String){
myDpm.setUserControlDisabledPackages(myComponent,pkgList) myDpm.setUserControlDisabledPackages(myComponent,pkgList)
refresh() refresh()
}else{ }else{
Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth(0.49F) modifier = Modifier.fillMaxWidth(0.49F)
@@ -279,7 +279,7 @@ private fun UserCtrlDisabledPkg(pkgName:String){
myDpm.setUserControlDisabledPackages(myComponent,pkgList) myDpm.setUserControlDisabledPackages(myComponent,pkgList)
refresh() refresh()
}else{ }else{
Toast.makeText(myContext, myContext.getString(R.string.not_exist), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.not_exist, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth(0.96F) modifier = Modifier.fillMaxWidth(0.96F)
@@ -317,7 +317,7 @@ private fun BlockUninstall(pkgName: String){
onClick = { onClick = {
focusMgr.clearFocus() focusMgr.clearFocus()
myDpm.setUninstallBlocked(myComponent,pkgName,true) myDpm.setUninstallBlocked(myComponent,pkgName,true)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
state = myDpm.isUninstallBlocked(myComponent,pkgName) state = myDpm.isUninstallBlocked(myComponent,pkgName)
}, },
modifier = Modifier.fillMaxWidth(0.49F) modifier = Modifier.fillMaxWidth(0.49F)
@@ -328,7 +328,7 @@ private fun BlockUninstall(pkgName: String){
onClick = { onClick = {
focusMgr.clearFocus() focusMgr.clearFocus()
myDpm.setUninstallBlocked(myComponent,pkgName,false) myDpm.setUninstallBlocked(myComponent,pkgName,false)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
state = myDpm.isUninstallBlocked(myComponent,pkgName) state = myDpm.isUninstallBlocked(myComponent,pkgName)
}, },
modifier = Modifier.fillMaxWidth(0.96F) modifier = Modifier.fillMaxWidth(0.96F)
@@ -578,9 +578,9 @@ private fun CredentialManagePolicy(pkgName: String){
}else{ }else{
myDpm.credentialManagerPolicy = null myDpm.credentialManagerPolicy = null
} }
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}catch(e:java.lang.IllegalArgumentException){ }catch(e:java.lang.IllegalArgumentException){
Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show()
}finally { }finally {
refreshPolicy() refreshPolicy()
credentialListText = credentialList.toText() credentialListText = credentialList.toText()
@@ -745,7 +745,7 @@ private fun KeepUninstalledApp(pkgName: String){
val getList = myDpm.getKeepUninstalledPackages(myComponent) val getList = myDpm.getKeepUninstalledPackages(myComponent)
if(getList!=null){ keepUninstallPkg = getList } if(getList!=null){ keepUninstallPkg = getList }
listText = keepUninstallPkg.toText() listText = keepUninstallPkg.toText()
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){
@@ -875,9 +875,9 @@ private fun DefaultDialerApp(pkgName: String){
onClick = { onClick = {
try{ try{
myDpm.setDefaultDialerApplication(pkgName) myDpm.setDefaultDialerApplication(pkgName)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}catch(e:IllegalArgumentException){ }catch(e:IllegalArgumentException){
Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show()
} }
}, },
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),

View File

@@ -129,7 +129,7 @@ private fun CreateWorkProfile(){
if(VERSION.SDK_INT>=33){intent.putExtra(EXTRA_PROVISIONING_ALLOW_OFFLINE,true)} if(VERSION.SDK_INT>=33){intent.putExtra(EXTRA_PROVISIONING_ALLOW_OFFLINE,true)}
createManagedProfile.launch(intent) createManagedProfile.launch(intent)
}catch(e:ActivityNotFoundException){ }catch(e:ActivityNotFoundException){
Toast.makeText(myContext,myContext.getString(R.string.unsupported),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.unsupported, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -157,7 +157,7 @@ private fun OrgOwnedProfile(){
color = colorScheme.onTertiaryContainer color = colorScheme.onTertiaryContainer
) )
} }
CopyTextButton(myContext, R.string.copy_command, stringResource(R.string.activate_org_profile_command, Binder.getCallingUid()/100000)) CopyTextButton(R.string.copy_command, stringResource(R.string.activate_org_profile_command, Binder.getCallingUid()/100000))
} }
} }
} }
@@ -188,7 +188,7 @@ private fun OrgID(){
Button( Button(
onClick = { onClick = {
myDpm.setOrganizationId(orgId) myDpm.setOrganizationId(orgId)
Toast.makeText(myContext, myContext.getString(R.string.success),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success,Toast.LENGTH_SHORT).show()
}, },
enabled = orgId.length in 6..64, enabled = orgId.length in 6..64,
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -229,7 +229,7 @@ private fun SuspendPersonalApp(){
Button( Button(
onClick = { onClick = {
myDpm.setManagedProfileMaximumTimeOff(myComponent,time.toLong()) myDpm.setManagedProfileMaximumTimeOff(myComponent,time.toLong())
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -260,7 +260,7 @@ private fun IntentFilter(){
Button( Button(
onClick = { onClick = {
myDpm.addCrossProfileIntentFilter(myComponent, IntentFilter(action), FLAG_PARENT_CAN_ACCESS_MANAGED) myDpm.addCrossProfileIntentFilter(myComponent, IntentFilter(action), FLAG_PARENT_CAN_ACCESS_MANAGED)
Toast.makeText(myContext, myContext.getString(R.string.success),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -269,7 +269,7 @@ private fun IntentFilter(){
Button( Button(
onClick = { onClick = {
myDpm.addCrossProfileIntentFilter(myComponent, IntentFilter(action), FLAG_MANAGED_CAN_ACCESS_PARENT) myDpm.addCrossProfileIntentFilter(myComponent, IntentFilter(action), FLAG_MANAGED_CAN_ACCESS_PARENT)
Toast.makeText(myContext, myContext.getString(R.string.success),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success,Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -279,7 +279,7 @@ private fun IntentFilter(){
Button( Button(
onClick = { onClick = {
myDpm.clearCrossProfileIntentFilters(myComponent) myDpm.clearCrossProfileIntentFilters(myComponent)
Toast.makeText(myContext, myContext.getString(R.string.success),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){

View File

@@ -41,7 +41,6 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.bintianqi.owndroid.dpm.scrollAnim
import com.bintianqi.owndroid.R import com.bintianqi.owndroid.R
import com.bintianqi.owndroid.Receiver import com.bintianqi.owndroid.Receiver
import com.bintianqi.owndroid.toText import com.bintianqi.owndroid.toText
@@ -177,7 +176,7 @@ private fun WifiSecLevel(){
enabled = isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&myDpm.isOrganizationOwnedDeviceWithManagedProfile), enabled = isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&myDpm.isOrganizationOwnedDeviceWithManagedProfile),
onClick = { onClick = {
myDpm.minimumRequiredWifiSecurityLevel=selectedWifiSecLevel myDpm.minimumRequiredWifiSecurityLevel=selectedWifiSecLevel
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){
@@ -232,9 +231,9 @@ private fun WifiSsidPolicy(){
Button( Button(
onClick = { onClick = {
if(inputSsid==""){ if(inputSsid==""){
Toast.makeText(myContext, myContext.getString(R.string.cannot_be_empty), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.cannot_be_empty, Toast.LENGTH_SHORT).show()
}else if(WifiSsid.fromBytes(inputSsid.toByteArray()) in ssidSet){ }else if(WifiSsid.fromBytes(inputSsid.toByteArray()) in ssidSet){
Toast.makeText(myContext, myContext.getString(R.string.already_exist), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.already_exist, Toast.LENGTH_SHORT).show()
}else{ }else{
ssidSet.add(WifiSsid.fromBytes(inputSsid.toByteArray())) ssidSet.add(WifiSsid.fromBytes(inputSsid.toByteArray()))
ssidList = ssidSet.toText() ssidList = ssidSet.toText()
@@ -248,13 +247,13 @@ private fun WifiSsidPolicy(){
Button( Button(
onClick = { onClick = {
if(inputSsid==""){ if(inputSsid==""){
Toast.makeText(myContext, myContext.getString(R.string.cannot_be_empty), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.cannot_be_empty, Toast.LENGTH_SHORT).show()
}else if(WifiSsid.fromBytes(inputSsid.toByteArray()) in ssidSet){ }else if(WifiSsid.fromBytes(inputSsid.toByteArray()) in ssidSet){
ssidSet.remove(WifiSsid.fromBytes(inputSsid.toByteArray())) ssidSet.remove(WifiSsid.fromBytes(inputSsid.toByteArray()))
inputSsid = "" inputSsid = ""
ssidList = ssidSet.toText() ssidList = ssidSet.toText()
}else{ }else{
Toast.makeText(myContext, myContext.getString(R.string.not_exist), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.not_exist, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth(0.96F) modifier = Modifier.fillMaxWidth(0.96F)
@@ -267,16 +266,16 @@ private fun WifiSsidPolicy(){
focusMgr.clearFocus() focusMgr.clearFocus()
if(selectedPolicyType==-1){ if(selectedPolicyType==-1){
if(policy==null&&ssidSet.isNotEmpty()){ if(policy==null&&ssidSet.isNotEmpty()){
Toast.makeText(myContext, myContext.getString(R.string.please_select_a_policy), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.please_select_a_policy, Toast.LENGTH_SHORT).show()
}else{ }else{
myDpm.wifiSsidPolicy = null myDpm.wifiSsidPolicy = null
refreshPolicy() refreshPolicy()
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
} }
}else{ }else{
myDpm.wifiSsidPolicy = if(ssidSet.size==0){ null }else{ WifiSsidPolicy(selectedPolicyType, ssidSet) } myDpm.wifiSsidPolicy = if(ssidSet.size==0){ null }else{ WifiSsidPolicy(selectedPolicyType, ssidSet) }
refreshPolicy() refreshPolicy()
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -343,9 +342,9 @@ private fun PrivateDNS(){
result = myDpm.setGlobalPrivateDnsModeSpecifiedHost(myComponent,inputHost) result = myDpm.setGlobalPrivateDnsModeSpecifiedHost(myComponent,inputHost)
Toast.makeText(myContext, operationResult[result], Toast.LENGTH_SHORT).show() Toast.makeText(myContext, operationResult[result], Toast.LENGTH_SHORT).show()
}catch(e:IllegalArgumentException){ }catch(e:IllegalArgumentException){
Toast.makeText(myContext, myContext.getString(R.string.invalid_hostname), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.invalid_hostname, Toast.LENGTH_SHORT).show()
}catch(e:SecurityException){ }catch(e:SecurityException){
Toast.makeText(myContext, myContext.getString(R.string.security_exception), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.security_exception, Toast.LENGTH_SHORT).show()
}finally { }finally {
status = dnsStatus[myDpm.getGlobalPrivateDnsMode(myComponent)] status = dnsStatus[myDpm.getGlobalPrivateDnsMode(myComponent)]
} }
@@ -376,10 +375,10 @@ private fun NetLog(){
val log = myDpm.retrieveNetworkLogs(myComponent,1234567890) val log = myDpm.retrieveNetworkLogs(myComponent,1234567890)
if(log!=null){ if(log!=null){
for(i in log){ Log.d("NetLog",i.toString()) } for(i in log){ Log.d("NetLog",i.toString()) }
Toast.makeText(myContext, myContext.getString(R.string.success),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}else{ }else{
Log.d("NetLog",myContext.getString(R.string.none)) Log.d("NetLog",myContext.getString(R.string.none))
Toast.makeText(myContext, myContext.getString(R.string.none),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.none, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -416,7 +415,7 @@ private fun WifiKeypair(){
Button( Button(
onClick = { onClick = {
val result = myDpm.grantKeyPairToWifiAuth(keyPair) val result = myDpm.grantKeyPairToWifiAuth(keyPair)
Toast.makeText(myContext, myContext.getString(if(result){R.string.success}else{R.string.fail}), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, if(result){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth(0.49F) modifier = Modifier.fillMaxWidth(0.49F)
) { ) {
@@ -425,7 +424,7 @@ private fun WifiKeypair(){
Button( Button(
onClick = { onClick = {
val result = myDpm.revokeKeyPairFromWifiAuth(keyPair) val result = myDpm.revokeKeyPairFromWifiAuth(keyPair)
Toast.makeText(myContext, myContext.getString(if(result){R.string.success}else{R.string.fail}), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, if(result){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth(0.96F) modifier = Modifier.fillMaxWidth(0.96F)
) { ) {
@@ -784,7 +783,7 @@ private fun APN(){
Button( Button(
onClick = { onClick = {
val success = myDpm.updateOverrideApn(myComponent,id,result) val success = myDpm.updateOverrideApn(myComponent,id,result)
Toast.makeText(myContext, myContext.getString(if(success){R.string.success}else{R.string.fail}), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, if(success){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
}, },
Modifier.fillMaxWidth(0.49F) Modifier.fillMaxWidth(0.49F)
){ ){

View File

@@ -163,8 +163,8 @@ private fun ResetPasswordToken(){
Spacer(Modifier.padding(vertical = 5.dp)) Spacer(Modifier.padding(vertical = 5.dp))
Button( Button(
onClick = { onClick = {
if(myDpm.clearResetPasswordToken(myComponent)){ Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() if(myDpm.clearResetPasswordToken(myComponent)){ Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}else{ Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() } }else{ Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show() }
}, },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm) enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm)
@@ -175,12 +175,12 @@ private fun ResetPasswordToken(){
onClick = { onClick = {
try { try {
if(myDpm.setResetPasswordToken(myComponent, myByteArray)){ if(myDpm.setResetPasswordToken(myComponent, myByteArray)){
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}else{ }else{
Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show()
} }
}catch(e:SecurityException){ }catch(e:SecurityException){
Toast.makeText(myContext, myContext.getString(R.string.security_exception), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.security_exception, Toast.LENGTH_SHORT).show()
} }
}, },
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),
@@ -192,8 +192,8 @@ private fun ResetPasswordToken(){
onClick = { onClick = {
if(!myDpm.isResetPasswordTokenActive(myComponent)){ if(!myDpm.isResetPasswordTokenActive(myComponent)){
try{ activateToken(myContext) } try{ activateToken(myContext) }
catch(e:NullPointerException){ Toast.makeText(myContext, myContext.getString(R.string.please_set_a_token), Toast.LENGTH_SHORT).show() } catch(e:NullPointerException){ Toast.makeText(myContext, R.string.please_set_a_token, Toast.LENGTH_SHORT).show() }
}else{ Toast.makeText(myContext, myContext.getString(R.string.token_already_activated), Toast.LENGTH_SHORT).show() } }else{ Toast.makeText(myContext, R.string.token_already_activated, Toast.LENGTH_SHORT).show() }
}, },
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -243,7 +243,7 @@ private fun ResetPassword(){
Button( Button(
onClick = { onClick = {
if(newPwd.length>=4||newPwd.isEmpty()){ confirmed=!confirmed if(newPwd.length>=4||newPwd.isEmpty()){ confirmed=!confirmed
}else{ Toast.makeText(myContext, myContext.getString(R.string.require_4_digit_password), Toast.LENGTH_SHORT).show() } }else{ Toast.makeText(myContext, R.string.require_4_digit_password, Toast.LENGTH_SHORT).show() }
}, },
enabled = isDeviceOwner(myDpm) || isProfileOwner(myDpm) || myDpm.isAdminActive(myComponent), enabled = isDeviceOwner(myDpm) || isProfileOwner(myDpm) || myDpm.isAdminActive(myComponent),
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@@ -259,8 +259,8 @@ private fun ResetPassword(){
Button( Button(
onClick = { onClick = {
val resetSuccess = myDpm.resetPasswordWithToken(myComponent,newPwd,myByteArray,resetPwdFlag) val resetSuccess = myDpm.resetPasswordWithToken(myComponent,newPwd,myByteArray,resetPwdFlag)
if(resetSuccess){ Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show();newPwd=""} if(resetSuccess){ Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show();newPwd=""}
else{ Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() } else{ Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show() }
confirmed=false confirmed=false
}, },
colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError), colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError),
@@ -273,8 +273,8 @@ private fun ResetPassword(){
Button( Button(
onClick = { onClick = {
val resetSuccess = myDpm.resetPassword(newPwd,resetPwdFlag) val resetSuccess = myDpm.resetPassword(newPwd,resetPwdFlag)
if(resetSuccess){ Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show(); newPwd=""} if(resetSuccess){ Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show(); newPwd=""}
else{ Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() } else{ Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show() }
confirmed=false confirmed=false
}, },
enabled = confirmed, enabled = confirmed,
@@ -315,7 +315,7 @@ private fun PasswordComplexity(){
Button( Button(
onClick = { onClick = {
myDpm.requiredPasswordComplexity = selectedItem myDpm.requiredPasswordComplexity = selectedItem
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -563,7 +563,7 @@ private fun KeyguardDisabledFeatures(){
if(widgets){result+=KEYGUARD_DISABLE_WIDGETS_ALL} if(widgets){result+=KEYGUARD_DISABLE_WIDGETS_ALL}
} }
myDpm.setKeyguardDisabledFeatures(myComponent,result) myDpm.setKeyguardDisabledFeatures(myComponent,result)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
calculateCustomFeature() calculateCustomFeature()
}, },
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),
@@ -611,7 +611,7 @@ private fun PasswordQuality(){
Button( Button(
onClick = { onClick = {
myDpm.setPasswordQuality(myComponent,selectedItem) myDpm.setPasswordQuality(myComponent,selectedItem)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
enabled = isDeviceOwner(myDpm) || isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm) || isProfileOwner(myDpm),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -629,6 +629,6 @@ private fun activateToken(myContext: Context){
if (confirmIntent != null) { if (confirmIntent != null) {
startActivity(myContext,confirmIntent, null) startActivity(myContext,confirmIntent, null)
} else { } else {
Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show()
} }
} }

View File

@@ -167,7 +167,7 @@ private fun LockScreenInfo(){
onClick = { onClick = {
focusMgr.clearFocus() focusMgr.clearFocus()
myDpm.setDeviceOwnerLockScreenInfo(myComponent,infoText) myDpm.setDeviceOwnerLockScreenInfo(myComponent,infoText)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -177,7 +177,7 @@ private fun LockScreenInfo(){
onClick = { onClick = {
focusMgr.clearFocus() focusMgr.clearFocus()
myDpm.setDeviceOwnerLockScreenInfo(myComponent,null) myDpm.setDeviceOwnerLockScreenInfo(myComponent,null)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -219,7 +219,7 @@ private fun DeviceAdmin(){
SelectionContainer { SelectionContainer {
Text(text = stringResource(R.string.activate_device_admin_command)) Text(text = stringResource(R.string.activate_device_admin_command))
} }
CopyTextButton(myContext, R.string.copy_command, stringResource(R.string.activate_device_admin_command)) CopyTextButton(R.string.copy_command, stringResource(R.string.activate_device_admin_command))
} }
} }
} }
@@ -256,7 +256,7 @@ private fun ProfileOwner(){
SelectionContainer{ SelectionContainer{
Text(text = stringResource(R.string.activate_profile_owner_command)) Text(text = stringResource(R.string.activate_profile_owner_command))
} }
CopyTextButton(myContext, R.string.copy_command, stringResource(R.string.activate_profile_owner_command)) CopyTextButton(R.string.copy_command, stringResource(R.string.activate_profile_owner_command))
} }
} }
} }
@@ -289,7 +289,7 @@ private fun DeviceOwner(){
SelectionContainer{ SelectionContainer{
Text(text = stringResource(R.string.activate_device_owner_command)) Text(text = stringResource(R.string.activate_device_owner_command))
} }
CopyTextButton(myContext, R.string.copy_command, stringResource(R.string.activate_device_owner_command)) CopyTextButton(R.string.copy_command, stringResource(R.string.activate_device_owner_command))
} }
} }
} }
@@ -357,7 +357,7 @@ private fun SpecificID(){
Spacer(Modifier.padding(vertical = 5.dp)) Spacer(Modifier.padding(vertical = 5.dp))
if(specificId!=""){ if(specificId!=""){
SelectionContainer(modifier = Modifier.horizontalScroll(rememberScrollState())){ Text(specificId) } SelectionContainer(modifier = Modifier.horizontalScroll(rememberScrollState())){ Text(specificId) }
CopyTextButton(myContext, R.string.copy, specificId) CopyTextButton(R.string.copy, specificId)
}else{ }else{
Text(stringResource(R.string.require_set_org_id)) Text(stringResource(R.string.require_set_org_id))
} }
@@ -387,7 +387,7 @@ private fun OrgName(){
onClick = { onClick = {
focusMgr.clearFocus() focusMgr.clearFocus()
myDpm.setOrganizationName(myComponent,orgName) myDpm.setOrganizationName(myComponent,orgName)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){
@@ -428,7 +428,7 @@ private fun SupportMsg(){
focusMgr.clearFocus() focusMgr.clearFocus()
myDpm.setShortSupportMessage(myComponent, shortMsg) myDpm.setShortSupportMessage(myComponent, shortMsg)
myDpm.setLongSupportMessage(myComponent, longMsg) myDpm.setLongSupportMessage(myComponent, longMsg)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -440,7 +440,7 @@ private fun SupportMsg(){
focusMgr.clearFocus() focusMgr.clearFocus()
myDpm.setShortSupportMessage(myComponent, null) myDpm.setShortSupportMessage(myComponent, null)
myDpm.setLongSupportMessage(myComponent, null) myDpm.setLongSupportMessage(myComponent, null)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -539,9 +539,9 @@ private fun TransformOwnership(){
onClick = { onClick = {
try { try {
myDpm.transferOwnership(myComponent,ComponentName(pkg, cls),null) myDpm.transferOwnership(myComponent,ComponentName(pkg, cls),null)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}catch(e:IllegalArgumentException){ }catch(e:IllegalArgumentException){
Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -559,6 +559,6 @@ private fun activateDeviceAdmin(inputContext:Context,inputComponent:ComponentNam
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, inputContext.getString(R.string.activate_device_admin_here)) intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, inputContext.getString(R.string.activate_device_admin_here))
addDeviceAdmin.launch(intent) addDeviceAdmin.launch(intent)
}catch(e:ActivityNotFoundException){ }catch(e:ActivityNotFoundException){
Toast.makeText(inputContext,inputContext.getString(R.string.unsupported),Toast.LENGTH_SHORT).show() Toast.makeText(inputContext, R.string.unsupported, Toast.LENGTH_SHORT).show()
} }
} }

View File

@@ -225,12 +225,12 @@ fun userServiceControl(context:Context, status:Boolean){
if (binder.pingBinder()) { if (binder.pingBinder()) {
service = IUserService.Stub.asInterface(binder) service = IUserService.Stub.asInterface(binder)
} else { } else {
Toast.makeText(context,context.getString(R.string.invalid_binder),Toast.LENGTH_SHORT).show() Toast.makeText(context, R.string.invalid_binder, Toast.LENGTH_SHORT).show()
} }
} }
override fun onServiceDisconnected(componentName: ComponentName) { override fun onServiceDisconnected(componentName: ComponentName) {
service = null service = null
Toast.makeText(context,context.getString(R.string.shizuku_service_disconnected),Toast.LENGTH_SHORT).show() Toast.makeText(context, R.string.shizuku_service_disconnected, Toast.LENGTH_SHORT).show()
} }
} }
val userServiceArgs = Shizuku.UserServiceArgs( val userServiceArgs = Shizuku.UserServiceArgs(

View File

@@ -1,6 +1,5 @@
package com.bintianqi.owndroid.dpm package com.bintianqi.owndroid.dpm
import android.os.IBinder
import android.system.Os import android.system.Os
import androidx.annotation.Keep import androidx.annotation.Keep
import com.bintianqi.owndroid.IUserService import com.bintianqi.owndroid.IUserService
@@ -11,10 +10,6 @@ var service:IUserService? = null
@Keep @Keep
class ShizukuService: IUserService.Stub() { class ShizukuService: IUserService.Stub() {
override fun asBinder(): IBinder {
TODO("Not yet implemented")
}
override fun destroy(){ } override fun destroy(){ }
override fun execute(command: String?): String { override fun execute(command: String?): String {

View File

@@ -217,7 +217,7 @@ private fun Switches(){
if(myDpm.canUsbDataSignalingBeDisabled()){ if(myDpm.canUsbDataSignalingBeDisabled()){
myDpm.isUsbDataSignalingEnabled = it myDpm.isUsbDataSignalingEnabled = it
}else{ }else{
Toast.makeText(myContext,myContext.getString(R.string.unsupported),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.unsupported, Toast.LENGTH_SHORT).show()
} }
} }
) )
@@ -238,8 +238,7 @@ private fun Keyguard(){
if(VERSION.SDK_INT>=23){ if(VERSION.SDK_INT>=23){
Button( Button(
onClick = { onClick = {
Toast.makeText(myContext, Toast.makeText(myContext, if(myDpm.setKeyguardDisabled(myComponent,true)){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
myContext.getString(if(myDpm.setKeyguardDisabled(myComponent,true)){R.string.success}else{R.string.fail}), Toast.LENGTH_SHORT).show()
}, },
enabled = isDeviceOwner(myDpm)|| (VERSION.SDK_INT>=28&&isProfileOwner(myDpm)&&myDpm.isAffiliatedUser), enabled = isDeviceOwner(myDpm)|| (VERSION.SDK_INT>=28&&isProfileOwner(myDpm)&&myDpm.isAffiliatedUser),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -248,8 +247,7 @@ private fun Keyguard(){
} }
Button( Button(
onClick = { onClick = {
Toast.makeText(myContext, Toast.makeText(myContext, if(myDpm.setKeyguardDisabled(myComponent,false)){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
myContext.getString(if(myDpm.setKeyguardDisabled(myComponent,false)){R.string.success}else{R.string.fail}), Toast.LENGTH_SHORT).show()
}, },
enabled = isDeviceOwner(myDpm)|| (VERSION.SDK_INT>=28&&isProfileOwner(myDpm)&&myDpm.isAffiliatedUser), enabled = isDeviceOwner(myDpm)|| (VERSION.SDK_INT>=28&&isProfileOwner(myDpm)&&myDpm.isAffiliatedUser),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -370,7 +368,7 @@ private fun PermissionPolicy(){
Button( Button(
onClick = { onClick = {
myDpm.setPermissionPolicy(myComponent,selectedPolicy) myDpm.setPermissionPolicy(myComponent,selectedPolicy)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -396,9 +394,9 @@ private fun MTEPolicy(){
onClick = { onClick = {
try { try {
myDpm.mtePolicy = selectedMtePolicy myDpm.mtePolicy = selectedMtePolicy
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}catch(e:java.lang.UnsupportedOperationException){ }catch(e:java.lang.UnsupportedOperationException){
Toast.makeText(myContext, myContext.getString(R.string.unsupported), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.unsupported, Toast.LENGTH_SHORT).show()
} }
selectedMtePolicy = myDpm.mtePolicy selectedMtePolicy = myDpm.mtePolicy
}, },
@@ -448,7 +446,7 @@ private fun NearbyStreamingPolicy(){
Button( Button(
onClick = { onClick = {
myDpm.nearbyNotificationStreamingPolicy = notificationPolicy myDpm.nearbyNotificationStreamingPolicy = notificationPolicy
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
@@ -531,7 +529,7 @@ private fun LockTaskFeatures(){
} }
myDpm.setLockTaskFeatures(myComponent,result) myDpm.setLockTaskFeatures(myComponent,result)
refreshFeature() refreshFeature()
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
} }
) { ) {
Text(stringResource(R.string.apply)) Text(stringResource(R.string.apply))
@@ -564,7 +562,7 @@ private fun LockTaskFeatures(){
focusMgr.clearFocus() focusMgr.clearFocus()
whitelist.add(inputPkg) whitelist.add(inputPkg)
myDpm.setLockTaskPackages(myComponent,whitelist.toTypedArray()) myDpm.setLockTaskPackages(myComponent,whitelist.toTypedArray())
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
refreshWhitelist() refreshWhitelist()
}, },
modifier = Modifier.fillMaxWidth(0.49F) modifier = Modifier.fillMaxWidth(0.49F)
@@ -577,9 +575,9 @@ private fun LockTaskFeatures(){
if(inputPkg in whitelist){ if(inputPkg in whitelist){
whitelist.remove(inputPkg) whitelist.remove(inputPkg)
myDpm.setLockTaskPackages(myComponent,whitelist.toTypedArray()) myDpm.setLockTaskPackages(myComponent,whitelist.toTypedArray())
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}else{ }else{
Toast.makeText(myContext, myContext.getString(R.string.not_exist), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.not_exist, Toast.LENGTH_SHORT).show()
} }
refreshWhitelist() refreshWhitelist()
}, },
@@ -626,7 +624,7 @@ private fun CaCert(){
Button( Button(
onClick = { onClick = {
val result = myDpm.installCaCert(myComponent, caCert) val result = myDpm.installCaCert(myComponent, caCert)
Toast.makeText(myContext, myContext.getString(if(result){R.string.success}else{R.string.fail}), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, if(result){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
refresh() refresh()
}, },
modifier = Modifier.fillMaxWidth(0.49F) modifier = Modifier.fillMaxWidth(0.49F)
@@ -638,8 +636,8 @@ private fun CaCert(){
if(exist){ if(exist){
myDpm.uninstallCaCert(myComponent, caCert) myDpm.uninstallCaCert(myComponent, caCert)
exist = myDpm.hasCaCertInstalled(myComponent, caCert) exist = myDpm.hasCaCertInstalled(myComponent, caCert)
Toast.makeText(myContext, myContext.getString(if(exist){R.string.fail}else{R.string.success}), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, if(exist){R.string.fail}else{R.string.success}, Toast.LENGTH_SHORT).show()
}else{ Toast.makeText(myContext, myContext.getString(R.string.not_exist), Toast.LENGTH_SHORT).show() } }else{ Toast.makeText(myContext, R.string.not_exist, Toast.LENGTH_SHORT).show() }
}, },
modifier = Modifier.fillMaxWidth(0.96F) modifier = Modifier.fillMaxWidth(0.96F)
) { ) {
@@ -650,7 +648,7 @@ private fun CaCert(){
Button( Button(
onClick = { onClick = {
myDpm.uninstallAllUserCaCerts(myComponent) myDpm.uninstallAllUserCaCerts(myComponent)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){
@@ -676,10 +674,10 @@ private fun SecurityLogs(){
val log = myDpm.retrieveSecurityLogs(myComponent) val log = myDpm.retrieveSecurityLogs(myComponent)
if(log!=null){ if(log!=null){
for(i in log){ Log.d("SecureLog",i.toString()) } for(i in log){ Log.d("SecureLog",i.toString()) }
Toast.makeText(myContext,myContext.getString(R.string.success),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}else{ }else{
Log.d("SecureLog",myContext.getString(R.string.none)) Log.d("SecureLog",myContext.getString(R.string.none))
Toast.makeText(myContext, myContext.getString(R.string.no_logs),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.no_logs, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -691,10 +689,10 @@ private fun SecurityLogs(){
val log = myDpm.retrievePreRebootSecurityLogs(myComponent) val log = myDpm.retrievePreRebootSecurityLogs(myComponent)
if(log!=null){ if(log!=null){
for(i in log){ Log.d("SecureLog",i.toString()) } for(i in log){ Log.d("SecureLog",i.toString()) }
Toast.makeText(myContext,myContext.getString(R.string.success),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}else{ }else{
Log.d("SecureLog",myContext.getString(R.string.none)) Log.d("SecureLog",myContext.getString(R.string.none))
Toast.makeText(myContext,myContext.getString(R.string.no_logs),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.no_logs, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()

View File

@@ -224,10 +224,7 @@ private fun UserOperation(){
Button( Button(
onClick = { onClick = {
focusMgr.clearFocus() focusMgr.clearFocus()
Toast.makeText( Toast.makeText(myContext, if(myDpm.switchUser(myComponent,userHandleById)) { R.string.success }else{ R.string.fail }, Toast.LENGTH_SHORT).show()
myContext,
myContext.getString(if(myDpm.switchUser(myComponent,userHandleById)) { R.string.success }else{ R.string.fail }), Toast.LENGTH_SHORT
).show()
}, },
enabled = isDeviceOwner(myDpm), enabled = isDeviceOwner(myDpm),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -242,7 +239,7 @@ private fun UserOperation(){
val result = myDpm.stopUser(myComponent,userHandleById) val result = myDpm.stopUser(myComponent,userHandleById)
Toast.makeText(myContext, userOperationResultCode(result,myContext), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, userOperationResultCode(result,myContext), Toast.LENGTH_SHORT).show()
}catch(e:IllegalArgumentException){ }catch(e:IllegalArgumentException){
Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show()
} }
}, },
enabled = isDeviceOwner(myDpm), enabled = isDeviceOwner(myDpm),
@@ -255,10 +252,10 @@ private fun UserOperation(){
onClick = { onClick = {
focusMgr.clearFocus() focusMgr.clearFocus()
if(myDpm.removeUser(myComponent,userHandleById)){ if(myDpm.removeUser(myComponent,userHandleById)){
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
idInput="" idInput=""
}else{ }else{
Toast.makeText(myContext, myContext.getString(R.string.fail), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.fail, Toast.LENGTH_SHORT).show()
} }
}, },
enabled = isDeviceOwner(myDpm), enabled = isDeviceOwner(myDpm),
@@ -369,14 +366,14 @@ private fun AffiliationID(){
Button( Button(
onClick = { onClick = {
if("" in affiliationID) { if("" in affiliationID) {
Toast.makeText(myContext, myContext.getString(R.string.include_empty_string), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.include_empty_string, Toast.LENGTH_SHORT).show()
}else if(affiliationID.isEmpty()){ }else if(affiliationID.isEmpty()){
Toast.makeText(myContext, myContext.getString(R.string.cannot_be_empty), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.cannot_be_empty, Toast.LENGTH_SHORT).show()
}else{ }else{
myDpm.setAffiliationIds(myComponent, affiliationID) myDpm.setAffiliationIds(myComponent, affiliationID)
affiliationID = myDpm.getAffiliationIds(myComponent) affiliationID = myDpm.getAffiliationIds(myComponent)
list = affiliationID.toText() list = affiliationID.toText()
Toast.makeText(myContext,myContext.getString(R.string.success),Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -411,7 +408,7 @@ private fun Username(){
Button( Button(
onClick = { onClick = {
myDpm.setProfileName(myComponent,inputUsername) myDpm.setProfileName(myComponent,inputUsername)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -469,7 +466,7 @@ private fun UserSessionMessage(){
onClick = { onClick = {
myDpm.setStartUserSessionMessage(myComponent,start) myDpm.setStartUserSessionMessage(myComponent,start)
myDpm.setEndUserSessionMessage(myComponent,end) myDpm.setEndUserSessionMessage(myComponent,end)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -480,7 +477,7 @@ private fun UserSessionMessage(){
onClick = { onClick = {
myDpm.setStartUserSessionMessage(myComponent,null) myDpm.setStartUserSessionMessage(myComponent,null)
myDpm.setEndUserSessionMessage(myComponent,null) myDpm.setEndUserSessionMessage(myComponent,null)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
}, },
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@@ -525,7 +522,7 @@ private fun UserIcon(){
uriToStream(myContext, userIconUri){stream -> uriToStream(myContext, userIconUri){stream ->
val bitmap = BitmapFactory.decodeStream(stream) val bitmap = BitmapFactory.decodeStream(stream)
myDpm.setUserIcon(myComponent,bitmap) myDpm.setUserIcon(myComponent,bitmap)
Toast.makeText(myContext, myContext.getString(R.string.success), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
} }
}, },
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()

View File

@@ -124,7 +124,7 @@ private fun Home(navCtrl:NavHostController,scrollState: ScrollState){
@Composable @Composable
private fun Internet(){ private fun Internet(){
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){ Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){
for(internetItem in RestrictionData().internet()){ for(internetItem in RestrictionData.internet()){
UserRestrictionItem(internetItem.restriction,internetItem.name,internetItem.desc,internetItem.ico) UserRestrictionItem(internetItem.restriction,internetItem.name,internetItem.desc,internetItem.ico)
} }
Spacer(Modifier.padding(vertical = 30.dp)) Spacer(Modifier.padding(vertical = 30.dp))
@@ -133,9 +133,8 @@ private fun Internet(){
@Composable @Composable
private fun Connectivity(){ private fun Connectivity(){
val myContext = LocalContext.current
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){ Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){
for(connectivityItem in RestrictionData().connectivity(myContext)){ for(connectivityItem in RestrictionData.connectivity()){
UserRestrictionItem(connectivityItem.restriction,connectivityItem.name,connectivityItem.desc,connectivityItem.ico) UserRestrictionItem(connectivityItem.restriction,connectivityItem.name,connectivityItem.desc,connectivityItem.ico)
} }
Spacer(Modifier.padding(vertical = 30.dp)) Spacer(Modifier.padding(vertical = 30.dp))
@@ -146,7 +145,7 @@ private fun Connectivity(){
fun Application(){ fun Application(){
val myContext = LocalContext.current val myContext = LocalContext.current
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){ Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){
for(applicationItem in RestrictionData().application(myContext)){ for(applicationItem in RestrictionData.application(myContext)){
UserRestrictionItem(applicationItem.restriction,applicationItem.name,applicationItem.desc,applicationItem.ico) UserRestrictionItem(applicationItem.restriction,applicationItem.name,applicationItem.desc,applicationItem.ico)
} }
Spacer(Modifier.padding(vertical = 30.dp)) Spacer(Modifier.padding(vertical = 30.dp))
@@ -156,7 +155,7 @@ fun Application(){
@Composable @Composable
private fun User(){ private fun User(){
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){ Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){
for(userItem in RestrictionData().user()){ for(userItem in RestrictionData.user()){
UserRestrictionItem(userItem.restriction,userItem.name,userItem.desc,userItem.ico) UserRestrictionItem(userItem.restriction,userItem.name,userItem.desc,userItem.ico)
} }
Spacer(Modifier.padding(vertical = 30.dp)) Spacer(Modifier.padding(vertical = 30.dp))
@@ -166,7 +165,7 @@ private fun User(){
@Composable @Composable
private fun Media(){ private fun Media(){
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){ Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){
for(mediaItem in RestrictionData().media()){ for(mediaItem in RestrictionData.media()){
UserRestrictionItem(mediaItem.restriction,mediaItem.name,mediaItem.desc,mediaItem.ico) UserRestrictionItem(mediaItem.restriction,mediaItem.name,mediaItem.desc,mediaItem.ico)
} }
Spacer(Modifier.padding(vertical = 30.dp)) Spacer(Modifier.padding(vertical = 30.dp))
@@ -177,7 +176,7 @@ private fun Media(){
private fun Other(){ private fun Other(){
val myContext = LocalContext.current val myContext = LocalContext.current
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){ Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())){
for(otherItem in RestrictionData().other(myContext)){ for(otherItem in RestrictionData.other(myContext)){
UserRestrictionItem(otherItem.restriction,otherItem.name,otherItem.desc,otherItem.ico) UserRestrictionItem(otherItem.restriction,otherItem.name,otherItem.desc,otherItem.ico)
} }
Spacer(Modifier.padding(vertical = 30.dp)) Spacer(Modifier.padding(vertical = 30.dp))
@@ -206,7 +205,7 @@ private fun UserRestrictionItem(
} }
}catch(e:SecurityException){ }catch(e:SecurityException){
if(isProfileOwner(myDpm)){ if(isProfileOwner(myDpm)){
Toast.makeText(myContext, myContext.getString(R.string.require_device_owner), Toast.LENGTH_SHORT).show() Toast.makeText(myContext, R.string.require_device_owner, Toast.LENGTH_SHORT).show()
} }
} }
}, },
@@ -214,7 +213,7 @@ private fun UserRestrictionItem(
) )
} }
private class RestrictionData{ private object RestrictionData{
fun internet():List<Restriction>{ fun internet():List<Restriction>{
val list:MutableList<Restriction> = mutableListOf() val list:MutableList<Restriction> = mutableListOf()
list += Restriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, R.string.config_mobile_network,"",R.drawable.signal_cellular_alt_fill0) list += Restriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, R.string.config_mobile_network,"",R.drawable.signal_cellular_alt_fill0)
@@ -241,7 +240,7 @@ private class RestrictionData{
list += Restriction(UserManager.DISALLOW_OUTGOING_CALLS,R.string.outgoing_calls,"",R.drawable.phone_forwarded_fill0) list += Restriction(UserManager.DISALLOW_OUTGOING_CALLS,R.string.outgoing_calls,"",R.drawable.phone_forwarded_fill0)
return list return list
} }
fun connectivity(myContext:Context):List<Restriction>{ fun connectivity():List<Restriction>{
val list:MutableList<Restriction> = mutableListOf() val list:MutableList<Restriction> = mutableListOf()
if(VERSION.SDK_INT>=26){ if(VERSION.SDK_INT>=26){
list += Restriction(UserManager.DISALLOW_BLUETOOTH,R.string.bluetooth,"",R.drawable.bluetooth_fill0) list += Restriction(UserManager.DISALLOW_BLUETOOTH,R.string.bluetooth,"",R.drawable.bluetooth_fill0)

View File

@@ -168,7 +168,8 @@ fun TopBar(
} }
@Composable @Composable
fun CopyTextButton(context: Context, @StringRes label: Int, content: String){ fun CopyTextButton(@StringRes label: Int, content: String){
val context = LocalContext.current
var ok by remember{mutableStateOf(false)} var ok by remember{mutableStateOf(false)}
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
Button( Button(
@@ -176,7 +177,7 @@ fun CopyTextButton(context: Context, @StringRes label: Int, content: String){
if(!ok){ if(!ok){
scope.launch{ scope.launch{
if(writeClipBoard(context,content)){ ok = true; delay(2000); ok = false } if(writeClipBoard(context,content)){ ok = true; delay(2000); ok = false }
else{ Toast.makeText(context,context.getString(R.string.fail),Toast.LENGTH_SHORT).show() } else{ Toast.makeText(context, R.string.fail, Toast.LENGTH_SHORT).show() }
} }
} }
} }