Skip to content

Commit bc6885e

Browse files
committed
Update binary will make sure startup leak scripts as well
1 parent 6b4e00b commit bc6885e

File tree

2 files changed

+85
-26
lines changed

2 files changed

+85
-26
lines changed

aFWall/proguard-rules.pro

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# @com.squareup.otto.Produce public *;
1919
#}
2020

21+
-dontnote org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
22+
-dontwarn org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
2123

2224
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
2325

@@ -32,4 +34,6 @@
3234

3335
-keep public class * extends android.support.v4.view.ActionProvider {
3436
public <init>(android.content.Context);
35-
}
37+
}
38+
39+
-optimizations !code/allocation/variable

aFWall/src/main/java/dev/ukanth/ufirewall/Api.java

+80-25
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public static String getSpecialDescription(Context ctx, String acct) {
264264
}
265265

266266
public static String getSpecialDescriptionSystem(Context ctx, String packageName) {
267-
switch (packageName){
267+
switch (packageName) {
268268
case "any":
269269
return ctx.getString(R.string.all_item);
270270
case "kernel":
@@ -1431,12 +1431,12 @@ public static List<PackageInfoData> getApps(Context ctx, GetAppList appList) {
14311431
if (G.enableLAN() && !app.selected_lan && Collections.binarySearch(selected_lan, app.uid) >= 0) {
14321432
app.selected_lan = true;
14331433
}
1434-
if(G.supportDual()) {
1435-
checkPartOfMultiUser(apinfo, name, uid, pkgmanager,multiUserAppsMap);
1434+
if (G.supportDual()) {
1435+
checkPartOfMultiUser(apinfo, name, uid, pkgmanager, multiUserAppsMap);
14361436
}
14371437
}
14381438

1439-
if(G.supportDual()) {
1439+
if (G.supportDual()) {
14401440
//run through multi user map
14411441
for (int i = 0; i < multiUserAppsMap.size(); i++) {
14421442
app = multiUserAppsMap.valueAt(i);
@@ -1512,7 +1512,7 @@ public static List<PackageInfoData> getSpecialData(boolean additional) {
15121512
specialData.add(new PackageInfoData(SPECIAL_UID_KERNEL, ctx.getString(R.string.kernel_item), "dev.afwall.special.kernel"));
15131513
specialData.add(new PackageInfoData(SPECIAL_UID_TETHER, ctx.getString(R.string.tethering_item), "dev.afwall.special.tether"));
15141514
specialData.add(new PackageInfoData(SPECIAL_UID_NTP, ctx.getString(R.string.ntp_item), "dev.afwall.special.ntp"));
1515-
if(additional) {
1515+
if (additional) {
15161516
specialData.add(new PackageInfoData(1020, "mDNS", "dev.afwall.special.mDNS"));
15171517
}
15181518
for (String acct : specialAndroidAccounts) {
@@ -1760,22 +1760,66 @@ private static boolean installBinary(Context ctx, int resId, String filename) {
17601760
}
17611761
}
17621762

1763-
/*private static boolean migrateSettings(Context ctx, int lastVer, int currentVer) {
1764-
if (lastVer <= 138) {
1765-
// migrate busybox/iptables path settings from <= 1.2.7-BETA
1766-
if (G.bb_path().equals("1")) {
1767-
G.bb_path("system");
1768-
} else if (G.bb_path().equals("2")) {
1769-
G.bb_path("builtin");
1770-
}
1771-
if (G.ip_path().equals("1")) {
1772-
G.ip_path("system");
1773-
} else if (G.ip_path().equals("2")) {
1774-
G.ip_path("auto");
1775-
}
1763+
private static void deleteStartFixFiles(final Context ctx) {
1764+
String path = G.initPath();
1765+
File f = new File(path);
1766+
final String initScript = "afwallstart";
1767+
if (f.exists() && f.isDirectory()) {
1768+
final String filePath = path + "/" + initScript;
1769+
new AsyncTask<Void, Void, Void>() {
1770+
@Override
1771+
public Void doInBackground(Void... args) {
1772+
if (mountDir(ctx, getFixLeakPath(initScript), "RW")) {
1773+
new RootCommand()
1774+
.setReopenShell(true).setCallback(new RootCommand.Callback() {
1775+
@Override
1776+
public void cbFunc(RootCommand state) {
1777+
if (state.exitCode == 0) {
1778+
sendToastBroadcast(ctx, ctx.getString(R.string.remove_initd));
1779+
} else {
1780+
sendToastBroadcast(ctx, ctx.getString(R.string.delete_initd_error));
1781+
}
1782+
}
1783+
}).setLogging(true).run(ctx, "rm -f " + filePath);
1784+
mountDir(ctx, getFixLeakPath(initScript), "RO");
1785+
} else {
1786+
Api.sendToastBroadcast(ctx, ctx.getString(R.string.mount_initd_error));
1787+
}
1788+
return null;
1789+
}
1790+
}.execute();
17761791
}
1777-
return true;
1778-
}*/
1792+
}
1793+
1794+
private static void updateFixLeakScript(Context ctx) {
1795+
final String initScript = "afwallstart";
1796+
final String srcPath = new File(ctx.getDir("bin", 0), initScript)
1797+
.getAbsolutePath();
1798+
1799+
new AsyncTask<Void, Void, Void>() {
1800+
@Override
1801+
public Void doInBackground(Void... args) {
1802+
String path = G.initPath();
1803+
if (path != null) {
1804+
File f = new File(path);
1805+
if (mountDir(ctx, getFixLeakPath(initScript), "RW")) {
1806+
//make sure it's executable
1807+
new RootCommand()
1808+
.setReopenShell(true)
1809+
.run(ctx, "chmod 755 " + f.getAbsolutePath());
1810+
if (RootTools.copyFile(srcPath, (f.getAbsolutePath() + "/" + initScript),
1811+
true, false)) {
1812+
Api.sendToastBroadcast(ctx, ctx.getString(R.string.success_initd));
1813+
}
1814+
mountDir(ctx, getFixLeakPath(initScript), "RO");
1815+
} else {
1816+
Api.sendToastBroadcast(ctx, ctx.getString(R.string.mount_initd_error));
1817+
}
1818+
}
1819+
return null;
1820+
}
1821+
}.execute();
1822+
}
17791823

17801824
/**
17811825
* Asserts that the binary files are installed in the cache directory.
@@ -1832,6 +1876,7 @@ public static boolean assertBinaries(Context ctx, boolean showErrors) {
18321876
ret &= installBinary(ctx, R.raw.afwallstart, "afwallstart");
18331877
//Log.d(TAG, "binary installation for " + abi + (ret ? " succeeded" : " failed"));
18341878

1879+
18351880
if (showErrors) {
18361881
if (ret) {
18371882
toast(ctx, ctx.getString(R.string.toast_bin_installed));
@@ -1851,6 +1896,17 @@ public static boolean assertBinaries(Context ctx, boolean showErrors) {
18511896
G.appVersion(currentVer);
18521897
}
18531898

1899+
//make sure we update afwall script as well
1900+
if (!G.initPath().isEmpty() && G.fixLeak()) {
1901+
try {
1902+
deleteStartFixFiles(ctx);
1903+
updateFixLeakScript(ctx);
1904+
}catch (Exception e) {
1905+
1906+
}
1907+
}
1908+
1909+
18541910
return ret;
18551911
}
18561912

@@ -2955,11 +3011,10 @@ private static void initSpecial() {
29553011
}
29563012

29573013

2958-
29593014
public static void updateLanguage(Context context, String lang) {
2960-
if(lang.equals("sys")){
2961-
Locale defaultLocale = Resources.getSystem().getConfiguration().locale;
2962-
Locale.setDefault(defaultLocale);
3015+
if (lang.equals("sys")) {
3016+
Locale defaultLocale = Resources.getSystem().getConfiguration().locale;
3017+
Locale.setDefault(defaultLocale);
29633018
Resources res = context.getResources();
29643019
Configuration conf = res.getConfiguration();
29653020
conf.locale = defaultLocale;
@@ -3330,7 +3385,7 @@ public static boolean isFixPathFileExist(String fileName) {
33303385
public static boolean mountDir(Context context, String path, String mountType) {
33313386
if (path != null) {
33323387
String busyboxPath = Api.getBusyBoxPath(context, false);
3333-
if(busyboxPath != null && !busyboxPath.trim().isEmpty()) {
3388+
if (busyboxPath != null && !busyboxPath.trim().isEmpty()) {
33343389
return RootTools.remount(path, mountType, busyboxPath);
33353390
} else {
33363391
return false;

0 commit comments

Comments
 (0)