From 8c40a5a716bb937072861f41e1a3ac3117114e66 Mon Sep 17 00:00:00 2001 From: BinTianqi Date: Wed, 14 Aug 2024 12:40:02 +0800 Subject: [PATCH] Fix a problem of Lock screen now Remove unused string resource --- .../java/com/bintianqi/owndroid/Receiver.kt | 1 - .../bintianqi/owndroid/dpm/ManagedProfile.kt | 4 +- .../com/bintianqi/owndroid/dpm/Permissions.kt | 16 ++--- .../bintianqi/owndroid/dpm/SystemManager.kt | 67 +++++++++++-------- app/src/main/res/values-tr/strings.xml | 15 ++--- app/src/main/res/values-zh-rCN/strings.xml | 9 +-- app/src/main/res/values/strings.xml | 13 ++-- 7 files changed, 61 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/com/bintianqi/owndroid/Receiver.kt b/app/src/main/java/com/bintianqi/owndroid/Receiver.kt index f284141..39b8970 100644 --- a/app/src/main/java/com/bintianqi/owndroid/Receiver.kt +++ b/app/src/main/java/com/bintianqi/owndroid/Receiver.kt @@ -40,7 +40,6 @@ class Receiver : DeviceAdminReceiver() { override fun onDisabled(context: Context, intent: Intent) { super.onDisabled(context, intent) context.toggleInstallAppActivity() - backToHomeStateFlow.value = true Toast.makeText(context, R.string.onDisabled, Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt index f730bdb..e14c1fe 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt @@ -300,7 +300,7 @@ private fun DeleteWorkProfile() { Spacer(Modifier.padding(vertical = 5.dp)) CheckBoxItem(R.string.wipe_external_storage, externalStorage, { externalStorage = it }) if(VERSION.SDK_INT >= 28) { CheckBoxItem(R.string.wipe_euicc, euicc, { euicc = it }) } - if(VERSION.SDK_INT >= 29) { CheckBoxItem(R.string.wipe_silently, silent, { silent = it }) } + CheckBoxItem(R.string.wipe_silently, silent, { silent = it }) AnimatedVisibility(!silent && VERSION.SDK_INT >= 28) { OutlinedTextField( value = reason, onValueChange = { reason = it }, @@ -312,6 +312,7 @@ private fun DeleteWorkProfile() { Button( onClick = { focusMgr.clearFocus() + silent = reason == "" warning = true }, colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError), @@ -337,7 +338,6 @@ private fun DeleteWorkProfile() { var flag = 0 if(externalStorage) { flag += WIPE_EXTERNAL_STORAGE } if(euicc && VERSION.SDK_INT >= 28) { flag += WIPE_EUICC } - if(silent && VERSION.SDK_INT >= 29) { flag += WIPE_SILENTLY } if(VERSION.SDK_INT >= 28 && !silent) { dpm.wipeData(flag, reason) } else { diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt index 1df9cd5..4a5aa1a 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt @@ -289,15 +289,13 @@ private fun ProfileOwner() { Text(text = stringResource(R.string.profile_owner), style = typography.headlineLarge) Text(stringResource(if(profileOwner) R.string.activated else R.string.deactivated), style = typography.titleLarge) Spacer(Modifier.padding(vertical = 5.dp)) - if(VERSION.SDK_INT >= 24) { - if(profileOwner) { - Button( - onClick = { deactivateDialog = true }, - enabled = !dpm.isManagedProfile(receiver), - colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError) - ) { - Text(stringResource(R.string.deactivate)) - } + if(VERSION.SDK_INT >= 24 && profileOwner) { + Button( + onClick = { deactivateDialog = true }, + enabled = !dpm.isManagedProfile(receiver), + colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError) + ) { + Text(stringResource(R.string.deactivate)) } } } 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 28496d6..66fe68d 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt @@ -246,6 +246,7 @@ private fun Switches() { val receiver = context.getReceiver() val deviceOwner = context.isDeviceOwner val profileOwner = context.isProfileOwner + val um = context.getSystemService(Context.USER_SERVICE) as UserManager Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(start = 20.dp, end = 16.dp)) { Spacer(Modifier.padding(vertical = 10.dp)) if(deviceOwner || profileOwner) { @@ -263,7 +264,7 @@ private fun Switches() { { dpm.isStatusBarDisabled}, { dpm.setStatusBarDisabled(receiver,it) }, padding = false ) } - if(deviceOwner || dpm.isOrgProfile(receiver)) { + if(deviceOwner || (VERSION.SDK_INT >= 23 && profileOwner && um.isSystemUser) || dpm.isOrgProfile(receiver)) { if(VERSION.SDK_INT >= 30) { SwitchItem(R.string.auto_time, "", R.drawable.schedule_fill0, { dpm.getAutoTimeEnabled(receiver) }, { dpm.setAutoTimeEnabled(receiver,it) }, padding = false @@ -285,7 +286,7 @@ private fun Switches() { { dpm.isBackupServiceEnabled(receiver) }, { dpm.setBackupServiceEnabled(receiver,it) }, padding = false ) } - if(VERSION.SDK_INT >= 23 && (deviceOwner || profileOwner)) { + if(VERSION.SDK_INT >= 24 && profileOwner && dpm.isManagedProfile(receiver)) { SwitchItem(R.string.disable_bt_contact_share, "", R.drawable.account_circle_fill0, { dpm.getBluetoothContactSharingDisabled(receiver) }, { dpm.setBluetoothContactSharingDisabled(receiver,it) }, padding = false ) @@ -323,42 +324,50 @@ private fun Keyguard() { Text(text = stringResource(R.string.keyguard), style = typography.headlineLarge) Spacer(Modifier.padding(vertical = 5.dp)) if(VERSION.SDK_INT >= 23) { - Button( - onClick = { - Toast.makeText(context, if(dpm.setKeyguardDisabled(receiver,true)) R.string.success else R.string.failed, Toast.LENGTH_SHORT).show() - }, - enabled = deviceOwner || (VERSION.SDK_INT >= 28 && profileOwner && dpm.isAffiliatedUser), - modifier = Modifier.fillMaxWidth() - ) { - Text(stringResource(R.string.disable)) - } - Button( - onClick = { - Toast.makeText(context, if(dpm.setKeyguardDisabled(receiver,false)) R.string.success else R.string.failed, Toast.LENGTH_SHORT).show() - }, - enabled = deviceOwner || (VERSION.SDK_INT >= 28 && profileOwner && dpm.isAffiliatedUser), + Row( + horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth() ) { - Text(stringResource(R.string.enable)) + Button( + onClick = { + Toast.makeText(context, if(dpm.setKeyguardDisabled(receiver,true)) R.string.success else R.string.failed, Toast.LENGTH_SHORT).show() + }, + enabled = deviceOwner || (VERSION.SDK_INT >= 28 && profileOwner && dpm.isAffiliatedUser), + modifier = Modifier.fillMaxWidth(0.49F) + ) { + Text(stringResource(R.string.disable)) + } + Button( + onClick = { + Toast.makeText(context, if(dpm.setKeyguardDisabled(receiver,false)) R.string.success else R.string.failed, Toast.LENGTH_SHORT).show() + }, + enabled = deviceOwner || (VERSION.SDK_INT >= 28 && profileOwner && dpm.isAffiliatedUser), + modifier = Modifier.fillMaxWidth(0.96F) + ) { + Text(stringResource(R.string.enable)) + } } - Spacer(Modifier.padding(vertical = 3.dp)) - Information{ Text(text = stringResource(R.string.require_no_password_to_disable)) } - Spacer(Modifier.padding(vertical = 8.dp)) + Spacer(Modifier.padding(vertical = 15.dp)) } + Text(text = stringResource(R.string.lock_now), style = typography.headlineLarge) + Spacer(Modifier.padding(vertical = 2.dp)) var flag by remember { mutableIntStateOf(0) } - Button( - onClick = { dpm.lockNow() }, - enabled = context.isDeviceAdmin, - modifier = Modifier.fillMaxWidth() - ) { - Text(stringResource(R.string.lock_now)) - } - if(VERSION.SDK_INT >= 26) { + if(VERSION.SDK_INT >= 26 && profileOwner && dpm.isManagedProfile(receiver)) { CheckBoxItem( R.string.evict_credential_encryptoon_key, flag == FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY, { flag = if(flag==0) {1}else{0} } ) + Spacer(Modifier.padding(vertical = 2.dp)) + } + Button( + onClick = { + if(VERSION.SDK_INT >= 26) dpm.lockNow(flag) else dpm.lockNow() + }, + enabled = context.isDeviceAdmin, + modifier = Modifier.fillMaxWidth() + ) { + Text(stringResource(R.string.lock_now)) } Spacer(Modifier.padding(vertical = 30.dp)) } @@ -919,7 +928,7 @@ private fun CaCert() { Text(text = uriPath) } Text( - text = if(uriPath == "") { stringResource(R.string.please_select_ca_cert) } else { stringResource(R.string.cacert_installed, exist) }, + text = if(uriPath == "") { stringResource(R.string.please_select_ca_cert) } else { stringResource(R.string.cert_installed, exist) }, modifier = Modifier.animateContentSize() ) Spacer(Modifier.padding(vertical = 5.dp)) diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 4c2c4d0..575e670 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -48,7 +48,6 @@ Kopyala Dosya Mevcut Değil G/Ç Hatası - Mevcut Durum: Başlat Stop Tümünü İzin Ver @@ -135,7 +134,6 @@ Ortak kriter modu USB sinyali Ekran kilidi - Ekran kilidini devre dışı bırakmak için parola ayarlanmamış olmalıdır Ekranı şimdi kilitle Kimlik doğrulama şifreleme anahtarını çıkar Hata raporu @@ -175,11 +173,11 @@ Küresel eylemlere izin ver Ekran kilidine izin ver Görevde etkinlik başlatmayı engelle - CA sertifikası - Lütfen bir sertifika seçin - Yüklenen sertifika: %1$s - Sertifika seç... - Tüm kullanıcı sertifikalarını kaldır + CA sertifikası + Lütfen bir sertifika seçin + Yüklenen sertifika: %1$s + Sertifika seç... + Tüm kullanıcı sertifikalarını kaldır Güvenlik kayıtları Yeniden başlatmadan önce güvenlik kayıtları Verileri sil @@ -303,7 +301,6 @@ Mevcut olmayan uygulamalar gizlidir Her zaman açık VPN Enable lockdown - Current app: Clear current config İzin Kapsam: iş profili @@ -468,7 +465,7 @@ Kullanıcı simgesini değiştir Kare bir resim seçmelisiniz Galeri yerine dosya seçici kullan - Resim seç... + Resim seç... Bilinmeyen sonuç (başarısız olabilir) Başarısız: yönetilen profil Başarısız: mevcut kullanıcı diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index bcf5583..8b4041d 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -45,7 +45,6 @@ 复制 文件不存在 IO异常 - 当前状态: 开始 停止 允许全部 @@ -130,7 +129,6 @@ 通用标准模式 USB信号 锁屏 - 禁用需要无密码 立即锁屏 移除凭证加密密钥 错误报告 @@ -170,9 +168,9 @@ 阻止启动未允许的应用 包名 不存在 - Ca证书 - 请选择Ca证书 - 证书已安装:%1$s + CA证书 + 请选择CA证书 + 证书已安装:%1$s 选择证书... 卸载所有用户证书 安全日志 @@ -298,7 +296,6 @@ 如果隐藏,有可能是没安装 VPN保持打开 启用锁定 - 当前应用: 清除当前配置 权限 作用域: 工作资料 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e5d0210..bf6f001 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,7 +48,6 @@ Copy File not exist IO Exception - Current status: Start Stop Allow all @@ -139,7 +138,6 @@ Common criteria mode USB signal Keyguard - Disable keyguard require no password is set. Lock screen now Evict credential encryption key Bug report @@ -178,11 +176,11 @@ Allow global actions Allow keyguard Block activity start in task - Ca certification - Please select a certification - Cert installed: %1$s - Select cert... - Uninstall all user cert + CA certificate + Please select a certificate + Certificate installed: %1$s + Select certificate... + Uninstall all user CA certificate Security logs Pre-reboot security logs Wipe data @@ -310,7 +308,6 @@ Non-existent apps is hidden Always-on VPN Enable lockdown - Current app: Clear current config Permission Scope: work profile