Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When exporting rules, only export the types of rules that were actual… #1401

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions app/src/main/java/dev/ukanth/ufirewall/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,10 @@ public static void exportAllPreferencesToFileConfirm(final Context ctx) {
}
}

private static void updateExportPackage(Map<String, JSONObject> exportMap, String packageName, int identifier) throws JSONException {
private static void updateExportPackage(Map<String, JSONObject> exportMap, String packageName, boolean isChecked, int identifier) throws JSONException {
if (!isChecked) {
return;
}
JSONObject obj;
if (packageName != null) {
if (exportMap.containsKey(packageName)) {
Expand All @@ -2344,16 +2347,15 @@ private static void updateExportPackage(Map<String, JSONObject> exportMap, Strin
exportMap.put(packageName, obj);
}
}

}

private static void updatePackage(Context ctx, String savedPkg_uid, Map<String, JSONObject> exportMap, int identifier) throws JSONException {
StringTokenizer tok = new StringTokenizer(savedPkg_uid, "|");
while (tok.hasMoreTokens()) {
String uid = tok.nextToken();
if (!uid.equals("")) {
if (!uid.isEmpty()) {
String packageName = ctx.getPackageManager().getNameForUid(Integer.parseInt(uid));
updateExportPackage(exportMap, packageName, identifier);
updateExportPackage(exportMap, packageName, /*is_checked=*/ true, identifier);
}
}
}
Expand All @@ -2364,16 +2366,13 @@ private static Map<String, JSONObject> getCurrentRulesAsMap(Context ctx) {

try {
for (PackageInfoData app : apps) {
if (app.selected_wifi || app.selected_3g || app.selected_roam || app.selected_vpn ||
app.selected_tether || app.selected_lan || app.selected_tor) {
updateExportPackage(exportMap, app.pkgName, WIFI_EXPORT);
updateExportPackage(exportMap, app.pkgName, DATA_EXPORT);
updateExportPackage(exportMap, app.pkgName, ROAM_EXPORT);
updateExportPackage(exportMap, app.pkgName, VPN_EXPORT);
updateExportPackage(exportMap, app.pkgName, TETHER_EXPORT);
updateExportPackage(exportMap, app.pkgName, LAN_EXPORT);
updateExportPackage(exportMap, app.pkgName, TOR_EXPORT);
}
updateExportPackage(exportMap, app.pkgName, app.selected_wifi, WIFI_EXPORT);
updateExportPackage(exportMap, app.pkgName, app.selected_3g, DATA_EXPORT);
updateExportPackage(exportMap, app.pkgName, app.selected_roam, ROAM_EXPORT);
updateExportPackage(exportMap, app.pkgName, app.selected_vpn, VPN_EXPORT);
updateExportPackage(exportMap, app.pkgName, app.selected_tether, TETHER_EXPORT);
updateExportPackage(exportMap, app.pkgName, app.selected_lan, LAN_EXPORT);
updateExportPackage(exportMap, app.pkgName, app.selected_tor, TOR_EXPORT);
}
} catch (JSONException e) {
Log.e(TAG, e.getLocalizedMessage());
Expand Down
Loading