replace prone useTor preference mirror value from FDroidApp with direct preference calls
This commit is contained in:
parent
1f565d7638
commit
292950898e
@ -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.
|
* Set the proxy settings based on whether Tor should be enabled or not.
|
||||||
*/
|
*/
|
||||||
private static void configureTor(boolean enabled) {
|
private static void configureTor(boolean enabled) {
|
||||||
useTor = enabled;
|
if (enabled) {
|
||||||
if (useTor) {
|
|
||||||
NetCipher.useTor();
|
NetCipher.useTor();
|
||||||
} else {
|
} else {
|
||||||
NetCipher.clearProxy();
|
NetCipher.clearProxy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkStartTor(Context context) {
|
public static void checkStartTor(Context context, Preferences preferences) {
|
||||||
if (useTor) {
|
if (preferences.isTorEnabled()) {
|
||||||
OrbotHelper.requestStartTor(context);
|
OrbotHelper.requestStartTor(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUsingTor() {
|
|
||||||
return useTor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Context getInstance() {
|
public static Context getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import android.database.Cursor;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.data.Schema.RepoTable.Cols;
|
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.
|
* Get the number of available mirrors, including the canonical repo.
|
||||||
*/
|
*/
|
||||||
public int getMirrorCount() {
|
public int getMirrorCount() {
|
||||||
|
|
||||||
|
final boolean isTorEnabled = Preferences.get().isTorEnabled();
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (String m : getMirrorList()) {
|
for (String m : getMirrorList()) {
|
||||||
if (FDroidApp.isUsingTor()) {
|
if (isTorEnabled) {
|
||||||
count++;
|
count++;
|
||||||
} else if (!m.contains(".onion")) {
|
} else if (!m.contains(".onion")) {
|
||||||
count++;
|
count++;
|
||||||
@ -430,11 +434,14 @@ public class Repo extends ValueObject {
|
|||||||
}
|
}
|
||||||
List<String> shuffledMirrors = getMirrorList();
|
List<String> shuffledMirrors = getMirrorList();
|
||||||
if (shuffledMirrors.size() > 0) {
|
if (shuffledMirrors.size() > 0) {
|
||||||
|
|
||||||
|
final boolean isTorEnabled = Preferences.get().isTorEnabled();
|
||||||
|
|
||||||
Collections.shuffle(shuffledMirrors);
|
Collections.shuffle(shuffledMirrors);
|
||||||
for (String m : shuffledMirrors) {
|
for (String m : shuffledMirrors) {
|
||||||
// Return a non default, and not last used mirror
|
// Return a non default, and not last used mirror
|
||||||
if (!m.equals(mirrorToSkip)) {
|
if (!m.equals(mirrorToSkip)) {
|
||||||
if (FDroidApp.isUsingTor()) {
|
if (isTorEnabled) {
|
||||||
return m;
|
return m;
|
||||||
} else {
|
} else {
|
||||||
// Filter-out onion mirrors for non-tor connections
|
// Filter-out onion mirrors for non-tor connections
|
||||||
|
@ -60,6 +60,7 @@ import android.widget.Toast;
|
|||||||
import org.fdroid.fdroid.AddRepoIntentService;
|
import org.fdroid.fdroid.AddRepoIntentService;
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.IndexUpdater;
|
import org.fdroid.fdroid.IndexUpdater;
|
||||||
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.UpdateService;
|
import org.fdroid.fdroid.UpdateService;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
@ -128,7 +129,7 @@ public class ManageReposActivity extends AppCompatActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
FDroidApp.checkStartTor(this);
|
FDroidApp.checkStartTor(this, Preferences.get());
|
||||||
|
|
||||||
/* let's see if someone is trying to send us a new repo */
|
/* let's see if someone is trying to send us a new repo */
|
||||||
addRepoFromIntent(getIntent());
|
addRepoFromIntent(getIntent());
|
||||||
|
@ -209,7 +209,7 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
FDroidApp.checkStartTor(this);
|
FDroidApp.checkStartTor(this, Preferences.get());
|
||||||
|
|
||||||
if (getIntent().hasExtra(EXTRA_VIEW_UPDATES)) {
|
if (getIntent().hasExtra(EXTRA_VIEW_UPDATES)) {
|
||||||
getIntent().removeExtra(EXTRA_VIEW_UPDATES);
|
getIntent().removeExtra(EXTRA_VIEW_UPDATES);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user