Test tor code

This commit is contained in:
GDR! 2015-12-24 14:55:33 +01:00 committed by Hans-Christoph Steiner
parent eeb612f9a2
commit ef255d12ae
5 changed files with 44 additions and 4 deletions

View File

@ -17,7 +17,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
@ -35,4 +35,5 @@ dependencies {
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'org.jsoup:jsoup:1.8.3'
compile 'org.mozilla:rhino:1.7.7'
compile 'info.guardianproject.netcipher:netcipher:1.2'
}

View File

@ -7,6 +7,8 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;
import info.guardianproject.netcipher.NetCipher;
/**
* Created by Christian Schabesberger on 14.08.15.
*
@ -37,10 +39,11 @@ public class Downloader {
* @param language the language (usually a 2-character code) to set as the preferred language
* @return the contents of the specified text file*/
public static String download(String siteUrl, String language) {
NetCipher.useTor();
String ret = "";
try {
URL url = new URL(siteUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
HttpURLConnection con = (HttpURLConnection) NetCipher.getHttpURLConnection(url);
con.setRequestProperty("Accept-Language", language);
ret = dl(con);
}
@ -81,10 +84,11 @@ public class Downloader {
* @return the contents of the specified text file*/
public static String download(String siteUrl) {
String ret = "";
NetCipher.useTor();
try {
URL url = new URL(siteUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
HttpURLConnection con = (HttpURLConnection) NetCipher.getHttpURLConnection(url);
ret = dl(con);
}
catch(Exception e) {

View File

@ -3,6 +3,7 @@ package org.schabi.newpipe;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.media.MediaPlayer;
@ -25,6 +26,7 @@ import android.widget.Button;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.VideoView;
import info.guardianproject.netcipher.NetCipher;
/**
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
@ -44,7 +46,7 @@ import android.widget.VideoView;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class PlayVideoActivity extends AppCompatActivity {
public class PlayVideoActivity extends AppCompatActivity implements OnSharedPreferenceChangeListener {
//// TODO: 11.09.15 add "choose stream" menu
@ -170,6 +172,9 @@ public class PlayVideoActivity extends AppCompatActivity {
if(prefs.getBoolean(PREF_IS_LANDSCAPE, false) && !isLandscape) {
toggleOrientation();
}
setTorPreference(prefs);
prefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
@ -187,6 +192,13 @@ public class PlayVideoActivity extends AppCompatActivity {
videoView.pause();
}
@Override
protected void onDestroy() {
super.onDestroy();
prefs = getPreferences(Context.MODE_PRIVATE);
prefs.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
@ -348,4 +360,20 @@ public class PlayVideoActivity extends AppCompatActivity {
editor.putBoolean(PREF_IS_LANDSCAPE, isLandscape);
editor.apply();
}
private void setTorPreference(SharedPreferences prefs) {
if(prefs.getBoolean(getString(R.string.useTor), false)) {
NetCipher.useTor();
} else {
NetCipher.setProxy(null);
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if(key.equals(getString(R.string.useTor))) {
setTorPreference(prefs);
}
}
}

View File

@ -63,4 +63,6 @@
<string name="detailUploaderThumbnailViewDescription">Uploader thumbnail</string>
<string name="detailThumbsDownImgViewDescription">Dislikes</string>
<string name="detailThumbsUpImgViewDescription">Likes</string>
<string name="useTor">Use Tor</string>
<string name="useTorTitle">Proxy connections via The Onion Router</string>
</resources>

View File

@ -72,5 +72,10 @@
android:summary="@string/autoPlayThroughIntentSummary"
android:defaultValue="false" />
<CheckBoxPreference
android:key="@string/useTor"
android:title="@string/useTorTitle"
android:defaultValue="false"/>
</PreferenceCategory>
</PreferenceScreen>