From 9bd5fef7fee951b11ff786011caf7f1b7cfb09e2 Mon Sep 17 00:00:00 2001 From: Muntashir Al-Islam Date: Wed, 20 Nov 2024 15:31:13 -0800 Subject: [PATCH] [Finder] Add new filter: freeze-unfreeze Signed-off-by: Muntashir Al-Islam --- .../AppManager/filters/FilterableAppInfo.java | 15 ++++ .../filters/options/FilterOption.java | 1 + .../filters/options/FilterOptions.java | 1 + .../filters/options/FreezeOption.java | 70 +++++++++++++++++++ app/src/main/res/values/arrays.xml | 1 + 5 files changed, 88 insertions(+) create mode 100644 app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FreezeOption.java diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/filters/FilterableAppInfo.java b/app/src/main/java/io/github/muntashirakon/AppManager/filters/FilterableAppInfo.java index daaeb062506..dded789853d 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/filters/FilterableAppInfo.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/filters/FilterableAppInfo.java @@ -44,6 +44,7 @@ import io.github.muntashirakon.AppManager.db.entity.Backup; import io.github.muntashirakon.AppManager.debloat.DebloatObject; import io.github.muntashirakon.AppManager.filters.options.ComponentsOption; +import io.github.muntashirakon.AppManager.filters.options.FreezeOption; import io.github.muntashirakon.AppManager.rules.compontents.ComponentUtils; import io.github.muntashirakon.AppManager.ssaid.SsaidSettings; import io.github.muntashirakon.AppManager.types.PackageSizeInfo; @@ -262,6 +263,20 @@ public boolean isFrozen() { return !isEnabled() || isSuspended() || isHidden(); } + public int getFreezeFlags() { + int flags = 0; + if (!isEnabled()) { + flags |= FreezeOption.FREEZE_TYPE_DISABLED; + } + if (isHidden()) { + flags |= FreezeOption.FREEZE_TYPE_HIDDEN; + } + if (isSuspended()) { + flags |= FreezeOption.FREEZE_TYPE_SUSPENDED; + } + return flags; + } + public boolean isStopped() { return ApplicationInfoCompat.isStopped(mApplicationInfo); } diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java b/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java index 0a9d1f764b7..d2e823ea120 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java @@ -215,6 +215,7 @@ public TestResult setMatchedPermissions(List matchedPermissions) { return this; } + @Nullable public List getMatchedPermissions() { return mMatchedPermissions; } diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOptions.java b/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOptions.java index 72eccfb0aae..4aa2cc3020f 100644 --- a/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOptions.java +++ b/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOptions.java @@ -16,6 +16,7 @@ public static FilterOption create(@NonNull String filterName) { case "components": return new ComponentsOption(); case "data_size": return new DataSizeOption(); case "data_usage": return new DataUsageOption(); + case "freeze-unfreeze": return new FreezeOption(); case "installed": return new InstalledOption(); case "installer": return new InstallerOption(); case "last_update": return new LastUpdateOption(); diff --git a/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FreezeOption.java b/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FreezeOption.java new file mode 100644 index 00000000000..b8b5ca7651a --- /dev/null +++ b/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FreezeOption.java @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package io.github.muntashirakon.AppManager.filters.options; + +import android.os.Build; + +import androidx.annotation.NonNull; + +import java.util.LinkedHashMap; +import java.util.Map; + +import io.github.muntashirakon.AppManager.filters.FilterableAppInfo; + +public class FreezeOption extends FilterOption { + public static final int FREEZE_TYPE_DISABLED = 1 << 0; + public static final int FREEZE_TYPE_HIDDEN = 1 << 1; + public static final int FREEZE_TYPE_SUSPENDED = 1 << 2; + + private final Map mKeysWithType = new LinkedHashMap() {{ + put(KEY_ALL, TYPE_NONE); + put("frozen", TYPE_NONE); + put("unfrozen", TYPE_NONE); + put("with_flags", TYPE_INT_FLAGS); + }}; + + private final Map mFrozenFlags = new LinkedHashMap() {{ + put(FREEZE_TYPE_DISABLED, "Disabled"); + put(FREEZE_TYPE_HIDDEN, "Hidden"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + put(FREEZE_TYPE_SUSPENDED, "Suspended"); + } + }}; + + public FreezeOption() { + super("freeze-unfreeze"); + } + + @NonNull + @Override + public Map getKeysWithType() { + return mKeysWithType; + } + + @Override + public Map getFlags(@NonNull String key) { + if (key.equals("with_flags")) { + return mFrozenFlags; + } + return super.getFlags(key); + } + + @NonNull + @Override + public TestResult test(@NonNull FilterableAppInfo info, @NonNull TestResult result) { + int freezeFlags = info.getFreezeFlags(); + switch (key) { + default: + return result.setMatched(true); + case "frozen": { + return result.setMatched(freezeFlags != 0); + } + case "unfrozen": { + return result.setMatched(freezeFlags == 0); + } + case "with_flags": { + return result.setMatched((freezeFlags & intValue) == intValue); + } + } + } +} diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 22b581e3063..11cfad13c5b 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -249,6 +249,7 @@ components data_size data_usage + freeze-unfreeze installed installer last_update