Skip to content

Commit

Permalink
fix config show when some app be disable
Browse files Browse the repository at this point in the history
  • Loading branch information
iamr0s committed May 5, 2023
1 parent baddbae commit 6764ab1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
applicationId = "com.rosan.dhizuku"
minSdk = 21
targetSdk = 33
versionCode = 5
versionName = "2.2"
versionCode = 6
versionName = "2.3"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ class ConfigViewModel(
val map = mutableMapOf<Int, ConfigViewState.Data>()
apps.forEach {
val packageName = packageManager.getPackagesForUid(it.uid)?.first()
map[it.uid] = if (packageName != null) {
val packageInfo = packageManager.getPackageInfo(packageName, 0)
val packageInfo = kotlin.runCatching {
packageName?.let {
packageManager.getPackageInfo(
it,
0
)
}
}.getOrNull()
map[it.uid] = if (packageInfo != null) {
val applicationInfo = packageInfo.applicationInfo
val uid = applicationInfo.uid
ConfigViewState.Data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.app.admin.DevicePolicyManager
import android.content.*
import android.net.Uri
import android.os.Build
import android.text.method.LinkMovementMethod
import android.widget.TextView
import androidx.compose.animation.AnimatedContent
Expand Down Expand Up @@ -137,7 +138,7 @@ fun ShizukuButton() {
command(
"dpm",
"set-device-owner",
"${context.packageName}/${DhizukuDAReceiver::class.qualifiedName}"
DhizukuDAReceiver.name.flattenToShortString()
)
}
console = letConsole
Expand Down Expand Up @@ -209,7 +210,7 @@ fun ADBButton() {
mutableStateOf(false)
}
val command =
"adb shell dpm set-device-owner ${context.packageName}/${DhizukuDAReceiver::class.qualifiedName}"
"adb shell dpm set-device-owner ${DhizukuDAReceiver.name.flattenToShortString()}"

Button(onClick = {
showDialog = true
Expand Down Expand Up @@ -264,6 +265,11 @@ fun DeactivateButton() {
val e = runCatching {
val manager =
context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
runCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
manager.clearProfileOwner(DhizukuDAReceiver.name)
}
}
manager.clearDeviceOwnerApp(context.packageName)
}.exceptionOrNull()
context.toast(if (e == null) R.string.deactivate_success else R.string.deactivate_failed)
Expand Down

0 comments on commit 6764ab1

Please sign in to comment.