Skip to content

Commit

Permalink
[Finder] Add without_* for with_* keys
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Nov 21, 2024
1 parent fc973b4 commit c23f310
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class ApkSizeOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_SIZE_BYTES);
put("le", TYPE_SIZE_BYTES);
put("ge", TYPE_SIZE_BYTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class AppLabelOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_STR_SINGLE);
put("contains", TYPE_STR_SINGLE);
put("starts_with", TYPE_STR_SINGLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class BackupOption extends FilterOption {
put("made_before", TYPE_TIME_MILLIS);
put("made_after", TYPE_TIME_MILLIS);
put("with_flags", TYPE_INT_FLAGS);
put("without_flags", TYPE_INT_FLAGS);
}};

private final Map<Integer, CharSequence> mBackupFlags = new LinkedHashMap<Integer, CharSequence>() {{
Expand All @@ -56,7 +57,7 @@ public Map<String, Integer> getKeysWithType() {

@Override
public Map<Integer, CharSequence> getFlags(@NonNull String key) {
if (key.equals("with_flags")) {
if (key.equals("with_flags") || key.equals("without_flags")) {
return mBackupFlags;
}
return super.getFlags(key);
Expand Down Expand Up @@ -141,6 +142,16 @@ public TestResult test(@NonNull FilterableAppInfo info, @NonNull TestResult resu
return result.setMatched(!matchedBackups.isEmpty())
.setMatchedBackups(matchedBackups);
}
case "without_flags": {
List<Backup> matchedBackups = new ArrayList<>();
for (Backup backup : backups) {
if ((backup.flags & intValue) != intValue) {
matchedBackups.add(backup);
}
}
return result.setMatched(!matchedBackups.isEmpty())
.setMatchedBackups(matchedBackups);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Map<Integer, CharSequence> getFlags(@NonNull String key) {
public TestResult test(@NonNull FilterableAppInfo info, @NonNull TestResult result) {
DebloatObject object = info.getBloatwareInfo();
if (object == null) {
return result.setMatched(key.equals("all"));
return result.setMatched(key.equals(KEY_ALL));
}
switch (key) {
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class CacheSizeOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_SIZE_BYTES);
put("le", TYPE_SIZE_BYTES);
put("ge", TYPE_SIZE_BYTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ComponentsOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put(KEY_ALL, TYPE_NONE);
put("with_type", TYPE_INT_FLAGS);
put("without_type", TYPE_INT_FLAGS);
put("eq", TYPE_STR_SINGLE);
put("contains", TYPE_STR_SINGLE);
put("starts_with", TYPE_STR_SINGLE);
Expand Down Expand Up @@ -50,7 +51,7 @@ public Map<String, Integer> getKeysWithType() {

@Override
public Map<Integer, CharSequence> getFlags(@NonNull String key) {
if (key.equals("with_type")) {
if (key.equals("with_type") || key.equals("without_type")) {
return mComponentTypeFlags;
}
return super.getFlags(key);
Expand All @@ -76,6 +77,17 @@ public TestResult test(@NonNull FilterableAppInfo info, @NonNull TestResult resu
return result.setMatched(!filteredComponents.isEmpty())
.setMatchedComponents(filteredComponents);
}
case "without_type": {
Map<ComponentInfo, Integer> filteredComponents = new LinkedHashMap<>();
for (ComponentInfo component : components.keySet()) {
int type = Objects.requireNonNull(components.get(component));
if ((intValue & type) == 0) {
filteredComponents.put(component, type);
}
}
return result.setMatched(filteredComponents.size() == components.size())
.setMatchedComponents(filteredComponents);
}
case "eq": {
Map<ComponentInfo, Integer> filteredComponents = new LinkedHashMap<>();
for (ComponentInfo component : components.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class DataSizeOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_SIZE_BYTES);
put("le", TYPE_SIZE_BYTES);
put("ge", TYPE_SIZE_BYTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class DataUsageOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_SIZE_BYTES);
put("le", TYPE_SIZE_BYTES);
put("ge", TYPE_SIZE_BYTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class FreezeOption extends FilterOption {
put("frozen", TYPE_NONE);
put("unfrozen", TYPE_NONE);
put("with_flags", TYPE_INT_FLAGS);
put("without_flags", TYPE_INT_FLAGS);
}};

private final Map<Integer, CharSequence> mFrozenFlags = new LinkedHashMap<Integer, CharSequence>() {{
Expand All @@ -43,7 +44,7 @@ public Map<String, Integer> getKeysWithType() {

@Override
public Map<Integer, CharSequence> getFlags(@NonNull String key) {
if (key.equals("with_flags")) {
if (key.equals("with_flags") || key.equals("without_flags")) {
return mFrozenFlags;
}
return super.getFlags(key);
Expand All @@ -65,6 +66,9 @@ public TestResult test(@NonNull FilterableAppInfo info, @NonNull TestResult resu
case "with_flags": {
return result.setMatched((freezeFlags & intValue) == intValue);
}
case "without_flags": {
return result.setMatched((freezeFlags & intValue) != intValue);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class InstalledOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("installed", TYPE_NONE);
put("uninstalled", TYPE_NONE);
put("installed_before", TYPE_TIME_MILLIS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class InstallerOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("installer", TYPE_STR_SINGLE);
put("installers", TYPE_STR_MULTIPLE);
put("regex", TYPE_REGEX);
Expand Down Expand Up @@ -62,7 +62,7 @@ public TestResult test(@NonNull FilterableAppInfo info, @NonNull TestResult resu
}

@NonNull
private static Set<String> getInstallers(InstallSourceInfoCompat installSourceInfo) {
private static Set<String> getInstallers(@NonNull InstallSourceInfoCompat installSourceInfo) {
Set<String> installers = new LinkedHashSet<>();
if (installSourceInfo.getInstallingPackageName() != null) {
installers.add(installSourceInfo.getInstallingPackageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class LastUpdateOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("before", TYPE_TIME_MILLIS);
put("after", TYPE_TIME_MILLIS);
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class MinSdkOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
put("eq", TYPE_INT);
put("le", TYPE_INT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class PackageNameOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_STR_SINGLE);
put("contains", TYPE_STR_SINGLE);
put("starts_with", TYPE_STR_SINGLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class RunningAppsOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("running", TYPE_NONE);
put("not_running", TYPE_NONE);
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class ScreenTimeOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_DURATION_MILLIS);
put("le", TYPE_DURATION_MILLIS);
put("ge", TYPE_DURATION_MILLIS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

public class SignatureOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("no_signer", TYPE_NONE);
put("with_source_stamp", TYPE_NONE);
put("with_lineage", TYPE_NONE);
put("with_source_stamp", TYPE_NONE);
put("without_lineage", TYPE_NONE);
put("without_source_stamp", TYPE_NONE);
put("sub_eq", TYPE_STR_SINGLE);
put("sub_contains", TYPE_STR_SINGLE);
put("sub_starts_with", TYPE_STR_SINGLE);
Expand Down Expand Up @@ -59,6 +61,10 @@ public TestResult test(@NonNull FilterableAppInfo info, @NonNull TestResult resu
return result.setMatched(signerInfo.getSourceStampCert() != null).setMatchedSubjectLines(subjectLines);
case "with_lineage":
return result.setMatched(signerInfo.getSignerCertsInLineage() != null).setMatchedSubjectLines(subjectLines);
case "without_source_stamp":
return result.setMatched(signerInfo.getSourceStampCert() == null).setMatchedSubjectLines(subjectLines);
case "without_lineage":
return result.setMatched(signerInfo.getSignerCertsInLineage() == null).setMatchedSubjectLines(subjectLines);
case "sub_eq": {
List<String> matchedSubjectLines = new ArrayList<>();
for (String subject : subjectLines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class TargetSdkOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_INT);
put("le", TYPE_INT);
put("ge", TYPE_INT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class TimesOpenedOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_INT);
put("le", TYPE_INT);
put("ge", TYPE_INT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class TotalSizeOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_SIZE_BYTES);
put("le", TYPE_SIZE_BYTES);
put("ge", TYPE_SIZE_BYTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class TrackersOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_INT);
put("le", TYPE_INT);
put("ge", TYPE_INT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class VersionNameOption extends FilterOption {
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
put("all", TYPE_NONE);
put(KEY_ALL, TYPE_NONE);
put("eq", TYPE_STR_SINGLE);
put("contains", TYPE_STR_SINGLE);
put("starts_with", TYPE_STR_SINGLE);
Expand Down

0 comments on commit c23f310

Please sign in to comment.