replace prone useTor preference mirror value from FDroidApp with direct preference calls

This commit is contained in:
Michael Pöhn 2019-04-01 22:41:44 +02:00
parent 1f565d7638
commit 292950898e
4 changed files with 15 additions and 14 deletions

View File

@ -640,30 +640,23 @@ public class FDroidApp extends Application {
}
}
private static boolean useTor;
/**
* Set the proxy settings based on whether Tor should be enabled or not.
*/
private static void configureTor(boolean enabled) {
useTor = enabled;
if (useTor) {
if (enabled) {
NetCipher.useTor();
} else {
NetCipher.clearProxy();
}
}
public static void checkStartTor(Context context) {
if (useTor) {
public static void checkStartTor(Context context, Preferences preferences) {
if (preferences.isTorEnabled()) {
OrbotHelper.requestStartTor(context);
}
}
public static boolean isUsingTor() {
return useTor;
}
public static Context getInstance() {
return instance;
}

View File

@ -28,6 +28,7 @@ import android.database.Cursor;
import android.text.TextUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Schema.RepoTable.Cols;
@ -390,9 +391,12 @@ public class Repo extends ValueObject {
* Get the number of available mirrors, including the canonical repo.
*/
public int getMirrorCount() {
final boolean isTorEnabled = Preferences.get().isTorEnabled();
int count = 0;
for (String m : getMirrorList()) {
if (FDroidApp.isUsingTor()) {
if (isTorEnabled) {
count++;
} else if (!m.contains(".onion")) {
count++;
@ -430,11 +434,14 @@ public class Repo extends ValueObject {
}
List<String> shuffledMirrors = getMirrorList();
if (shuffledMirrors.size() > 0) {
final boolean isTorEnabled = Preferences.get().isTorEnabled();
Collections.shuffle(shuffledMirrors);
for (String m : shuffledMirrors) {
// Return a non default, and not last used mirror
if (!m.equals(mirrorToSkip)) {
if (FDroidApp.isUsingTor()) {
if (isTorEnabled) {
return m;
} else {
// Filter-out onion mirrors for non-tor connections

View File

@ -60,6 +60,7 @@ import android.widget.Toast;
import org.fdroid.fdroid.AddRepoIntentService;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.IndexUpdater;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils;
@ -128,7 +129,7 @@ public class ManageReposActivity extends AppCompatActivity
@Override
protected void onResume() {
super.onResume();
FDroidApp.checkStartTor(this);
FDroidApp.checkStartTor(this, Preferences.get());
/* let's see if someone is trying to send us a new repo */
addRepoFromIntent(getIntent());

View File

@ -209,7 +209,7 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
protected void onResume() {
super.onResume();
FDroidApp.checkStartTor(this);
FDroidApp.checkStartTor(this, Preferences.get());
if (getIntent().hasExtra(EXTRA_VIEW_UPDATES)) {
getIntent().removeExtra(EXTRA_VIEW_UPDATES);