Skip to content

Commit

Permalink
feat: Re-authorization is required when uninstall app but keep data
Browse files Browse the repository at this point in the history
  • Loading branch information
iamr0s committed Oct 1, 2024
1 parent 39100ff commit d4cd734
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ fun PackageManager.getPackageNameForUid(uid: Int): String? =

fun PackageManager.getPackageInfoForUid(
uid: Int,
flags: Int = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) PackageManager.MATCH_UNINSTALLED_PACKAGES
else 0) or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) PackageManager.GET_SIGNING_CERTIFICATES
else PackageManager.GET_SIGNATURES)
flags: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) PackageManager.GET_SIGNING_CERTIFICATES
else PackageManager.GET_SIGNATURES
): PackageInfo? = kotlin.runCatching {
getPackageInfo(getPackageNameForUid(uid) ?: return null, flags)
}.getOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ class AppRepoImpl(
val packageNames = packageManager.getPackagesForUid(entity.uid) ?: emptyArray()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
packageNames.forEach {
devicePolicyManager.setDelegatedScopes(DhizukuState.component, it, emptyList())
kotlin.runCatching {
devicePolicyManager.setDelegatedScopes(
DhizukuState.component,
it,
emptyList()
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ class ActivateViewModel : ViewModel(), KoinComponent {
collectDataJob = viewModelScope.launch(Dispatchers.IO) {
// http://aospxref.com/android-14.0.0_r2/xref/packages/apps/Settings/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java#271

val flags =
(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) PackageManager.MATCH_UNINSTALLED_PACKAGES
else 0) or PackageManager.GET_META_DATA
val flags = PackageManager.GET_META_DATA

val data = packageManager.queryBroadcastReceivers(
Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.rosan.dhizuku.ui.page.settings.app_management

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -45,9 +44,7 @@ class AppManagementViewModel : ViewModel(), KoinComponent {
collectRepoJob?.cancel()
collectRepoJob = viewModelScope.launch(Dispatchers.IO) {
repo.flowAll().collect {
val flags =
(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) PackageManager.MATCH_UNINSTALLED_PACKAGES
else 0) or PackageManager.GET_META_DATA or PackageManager.GET_PERMISSIONS
val flags = PackageManager.GET_META_DATA or PackageManager.GET_PERMISSIONS
val data = packageManager
.getInstalledPackages(flags)
.mapNotNull { packageInfo ->
Expand Down

0 comments on commit d4cd734

Please sign in to comment.