Skip to content

Commit

Permalink
add more permission to permission manage
Browse files Browse the repository at this point in the history
update activation status when failed to use Dhizuku in Dhizuku mode
  • Loading branch information
BinTianqi committed Aug 8, 2024
1 parent cd26c2a commit 8f93c85
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 39 deletions.
9 changes: 7 additions & 2 deletions app/src/main/java/com/bintianqi/owndroid/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -181,14 +182,18 @@ private fun HomePage(navCtrl:NavHostController, pkgName: MutableState<String>) {
val dpm = context.getDPM()
val receiver = context.getReceiver()
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
var activateType = if(sharedPref.getBoolean("dhizuku", false)) stringResource(R.string.dhizuku) + " - " else ""
activateType += stringResource(
val refreshStatus by dhizukuErrorStatus.collectAsState()
var activateType by remember { mutableStateOf("") }
LaunchedEffect(refreshStatus) {
activateType = if(sharedPref.getBoolean("dhizuku", false)) context.getString(R.string.dhizuku) + " - " else ""
activateType += context.getString(
if(context.isDeviceOwner) { R.string.device_owner }
else if(context.isProfileOwner) {
if(VERSION.SDK_INT >= 24 && dpm.isManagedProfile(receiver)) R.string.work_profile_owner else R.string.profile_owner
}
else if(context.isDeviceAdmin) R.string.device_admin else R.string.click_to_activate
)
}
LaunchedEffect(Unit) { pkgName.value = "" }
Column(modifier = Modifier.background(colorScheme.background).statusBarsPadding().verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 25.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ private fun PermissionManage(pkgName: String) {
val dpm = context.getDPM()
val receiver = context.getReceiver()
var showDialog by remember { mutableStateOf(false) }
var selectedPermission by remember { mutableStateOf(PermissionPickerItem("", R.string.unknown, R.drawable.block_fill0)) }
var selectedPermission by remember { mutableStateOf(PermissionItem("", R.string.unknown, R.drawable.block_fill0)) }
val statusMap = remember { mutableStateMapOf<String, Int>() }
val profileOwner = context.isProfileOwner
val grantState = mapOf(
PERMISSION_GRANT_STATE_DEFAULT to stringResource(R.string.default_stringres),
PERMISSION_GRANT_STATE_GRANTED to stringResource(R.string.granted),
Expand All @@ -417,9 +418,11 @@ private fun PermissionManage(pkgName: String) {
LaunchedEffect(pkgName) {
if(pkgName != "") {
permissionList().forEach { statusMap[it.permission] = dpm.getPermissionGrantState(receiver, pkgName, it.permission) }
} else {
statusMap.clear()
}
}
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 4.dp))
for(permission in permissionList()) {
Row(
Expand All @@ -432,7 +435,7 @@ private fun PermissionManage(pkgName: String) {
showDialog = true
}
}
.padding(top = 8.dp, bottom = 8.dp, end = 8.dp)
.padding(8.dp)
) {
Icon(
painter = painterResource(permission.icon),
Expand Down Expand Up @@ -487,7 +490,9 @@ private fun PermissionManage(pkgName: String) {
Column {
Text(selectedPermission.permission)
Spacer(Modifier.padding(vertical = 4.dp))
GrantPermissionItem(R.string.grant, PERMISSION_GRANT_STATE_GRANTED)
if(!(VERSION.SDK_INT >=31 && profileOwner && selectedPermission.profileOwnerRestricted)) {
GrantPermissionItem(R.string.grant, PERMISSION_GRANT_STATE_GRANTED)
}
GrantPermissionItem(R.string.deny, PERMISSION_GRANT_STATE_DENIED)
GrantPermissionItem(R.string.default_stringres, PERMISSION_GRANT_STATE_DEFAULT)
}
Expand Down
78 changes: 48 additions & 30 deletions app/src/main/java/com/bintianqi/owndroid/dpm/DPM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,48 +231,66 @@ fun Context.resetDevicePolicy() {
}


data class PermissionPickerItem(
data class PermissionItem(
val permission: String,
@StringRes val label: Int,
@DrawableRes val icon: Int
@DrawableRes val icon: Int,
val profileOwnerRestricted: Boolean = false
)

fun permissionList(): List<PermissionPickerItem>{
val list = mutableListOf<PermissionPickerItem>()
list.add(PermissionPickerItem(Manifest.permission.READ_EXTERNAL_STORAGE, R.string.permission_READ_EXTERNAL_STORAGE, R.drawable.folder_fill0))
list.add(PermissionPickerItem(Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_WRITE_EXTERNAL_STORAGE, R.drawable.folder_fill0))
fun permissionList(): List<PermissionItem>{
val list = mutableListOf<PermissionItem>()
if(VERSION.SDK_INT >= 33) {
list.add(PermissionPickerItem(Manifest.permission.READ_MEDIA_AUDIO, R.string.permission_READ_MEDIA_AUDIO, R.drawable.music_note_fill0))
list.add(PermissionPickerItem(Manifest.permission.READ_MEDIA_VIDEO, R.string.permission_READ_MEDIA_VIDEO, R.drawable.movie_fill0))
list.add(PermissionPickerItem(Manifest.permission.READ_MEDIA_IMAGES, R.string.permission_READ_MEDIA_IMAGES, R.drawable.image_fill0))
list.add(PermissionItem(Manifest.permission.POST_NOTIFICATIONS, R.string.permission_POST_NOTIFICATIONS, R.drawable.notifications_fill0))
}
list.add(PermissionPickerItem(Manifest.permission.CAMERA, R.string.permission_CAMERA, R.drawable.photo_camera_fill0))
list.add(PermissionPickerItem(Manifest.permission.RECORD_AUDIO, R.string.permission_RECORD_AUDIO, R.drawable.mic_fill0))
list.add(PermissionPickerItem(Manifest.permission.ACCESS_COARSE_LOCATION, R.string.permission_ACCESS_COARSE_LOCATION, R.drawable.location_on_fill0))
list.add(PermissionPickerItem(Manifest.permission.ACCESS_FINE_LOCATION, R.string.permission_ACCESS_FINE_LOCATION, R.drawable.location_on_fill0))
list.add(PermissionItem(Manifest.permission.READ_EXTERNAL_STORAGE, R.string.permission_READ_EXTERNAL_STORAGE, R.drawable.folder_fill0))
list.add(PermissionItem(Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_WRITE_EXTERNAL_STORAGE, R.drawable.folder_fill0))
if(VERSION.SDK_INT >= 33) {
list.add(PermissionItem(Manifest.permission.READ_MEDIA_AUDIO, R.string.permission_READ_MEDIA_AUDIO, R.drawable.music_note_fill0))
list.add(PermissionItem(Manifest.permission.READ_MEDIA_VIDEO, R.string.permission_READ_MEDIA_VIDEO, R.drawable.movie_fill0))
list.add(PermissionItem(Manifest.permission.READ_MEDIA_IMAGES, R.string.permission_READ_MEDIA_IMAGES, R.drawable.image_fill0))
}
list.add(PermissionItem(Manifest.permission.CAMERA, R.string.permission_CAMERA, R.drawable.photo_camera_fill0, true))
list.add(PermissionItem(Manifest.permission.RECORD_AUDIO, R.string.permission_RECORD_AUDIO, R.drawable.mic_fill0, true))
list.add(PermissionItem(Manifest.permission.ACCESS_COARSE_LOCATION, R.string.permission_ACCESS_COARSE_LOCATION, R.drawable.location_on_fill0, true))
list.add(PermissionItem(Manifest.permission.ACCESS_FINE_LOCATION, R.string.permission_ACCESS_FINE_LOCATION, R.drawable.location_on_fill0, true))
if(VERSION.SDK_INT >= 29) {
list.add(PermissionPickerItem(Manifest.permission.ACCESS_BACKGROUND_LOCATION, R.string.permission_ACCESS_BACKGROUND_LOCATION, R.drawable.location_on_fill0))
list.add(PermissionItem(Manifest.permission.ACCESS_BACKGROUND_LOCATION, R.string.permission_ACCESS_BACKGROUND_LOCATION, R.drawable.location_on_fill0, true))
}
list.add(PermissionItem(Manifest.permission.READ_CONTACTS, R.string.permission_READ_CONTACTS, R.drawable.contacts_fill0))
list.add(PermissionItem(Manifest.permission.WRITE_CONTACTS, R.string.permission_WRITE_CONTACTS, R.drawable.contacts_fill0))
list.add(PermissionItem(Manifest.permission.READ_CALENDAR, R.string.permission_READ_CALENDAR, R.drawable.calendar_month_fill0))
list.add(PermissionItem(Manifest.permission.WRITE_CALENDAR, R.string.permission_WRITE_CALENDAR, R.drawable.calendar_month_fill0))
if(VERSION.SDK_INT >= 31) {
list.add(PermissionItem(Manifest.permission.BLUETOOTH_CONNECT, R.string.permission_BLUETOOTH_CONNECT, R.drawable.bluetooth_fill0))
list.add(PermissionItem(Manifest.permission.BLUETOOTH_SCAN, R.string.permission_BLUETOOTH_SCAN, R.drawable.bluetooth_searching_fill0))
list.add(PermissionItem(Manifest.permission.BLUETOOTH_ADVERTISE, R.string.permission_BLUETOOTH_ADVERTISE, R.drawable.bluetooth_fill0))
}
list.add(PermissionPickerItem(Manifest.permission.READ_CONTACTS, R.string.permission_READ_CONTACTS, R.drawable.contacts_fill0))
list.add(PermissionPickerItem(Manifest.permission.WRITE_CONTACTS, R.string.permission_WRITE_CONTACTS, R.drawable.contacts_fill0))
list.add(PermissionPickerItem(Manifest.permission.READ_CALENDAR, R.string.permission_READ_CALENDAR, R.drawable.calendar_month_fill0))
list.add(PermissionPickerItem(Manifest.permission.WRITE_CALENDAR, R.string.permission_WRITE_CALENDAR, R.drawable.calendar_month_fill0))
list.add(PermissionPickerItem(Manifest.permission.CALL_PHONE, R.string.permission_CALL_PHONE, R.drawable.call_fill0))
list.add(PermissionPickerItem(Manifest.permission.READ_PHONE_STATE, R.string.permission_READ_PHONE_STATE, R.drawable.mobile_phone_fill0))
list.add(PermissionPickerItem(Manifest.permission.READ_SMS, R.string.permission_READ_SMS, R.drawable.sms_fill0))
list.add(PermissionPickerItem(Manifest.permission.RECEIVE_SMS, R.string.permission_RECEIVE_SMS, R.drawable.sms_fill0))
list.add(PermissionPickerItem(Manifest.permission.SEND_SMS, R.string.permission_SEND_SMS, R.drawable.sms_fill0))
list.add(PermissionPickerItem(Manifest.permission.READ_CALL_LOG, R.string.permission_READ_CALL_LOG, R.drawable.call_log_fill0))
list.add(PermissionPickerItem(Manifest.permission.WRITE_CALL_LOG, R.string.permission_WRITE_CALL_LOG, R.drawable.call_log_fill0))
list.add(PermissionPickerItem(Manifest.permission.BODY_SENSORS, R.string.permission_BODY_SENSORS, R.drawable.sensors_fill0))
if(VERSION.SDK_INT >= 33) {
list.add(PermissionPickerItem(Manifest.permission.BODY_SENSORS_BACKGROUND, R.string.permission_BODY_SENSORS_BACKGROUND, R.drawable.sensors_fill0))
list.add(PermissionItem(Manifest.permission.NEARBY_WIFI_DEVICES, R.string.permission_NEARBY_WIFI_DEVICES, R.drawable.wifi_fill0))
}
if(VERSION.SDK_INT > 29) {
list.add(PermissionPickerItem(Manifest.permission.ACTIVITY_RECOGNITION, R.string.permission_ACTIVITY_RECOGNITION, R.drawable.history_fill0))
list.add(PermissionItem(Manifest.permission.CALL_PHONE, R.string.permission_CALL_PHONE, R.drawable.call_fill0))
if(VERSION.SDK_INT >= 26) {
list.add(PermissionItem(Manifest.permission.ANSWER_PHONE_CALLS, R.string.permission_ANSWER_PHONE_CALLS, R.drawable.call_fill0))
list.add(PermissionItem(Manifest.permission.READ_PHONE_NUMBERS, R.string.permission_READ_PHONE_STATE, R.drawable.mobile_phone_fill0))
}
list.add(PermissionItem(Manifest.permission.READ_PHONE_STATE, R.string.permission_READ_PHONE_STATE, R.drawable.mobile_phone_fill0))
list.add(PermissionItem(Manifest.permission.USE_SIP, R.string.permission_USE_SIP, R.drawable.call_fill0))
if(VERSION.SDK_INT >= 31) {
list.add(PermissionItem(Manifest.permission.UWB_RANGING, R.string.permission_UWB_RANGING, R.drawable.cell_tower_fill0))
}
list.add(PermissionItem(Manifest.permission.READ_SMS, R.string.permission_READ_SMS, R.drawable.sms_fill0))
list.add(PermissionItem(Manifest.permission.RECEIVE_SMS, R.string.permission_RECEIVE_SMS, R.drawable.sms_fill0))
list.add(PermissionItem(Manifest.permission.SEND_SMS, R.string.permission_SEND_SMS, R.drawable.sms_fill0))
list.add(PermissionItem(Manifest.permission.READ_CALL_LOG, R.string.permission_READ_CALL_LOG, R.drawable.call_log_fill0))
list.add(PermissionItem(Manifest.permission.WRITE_CALL_LOG, R.string.permission_WRITE_CALL_LOG, R.drawable.call_log_fill0))
list.add(PermissionItem(Manifest.permission.RECEIVE_WAP_PUSH, R.string.permission_RECEIVE_WAP_PUSH, R.drawable.wifi_fill0))
list.add(PermissionItem(Manifest.permission.BODY_SENSORS, R.string.permission_BODY_SENSORS, R.drawable.sensors_fill0, true))
if(VERSION.SDK_INT >= 33) {
list.add(PermissionPickerItem(Manifest.permission.POST_NOTIFICATIONS, R.string.permission_POST_NOTIFICATIONS, R.drawable.notifications_fill0))
list.add(PermissionItem(Manifest.permission.BODY_SENSORS_BACKGROUND, R.string.permission_BODY_SENSORS_BACKGROUND, R.drawable.sensors_fill0))
}
if(VERSION.SDK_INT > 29) {
list.add(PermissionItem(Manifest.permission.ACTIVITY_RECOGNITION, R.string.permission_ACTIVITY_RECOGNITION, R.drawable.history_fill0, true))
}
return list
}
11 changes: 10 additions & 1 deletion app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@
<string name="automation_debug">Debug mode</string> <!--TODO-->

<!--AndroidPermission-->
<string name="permission_POST_NOTIFICATIONS">Bildirim gönder</string>
<string name="permission_READ_EXTERNAL_STORAGE">Harici depolamayı oku</string>
<string name="permission_WRITE_EXTERNAL_STORAGE">Harici depolamaya yaz</string>
<string name="permission_READ_MEDIA_AUDIO">Medya oku (ses)</string>
Expand All @@ -585,17 +586,25 @@
<string name="permission_ACCESS_COARSE_LOCATION">Yaklaşık konuma eriş</string>
<string name="permission_ACCESS_FINE_LOCATION">Kesin konuma eriş</string>
<string name="permission_ACCESS_BACKGROUND_LOCATION">Arka planda konuma eriş</string>
<string name="permission_BLUETOOTH_CONNECT">Bluetooth connect</string> <!--TODO-->
<string name="permission_BLUETOOTH_SCAN">Bluetooth scan</string> <!--TODO-->
<string name="permission_BLUETOOTH_ADVERTISE">Bluetooth advertise</string> <!--TODO-->
<string name="permission_NEARBY_WIFI_DEVICES">Nearby Wi-Fi devices</string> <!--TODO-->
<string name="permission_CALL_PHONE">Telefonla arama yap</string>
<string name="permission_ANSWER_PHONE_CALLS">Answer phone calls</string> <!--TODO-->
<string name="permission_READ_PHONE_NUMBERS">Read phone numbers</string> <!--TODO-->
<string name="permission_READ_PHONE_STATE">Telefon durumunu oku</string>
<string name="permission_USE_SIP">Use SIP</string> <!--TODO-->
<string name="permission_UWB_RANGING">UWB ranging</string> <!--TODO-->
<string name="permission_READ_SMS">SMS oku</string>
<string name="permission_RECEIVE_SMS">SMS al</string>
<string name="permission_SEND_SMS">SMS gönder</string>
<string name="permission_READ_CALL_LOG">Arama kaydını oku</string>
<string name="permission_WRITE_CALL_LOG">Arama kaydına yaz</string>
<string name="permission_RECEIVE_WAP_PUSH">Receive WAP push</string> <!--TODO-->
<string name="permission_BODY_SENSORS">Vücut sensörlerine eriş</string>
<string name="permission_BODY_SENSORS_BACKGROUND">Arka planda vücut sensörlerine eriş</string>
<string name="permission_ACTIVITY_RECOGNITION">Aktivite tanıma</string>
<string name="permission_POST_NOTIFICATIONS">Bildirim gönder</string>

<string name="version_name">Version name</string> <!--TODO-->
<string name="version_code">Version code</string> <!--TODO-->
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@
<string name="automation_debug">调试模式</string>

<!--AndroidPermission-->
<string name="permission_POST_NOTIFICATIONS">发送通知</string>
<string name="permission_READ_EXTERNAL_STORAGE">读取外部存储</string>
<string name="permission_WRITE_EXTERNAL_STORAGE">写入外部存储</string>
<string name="permission_READ_MEDIA_AUDIO">读取音频</string>
Expand All @@ -577,17 +578,25 @@
<string name="permission_ACCESS_COARSE_LOCATION">粗略位置</string>
<string name="permission_ACCESS_FINE_LOCATION">准确位置</string>
<string name="permission_ACCESS_BACKGROUND_LOCATION">后台获取位置</string>
<string name="permission_BLUETOOTH_CONNECT">蓝牙连接</string>
<string name="permission_BLUETOOTH_SCAN">蓝牙扫描</string>
<string name="permission_BLUETOOTH_ADVERTISE">使设备可被发现</string>
<string name="permission_NEARBY_WIFI_DEVICES">附近的Wi-Fi设备</string>
<string name="permission_CALL_PHONE">打电话</string>
<string name="permission_ANSWER_PHONE_CALLS">接电话</string>
<string name="permission_READ_PHONE_NUMBERS">读取手机号码</string>
<string name="permission_READ_PHONE_STATE">读取手机状态</string>
<string name="permission_USE_SIP">使用SIP</string>
<string name="permission_UWB_RANGING">超宽频</string>
<string name="permission_READ_SMS">读取短信</string>
<string name="permission_RECEIVE_SMS">接收短信</string>
<string name="permission_SEND_SMS">发送短信</string>
<string name="permission_READ_CALL_LOG">读取通话记录</string>
<string name="permission_WRITE_CALL_LOG">写入通话记录</string>
<string name="permission_RECEIVE_WAP_PUSH">接收WAP推送</string>
<string name="permission_BODY_SENSORS">身体传感器</string>
<string name="permission_BODY_SENSORS_BACKGROUND">后台使用身体传感器</string>
<string name="permission_ACTIVITY_RECOGNITION">查看使用情况</string>
<string name="permission_POST_NOTIFICATIONS">发送通知</string>

<string name="version_name">版本名</string>
<string name="version_code">版本号</string>
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@
<string name="automation_debug">Debug mode</string>

<!--AndroidPermission-->
<string name="permission_POST_NOTIFICATIONS">Post notifications</string>
<string name="permission_READ_EXTERNAL_STORAGE">Read external storage</string>
<string name="permission_WRITE_EXTERNAL_STORAGE">Write external storage</string>
<string name="permission_READ_MEDIA_AUDIO">Read media (audio)</string>
Expand All @@ -591,17 +592,25 @@
<string name="permission_ACCESS_COARSE_LOCATION">Access coarse location</string>
<string name="permission_ACCESS_FINE_LOCATION">Access fine location</string>
<string name="permission_ACCESS_BACKGROUND_LOCATION">Access location in background</string>
<string name="permission_BLUETOOTH_CONNECT">Bluetooth connect</string>
<string name="permission_BLUETOOTH_SCAN">Bluetooth scan</string>
<string name="permission_BLUETOOTH_ADVERTISE">Bluetooth advertise</string>
<string name="permission_NEARBY_WIFI_DEVICES">Nearby Wi-Fi devices</string>
<string name="permission_CALL_PHONE">Call phone</string>
<string name="permission_ANSWER_PHONE_CALLS">Answer phone calls</string>
<string name="permission_READ_PHONE_NUMBERS">Read phone numbers</string>
<string name="permission_READ_PHONE_STATE">Read phone state</string>
<string name="permission_USE_SIP">Use SIP</string>
<string name="permission_UWB_RANGING">UWB ranging</string>
<string name="permission_READ_SMS">Read SMS</string>
<string name="permission_RECEIVE_SMS">Receive SMS</string>
<string name="permission_SEND_SMS">Send SMS</string>
<string name="permission_READ_CALL_LOG">Read call log</string>
<string name="permission_WRITE_CALL_LOG">Write call log</string>
<string name="permission_RECEIVE_WAP_PUSH">Receive WAP push</string>
<string name="permission_BODY_SENSORS">Access body sensors</string>
<string name="permission_BODY_SENSORS_BACKGROUND">Access body sensors in background</string>
<string name="permission_ACTIVITY_RECOGNITION">Activity recognition</string>
<string name="permission_POST_NOTIFICATIONS">Post notifications</string>

<string name="version_name">Version name</string>
<string name="version_code">Version code</string>
Expand Down

0 comments on commit 8f93c85

Please sign in to comment.