mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
fix creating managed profile problem
This commit is contained in:
@@ -76,7 +76,7 @@ fun ApplicationManage(){
|
|||||||
keyboardActions = KeyboardActions(onDone = {focusMgr.clearFocus()})
|
keyboardActions = KeyboardActions(onDone = {focusMgr.clearFocus()})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if(VERSION.SDK_INT>=24){
|
if(VERSION.SDK_INT>=24&&isDeviceOwner(myDpm)){
|
||||||
val isSuspended: Boolean = try{ myDpm.isPackageSuspended(myComponent,pkgName) }
|
val isSuspended: Boolean = try{ myDpm.isPackageSuspended(myComponent,pkgName) }
|
||||||
catch(e:NameNotFoundException){ false }
|
catch(e:NameNotFoundException){ false }
|
||||||
catch(w:NameNotFoundException){ false }
|
catch(w:NameNotFoundException){ false }
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ fun DeviceControl(){
|
|||||||
{myDpm.isStatusBarDisabled},{b -> myDpm.setStatusBarDisabled(myComponent,b) }
|
{myDpm.isStatusBarDisabled},{b -> myDpm.setStatusBarDisabled(myComponent,b) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if(VERSION.SDK_INT>=30&&isDeviceOwner(myDpm)){
|
if(isDeviceOwner(myDpm)){
|
||||||
|
if(VERSION.SDK_INT>=30){
|
||||||
DeviceCtrlItem(R.string.auto_time,R.string.place_holder,R.drawable.schedule_fill0,
|
DeviceCtrlItem(R.string.auto_time,R.string.place_holder,R.drawable.schedule_fill0,
|
||||||
{myDpm.getAutoTimeEnabled(myComponent)},{b -> myDpm.setAutoTimeEnabled(myComponent,b) }
|
{myDpm.getAutoTimeEnabled(myComponent)},{b -> myDpm.setAutoTimeEnabled(myComponent,b) }
|
||||||
)
|
)
|
||||||
@@ -68,6 +69,7 @@ fun DeviceControl(){
|
|||||||
}else{
|
}else{
|
||||||
DeviceCtrlItem(R.string.auto_time,R.string.place_holder,R.drawable.schedule_fill0,{myDpm.autoTimeRequired},{b -> myDpm.setAutoTimeRequired(myComponent,b)})
|
DeviceCtrlItem(R.string.auto_time,R.string.place_holder,R.drawable.schedule_fill0,{myDpm.autoTimeRequired},{b -> myDpm.setAutoTimeRequired(myComponent,b)})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
|
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
|
||||||
DeviceCtrlItem(R.string.master_mute,R.string.place_holder,R.drawable.volume_up_fill0,
|
DeviceCtrlItem(R.string.master_mute,R.string.place_holder,R.drawable.volume_up_fill0,
|
||||||
{myDpm.isMasterVolumeMuted(myComponent)},{b -> myDpm.setMasterVolumeMuted(myComponent,b) }
|
{myDpm.isMasterVolumeMuted(myComponent)},{b -> myDpm.setMasterVolumeMuted(myComponent,b) }
|
||||||
@@ -155,7 +157,8 @@ fun DeviceControl(){
|
|||||||
val result = myDpm.requestBugreport(myComponent)
|
val result = myDpm.requestBugreport(myComponent)
|
||||||
Toast.makeText(myContext, if(result){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show()
|
Toast.makeText(myContext, if(result){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show()
|
||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
enabled = isDeviceOwner(myDpm)
|
||||||
) {
|
) {
|
||||||
Text("请求错误报告")
|
Text("请求错误报告")
|
||||||
}
|
}
|
||||||
@@ -488,10 +491,12 @@ fun DeviceControl(){
|
|||||||
var confirmed by remember{ mutableStateOf(false) }
|
var confirmed by remember{ mutableStateOf(false) }
|
||||||
Text(text = "清除数据",style = typography.titleLarge,modifier = Modifier.padding(6.dp),color = colorScheme.onErrorContainer)
|
Text(text = "清除数据",style = typography.titleLarge,modifier = Modifier.padding(6.dp),color = colorScheme.onErrorContainer)
|
||||||
RadioButtonItem("默认",{flag==0},{flag=0}, colorScheme.onErrorContainer)
|
RadioButtonItem("默认",{flag==0},{flag=0}, colorScheme.onErrorContainer)
|
||||||
RadioButtonItem("WIPE_EXTERNAL_STORAGE",{flag==0x0001},{flag=0x0001}, colorScheme.onErrorContainer)
|
RadioButtonItem("WIPE_EXTERNAL_STORAGE",{flag==WIPE_EXTERNAL_STORAGE},{flag=WIPE_EXTERNAL_STORAGE}, colorScheme.onErrorContainer)
|
||||||
RadioButtonItem("WIPE_RESET_PROTECTION_DATA",{flag==0x0002},{flag=0x0002}, colorScheme.onErrorContainer)
|
if(VERSION.SDK_INT>=22){
|
||||||
RadioButtonItem("WIPE_EUICC",{flag==0x0004},{flag=0x0004}, colorScheme.onErrorContainer)
|
RadioButtonItem("WIPE_RESET_PROTECTION_DATA",{flag==WIPE_RESET_PROTECTION_DATA},{flag=WIPE_RESET_PROTECTION_DATA}, colorScheme.onErrorContainer)
|
||||||
RadioButtonItem("WIPE_SILENTLY",{flag==0x0008},{flag=0x0008}, colorScheme.onErrorContainer)
|
}
|
||||||
|
if(VERSION.SDK_INT>=28){ RadioButtonItem("WIPE_EUICC",{flag==WIPE_EUICC},{flag=WIPE_EUICC}, colorScheme.onErrorContainer) }
|
||||||
|
if(VERSION.SDK_INT>=29){ RadioButtonItem("WIPE_SILENTLY",{flag==WIPE_SILENTLY},{flag=WIPE_SILENTLY}, colorScheme.onErrorContainer) }
|
||||||
Text(text = "清空数据的不能是系统用户",color = colorScheme.onErrorContainer,
|
Text(text = "清空数据的不能是系统用户",color = colorScheme.onErrorContainer,
|
||||||
style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium})
|
style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium})
|
||||||
Button(
|
Button(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.binbin.androidowner
|
package com.binbin.androidowner
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Activity
|
||||||
import android.app.admin.DevicePolicyManager
|
import android.app.admin.DevicePolicyManager
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -45,6 +46,7 @@ import java.io.IOException
|
|||||||
|
|
||||||
lateinit var getCaCert: ActivityResultLauncher<Intent>
|
lateinit var getCaCert: ActivityResultLauncher<Intent>
|
||||||
lateinit var createUser:ActivityResultLauncher<Intent>
|
lateinit var createUser:ActivityResultLauncher<Intent>
|
||||||
|
lateinit var createManagedProfile:ActivityResultLauncher<Intent>
|
||||||
var caCert = byteArrayOf()
|
var caCert = byteArrayOf()
|
||||||
|
|
||||||
@ExperimentalMaterial3Api
|
@ExperimentalMaterial3Api
|
||||||
@@ -69,11 +71,17 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
createUser = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
createUser = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
when(it.resultCode){
|
when(it.resultCode){
|
||||||
UserManager.USER_CREATION_FAILED_NO_MORE_USERS->Toast.makeText(applicationContext, "用户太多了", Toast.LENGTH_SHORT).show();
|
UserManager.USER_CREATION_FAILED_NO_MORE_USERS->Toast.makeText(applicationContext, "用户太多了", Toast.LENGTH_SHORT).show()
|
||||||
UserManager.USER_CREATION_FAILED_NOT_PERMITTED->Toast.makeText(applicationContext, "不是管理员用户", Toast.LENGTH_SHORT).show();
|
UserManager.USER_CREATION_FAILED_NOT_PERMITTED->Toast.makeText(applicationContext, "不是管理员用户", Toast.LENGTH_SHORT).show()
|
||||||
else->Toast.makeText(applicationContext, "成功", Toast.LENGTH_SHORT).show()
|
else->Toast.makeText(applicationContext, "成功", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
createManagedProfile = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
|
when(it.resultCode){
|
||||||
|
Activity.RESULT_OK->Toast.makeText(applicationContext, "创建成功", Toast.LENGTH_SHORT).show()
|
||||||
|
Activity.RESULT_CANCELED->Toast.makeText(applicationContext, "用户已取消", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
setContent {
|
setContent {
|
||||||
AndroidOwnerTheme {
|
AndroidOwnerTheme {
|
||||||
MyScaffold()
|
MyScaffold()
|
||||||
@@ -168,7 +176,11 @@ fun HomePage(navCtrl:NavHostController){
|
|||||||
val myContext = LocalContext.current
|
val myContext = LocalContext.current
|
||||||
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||||
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
|
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
|
||||||
val activateType = if(isDeviceOwner(myDpm)){"Device Owner"}else if(isProfileOwner(myDpm)){"Profile Owner"}else if(myDpm.isAdminActive(myComponent)){"Device Admin"}else{""}
|
val activateType =
|
||||||
|
if(isDeviceOwner(myDpm)){"Device Owner"}
|
||||||
|
else if(isProfileOwner(myDpm)){if(VERSION.SDK_INT>=24&&myDpm.isManagedProfile(myComponent)){"工作资料"}else{"Profile Owner"}}
|
||||||
|
else if(myDpm.isAdminActive(myComponent)){"Device Admin"}
|
||||||
|
else{""}
|
||||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||||
val isWear = sharedPref.getBoolean("isWear",false)
|
val isWear = sharedPref.getBoolean("isWear",false)
|
||||||
caCert = byteArrayOf()
|
caCert = byteArrayOf()
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ fun Network(){
|
|||||||
{myDpm.isPreferentialNetworkServiceEnabled},{b -> myDpm.isPreferentialNetworkServiceEnabled = b}
|
{myDpm.isPreferentialNetworkServiceEnabled},{b -> myDpm.isPreferentialNetworkServiceEnabled = b}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if(VERSION.SDK_INT>=30){
|
if(VERSION.SDK_INT>=30&&isDeviceOwner(myDpm)){
|
||||||
DeviceCtrlItem(R.string.wifi_lockdown,R.string.place_holder,R.drawable.wifi_password_fill0,
|
DeviceCtrlItem(R.string.wifi_lockdown,R.string.place_holder,R.drawable.wifi_password_fill0,
|
||||||
{myDpm.hasLockdownAdminConfiguredNetworks(myComponent)},{b -> myDpm.setConfiguredNetworksLockdownState(myComponent,b)}
|
{myDpm.hasLockdownAdminConfiguredNetworks(myComponent)},{b -> myDpm.setConfiguredNetworksLockdownState(myComponent,b)}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -177,9 +177,6 @@ fun DpmPermissions(navCtrl:NavHostController){
|
|||||||
Text(text = "设备信息", style = typography.titleLarge,color = titleColor)
|
Text(text = "设备信息", style = typography.titleLarge,color = titleColor)
|
||||||
val orgDevice = myDpm.isOrganizationOwnedDeviceWithManagedProfile
|
val orgDevice = myDpm.isOrganizationOwnedDeviceWithManagedProfile
|
||||||
Text("由组织拥有的受管理资料设备:$orgDevice",style=bodyTextStyle)
|
Text("由组织拥有的受管理资料设备:$orgDevice",style=bodyTextStyle)
|
||||||
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
|
|
||||||
Text("Managed profile: ${myDpm.isManagedProfile(myComponent)}",style=bodyTextStyle)
|
|
||||||
}
|
|
||||||
if(VERSION.SDK_INT>=34&&(isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&myDpm.isOrganizationOwnedDeviceWithManagedProfile))){
|
if(VERSION.SDK_INT>=34&&(isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&myDpm.isOrganizationOwnedDeviceWithManagedProfile))){
|
||||||
val financed = myDpm.isDeviceFinanced
|
val financed = myDpm.isDeviceFinanced
|
||||||
Text("企业资产 : $financed",style=bodyTextStyle)
|
Text("企业资产 : $financed",style=bodyTextStyle)
|
||||||
|
|||||||
@@ -194,28 +194,39 @@ fun UserManage(navCtrl:NavHostController){
|
|||||||
|
|
||||||
Column(modifier = sections()) {
|
Column(modifier = sections()) {
|
||||||
Text(text = "工作资料", style = typography.titleLarge)
|
Text(text = "工作资料", style = typography.titleLarge)
|
||||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween){
|
if(VERSION.SDK_INT>=24){Text(text = "可以创建工作资料:${myDpm.isProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE)}", style = bodyTextStyle)}
|
||||||
|
if(isDeviceOwner(myDpm)){Text(text = "Device owner不能创建工作资料", style = bodyTextStyle)}
|
||||||
|
if(VERSION.SDK_INT<24||(VERSION.SDK_INT>=24&&myDpm.isProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE))){
|
||||||
|
var skipEncrypt by remember{mutableStateOf(false)}
|
||||||
|
if(VERSION.SDK_INT>=24){CheckBoxItem("跳过加密",{skipEncrypt},{skipEncrypt=!skipEncrypt})}
|
||||||
Button(
|
Button(
|
||||||
onClick = { createWorkProfile(myContext)},
|
onClick = {
|
||||||
modifier = Modifier.fillMaxWidth(0.49F)
|
val intent = Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE)
|
||||||
|
if(VERSION.SDK_INT>=23){
|
||||||
|
intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,myComponent)
|
||||||
|
}else{
|
||||||
|
intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,"com.binbin.androidowner")
|
||||||
|
}
|
||||||
|
if(VERSION.SDK_INT>=24){intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION,skipEncrypt)}
|
||||||
|
if(VERSION.SDK_INT>=33){intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_ALLOW_OFFLINE,true)}
|
||||||
|
createManagedProfile.launch(intent)
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text("创建")
|
Text("创建")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(isProfileOwner(myDpm)){
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
try{
|
|
||||||
myDpm.setProfileEnabled(myComponent)
|
myDpm.setProfileEnabled(myComponent)
|
||||||
}catch(e:SecurityException){
|
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||||
Toast.makeText(myContext, "失败", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
enabled = isProfileOwner(myDpm)||isDeviceOwner(myDpm),
|
modifier = Modifier.fillMaxWidth()
|
||||||
modifier = Modifier.fillMaxWidth(0.96F)
|
|
||||||
) {
|
) {
|
||||||
Text(text = "启用")
|
Text(text = "启用")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text("可能无法创建工作资料",style = bodyTextStyle)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(VERSION.SDK_INT>=24){
|
if(VERSION.SDK_INT>=24){
|
||||||
|
|||||||
Reference in New Issue
Block a user