Merge pull request #95 from esensar/feature/disable-uninstall-of-system-apps

Hide uninstall button for system apps
This commit is contained in:
Tibor Kaputa 2023-07-27 15:54:08 +02:00 committed by GitHub
commit d331d70131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -584,7 +584,7 @@ class MainActivity : SimpleActivity(), FlingListener {
menu.findItem(R.id.hide_icon).isVisible = gridItem.type == ITEM_TYPE_ICON && isOnAllAppsFragment
menu.findItem(R.id.resize).isVisible = gridItem.type == ITEM_TYPE_WIDGET
menu.findItem(R.id.app_info).isVisible = gridItem.type == ITEM_TYPE_ICON
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON && isUninstallable(gridItem.packageName)
menu.findItem(R.id.remove).isVisible = !isOnAllAppsFragment
setOnMenuItemClickListener { item ->
resetFragmentTouches()

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.launcher.extensions
import android.app.Activity
import android.content.ComponentName
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.net.Uri
import android.provider.Settings
import com.simplemobiletools.commons.extensions.showErrorToast
@ -41,6 +42,14 @@ fun Activity.launchAppInfo(packageName: String) {
}
}
fun Activity.isUninstallable(packageName: String): Boolean {
return try {
(packageManager.getApplicationInfo(packageName, 0).flags and ApplicationInfo.FLAG_SYSTEM) == 0
} catch (ignored: Exception) {
false
}
}
fun Activity.uninstallApp(packageName: String) {
Intent(Intent.ACTION_DELETE).apply {
data = Uri.fromParts("package", packageName, null)