Hide uninstall button for system apps

This commit is contained in:
Ensar Sarajčić 2023-07-27 13:59:56 +02:00
parent 8d6c839c15
commit 1e4e2571dd
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.hide_icon).isVisible = gridItem.type == ITEM_TYPE_ICON && isOnAllAppsFragment
menu.findItem(R.id.resize).isVisible = gridItem.type == ITEM_TYPE_WIDGET 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.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 menu.findItem(R.id.remove).isVisible = !isOnAllAppsFragment
setOnMenuItemClickListener { item -> setOnMenuItemClickListener { item ->
resetFragmentTouches() resetFragmentTouches()

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.launcher.extensions
import android.app.Activity import android.app.Activity
import android.content.ComponentName import android.content.ComponentName
import android.content.Intent import android.content.Intent
import android.content.pm.ApplicationInfo
import android.net.Uri import android.net.Uri
import android.provider.Settings import android.provider.Settings
import com.simplemobiletools.commons.extensions.showErrorToast 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) { fun Activity.uninstallApp(packageName: String) {
Intent(Intent.ACTION_DELETE).apply { Intent(Intent.ACTION_DELETE).apply {
data = Uri.fromParts("package", packageName, null) data = Uri.fromParts("package", packageName, null)