From 239c924b601febeb90fdfa595b412abddd35a720 Mon Sep 17 00:00:00 2001 From: Konstantin Svist Date: Fri, 1 Nov 2024 14:59:41 -0700 Subject: [PATCH 1/2] When exporting rules, only export the types of rules that were actually enabled Should fix #1399 --- .../main/java/dev/ukanth/ufirewall/Api.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/dev/ukanth/ufirewall/Api.java b/app/src/main/java/dev/ukanth/ufirewall/Api.java index 52213862..a12ee09c 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/Api.java +++ b/app/src/main/java/dev/ukanth/ufirewall/Api.java @@ -2332,7 +2332,10 @@ public static void exportAllPreferencesToFileConfirm(final Context ctx) { } } - private static void updateExportPackage(Map exportMap, String packageName, int identifier) throws JSONException { + private static void updateExportPackage(Map exportMap, String packageName, boolean isCheckded, int identifier) throws JSONException { + if (!isCheckded) { + return; + } JSONObject obj; if (packageName != null) { if (exportMap.containsKey(packageName)) { @@ -2344,16 +2347,15 @@ private static void updateExportPackage(Map exportMap, Strin exportMap.put(packageName, obj); } } - } private static void updatePackage(Context ctx, String savedPkg_uid, Map 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, true, identifier); } } } @@ -2364,16 +2366,13 @@ private static Map 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()); From e758974628627d220b6d14361d3f499d24a317f7 Mon Sep 17 00:00:00 2001 From: Konstantin Svist Date: Fri, 1 Nov 2024 19:46:58 -0700 Subject: [PATCH 2/2] fix spelling --- app/src/main/java/dev/ukanth/ufirewall/Api.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/dev/ukanth/ufirewall/Api.java b/app/src/main/java/dev/ukanth/ufirewall/Api.java index a12ee09c..be0cd31b 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/Api.java +++ b/app/src/main/java/dev/ukanth/ufirewall/Api.java @@ -2332,8 +2332,8 @@ public static void exportAllPreferencesToFileConfirm(final Context ctx) { } } - private static void updateExportPackage(Map exportMap, String packageName, boolean isCheckded, int identifier) throws JSONException { - if (!isCheckded) { + private static void updateExportPackage(Map exportMap, String packageName, boolean isChecked, int identifier) throws JSONException { + if (!isChecked) { return; } JSONObject obj; @@ -2355,7 +2355,7 @@ private static void updatePackage(Context ctx, String savedPkg_uid, Map