Skip to content

Commit

Permalink
feat(split tunneling): update SplitTunnelingViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Nov 30, 2023
1 parent b2fc090 commit daa3b81
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ public void onItemsSelectionStateChanged(boolean isAllItemSelected) {
this.adapter.set(adapter);
this.menuHandler = adapter.getMenuHandler();
this.preference = preference;

disallowedApps.clear();
disallowedApps.addAll(getDisallowedPackages());

reloadDisallowedApps();
isAllItemsAllowed.set(disallowedApps.size() == 0);
}

Expand All @@ -92,11 +89,19 @@ public void getApplicationsList(PackageManager packageManager) {
public void selectAll() {
allowAllPackages();
menuHandler.selectAll();
reloadDisallowedApps();
}

public void deselectAll() {
disallowAllApps(new HashSet<>(apps));
disallowAllApps(new HashSet<>(systemApps));
menuHandler.deselectAll();
reloadDisallowedApps();
}

private void reloadDisallowedApps() {
disallowedApps.clear();
disallowedApps.addAll(getDisallowedPackages());
}

private void toggleSystemApps(Boolean value) {
Expand Down Expand Up @@ -159,16 +164,16 @@ protected List<ApplicationItem> doInBackground(Void... voids) {
Set<String> systemPackageNames = new HashSet<>();
for (ApplicationInfo info : applicationInfoList) {
try {
if (null != packageManager.getLaunchIntentForPackage(info.packageName) ||
null != packageManager.getLeanbackLaunchIntentForPackage(info.packageName) ||
null != packageManager.getInstallerPackageName(info.packageName)
) {
if (packageNames.add(info.loadLabel(packageManager).toString())) {
items.add(new ApplicationItem(info.loadLabel(packageManager).toString(), info.packageName,
info.loadIcon(packageManager)));
}
}
if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.INTERNET, info.packageName)) {
if (null != packageManager.getLaunchIntentForPackage(info.packageName) ||
null != packageManager.getLeanbackLaunchIntentForPackage(info.packageName) ||
null != packageManager.getInstallerPackageName(info.packageName)
) {
if (packageNames.add(info.loadLabel(packageManager).toString())) {
items.add(new ApplicationItem(info.loadLabel(packageManager).toString(), info.packageName,
info.loadIcon(packageManager)));
}
}
if (systemPackageNames.add(info.loadLabel(packageManager).toString())) {
systemItems.add(new ApplicationItem(info.loadLabel(packageManager).toString(), info.packageName,
info.loadIcon(packageManager)));
Expand Down

0 comments on commit daa3b81

Please sign in to comment.