commit 2b7dd42d77588eb00632e3d0c72f6af7a3c6cb37 Author: bim dsnake@protonmail.com Date: Wed Sep 9 11:28:55 2020 -0400
VpnUtils.getSharedPrefs was an exact duplicate of Prefs.getSharedPrefs --- .../org/torproject/android/OrbotMainActivity.java | 3 +-- .../torproject/android/service/OrbotService.java | 17 ++++------------- .../org/torproject/android/service/util/Prefs.java | 21 ++++++++++----------- .../android/service/vpn/OrbotVpnManager.java | 5 +++-- .../torproject/android/service/vpn/VpnUtils.java | 11 +---------- 5 files changed, 19 insertions(+), 38 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index 47f725ec..11c5d408 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -61,7 +61,6 @@ import org.torproject.android.service.util.Prefs; import org.torproject.android.service.util.Utils; import org.torproject.android.service.vpn.VpnConstants; import org.torproject.android.service.vpn.VpnPrefs; -import org.torproject.android.service.vpn.VpnUtils; import org.torproject.android.settings.Languages; import org.torproject.android.settings.LocaleHelper; import org.torproject.android.settings.SettingsPreferences; @@ -202,7 +201,7 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan }
// Resets previous DNS Port to the default. - VpnUtils.getSharedPrefs(getApplicationContext()).edit().putInt(VpnPrefs.PREFS_DNS_PORT, + Prefs.getSharedPrefs(getApplicationContext()).edit().putInt(VpnPrefs.PREFS_DNS_PORT, VpnConstants.TOR_DNS_PORT_DEFAULT).apply();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java index a61828d5..e6d70ce5 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java @@ -7,7 +7,6 @@
package org.torproject.android.service;
- import android.annotation.SuppressLint; import android.app.Application; import android.app.Notification; @@ -28,7 +27,6 @@ import android.database.Cursor; import android.net.Uri; import android.net.VpnService; import android.os.Build; -import android.os.Environment; import android.os.Handler; import android.os.IBinder; import android.provider.BaseColumns; @@ -70,8 +68,6 @@ import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.net.Socket; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -85,10 +81,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeoutException;
-import static org.torproject.android.service.vpn.VpnUtils.getSharedPrefs; - -public class OrbotService extends VpnService implements TorServiceConstants, OrbotConstants -{ +public class OrbotService extends VpnService implements TorServiceConstants, OrbotConstants {
public final static String BINARY_TOR_VERSION = org.torproject.android.binary.TorServiceConstants.BINARY_TOR_VERSION; private String mCurrentStatus = STATUS_OFF; @@ -467,10 +460,8 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb super.onDestroy(); }
- private void stopTor () - { - new Thread(() -> stopTorAsync()).start(); - + private void stopTor() { + new Thread(this::stopTorAsync).start(); }
private void stopTorAsync () { @@ -1217,7 +1208,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb confDns = st.nextToken().split(":")[1]; confDns = confDns.substring(0, confDns.length() - 1); mPortDns = Integer.parseInt(confDns); - getSharedPrefs(getApplicationContext()).edit().putInt(VpnPrefs.PREFS_DNS_PORT, mPortDns).apply(); + Prefs.getSharedPrefs(getApplicationContext()).edit().putInt(VpnPrefs.PREFS_DNS_PORT, mPortDns).apply(); }
String confTrans = conn.getInfo("net/listeners/trans"); diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java b/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java index 9b6ab825..099e2677 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java +++ b/orbotservice/src/main/java/org/torproject/android/service/util/Prefs.java @@ -3,6 +3,7 @@ package org.torproject.android.service.util;
import android.content.Context; import android.content.SharedPreferences; + import org.torproject.android.service.OrbotConstants;
import java.util.Locale; @@ -20,7 +21,7 @@ public class Prefs { private final static String PREF_OPEN_PROXY_ON_ALL_INTERFACES = "pref_open_proxy_on_all_interfaces"; private final static String PREF_USE_VPN = "pref_vpn"; private final static String PREF_EXIT_NODES = "pref_exit_nodes"; - + private static SharedPreferences prefs;
public static void setContext(Context context) { @@ -100,18 +101,16 @@ public class Prefs { public static void putStartOnBoot(boolean value) { putBoolean(PREF_START_ON_BOOT, value); } - - public static String getExitNodes () - { - return prefs.getString(PREF_EXIT_NODES, ""); + + public static String getExitNodes() { + return prefs.getString(PREF_EXIT_NODES, ""); } - - public static void setExitNodes (String exits) - { - putString(PREF_EXIT_NODES,exits); + + public static void setExitNodes(String exits) { + putString(PREF_EXIT_NODES, exits); }
- public static SharedPreferences getSharedPrefs (Context context) { - return context.getSharedPreferences(OrbotConstants.PREF_TOR_SHARED_PREFS,0 | Context.MODE_MULTI_PROCESS); + public static SharedPreferences getSharedPrefs(Context context) { + return context.getSharedPreferences(OrbotConstants.PREF_TOR_SHARED_PREFS, Context.MODE_MULTI_PROCESS); } } diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java index 3dd315fd..ea27af99 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java +++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java @@ -39,6 +39,7 @@ import org.torproject.android.service.OrbotService; import org.torproject.android.service.R; import org.torproject.android.service.TorServiceConstants; import org.torproject.android.service.util.CustomNativeLoader; +import org.torproject.android.service.util.Prefs;
import java.io.BufferedReader; import java.io.File; @@ -77,7 +78,7 @@ public class OrbotVpnManager implements Handler.Callback {
private final static boolean mIsLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
- private File filePdnsd = null; + private File filePdnsd;
private final static String PDNSD_BIN = "pdnsd";
@@ -326,7 +327,7 @@ public class OrbotVpnManager implements Handler.Callback {
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void doLollipopAppRouting (VpnService.Builder builder) throws NameNotFoundException { - SharedPreferences prefs = VpnUtils.getSharedPrefs(mService.getApplicationContext()); + SharedPreferences prefs = Prefs.getSharedPrefs(mService.getApplicationContext()); ArrayList<TorifiedApp> apps = TorifiedApp.getApps(mService, prefs);
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/VpnUtils.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/VpnUtils.java index 68841fda..e1cdd375 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/vpn/VpnUtils.java +++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/VpnUtils.java @@ -1,7 +1,5 @@ package org.torproject.android.service.vpn;
-import android.content.Context; -import android.content.SharedPreferences; import android.util.Log;
import org.apache.commons.io.IOUtils; @@ -13,16 +11,9 @@ import java.io.InputStreamReader; import java.util.List;
import static java.lang.Runtime.getRuntime; -import static org.torproject.android.service.vpn.VpnPrefs.PREF_TOR_SHARED_PREFS;
public class VpnUtils {
- public static SharedPreferences getSharedPrefs(Context context) { - return context.getSharedPreferences(PREF_TOR_SHARED_PREFS, - Context.MODE_MULTI_PROCESS); - } - - public static int findProcessId(String command) throws IOException {
String[] cmds = {"ps -ef","ps -A","toolbox ps"}; @@ -73,7 +64,7 @@ public class VpnUtils {
for (int i = 0; i < cmds.length; i++) {
- Process proc = null; + Process proc;
try { proc = getRuntime().exec(cmds[i] + "killall " + signal + " " + fileProcBin.getName
tor-commits@lists.torproject.org