Skip to content

Commit

Permalink
move getSharedPrefs() from TorServiceUtils to Prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
eighthave committed Oct 28, 2019
1 parent 6bf442e commit 22bf175
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 22 deletions.
Expand Up @@ -61,7 +61,6 @@
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.service.vpn.TorifiedApp;
import org.torproject.android.service.vpn.VpnConstants;
import org.torproject.android.service.vpn.VpnPrefs;
Expand Down Expand Up @@ -124,7 +123,7 @@ public class MiniMainActivity extends AppCompatActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
mPrefs = Prefs.getSharedPrefs(getApplicationContext());

/* Create the widgets before registering for broadcasts to guarantee
* that the widgets exist when the status updates try to update them */
Expand Down
Expand Up @@ -13,7 +13,7 @@
import android.widget.Switch;
import org.torproject.android.mini.R;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.vpn.TorifiedApp;

import static org.torproject.android.mini.MiniMainActivity.getApp;
Expand All @@ -40,7 +40,7 @@ protected void onCreate(Bundle savedInstanceState) {

final String pkgId = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);

mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
mPrefs = Prefs.getSharedPrefs(getApplicationContext());

ApplicationInfo aInfo = null;
try {
Expand Down
Expand Up @@ -28,7 +28,7 @@
import android.widget.TextView;
import org.torproject.android.mini.R;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.vpn.TorifiedApp;

import java.util.ArrayList;
Expand Down Expand Up @@ -63,7 +63,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onResume() {
super.onResume();
mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
mPrefs = Prefs.getSharedPrefs(getApplicationContext());
reloadApps();
}

Expand Down
Expand Up @@ -57,7 +57,6 @@
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.service.vpn.VpnConstants;
import org.torproject.android.service.vpn.VpnPrefs;
import org.torproject.android.settings.Languages;
Expand Down Expand Up @@ -167,7 +166,7 @@ private void migratePreferences() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
mPrefs = Prefs.getSharedPrefs(getApplicationContext());

migratePreferences(); // Migrate old preferences

Expand Down
Expand Up @@ -29,7 +29,7 @@
import android.widget.TextView;
import org.torproject.android.R;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.vpn.TorifiedApp;

import java.util.ArrayList;
Expand Down Expand Up @@ -65,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onResume() {
super.onResume();
mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
mPrefs = Prefs.getSharedPrefs(getApplicationContext());
reloadApps();
}

Expand Down
Expand Up @@ -610,7 +610,7 @@ public void startTransportSync(TransportListener transportListener) {

private boolean torUpgradeAndConfig() throws IOException, TimeoutException {

SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());
String version = prefs.getString(PREF_BINARY_TOR_VERSION_INSTALLED,null);

logNotice("checking binary version: " + version);
Expand Down Expand Up @@ -638,7 +638,7 @@ private boolean torUpgradeAndConfig() throws IOException, TimeoutException {

private File updateTorrcCustomFile () throws IOException, TimeoutException
{
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());

StringBuffer extraLines = new StringBuffer();

Expand Down Expand Up @@ -838,7 +838,7 @@ private void startTor() {
// make sure there are no stray daemons running
killAllDaemons();

SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());
String version = prefs.getString(PREF_BINARY_TOR_VERSION_INSTALLED,null);
logNotice("checking binary version: " + version);

Expand Down Expand Up @@ -1152,7 +1152,7 @@ private int getControlPort ()
bufferedReader.close();

//store last valid control port
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());
prefs.edit().putInt("controlport", result).commit();

}
Expand Down Expand Up @@ -1471,7 +1471,7 @@ public void onReceive(Context context, Intent intent) {
if (mCurrentStatus == STATUS_OFF)
return;

SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());

boolean doNetworKSleep = prefs.getBoolean(OrbotConstants.PREF_DISABLE_NETWORK, true);

Expand Down Expand Up @@ -1530,7 +1530,7 @@ private StringBuffer processSettingsImpl (StringBuffer extraLines) throws IOExce
{
logNotice(getString(R.string.updating_settings_in_tor_service));

SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());

boolean useBridges = Prefs.bridgesEnabled();

Expand Down Expand Up @@ -1897,7 +1897,7 @@ private void handleIntent( Intent intent ) {

private void setExitNode (String newExits)
{
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());

if (TextUtils.isEmpty(newExits))
{
Expand Down
Expand Up @@ -3,6 +3,7 @@

import android.content.Context;
import android.content.SharedPreferences;
import org.torproject.android.service.OrbotConstants;

import java.util.Locale;

Expand All @@ -24,7 +25,7 @@ public class Prefs {

public static void setContext(Context context) {
if (prefs == null)
prefs = TorServiceUtils.getSharedPrefs(context);
prefs = getSharedPrefs(context);
}

private static void putBoolean(String key, boolean value) {
Expand Down Expand Up @@ -109,4 +110,8 @@ 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);
}
}
Expand Up @@ -13,10 +13,6 @@

public class TorServiceUtils implements TorServiceConstants {

public static SharedPreferences getSharedPrefs (Context context) {
return context.getSharedPreferences(OrbotConstants.PREF_TOR_SHARED_PREFS,0 | Context.MODE_MULTI_PROCESS);
}

public static boolean isPortOpen(final String ip, final int port, final int timeout) {
try {
Socket socket = new Socket();
Expand Down

0 comments on commit 22bf175

Please sign in to comment.