-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Finder] Add new filter: freeze-unfreeze
Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
- Loading branch information
1 parent
626d250
commit 9bd5fef
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FreezeOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters