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();
|
|
|
|
// if Orbot is installed, then default to using Tor, the user can still override
|
|
|
|
if (OrbotHelper.requestStartTor(this)) {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
configureTor(prefs.getBoolean(getString(R.string.useTor), true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-01 22:16:41 +01:00
|
|
|
}
|