DivestOS/Patches/LineageOS-21.0/android_packages_apps_Settings/0018-disable_apps.patch
Tavi 26f1ce99a9
21.0: more work
packages/apps/Settings done

Signed-off-by: Tavi <tavi@divested.dev>
2024-05-20 14:13:53 -04:00

99 lines
4.4 KiB
Diff

From 4a4a7301a534fa2c54f12c9f93a3832105b36967 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 void onDestroy() {
}
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 void onClick(View v) {
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 @@ void updateUninstallButton() {
}
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 @@ private void refreshAndFinishIfPossible(boolean removeTaskWhenFinishing) {
@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 @@ void updateForceStopButton() {
@VisibleForTesting
void updateForceStopButtonInner(boolean enabled) {
+ mButtonsPref.setButton3Visible(true);
if (mAppsControlDisallowedBySystem) {
mButtonsPref.setButton3Enabled(false);
} else {
@@ -530,6 +566,7 @@ void uninstallPkg(String packageName, boolean allUsers) {
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);