Skip to content

Commit

Permalink
Create managed user: select mutiple flags
Browse files Browse the repository at this point in the history
Fix App manager TopAppBar color
Optimize some strings
Create managed profile: Offline provisioning and Migrate account
  • Loading branch information
BinTianqi committed Oct 2, 2024
1 parent 0788634 commit 36609d6
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 57 deletions.
4 changes: 1 addition & 3 deletions Readme-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

### Description

Use Device admin and Device owner privilege to take full control of your device.

This app is renamed to "OwnDroid" from "Android Owner".
Use Device admin and Device owner privilege to take full control of your device.

### Docs

Expand Down
2 changes: 0 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

使用安卓的Device Admin和Device Owner特权,完全掌控你的设备。

这个APP已经改名为"OwnDroid",原名"Android Owner"

### 文档

全新的OwnDroid文档:[owndroid.pages.dev](https://owndroid.pages.dev/zh_CN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableIntState
Expand Down Expand Up @@ -131,7 +132,8 @@ fun ApplicationManage(navCtrl:NavHostController, dialogStatus: MutableIntState)
singleLine = true
)
},
navigationIcon = { NavIcon { navCtrl.navigateUp() } }
navigationIcon = { NavIcon { navCtrl.navigateUp() } },
colors = TopAppBarDefaults.topAppBarColors(containerColor = colorScheme.background)
)
}
) { paddingValues->
Expand Down
55 changes: 50 additions & 5 deletions app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.bintianqi.owndroid.dpm

import android.accounts.Account
import android.annotation.SuppressLint
import android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE
import android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE
import android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ALLOW_OFFLINE
import android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME
import android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME
import android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION
import android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION
import android.app.admin.DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT
import android.app.admin.DevicePolicyManager.FLAG_PARENT_CAN_ACCESS_MANAGED
Expand Down Expand Up @@ -43,6 +46,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -126,28 +131,68 @@ private fun Home(navCtrl: NavHostController) {
private fun CreateWorkProfile() {
val context = LocalContext.current
val receiver = context.getReceiver()
val focusMgr = LocalFocusManager.current
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.create_work_profile), style = typography.headlineLarge)
Spacer(Modifier.padding(vertical = 5.dp))
var skipEncrypt by remember { mutableStateOf(false) }
if(VERSION.SDK_INT>=24) {
var offlineProvisioning by remember { mutableStateOf(true) }
var migrateAccount by remember { mutableStateOf(false) }
var migrateAccountName by remember { mutableStateOf("") }
var migrateAccountType by remember { mutableStateOf("") }
var keepAccount by remember { mutableStateOf(true) }
if(VERSION.SDK_INT >= 22) {
CheckBoxItem(R.string.migrate_account, migrateAccount, { migrateAccount = it })
AnimatedVisibility(migrateAccount) {
val fr = FocusRequester()
Column(modifier = Modifier.padding(start = 10.dp)) {
OutlinedTextField(
value = migrateAccountName, onValueChange = { migrateAccountName = it },
label = { Text(stringResource(R.string.account_name)) },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
keyboardActions = KeyboardActions { fr.requestFocus() },
modifier = Modifier.fillMaxWidth()
)
OutlinedTextField(
value = migrateAccountType, onValueChange = { migrateAccountType = it },
label = { Text(stringResource(R.string.account_type)) },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions { focusMgr.clearFocus() },
modifier = Modifier.fillMaxWidth().focusRequester(fr)
)
if(VERSION.SDK_INT >= 26) {
CheckBoxItem(R.string.keep_account, keepAccount, { keepAccount = it })
}
}
}
}
if(VERSION.SDK_INT >= 24) {
CheckBoxItem(R.string.skip_encryption, skipEncrypt, { skipEncrypt = it })
}
if(VERSION.SDK_INT >= 33) {
CheckBoxItem(R.string.offline_provisioning, offlineProvisioning, { offlineProvisioning = it })
}
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = {
try {
val intent = Intent(ACTION_PROVISION_MANAGED_PROFILE)
if(VERSION.SDK_INT>=23) {
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,receiver)
}else{
} else {
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, context.packageName)
}
if(VERSION.SDK_INT>=24) { intent.putExtra(EXTRA_PROVISIONING_SKIP_ENCRYPTION,skipEncrypt) }
if(VERSION.SDK_INT>=33) { intent.putExtra(EXTRA_PROVISIONING_ALLOW_OFFLINE,true) }
if(migrateAccount && VERSION.SDK_INT >= 22) {
intent.putExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE, Account(migrateAccountName, migrateAccountType))
if(VERSION.SDK_INT >= 26) {
intent.putExtra(EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION, keepAccount)
}
}
if(VERSION.SDK_INT >= 24) { intent.putExtra(EXTRA_PROVISIONING_SKIP_ENCRYPTION, skipEncrypt) }
if(VERSION.SDK_INT >= 33) { intent.putExtra(EXTRA_PROVISIONING_ALLOW_OFFLINE, offlineProvisioning) }
createManagedProfile.launch(intent)
}catch(e:ActivityNotFoundException) {
} catch(e:ActivityNotFoundException) {
Toast.makeText(context, R.string.unsupported, Toast.LENGTH_SHORT).show()
}
},
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,11 @@ private fun MaxFailedPasswordForWipe() {
)
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = { focusMgr.clearFocus(); dpm.setMaximumFailedPasswordsForWipe(receiver,inputContent.toInt()) },
onClick = {
focusMgr.clearFocus()
dpm.setMaximumFailedPasswordsForWipe(receiver, inputContent.toInt())
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth(),
enabled = inputContent != ""
) {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,14 @@ fun DeviceInfo() {
)
if(VERSION.SDK_INT >= 23) { encryptionStatus[DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY] = stringResource(R.string.es_active_default_key) }
if(VERSION.SDK_INT >= 24) { encryptionStatus[DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER] = stringResource(R.string.es_active_per_user) }
Text(stringResource(R.string.encrypt_status_is)+encryptionStatus[dpm.storageEncryptionStatus])
Text(stringResource(R.string.encrypt_status_is, encryptionStatus[dpm.storageEncryptionStatus] ?: ""))
Spacer(Modifier.padding(vertical = 2.dp))
if(VERSION.SDK_INT >= 28) {
Text(stringResource(R.string.support_device_id_attestation) + dpm.isDeviceIdAttestationSupported)
Text(stringResource(R.string.support_device_id_attestation, dpm.isDeviceIdAttestationSupported))
}
Spacer(Modifier.padding(vertical = 2.dp))
if (VERSION.SDK_INT >= 30) {
Text(stringResource(R.string.support_unique_device_attestation) + dpm.isUniqueDeviceAttestationSupported)
Text(stringResource(R.string.support_unique_device_attestation, dpm.isUniqueDeviceAttestationSupported))
}
Spacer(Modifier.padding(vertical = 2.dp))
val adminList = dpm.activeAdmins
Expand Down Expand Up @@ -658,7 +658,7 @@ private fun DisableAccountManagement() {
OutlinedTextField(
value = inputText,
onValueChange = { inputText = it },
label = { Text(stringResource(R.string.account_types_are)) },
label = { Text(stringResource(R.string.account_type)) },
modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ fun FactoryResetProtection() {
AnimatedVisibility(usePolicy) {
Column {
CheckBoxItem(R.string.enable_frp, enabled, { enabled = it })
Text(stringResource(R.string.account_list_is))
Text(stringResource(R.string.account_list_is) + "\n")
Text(
text = if(accountList.isEmpty()) stringResource(R.string.none) else accountList.joinToString(separator = "\n"),
modifier = Modifier.animateContentSize()
Expand Down
26 changes: 12 additions & 14 deletions app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -66,9 +65,9 @@ import androidx.navigation.compose.rememberNavController
import com.bintianqi.owndroid.R
import com.bintianqi.owndroid.fileUriFlow
import com.bintianqi.owndroid.getFile
import com.bintianqi.owndroid.toggle
import com.bintianqi.owndroid.ui.Animations
import com.bintianqi.owndroid.ui.CheckBoxItem
import com.bintianqi.owndroid.ui.RadioButtonItem
import com.bintianqi.owndroid.ui.SubPageItem
import com.bintianqi.owndroid.ui.TopBar
import com.bintianqi.owndroid.uriToStream
Expand Down Expand Up @@ -290,6 +289,7 @@ private fun CreateUser() {
val receiver = context.getReceiver()
val focusMgr = LocalFocusManager.current
var userName by remember { mutableStateOf("") }
val flags = remember { mutableStateListOf<Int>() }
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.create_user), style = typography.headlineLarge)
Expand All @@ -303,31 +303,29 @@ private fun CreateUser() {
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() })
)
Spacer(Modifier.padding(vertical = 5.dp))
var selectedFlag by remember { mutableIntStateOf(0) }
RadioButtonItem(R.string.none, selectedFlag == 0, { selectedFlag = 0 })
RadioButtonItem(
CheckBoxItem(
R.string.create_user_skip_wizard,
selectedFlag == DevicePolicyManager.SKIP_SETUP_WIZARD,
{ selectedFlag = DevicePolicyManager.SKIP_SETUP_WIZARD }
DevicePolicyManager.SKIP_SETUP_WIZARD in flags,
{ flags.toggle(it, DevicePolicyManager.SKIP_SETUP_WIZARD) }
)
if(VERSION.SDK_INT >= 28) {
RadioButtonItem(
CheckBoxItem(
R.string.create_user_ephemeral_user,
selectedFlag == DevicePolicyManager.MAKE_USER_EPHEMERAL,
{ selectedFlag = DevicePolicyManager.MAKE_USER_EPHEMERAL }
DevicePolicyManager.MAKE_USER_EPHEMERAL in flags,
{ flags.toggle(it, DevicePolicyManager.MAKE_USER_EPHEMERAL) }
)
RadioButtonItem(
CheckBoxItem(
R.string.create_user_enable_all_system_app,
selectedFlag == DevicePolicyManager.LEAVE_ALL_SYSTEM_APPS_ENABLED,
{ selectedFlag = DevicePolicyManager.LEAVE_ALL_SYSTEM_APPS_ENABLED }
DevicePolicyManager.LEAVE_ALL_SYSTEM_APPS_ENABLED in flags,
{ flags.toggle(it, DevicePolicyManager.LEAVE_ALL_SYSTEM_APPS_ENABLED) }
)
}
var newUserHandle: UserHandle? by remember { mutableStateOf(null) }
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = {
newUserHandle = dpm.createAndManageUser(receiver, userName, receiver, null, selectedFlag)
focusMgr.clearFocus()
newUserHandle = dpm.createAndManageUser(receiver, userName, receiver, null, flags.sum())
Toast.makeText(context, if(newUserHandle!=null) R.string.success else R.string.failed, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.fillMaxWidth()
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
<string name="reset_device_policy">Reset device policy</string> <!--TODO-->
<string name="activate_device_admin">Cihaz Yöneticisini Etkinleştir</string>
<string name="device_info">Cihaz Bilgisi</string>
<string name="support_device_id_attestation">Cihaz Kimliği Doğrulama Desteği: </string>
<string name="support_unique_device_attestation">Benzersiz Cihaz Doğrulama Desteği: </string>
<string name="support_device_id_attestation">Cihaz Kimliği Doğrulama Desteği: %1$s</string>
<string name="support_unique_device_attestation">Benzersiz Cihaz Doğrulama Desteği: %1$s</string>
<string name="is_device_financed">Finansmanlı Cihaz: %1$s</string>
<string name="dpmrh">Cihaz Politikası Yönetim Rolü: %1$s</string>

Expand All @@ -81,15 +81,14 @@
<string name="enrollment_specific_id">Kayıt Özel Kimliği</string>
<string name="org_name">Organizasyon Adı</string>
<string name="disable_account_management">Hesap Yönetimini Devre Dışı Bırak</string>
<string name="account_types_are">Hesap Türleri: </string>
<string name="account_type">Hesap Türleri</string>
<string name="transfer_ownership">Sahipliği Devret</string>
<string name="transfer_ownership_desc">Cihaz sahibi veya profil sahibi ayrıcalığını başka bir uygulamaya devredin.</string>
<string name="target_package_name">Hedef Paket Adı</string>
<string name="target_class_name">Hedef Sınıf Adı</string>
<string name="device_owner_lock_screen_info">Ekran Kilidi Bilgisi</string>
<string name="support_msg">Destek Mesajı</string>
<string name="short_support_msg">Kısa Mesaj</string>
<string name="support_msg_desc">Bu uygulama tarafından devre dışı bırakılan işlevleri kullanmaya çalışan kullanıcılara destek mesajı gösterilir. (Çok satırlı izin verilir) </string>
<string name="long_support_msg">Uzun Mesaj</string>
<string name="transfer">Transfer</string>
<string name="activate_device_admin_here">Cihaz Yöneticisini Burada Etkinleştir.</string>
Expand Down Expand Up @@ -186,12 +185,12 @@
<string name="wipe_silently">Sessizce sil</string>
<string name="wipe_data_warning">All data on your device will be ERASED</string> <!--TODO-->
<string name="wipe_work_profile_warning">Your work profile will be DELETED</string> <!--TODO-->
<string name="encrypt_status_is">Şifreleme durumu: </string>
<string name="encrypt_status_is">Şifreleme durumu: %1$s</string>
<string name="frp_policy">FRP politikası</string>
<string name="factory_reset_protection_policy">Fabrika ayarlarına sıfırlama koruma politikası</string>
<string name="frp_policy_not_supported">FRP politikası bu cihazda desteklenmiyor</string>
<string name="enable_frp">FRP\'yi etkinleştir</string>
<string name="account_list_is">Hesap listesi: </string>
<string name="account_list_is">"Hesap listesi: "</string>

<!--SystemUpdatePolicy-->
<string name="is_security_patch">Güvenlik yaması: %1$s</string>
Expand All @@ -207,7 +206,7 @@
<string name="install_system_update">Sistem güncellemesini yükle</string>
<string name="select_ota_package" tools:ignore="TypographyEllipsis">OTA paketini seç...</string>
<string name="start_install_system_update">Sistem güncellemesi yüklemeye başla</string>
<string name="install_system_update_failed">Sistem güncellemesi yükleme başarısız: </string>
<string name="install_system_update_failed">"Sistem güncellemesi yükleme başarısız: "</string>
<string name="battery_low">Pil zayıf</string>
<string name="update_file_invalid">Güncelleme dosyası geçersiz</string>
<string name="incorrect_os_ver">Yanlış işletim sistemi sürümü</string>
Expand All @@ -221,7 +220,7 @@
<string name="preferential_network_service">Tercihli ağ hizmeti</string>
<string name="lockdown_admin_configured_network">Yönetici tarafından yapılandırılmış ağı kilitle</string>
<string name="wifi_ssid_policy">WiFi SSID politikası</string>
<string name="ssid_list_is">SSID listesi: </string>
<string name="ssid_list_is">SSID listesi:</string>
<string name="cannot_be_empty">Boş olamaz</string>
<string name="already_exist">Zaten mevcut</string>
<string name="private_dns">Özel DNS</string>
Expand Down Expand Up @@ -273,6 +272,10 @@
<string name="work_profile_owner">Profil sahibi (İş profili)</string>
<string name="work_profile_activated">İş profili etkinleştirildi</string>
<string name="create_work_profile">İş profili oluştur</string>
<string name="offline_provisioning">Offline mode</string> <!--TODO-->
<string name="migrate_account">Migrate account</string> <!--TODO-->
<string name="account_name">Account name</string> <!--TODO-->
<string name="keep_account">Keep account</string> <!--TODO-->
<string name="is_org_owned_profile">Kuruluşa ait iş profili: %1$s</string>
<string name="org_owned_work_profile">Kuruluş iş profili</string>
<string name="skip_encryption">Şifrelemeyi atla</string>
Expand Down Expand Up @@ -313,7 +316,7 @@
<!--ucd: user control disabled-->
<string name="ucd">Kullanıcı kontrolünü devre dışı bırak</string>
<string name="ucd_desc">Bunu ayarlarsanız, bu uygulamaların depolama alanını temizleyemez veya zorla durduramazsınız. </string>
<string name="app_list_is">Uygulama listesi: </string>
<string name="app_list_is">Uygulama listesi:</string>
<string name="clear_list">Listeyi temizle</string>
<string name="permission_manage">İzin yönetimi</string>
<string name="cross_profile_package">Profil geçişli paket</string>
Expand Down Expand Up @@ -463,7 +466,6 @@
<string name="affiliation_id">Bağlılık ID</string>
<string name="include_empty_string">Boş string dahil et</string>
<string name="change_user_icon">Kullanıcı simgesini değiştir</string>
<string name="pick_a_square_image">Kare bir resim seçmelisiniz</string>
<string name="file_picker_instead_gallery">Galeri yerine dosya seçici kullan</string>
<string name="select_picture" tools:ignore="TypographyEllipsis">Resim seç...</string>
<string name="unknown_result">Bilinmeyen sonuç (başarısız olabilir)</string>
Expand Down
Loading

0 comments on commit 36609d6

Please sign in to comment.