Skip to content

Commit

Permalink
[Finder] Add new filter: freeze-unfreeze
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
  • Loading branch information
MuntashirAkon committed Nov 20, 2024
1 parent 626d250 commit 9bd5fef
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public TestResult setMatchedPermissions(List<String> matchedPermissions) {
return this;
}

@Nullable
public List<String> getMatchedPermissions() {
return mMatchedPermissions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put(KEY_ALL, TYPE_NONE);
put("frozen", TYPE_NONE);
put("unfrozen", TYPE_NONE);
put("with_flags", TYPE_INT_FLAGS);
}};

private final Map<Integer, CharSequence> mFrozenFlags = new LinkedHashMap<Integer, CharSequence>() {{
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<String, Integer> getKeysWithType() {
return mKeysWithType;
}

@Override
public Map<Integer, CharSequence> 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);
}
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
<item>components</item>
<item>data_size</item>
<item>data_usage</item>
<item>freeze-unfreeze</item>
<item>installed</item>
<item>installer</item>
<item>last_update</item>
Expand Down

0 comments on commit 9bd5fef

Please sign in to comment.