Skip to content

Commit 5aed36f

Browse files
committed
Filters: rename shared_uid to uid
Allow any UID-based filtering, not just shared UID-based filtering. Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
1 parent 6dbf22b commit 5aed36f

7 files changed

Lines changed: 110 additions & 82 deletions

File tree

app/src/main/java/io/github/muntashirakon/AppManager/filters/FilterableAppInfo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public int getUserId() {
126126
return mUserId;
127127
}
128128

129+
@Override
130+
public int getUid() {
131+
return mApplicationInfo.uid;
132+
}
133+
129134
@Override
130135
@NonNull
131136
public String getAppLabel() {

app/src/main/java/io/github/muntashirakon/AppManager/filters/IFilterableAppInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public interface IFilterableAppInfo {
2727

2828
int getUserId();
2929

30+
int getUid();
31+
3032
@NonNull
3133
String getAppLabel();
3234

app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public static FilterOption create(@NonNull String filterName) {
2727
case "pkg_name": return new PackageNameOption();
2828
case "running_apps": return new RunningAppsOption();
2929
case "screen_time": return new ScreenTimeOption();
30-
case "shared_uid": return new SharedUidOption();
3130
case "signature": return new SignatureOption();
3231
case "target_sdk": return new TargetSdkOption();
3332
case "times_opened": return new TimesOpenedOption();
3433
case "total_size": return new TotalSizeOption();
3534
case "trackers": return new TrackersOption();
35+
case "uid": return new UidOption();
3636
case "version_name": return new VersionNameOption();
3737
}
3838
throw new IllegalArgumentException("Invalid filter: " + filterName);

app/src/main/java/io/github/muntashirakon/AppManager/filters/options/SharedUidOption.java

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
package io.github.muntashirakon.AppManager.filters.options;
4+
5+
import android.content.Context;
6+
import android.text.SpannableStringBuilder;
7+
8+
import androidx.annotation.NonNull;
9+
10+
import java.util.LinkedHashMap;
11+
import java.util.Map;
12+
import java.util.Objects;
13+
14+
import io.github.muntashirakon.AppManager.filters.IFilterableAppInfo;
15+
import io.github.muntashirakon.AppManager.utils.ArrayUtils;
16+
import io.github.muntashirakon.AppManager.utils.LangUtils;
17+
18+
public class UidOption extends FilterOption {
19+
private final Map<String, Integer> mKeysWithType = new LinkedHashMap<String, Integer>() {{
20+
put(KEY_ALL, TYPE_NONE);
21+
put("uid_eq", TYPE_INT);
22+
put("uid_le", TYPE_INT);
23+
put("uid_ge", TYPE_INT);
24+
put("with_shared", TYPE_NONE);
25+
put("without_shared", TYPE_NONE);
26+
put("shared_uid_name", TYPE_STR_SINGLE);
27+
put("shared_uid_names", TYPE_STR_MULTIPLE);
28+
put("shared_uid_name_regex", TYPE_REGEX);
29+
}};
30+
31+
public UidOption() {
32+
super("uid");
33+
}
34+
35+
@NonNull
36+
@Override
37+
public Map<String, Integer> getKeysWithType() {
38+
return mKeysWithType;
39+
}
40+
41+
@NonNull
42+
@Override
43+
public TestResult test(@NonNull IFilterableAppInfo info, @NonNull TestResult result) {
44+
switch (key) {
45+
case KEY_ALL:
46+
return result.setMatched(false);
47+
case "uid_eq":
48+
return result.setMatched(info.getUid() == intValue);
49+
case "uid_le":
50+
return result.setMatched(info.getUid() <= intValue);
51+
case "uid_ge":
52+
return result.setMatched(info.getUid() >= intValue);
53+
case "with_shared":
54+
return result.setMatched(info.getSharedUserId() != null);
55+
case "without_shared":
56+
return result.setMatched(info.getSharedUserId() == null);
57+
case "shared_uid_name":
58+
return result.setMatched(Objects.equals(info.getSharedUserId(), value));
59+
case "shared_uid_names":
60+
return result.setMatched(ArrayUtils.contains(stringValues, info.getSharedUserId()));
61+
case "shared_uid_name_regex":
62+
return result.setMatched(regexValue.matcher(info.getSharedUserId()).matches());
63+
default:
64+
throw new UnsupportedOperationException("Invalid key " + key);
65+
}
66+
}
67+
68+
@NonNull
69+
@Override
70+
public CharSequence toLocalizedString(@NonNull Context context) {
71+
SpannableStringBuilder sb = new SpannableStringBuilder("UID");
72+
switch (key) {
73+
case KEY_ALL:
74+
return sb.append(LangUtils.getSeparatorString()).append("any");
75+
case "uid_eq":
76+
return sb.append(" = ").append(Integer.toString(intValue));
77+
case "uid_le":
78+
return sb.append(" ≤ ").append(Integer.toString(intValue));
79+
case "uid_ge":
80+
return sb.append(" ≥ ").append(Integer.toString(intValue));
81+
case "with_shared":
82+
return "Only the apps with a shared UID";
83+
case "without_shared":
84+
return "Only the apps without a shared UID";
85+
case "shared_uid_name":
86+
return "Only the apps with the shared UID " + value;
87+
case "shared_uid_names":
88+
return "Only the apps with the shared UID (exclusive) " + String.join(", ", stringValues);
89+
case "shared_uid_name_regex":
90+
return "Only the apps with the shared UID that matches '" + value + "'";
91+
default:
92+
throw new UnsupportedOperationException("Invalid key " + key);
93+
}
94+
}
95+
}

app/src/main/java/io/github/muntashirakon/AppManager/main/ApplicationItem.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ public int getUserId() {
360360
return -1;
361361
}
362362

363+
@Override
364+
public int getUid() {
365+
int uid = mApplicationInfo != null ? mApplicationInfo.uid : this.uid;
366+
return UserHandleHidden.getAppId(uid);
367+
}
368+
363369
public void setPackageUsageInfo(@Nullable PackageUsageInfo packageUsageInfo) {
364370
mPackageUsageInfo = packageUsageInfo;
365371
}

app/src/main/res/values/arrays.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@
264264
<item>pkg_name</item>
265265
<item>running_apps</item>
266266
<item>screen_time</item>
267-
<item>shared_uid</item>
268267
<item>signature</item>
269268
<item>target_sdk</item>
270269
<item>times_opened</item>
271270
<item>total_size</item>
272271
<item>trackers</item>
272+
<item>uid</item>
273273
<item>version_name</item>
274274
</string-array>
275275
<string name="usage_daily">Daily</string>

0 commit comments

Comments
 (0)