2016-01-01 22:16:41 +01:00
|
|
|
package org.schabi.newpipe;
|
|
|
|
|
|
|
|
import android.app.Application;
|
2016-01-01 23:04:29 +01:00
|
|
|
import android.content.Context;
|
2016-01-01 22:16:41 +01:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import info.guardianproject.netcipher.NetCipher;
|
|
|
|
import info.guardianproject.netcipher.proxy.OrbotHelper;
|
|
|
|
|
|
|
|
public class App extends Application {
|
|
|
|
|
2016-01-01 23:04:29 +01:00
|
|
|
private static boolean useTor;
|
|
|
|
|
2016-01-01 22:16:41 +01:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2016-01-04 00:10:51 +01:00
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
if(prefs.getBoolean(getString(R.string.useTorKey), false)) {
|
|
|
|
OrbotHelper.requestStartTor(this);
|
|
|
|
configureTor(true);
|
|
|
|
} else {
|
|
|
|
configureTor(false);
|
2016-01-01 22:16:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the proxy settings based on whether Tor should be enabled or not.
|
|
|
|
*/
|
2016-01-01 23:04:29 +01:00
|
|
|
static void configureTor(boolean enabled) {
|
|
|
|
useTor = enabled;
|
2016-01-01 22:16:41 +01:00
|
|
|
if (useTor) {
|
|
|
|
NetCipher.useTor();
|
|
|
|
} else {
|
|
|
|
NetCipher.setProxy(null);
|
|
|
|
}
|
|
|
|
}
|
2016-01-01 23:04:29 +01:00
|
|
|
|
|
|
|
static void checkStartTor(Context context) {
|
|
|
|
if (useTor) {
|
|
|
|
OrbotHelper.requestStartTor(context);
|
|
|
|
}
|
|
|
|
}
|
2016-01-02 22:47:21 +01:00
|
|
|
|
|
|
|
static boolean isUsingTor() {
|
|
|
|
return useTor;
|
|
|
|
}
|
2016-01-01 22:16:41 +01:00
|
|
|
}
|