Skip to content

Commit

Permalink
Merge pull request #1401 from Fry-kun/export-fix
Browse files Browse the repository at this point in the history
When exporting rules, only export the types of rules that were actual…
  • Loading branch information
ukanth authored Nov 2, 2024
2 parents ba86d7f + e758974 commit a1fe38b
Showing 1 changed file with 13 additions and 14 deletions.
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

0 comments on commit a1fe38b

Please sign in to comment.