DivestOS/Patches/LineageOS-21.0/android_packages_apps_Settings/0018-disable_apps.patch
Tavi 23a2127669
21.0: More work
Signed-off-by: Tavi <tavi@divested.dev>
2024-05-20 18:50:40 -04:00

99 lines
4.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dmitry Muhomor <muhomor.dmitry@gmail.com>
Date: Sun, 17 Apr 2022 18:00:53 +0300
Subject: [PATCH] add an ability to disable non-system apps from the "App info"
screen
---
.../AppButtonsPreferenceController.java | 41 ++++++++++++++++++-
1 file changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java b/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
index 03053fdeeb6..e0d2d2ee61c 100644
--- a/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java
@@ -205,6 +205,15 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
}
private class UninstallAndDisableButtonListener implements View.OnClickListener {
+ private boolean mChangeEnabledStateOfUserApp;
+
+ UninstallAndDisableButtonListener() {
+ this(false);
+ }
+
+ UninstallAndDisableButtonListener(boolean changeEnabledStateOfUserApp) {
+ mChangeEnabledStateOfUserApp = changeEnabledStateOfUserApp;
+ }
@Override
public void onClick(View v) {
@@ -236,8 +245,13 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
mUserId);
if (admin != null && !uninstallBlockedBySystem) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mActivity, admin);
- } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 || mChangeEnabledStateOfUserApp) {
if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
+ if (mChangeEnabledStateOfUserApp) {
+ handleDialogClick(ButtonActionDialogFragment.DialogType.DISABLE);
+ return;
+ }
+
showDialogInner(ButtonActionDialogFragment.DialogType.DISABLE);
} else {
mMetricsFeatureProvider.action(
@@ -468,6 +482,25 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
}
mButtonsPref.setButton2Enabled(enabled);
+
+ if (enabled && !isBundled) {
+ // "enabled" means "show uninstall button" in this context
+ int text;
+ int icon;
+ if (mAppEntry.info.enabled) {
+ text = R.string.disable_text;
+ icon = R.drawable.ic_settings_disable;
+ } else {
+ text = R.string.enable_text;
+ icon = R.drawable.ic_settings_enable;
+ }
+ mButtonsPref
+ .setButton4Text(text)
+ .setButton4Icon(icon)
+ .setButton4Visible(true)
+ .setButton4OnClickListener(new UninstallAndDisableButtonListener(true))
+ ;
+ }
}
/**
@@ -491,7 +524,9 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
@VisibleForTesting
void updateForceStopButton() {
- if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
+ if (!mPackageInfo.applicationInfo.enabled) {
+ mButtonsPref.setButton3Visible(false);
+ } else if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
// User can't force stop device admin.
Log.w(TAG, "User can't force stop device admin");
updateForceStopButtonInner(false /* enabled */);
@@ -516,6 +551,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
@VisibleForTesting
void updateForceStopButtonInner(boolean enabled) {
+ mButtonsPref.setButton3Visible(true);
if (mAppsControlDisallowedBySystem) {
mButtonsPref.setButton3Enabled(false);
} else {
@@ -530,6 +566,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
Uri packageUri = Uri.parse("package:" + packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers);
+ uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_SHOW_MORE_OPTIONS_BUTTON, false);
mMetricsFeatureProvider.action(mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP);
mFragment.startActivityForResult(uninstallIntent, mRequestUninstall);