setup Tor at app start, and config immediately when pref is changed
This adds an Application subclass to get the onCreate() method, which is called once at the first start up of the app, before any Activity starts. Tor is configured there to ensure it is setup before anything happens. This also moves the "Use Tor" pref listener to a more appropriate place.
This commit is contained in:
parent
6bd2468d44
commit
d3879a0398
6 changed files with 54 additions and 29 deletions
32
app/src/main/java/org/schabi/newpipe/App.java
Normal file
32
app/src/main/java/org/schabi/newpipe/App.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package org.schabi.newpipe;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import info.guardianproject.netcipher.NetCipher;
|
||||
import info.guardianproject.netcipher.proxy.OrbotHelper;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
@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.
|
||||
*/
|
||||
static void configureTor(boolean useTor) {
|
||||
if (useTor) {
|
||||
NetCipher.useTor();
|
||||
} else {
|
||||
NetCipher.setProxy(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue