diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt index 0987ca5..c15c440 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt @@ -84,6 +84,7 @@ fun ApplicationManage(navCtrl:NavHostController, pkgName: MutableState, ) val clearAppDataDialog = remember { mutableStateOf(false) } val defaultDialerAppDialog = remember { mutableStateOf(false) } + val enableSystemAppDialog = remember { mutableStateOf(false) } Scaffold( topBar = { TopBar(backStackEntry, navCtrl, localNavCtrl) { @@ -119,7 +120,9 @@ fun ApplicationManage(navCtrl:NavHostController, pkgName: MutableState, popEnterTransition = Animations.navHostPopEnterTransition, popExitTransition = Animations.navHostPopExitTransition ) { - composable(route = "Home") { Home(localNavCtrl, pkgName.value, dialogStatus, clearAppDataDialog, defaultDialerAppDialog) } + composable(route = "Home") { + Home(localNavCtrl, pkgName.value, dialogStatus, clearAppDataDialog, defaultDialerAppDialog, enableSystemAppDialog) + } composable(route = "UserControlDisabled") { UserCtrlDisabledPkg(pkgName.value) } composable(route = "PermissionManage") { PermissionManage(pkgName.value, navCtrl) } composable(route = "CrossProfilePackage") { CrossProfilePkg(pkgName.value) } @@ -143,6 +146,9 @@ fun ApplicationManage(navCtrl:NavHostController, pkgName: MutableState, if(defaultDialerAppDialog.value) { DefaultDialerAppDialog(defaultDialerAppDialog, pkgName.value) } + if(enableSystemAppDialog.value) { + EnableSystemAppDialog(enableSystemAppDialog, pkgName.value) + } } @Composable @@ -151,7 +157,8 @@ private fun Home( pkgName: String, dialogStatus: MutableIntState, clearAppDataDialog: MutableState, - defaultDialerAppDialog: MutableState + defaultDialerAppDialog: MutableState, + enableSystemAppDialog: MutableState ) { Column( modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()) @@ -255,6 +262,9 @@ private fun Home( if(isDeviceOwner(dpm)||isProfileOwner(dpm)) { SubPageItem(R.string.permitted_ime, "", R.drawable.keyboard_fill0) { navCtrl.navigate("IME") } } + if(isDeviceOwner(dpm) || isProfileOwner(dpm)) { + SubPageItem(R.string.enable_system_app, "", R.drawable.enable_fill0) { enableSystemAppDialog.value = true } + } if(VERSION.SDK_INT>=28&&isDeviceOwner(dpm)) { SubPageItem(R.string.keep_uninstalled_packages, "", R.drawable.delete_fill0) { navCtrl.navigate("KeepUninstalled") } } @@ -932,9 +942,7 @@ private fun ClearAppDataDialog(status: MutableState, pkgName: String) { val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager val receiver = ComponentName(context,Receiver::class.java) AlertDialog( - title = { - Text(text = stringResource(R.string.clear_app_storage)) - }, + title = { Text(text = stringResource(R.string.clear_app_storage)) }, text = { Text(stringResource(R.string.app_storage_will_be_cleared) + "\n" + pkgName) }, @@ -977,9 +985,7 @@ private fun DefaultDialerAppDialog(status: MutableState, pkgName: Strin val context = LocalContext.current val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager AlertDialog( - title = { - Text(stringResource(R.string.set_default_dialer)) - }, + title = { Text(stringResource(R.string.set_default_dialer)) }, text = { Text(stringResource(R.string.app_will_be_default_dialer) + "\n" + pkgName) }, @@ -1008,6 +1014,41 @@ private fun DefaultDialerAppDialog(status: MutableState, pkgName: Strin ) } +@Composable +private fun EnableSystemAppDialog(status: MutableState, pkgName: String) { + val context = LocalContext.current + val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager + val receiver = ComponentName(context,Receiver::class.java) + AlertDialog( + title = { Text(stringResource(R.string.enable_system_app)) }, + text = { + Text(stringResource(R.string.enable_system_app_desc) + "\n" + pkgName) + }, + onDismissRequest = { status.value = false }, + dismissButton = { + TextButton(onClick = { status.value = false }) { + Text(stringResource(R.string.cancel)) + } + }, + confirmButton = { + TextButton( + onClick = { + try { + dpm.enableSystemApp(receiver, pkgName) + Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show() + } catch(e: IllegalArgumentException) { + Toast.makeText(context, R.string.fail, Toast.LENGTH_SHORT).show() + } + status.value = false + } + ) { + Text(stringResource(R.string.confirm)) + } + }, + modifier = Modifier.fillMaxWidth() + ) +} + @Composable private fun AppControlDialog(status: MutableIntState) { val enabled = dialogGetStatus() diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt index 9154a99..caca350 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt @@ -105,6 +105,7 @@ import com.bintianqi.owndroid.ui.TopBar import com.bintianqi.owndroid.uriToStream import java.util.Date import java.util.TimeZone +import java.util.concurrent.Executors @Composable fun SystemManage(navCtrl:NavHostController) { @@ -1121,8 +1122,9 @@ fun InstallSystemUpdate() { AnimatedVisibility(uri != Uri.parse("")) { Button( onClick = { + val executor = Executors.newCachedThreadPool() try { - dpm.installSystemUpdate(receiver, uri, { it.run() }, callback) + dpm.installSystemUpdate(receiver, uri, executor, callback) Toast.makeText(context, R.string.start_install_system_update, Toast.LENGTH_SHORT).show() }catch(e: Exception) { Toast.makeText( diff --git a/app/src/main/res/drawable/enable_fill0.xml b/app/src/main/res/drawable/enable_fill0.xml new file mode 100644 index 0000000..7254632 --- /dev/null +++ b/app/src/main/res/drawable/enable_fill0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 2f2a161..13573e3 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -304,6 +304,8 @@ 选择APK... 静默安装 请求安装 + 启用系统应用 + 重新启用一个默认被禁用的系统应用 应用安装器: 等待用户操作 被阻止 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7fd91d1..1491013 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -289,6 +289,8 @@ App info Not installed Block uninstall + Enable system app + Re-enable a system app that was disabled by default Disable user control If you set this, you cannot clear these apps\' storage or force stop them.